
function OpenPopup(inFile, inWidth, inHeight) 
{
	var OpenWin;
 if(navigator.appName == "Microsoft Internet Explorer")
		OpenWin = this.open( ""+inFile+"", "", "height="+inHeight+",width="+inWidth+",left=20,top=20,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=yes");
	else
		//toolbar=yes or else it crashes on firefox os x 1.0PR
		OpenWin = this.open( ""+inFile+"", "", "height="+inHeight+",width="+inWidth+",left=20,top=20,toolbar=yes,menubar=no,location=no,scrollbars=no,resizable=yes");

if(OpenWin) 
	OpenWin.focus();
}

//ajax
 function createXMLHttpRequest() 
 {
   try { return new XMLHttpRequest(); } catch(e) {}
   try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) {}
   try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
   alert("XMLHttpRequest not supported");
   return null;
 }
 

function VoteUp(id)
{
	if(checkCookie("cookie[" + id + "]"))
	{
		document.getElementById(id + '_voted').innerHTML = "&nbsp;&nbsp;already voted";
	}
	else
	{
	document.getElementById(id + '_up').innerHTML = parseInt(document.getElementById(id + '_up').innerHTML)+1;
	startRequest("vote.php?id="+id+"&vote=1");
	}
}

function VoteDown(id)
{
	if(checkCookie("cookie[" + id + "]"))
	{
		document.getElementById(id + '_voted').innerHTML ="&nbsp;already voted";
		
	}
	else
	{
		document.getElementById(id + '_down').innerHTML = parseInt(document.getElementById(id + '_down').innerHTML)+1;
		startRequest("vote.php?id="+id+"&vote=2");
	}
}

function startRequest(voteurl)
{
	//currentLoops = 0;
	
		var req; 
   if (window.XMLHttpRequest) // Non-IE browsers  
   {  
   		req = new XMLHttpRequest();  
   }  
   else if (window.ActiveXObject) // IE  
   {  
   		req = new ActiveXObject("Microsoft.XMLHTTP");  
   }  
   
	
	//alert("startRequest");
		
	//createXMLHttpRequest();
	xmlHttp = createXMLHttpRequest();
	xmlHttp.onreadystatechange = handleStateChange;
	xmlHttp.open("GET", voteurl, true);
	xmlHttp.send(null);
}

function handleStateChange()
{
	if(xmlHttp.readyState == 4 && xmlHttp.status == 200)
	{
		processRequest();
	}
}



function processRequest()
{
	var data = xmlHttp.responseText;
	
	//alert(data);
	//alert(document.getElementById(data).innerHTML);
	
	//document.getElementById(data).innerHTML = parseInt(document.getElementById(data).innerHTML)+1;
	
}

/*
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    return unescape(document.cookie.substring(c_start,c_end));
    }
  }
return "";
}
*/


   
function getCookie( name ) 
{

	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) {
	return null;
	}
	
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function checkCookie(id)
{
	
	//return false;
	
	cookieData=getCookie(id);
	if (cookieData!=null && cookieData!="")
	{
		//printf("cookie: true, " + id  + ", "+ cookieData);
		// printf("checkCookie true");
	  return true;
	}
	else
	{
		//printf("cookie: false, " + id  + ", "+ cookieData);
		//printf("checkCookie false");
		return false;
	}
}




//tests
 
function VoteUp2(id)
{
	
	checkCookie2("cookie[" + id + "]")
}

function getCookie2( name ) 
{
	alert(name);
	
	var start = document.cookie.indexOf( name + "=" );
	
	var len = start + name.length + 1;
	
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ) 
	{
	return null;
	}
	
	if ( start == -1 ) return null;
		var end = document.cookie.indexOf( ';', len );
	if ( end == -1 ) 
		end = document.cookie.length;
	
	return unescape( document.cookie.substring( len, end ) );
}

function checkCookie2(id)
{
	cookieData=getCookie2(id);
	if (cookieData!=null && cookieData!="")
	{
		printf("cookie: true, " + id  + ", "+ cookieData);
		// printf("checkCookie true");
	  return true;
	}
	else
	{
		printf("cookie: false, " + id  + ", "+ cookieData);
		//printf("checkCookie false");
		return false;
	}
}

function printf(message)
{
	throw new Error(message);   
}

function addLoadEvent(func) 
{ 
	  var oldonload = window.onload; 
	  if (typeof window.onload != 'function') { 
	    window.onload = func; 
	  } else { 
	    window.onload = function() { 
	      if (oldonload) { 
	        oldonload(); 
	      } 
	      func(); 
	    } 
	  } 
} 