/*
Author: Addam M. Driver
Date: 10/31/2006
*/

var sMax;	// Isthe maximum number of stars
var holder; // Is the holding pattern for clicked state
var preSet; // Is the PreSet value onces a selection has been made
var rated;
var starratingmade=false;

// Rollover for image Stars //
function rating(num){
	sMax = 0;	// Isthe maximum number of stars
	for(n=0; n<num.parentNode.childNodes.length; n++){
		if(num.parentNode.childNodes[n].nodeName == "A"){
			sMax++;	
		}
	}
	
	if(!rated){
		s = num.id.replace("_", ''); // Get the selected star
		a = 0;
		for(i=1; i<=sMax; i++){		
			if(i<=s){
				document.getElementById("_"+i).className = "on";
				document.getElementById("rateStatus").innerHTML = num.title;	
				holder = a+1;
				a++;
			}else{
				document.getElementById("_"+i).className = "";
			}
		}
	}
}

// For when you roll out of the the whole thing //
function off(me){
	if(!rated){
		if(!preSet){	
			for(i=1; i<=sMax; i++){		
				document.getElementById("_"+i).className = "";
				document.getElementById("rateStatus").innerHTML = me.parentNode.title;
			}
		}else{
			rating(preSet);
			document.getElementById("rateStatus").innerHTML = document.getElementById("ratingSaved").innerHTML;
		}
	}
}

// When you actually rate something //
function rateIt(me,rndid,itemid){
	if(!rated){
		document.getElementById("rateStatus").innerHTML = document.getElementById("ratingSaved").innerHTML + " :: "+me.title;
		preSet = me;
		rated=1;
		sendRate(me,rndid,itemid);
		rating(me);
	}
}

function handleStarResult(param){

   var res = param.replace('<data>','');
   res = res.replace('</data>','');
   res = res.replace('<?xml version="1.0" encoding="UTF-8"?>','');
	
   if (res=="1") {
	   s=" star.";
   }
   else
   {
	   s=" stars.";
   }
   alert("Thankyou for rating this item. Value selected: " + res + s + 
		 " Please now enter a comment.");
   starratingmade=true;
}

// Send the rating information somewhere using Ajax or something like that.
function sendRate(sel,rndid,itemid){
	//alert("Thankyou for rating this item. You selected: "+sel.title);
		strURL = '/clients/infostore/MODULES/COMBINED/interface/COMBINEDMOD_saverating.aspx?rating=' + sel.title + "&rndid=" + rndid + "&itemid=" + itemid;
		strSubmit = ''; // not passing params
		strResultFunc = 'handleStarResult';
	//	alert(strURL);
		s = xmlhttpPost(strURL, strSubmit, strResultFunc) ;
}

function openfeedback(){
	
	document.getElementById("rateform").style.display="block";
	document.getElementById("rateuslink").style.display="none";
	
	
}



function openmore (morespan, openid)
{
	document.getElementById(morespan).style.display = "none";
	document.getElementById(openid).style.display = "block";
}

function openmorespan (morespan, openid)
{
	document.getElementById(morespan).style.display = "none";
	document.getElementById(openid).style.display = "inline";
}

function checkstarratingmade(checkrequired)
{
	var retval = true;
	var emailvalue=document.getElementById("emailfld").value;
	var isemail = emailvalue.indexOf("@")>0;
	if (checkrequired=='true') {
		if (starratingmade==false){
			alert("Please rate our service using the stars before submitting a comment.");
			retval=false;
		}
	}
/*	if (retval==true) {
		if (!isemail) {
			alert("Please enter a valid email address.");
			retval=false;
		}
	}*/

    return retval;
}


