// Global variables
var active_div_replace=false;
var pageName;
var t;	//timeout for player
var firstUrlPart;
var lastUrlPart;
var numberOfStars = 5;

////Ajax code
var request="";

if(window.XMLHttpRequest)  
{
	request= new XMLHttpRequest();
}
else if (window.ActiveXObject)
{
	request= new ActiveXObject("Microsoft.XMLHTTP");
}

// Include the content of a given URL in a div
function replace_content(pURL, pNodeId) {
  if (!active_div_replace){
    active_div_replace=true;
    var url=pURL;
    if (arguments.length>=2) {
      rfNodeId=pNodeId;
    }
   	// empty the div
   	// document.getElementById(rfNodeId).innerHTML='';
   	//alert(pURL);
    
    if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc 
      xmlhttp=new XMLHttpRequest();
      xmlhttp.onreadystatechange=replace_div_HTML;
      xmlhttp.open("GET", pURL, true); // leave true for Gecko
      xmlhttp.send(null);
    } else if (window.ActiveXObject) { //IE 
      xmlhttp=new ActiveXObject('Microsoft.XMLHTTP'); 
      if (xmlhttp) {
        xmlhttp.onreadystatechange=replace_div_HTML;
        xmlhttp.open('GET', pURL, false);
        
        xmlhttp.send();
      }
    } else {
      alert('Your browser does not appear to support remote scripting.');
      xmlhttp=false;
      active_div_replace=false;
    }
    
    if ((typeof(xmlhttp))!='object') {
      document.write('You need to upgrade your browser to use this page.\r\nAs of March 2006 more than 98% of the web browsers in use support the remote scripting object. Either your browser does not support remote scripting or the support has been disabled.');
      active_div_replace=false;
    }
  }else{
    window.setTimeout("replace_content('"+pURL+"','"+pNodeId+"');",1);
  }
}

function replace_div_HTML(){
  if (xmlhttp.readyState==4) {
    if (xmlhttp.status==200) {
      if (rfNodeId=='') {
        document.write(xmlhttp.responseText);
        active_div_replace=false;
      }else{
        document.getElementById(rfNodeId).innerHTML=xmlhttp.responseText;
		active_div_replace=false;
      }
    }
  }
}

function replace_content_not(pURL, pNodeId) {
  if (!active_div_replace){
    active_div_replace=true;
    var url=pURL;
    if (arguments.length>=2) {
      rfNodeId=pNodeId;
    }
   	// empty the div
   	// document.getElementById(rfNodeId).innerHTML='';
   	//alert(pURL);
    
    if (window.XMLHttpRequest) { // code for Mozilla, Safari, etc 
      xmlhttp=new XMLHttpRequest();
      xmlhttp.onreadystatechange=replace_div_HTML_not;
      xmlhttp.open("GET", pURL, true); // leave true for Gecko
      xmlhttp.send(null);
    } else if (window.ActiveXObject) { //IE 
      xmlhttp=new ActiveXObject('Microsoft.XMLHTTP'); 
      if (xmlhttp) {
        xmlhttp.onreadystatechange=replace_div_HTML_not;
        xmlhttp.open('GET', pURL, false);
        
        xmlhttp.send();
      }
    } else {
      alert('Your browser does not appear to support remote scripting.');
      xmlhttp=false;
      active_div_replace=false;
    }
    
    if ((typeof(xmlhttp))!='object') {
      document.write('You need to upgrade your browser to use this page.\r\nAs of March 2006 more than 98% of the web browsers in use support the remote scripting object. Either your browser does not support remote scripting or the support has been disabled.');
      active_div_replace=false;
    }
  }else{
    window.setTimeout("replace_content('"+pURL+"','"+pNodeId+"');",1);
  }
}

function replace_div_HTML_not(){
  if (xmlhttp.readyState==4) {
    if (xmlhttp.status==200) {
      if (rfNodeId=='') {
        document.write(xmlhttp.responseText);
        active_div_replace=false;
      }else{
        //document.getElementById(rfNodeId).innerHTML=xmlhttp.responseText;
		active_div_replace=false;
      }
    }
  }
}

function checkForm(formName,textFormName)
{
	error = false;
	if(formName.comment.value == '')
	{
		alert("Please put in a comment");
		error = true;
	}
	else if(formName.name.value == '')
	{
		alert("Please put in your name/url");
		error = true;
	}
	else if(formName.captcha.value == '')
	{
		alert("Please enter the captcha");
		error = true;
	}
	else
	{
		code = formName.captcha.value;
		call(code,textFormName);
		return false;
	}
	
	if(error == true)
		return false;
	else
		return true;
}

function call(code,textFormName)
{
	var url ="validateCaptcha.php?id="+code+"&formName="+textFormName;
	//alert(url);
	request.open("GET",url,true);
	request.onreadystatechange=callabc;
	request.send(null);
}

function callabc()
{	
	if(request.readyState==4)
	{
		if(request.status==200)
		{
			var text=request.responseText;	
			//alert(text);
			//return false;
			if(text == "captcha code is not correct. ")
			{
				alert(text);
				return false ;
			}
			else
			{
				document.getElementById(text).submit();
				//text.submit();
			}	  
		}	 
		 
	}
}

function clearStars(star_empty,id)
{
	for(i=1;i<=numberOfStars;i++)
		document.getElementById('star'+id+'_'+i).src = star_empty;
}

function starMouseOver_star(id,number,star_empty,star)
{
	clearStars(star_empty,id);
	for(i=1;i<=number;i++)
		document.getElementById('star'+id+'_'+i).src = star;
}

function starMouseOut_star(id,number,star_empty,star,rating)
{
	clearStars(star_empty,id);
	if(rating != 0)
	{
		for(i=1;i<=rating;i++)
			document.getElementById('star'+id+'_'+i).src = star;
	}
}

function DoTheClick(id,number,star_empty,star,rating_path)
{
	clearStars(star_empty,id);
	for(i=1;i<=number;i++)
	{
		document.getElementById('star'+id+'_'+i).src = star;
	}
	removeClicks(id);
	
	//do the rating here
	//alert(number);
	//alert(rating_path);
	replace_content_not(rating_path, 'not')
}

function removeClicks(id)
{
	//remove clicks
	for(i=1;i<=numberOfStars;i++)
	{
		document.getElementById('star'+id+'_'+i).onclick = "";
		document.getElementById('star'+id+'_'+i).onmouseout = "";
		document.getElementById('star'+id+'_'+i).onmouseover = "";
	}
}