var rate_title=new Array('Poor','Average','Fair','Good','Excellent');
var http2,addid,evnt;
function readall(advid)
{
	if(http2 && http2.readyState!=0)
	{
		http2.abort();
		http2 = null;		
	}

	http2=createRequestObject();
	addid=advid;
	
	var url = "readrates.php?advid="+advid;
	document.getElementById('loading').style.visibility = "visible";

	//document.write('<form><textarea>'+url+'</textarea></form>');


	http2.onreadystatechange = select_handleresponse2;
	http2.open("GET", url, true);
    http2.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    http2.send(null);
}

function select_handleresponse2() {
	if (http2.readyState == 4) {		
		if (http2.status == 200) {
			xmldoc=http2.responseXML;
			//document.write('<form><textarea>'+http2.responseText+'</textarea></form>');

			xml_nodes = xmldoc.documentElement.getElementsByTagName("record");

			var xml_len=xml_nodes.length;
			var advid,rate,review,reviewver,datecreated,ratecontent,content,email;


			content='<div STYLE="position:absolute;height:300px;width:330px;border:3px solid #008BCE; background-color:#F0F8FB;overflow:scroll;"><table cellspacing="0" cellpadding="0" border="0" width="300"><tr><td colspan=2><table><tr><td width="300px"><img src="http://imgs.bharatmatrimony.com/bmimages/wd/trans.gif" width="1" height="10" alt="" /><br /><img src="http://imgs.bharatmatrimony.com/bmimages/wd/trans.gif" width="6" height="1" alt="" /><font class="contlinks1bold"><strong>'+document.getElementById("bussiness"+addid).innerHTML+'</strong></font><br /></td><td valign="top" align="right"><a href="javascript:void(0);"  class="mediumtxt" onclick="javascript:document.getElementById(\'reviewpop'+addid+'\').style.visibility=\'hidden\';" style="font-size:12px;" title="Close"><b>x</b></a>&nbsp;<br /></td></tr></table></td></tr><tr><td colspan="2" class="mediumtxt" valign="middle"><img src="http://imgs.bharatmatrimony.com/bmimages/wd/trans.gif" width="1" height="10" alt="" /><br /><img src="http://imgs.bharatmatrimony.com/bmimages/wd/trans.gif" width="6" height="1" alt="" /><img src="http://imgs.bharatmatrimony.com/bmimages/wd/trans.gif" width="60" height="1" /></td></tr><tr><td colspan="2" height="15"></td></tr>';

			if(xml_len!=0)
				content+='<tr><td class="mediumtxt" style="padding-left: 6px;"><a href="javascript:void(0);" onclick="javascript: review('+addid+');" title="Ratings, Write/Read Reviews" class="contlinks1">Write review</a></td><td class="mediumtxt" align="right" style="padding-right: 6px;">Total Reviews - '+xml_len+'</td></tr>';
			else
				content+='<tr><td align="center" valign="middle"  colspan="2" class="mediumtxt">No reviews found.&nbsp;<a href="javascript:void(0);" onclick="javascript: review('+addid+');" title="Ratings, Write/Read Reviews" class="contlinks1">Write review</a></td></tr>';
	
			for(var j=0;j<xml_len;j++) {
				rate=parseFloat(xml_nodes[j].getAttribute("rate"));
				review=xml_nodes[j].getAttribute("review");	
				reviewver=xml_nodes[j].getAttribute("reviewver");	
				datecreated=xml_nodes[j].getAttribute("datecreated");	
				email=xml_nodes[j].getAttribute("email");	


				ratecontent='';

				for(var i=1;i<=parseInt(rate);i++)
					ratecontent+='<img src="http://imgs.bharatmatrimony.com/bmimages/wd/rating_high.gif">&nbsp;';
				for(;i<=5;i++)
					ratecontent+='<img src="http://imgs.bharatmatrimony.com/bmimages/wd/rating_low.gif">&nbsp;';

				content+='<tr><td colspan="2"><hr style="color:#FFD800; height:1px;" align="center" width="300" /></td></tr><tr><td colspan="2" valign="top" width="300"><table border="0" cellpadding="3" cellspacing="0" border="0" align="center" width="300"><tr><td colspan="2" class="mediumtxt" ><b>User Rating :</b> <img src="http://imgs.bharatmatrimony.com/bmimages/wd/trans.gif" width="10" height="1" alt="" />'+ratecontent+'</td></tr>';

				if(review!='')
				content+='<tr><td width="60px" class="mediumtxt" valign="top"><b>Review :</b></td><td width="240px" class="mediumtxt">'+review+'</td></tr>';

				content+='<tr><td class="mediumtxt" valign="top"><b>Reviewer&nbsp;:</b></td><td class="mediumtxt">'+reviewver+', <a href="mailto:'+email+'" class="contlinks">'+email+'</a> '+datecreated+'</td></tr><tr><td colspan="2" height="10"></td></tr></table></td></tr>';

			}
			content+='</table></div>';
			displayNone(addid);
			document.getElementById('reviewpop'+addid).innerHTML=content;
			document.getElementById('loading').style.visibility = "hidden";
		} else {
			http2.abort();
		}
	}
}

var http1,add_id,comp_name;
function makerequest1(advid,compname,divname1,divname2) {

	var uname=document.getElementById('uname'+advid).value;
	var poprate=document.getElementById('poprate'+advid).value;
	var email=document.getElementById('email'+advid).value;
	var ureview=document.getElementById('ureview'+advid).value;

	if(poprate=='0' || poprate=='')
	{
		alert('please select rate');
		return false;
	}	

	if(uname=='')
	{
		alert('please enter your name');
		document.getElementById('uname'+advid).focus();
		return false;
	}
	if (!isEmailAddress(document.getElementById('email'+advid),'email id'))
			return false;
	if(ureview==''){
		alert('please enter your review');
		document.getElementById('ureview'+advid).focus();
		return false;
	}
	if(http1 && http1.readyState!=0)
	{
		http1.abort();
		http1 = null;		
	}

	http1=createRequestObject();
	
	var url = "wdreviewsubmit.php";
	add_id=advid;
	comp_name=compname

	//document.getElementById('loading').style.visibility = "visible";

	var post="advid="+advid+"&uname="+uname+"&poprate="+poprate+"&email="+email+"&ureview="+ureview;
	document.getElementById(divname1).innerHTML = '<div style="height:450px;float:left;padding:12px;"><div style="float:left;width:430px;"><p style="padding-left:10px;padding-top:5px;padding-right:10px;" align="center"><font class="headText"><b>Loading...</b><br><br><img src="http://imgs.bharatmatrimony.com/bmimages/wd/wd_ajaxloader.gif" border="0" alt="" ></font></p></div></div>';
	http1.onreadystatechange = function(){
		  if (http1.readyState == 4) {

                        var http_status=http1.responseText;

                        var err;
                        if(http_status=='1')
                                err="You have posted review for this item!";
                        else if(http_status=='2'){
                                err="Thank you for reviewing/rating the ad by "+comp_name+". Your review will be added after moderation.";
                        }else{
                                err="Oops! server is busy, please try after some time";
                        }
                        document.getElementById(divname1).style.display="none";
                        document.getElementById(divname2).style.display="block";
                        document.getElementById(divname2).innerHTML = err;

}};
	http1.open("POST", url, true);
    	http1.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    	http1.send(post);
	return false;
}

var ids;
function displayNone(cid)
{
	var adv_ids=ids.split(",");
	var count_ids=adv_ids.length;

	if(count_ids)
	{
		for(var t=0;t<count_ids;t++)
		{
			if(adv_ids[t]!=cid)
			{
				page_div=document.getElementById('reviewpop'+adv_ids[t]);
				if(page_div=='[object HTMLDivElement]' || page_div=='[object]')
					page_div.style.visibility="hidden";
			}
		}
	}
	if(document.getElementById('reviewpop'+cid)=='[object HTMLDivElement]' || document.getElementById('reviewpop'+cid)=='[object]')
		document.getElementById('reviewpop'+cid).style.visibility="visible";
}

function changeover(advid,num)
{
	var star;
	var i=0;

	for(;i<=num;i++)
	{
		star=document.getElementById("ratingimg"+advid+"_"+i);
		star.src="http://imgs.bharatmatrimony.com/bmimages/wd/rating_high.gif";
		document.getElementById("ratingtitle"+advid).innerHTML=rate_title[i];
	}
	if(num<4)
	for(;i<=4;i++)
	{
		star=document.getElementById("ratingimg"+advid+"_"+i);
		star.src="http://imgs.bharatmatrimony.com/bmimages/wd/rating_low.gif";
	}	
}

function changeout(advid)
{
	var star;
	var i=0;
	var poprate=parseInt(document.getElementById("poprate"+advid).value);

	if(poprate=='' || !poprate)
		document.getElementById("ratingtitle"+advid).innerHTML='';
	else
		document.getElementById("ratingtitle"+advid).innerHTML=rate_title[poprate-1];

	poprate=poprate-1;	


	for(;i<=poprate;i++)
	{
		star=document.getElementById("ratingimg"+advid+"_"+i);
		star.src="http://imgs.bharatmatrimony.com/bmimages/wd/rating_high.gif";
	}
	if(poprate<4)
	for(;i<=4;i++)
	{
		star=document.getElementById("ratingimg"+advid+"_"+i);
		star.src="http://imgs.bharatmatrimony.com/bmimages/wd/rating_low.gif";
	}
}

function updateRating(advid,num)
{ 
	var star;
	var i=0;
	document.getElementById("poprate"+advid).value=num+1;
	document.getElementById("ratingtitle"+advid).innerHTML=rate_title[num];

	for(;i<=num;i++)
	{
		star=document.getElementById("ratingimg"+advid+"_"+i);
		star.src="http://imgs.bharatmatrimony.com/bmimages/wd/rating_high.gif";
	}
	if(num<4)
	for(;i<=4;i++)
	{
		star=document.getElementById("ratingimg"+advid+"_"+i);
		star.src="http://imgs.bharatmatrimony.com/bmimages/wd/rating_low.gif";
	}
}


function displayStars(advid)
{
	var stars;

	stars='';

	for(var i=0;i<rate_title.length;i++)
	{
		stars+='<img src="http://imgs.bharatmatrimony.com/bmimages/wd/rating_low.gif" id="ratingimg'+advid+'_'+i+'" onmouseover="javascript: changeover('+advid+','+i+');" onmouseout="javascript: changeout('+advid+')"; onclick="updateRating('+advid+','+i+')">';
	}
	stars+='&nbsp;&nbsp;<font class="smalltxt" style="color:#969696;"><b><span id="ratingtitle'+advid+'"></span></b></font>';

	return stars;
}
function review(e,compname,advid){
	hideall_div(advid);
	//document.getElementById('reviewpop'+advid).innerHTML=get_content(advid);
	var posi = new Array();
	posi=trackClick(e);
	evnt=posi;
	var forwardto_form='<div STYLE="position:absolute;height:380px;width:330px;border:3px solid #FF6000;overflow:no;background-color:#ffffff;"><table cellspacing="0" cellpadding="0" border="0" width="330"><tr><td colspan=2 align="right" height="25" bgcolor="#E7E7E7" style="padding-left:10px;border:1px solid #ffffff;"><div style="float:left;" class="normaltext"><b>Please review this service?</b></font></div>  <div style="float:right;padding-right:5px;"><a href="javascript:;" onclick="javascript:hide_spam_div(\'div_review\');" title="Close"><img src="http://imgs.bharatmatrimony.com/bmimages/wd/wd-pop-close.gif" width="15" height="14" border="0" alt="Close"></a></div></td></tr><tr><td colspan=2><table><tr><td><img src="http://imgs.bharatmatrimony.com/bmimages/wd/trans.gif" width="1" height="10" alt="" /><br /><img src="http://imgs.bharatmatrimony.com/bmimages/wd/trans.gif" width="6" height="1" alt="" /><div style="padding:0px 7px;" class="normaltext">Here\'s an opportunity to share your reviews with all our members and visitors to the site .</div></td></tr><tr><td><img src="http://imgs.bharatmatrimony.com/bmimages/wd/trans.gif" width="1" height="10" alt="" /><br /><img src="http://imgs.bharatmatrimony.com/bmimages/wd/trans.gif" width="6" height="1" alt="" /><font class="normaltext"><strong>'+compname+'</strong></font><br /></td></tr></table></td></tr><tr><td colspan="2" class="normaltext" valign="middle"><img src="http://imgs.bharatmatrimony.com/bmimages/wd/trans.gif" width="1" height="10" alt="" /><br/><img src="http://imgs.bharatmatrimony.com/bmimages/wd/trans.gif" width="10" height="1" alt="" /><strong>Rate this service:</strong><img src="http://imgs.bharatmatrimony.com/bmimages/wd/trans.gif" width="10" height="1" alt="" /><img src="http://imgs.bharatmatrimony.com/bmimages/wd/trans.gif" alt="" height="1" width="10"><img src="http://imgs.bharatmatrimony.com/bmimages/wd/rating_low.gif" id="ratingimg'+advid+'_0" onmouseover="javascript: changeover('+advid+',0);" onmouseout="javascript: changeout('+advid+')" ;="" onclick="updateRating('+advid+',0)"><img src="http://imgs.bharatmatrimony.com/bmimages/wd/rating_low.gif" id="ratingimg'+advid+'_1" onmouseover="javascript: changeover('+advid+',1);" onmouseout="javascript: changeout('+advid+')" ;="" onclick="updateRating('+advid+',1)"><img src="http://imgs.bharatmatrimony.com/bmimages/wd/rating_low.gif" id="ratingimg'+advid+'_2" onmouseover="javascript: changeover('+advid+',2);" onmouseout="javascript: changeout('+advid+')" ;="" onclick="updateRating('+advid+',2)"><img src="http://imgs.bharatmatrimony.com/bmimages/wd/rating_low.gif" id="ratingimg'+advid+'_3" onmouseover="javascript: changeover('+advid+',3);" onmouseout="javascript: changeout('+advid+')" ;="" onclick="updateRating('+advid+',3)"><img src="http://imgs.bharatmatrimony.com/bmimages/wd/rating_low.gif" id="ratingimg'+advid+'_4" onmouseover="javascript: changeover('+advid+',4);" onmouseout="javascript: changeout('+advid+')" ;="" onclick="updateRating('+advid+',4)">&nbsp;&nbsp;<font class="smalltxt" style="color: rgb(150, 150, 150);"><b><span id="ratingtitle'+advid+'"></span></b></font><br /></td></tr><tr><td style="padding:10px;" colspan="2"><form method=post><table cellspacing="0" cellpadding="0" border="0" style="width:100%;" align="left"><tr><td class="smallText" width="105"><strong>Your Name:</strong></td><td><input type="hidden" name="poprate'+advid+'" id="poprate'+advid+'" value="0"/><input type="text" name="uname'+advid+'" id="uname'+advid+'" class="textfield" style="width:200px;border:1px solid #A7A7A7;" /></td></tr><tr><td colspan="2"><img src="http://imgs.bharatmatrimony.com/bmimages/wd/trans.gif" width="1" height="10" alt="" /><br /></td></tr><tr><td class="smallText"><strong>Your Email:</strong></td><td><input type="text" name="email'+advid+'" id="email'+advid+'" class="textfield" style="width:200px;border:1px solid #A7A7A7;" /></td></tr><tr><td colspan="2"><img src="http://imgs.bharatmatrimony.com/bmimages/wd/trans.gif" width="1" height="10" alt="" /><br /></td></tr><tr><td class="smallText" valign="top"><strong>Your Review:</strong></td><td><textarea name="ureview'+advid+'" id="ureview'+advid+'" class="textfield" style="width:202px; height:50px;border:1px solid #A7A7A7;"></textarea></td></tr><tr align="center"><td height="65" colspan="2"><div class="normaltext" style="text-align:left;width:300px;background-color:#FFFFFF;background-color:#FFF3BB; height:32px; padding:5px;">Note: BharatMatrimony.com is not responsible or liable in any for ratings and reviews posted by its users</div></td></tr><tr><td  colspan=2><div style="float:left;margin-top:5px;" ><img src="http://imgs.bharatmatrimony.com/bmimages/wd/wd-pop-bullet.gif" width="4" height="7" border="0" alt="" hspace="5"><a href="wdadreview.php?adid='+advid+'" class="normaltext" style="color:#0056A6;">More reviews on this service</a> </div><div style="float:left;padding-left:25px;"><input type="image" onclick="javascript: return makerequest1('+advid+',\''+compname+'\');" src="http://imgs.bharatmatrimony.com/bmimages/wd/submit-button.gif" width="61" height="21" border="0" alt="">&nbsp;&nbsp;<image src="http://imgs.bharatmatrimony.com/bmimages/wd/cancel-button.gif" onclick="javascript:hide_spam_div(\'div_review\');" width="61" height="21" border="0" alt=""></div></td></tr><tr><td align="left" colspan=2> </td></tr></table></form></td></tr></table></div>';

	document.getElementById("div_review").style.visibility="visible";
	document.getElementById("div_review").style.left=posi[0]+"px";	
	document.getElementById("div_review").style.top=posi[1]+"px";	
	document.getElementById("div_review").innerHTML=forwardto_form;
}

//To validate Email addresses
function isEmailAddress(eleobj,str) {

	var strng;

	strng=eleobj.value;

	if(!isNoEmpty(eleobj,str))
		return false;

    var emailFilter=/^.+@.+\..{2,3}$/;

    if (!(emailFilter.test(strng))) { 
       alert('please enter a valid '+str);
	   eleobj.focus();
	   return false;
    }
    else {
//test email for illegal characters
       var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
         if (strng.match(illegalChars)) {
		  alert('the '+str+' contains illegal characters');
		  eleobj.focus();
		  return false;
       }
    }
	return true;    
}

function isNoEmpty(eleobj,str)
{
	var strng;

	strng=eleobj.value;

	if (strng == '') {
	  alert('please enter '+str);
	  eleobj.focus();
	  return false;
	}
	return true;
}



