var loadimage1="<br/><br/><center><img src='/images/load.gif'></center><br/><br/>";
var MainDivId="";
var MailtoNameId="";
var MailtoEmailId="";
var MailFromNameId="";
var MailFromEmailId="";
var OptNoteTxtId="";
var request=false;
var xmlHttp;
var myString='';
var current=-1;

function createAjaxObject()
{try{request=new XMLHttpRequest();}
 catch(trymicrosoft)
 {try{request=new ActiveXObject("Msxml2.XMLHTTP");}
  catch (othermicrosoft)
  {try{request=new ActiveXObject("Microsoft.XMLHTTP");}
   catch(failed) {request=false;}
   }
  }
}

function isValidEmail(emailaddress, mailtoTxtId)
{var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
 var returnval=emailfilter.test(emailaddress);
 if(returnval===false)
 {alert("Please Enter A Valid Email Address.");
  document.getElementById(mailtoTxtId).value="";
  document.getElementById(mailtoTxtId).select();
  return false;
  }
return true;
}

function common_sendMailRequest(frm, dealId, mailData, opt)
{var url="";
 if(opt==2)
  {var mail_type='';
   if(frm.mail_type[0].checked) {mail_type=frm.mail_type[0].value;}
   else if(frm.mail_type[1].checked) {mail_type=frm.mail_type[1].value;}
  }
 createAjaxObject();
 if(request)
 {	MainDivId="MAILSENTMSG_" + dealId;
	MailToNameId="NAMETO_" + dealId;
	MailToEmailId="MAILTO_" + dealId;
	MailFromNameId="NAMEFROM_" + dealId;
	MailFromEmailId="MAILFROM_" + dealId;
	OptNoteTxtId="NOTE_" + dealId;

	var mailtoname=document.getElementById(MailToNameId).value;
	var mailtoemail=document.getElementById(MailToEmailId).value;
	var mailfromname=document.getElementById(MailFromNameId).value;
	var mailfromemail=document.getElementById(MailFromEmailId).value;
	var optNote=document.getElementById(OptNoteTxtId).value;

	if(mailtoname===""){alert("Please Enter Name Of Your Friend");document.getElementById(MailToNameId).select();}
	else if(mailtoemail===""){alert("Please Enter Email Address Of Your Friend");document.getElementById(MailToEmailId).select();}
	else if(!isValidEmail(mailtoemail, MailToEmailId)){}
	else if(mailfromname===""){alert("Please Enter Your Name");document.getElementById(MailFromNameId).select();}
	else if(mailfromemail===""){alert("Please Enter Your Email Address");document.getElementById(MailFromEmailId).select();}
	else if(!isValidEmail(mailfromemail, MailFromEmailId)){}
	//else if(optNote===""){alert("Please Enter Personalized  Message");document.getElementById(OptNoteTxtId).select();}
	else {if(isValidEmail(mailtoemail, MailToEmailId))
		{if(opt==2)
		  {url="sendmail.php?mailtoemail=" + mailtoemail + "&mailfromname=" + mailfromname + "&mailfromemail=" + mailfromemail + "&mailtoname=" + mailtoname + "&" + mailData + "&optionalnote=" + optNote +"&mail_type=" + mail_type +"&sid="+Math.random();}
		 if(opt==1)
		  {url="sendmail.php?mailtoemail=" + mailtoemail + "&mailfromname=" + mailfromname + "&mailfromemail=" + mailfromemail + "&mailtoname=" + mailtoname + "&" + mailData + "&optionalnote=" + optNote +"&sid="+Math.random();}
		 myString=mailData;
		 couponid_fun=dealId;
		 /*mailData alert(url);*/
		 request.open("GET", url,true);
		 if(opt==1) {request.onreadystatechange=getSendMailResponse;}
		 if(opt==2) {request.onreadystatechange=getSendMailResponse_Coupons;}
		 request.send(null);
		}
	}
 }
}

function sendMailRequest(frm, dealId, mailData) {common_sendMailRequest(frm, dealId, mailData, 1);}
function sendMailRequest_Coupons(frm, dealId, mailData) {common_sendMailRequest(frm, dealId, mailData, 2);}

function getSendMailResponse() {common_getSendMailResponse();}
function getSendMailResponse_Coupons() {common_getSendMailResponse();}

function common_getSendMailResponse()
{ if(request.readyState==4)
    {if(request.status==200)
       {var response=request.responseText;
	if(response=="SUCCESS")
	{document.getElementById(MainDivId).innerHTML="<b><font color=green size=2>Mail Successfully Sent !!!</font></b>";
	 document.getElementById(MailToNameId).value="";
	 document.getElementById(MailToEmailId).value="";
	 document.getElementById(MailFromNameId).value="";
	 document.getElementById(MailFromEmailId).value="";
	 document.getElementById(OptNoteTxtId).value="";
	 setTimeout("document.getElementById(MainDivId).innerHTML=\"\";",2500);
	 var rExp=/Awesome Coupon /gi;
	 var results=myString.search(rExp);
	 if(results > 0)
	 {setTimeout("document.getElementById(\"tell_\"+couponid_fun).style.display=\"none\";",5000);}
	 results=0;
	}
       }
    }
}

function sendMailUI(mailDivId, mailData, id)
{//var sendmailui="<B>Email Address : </B><INPUT TYPE=\"TEXT\" NAME=\"MAILTO_"+ id +"\" ID=\"MAILTO_"+ id +"\">&nbsp;<INPUT TYPE=\"BUTTON\" NAME=\"SENDMAIL\" onClick=\"javascript:sendMailRequest(this.form, 'MAILTO_"+ id +"', 'NOTE_"+ id +"', '"+ mailData +"', '"+ mailDivId +"');\" VALUE=\"SEND\">&nbsp;<INPUT TYPE=\"BUTTON\" NAME=\"CANCEL\" onClick=\"javascript:cancelMailSend('"+mailDivId+"')\" VALUE=\"CANCEL\">";
 var prevUIData="<TABLE BORDER=0 align=center cellspacing=\"0\" cellpadding=\"0\"><TR><TD width=\"100%\" COLSPAN=5><TABLE border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\" ><TR><TD class=\"hline\" WIDTH=100%></TD></TR></TABLE></TD></TR><TR><TD class=\"vline\"><img src=\"images/clear.gif\"></TD><TD>";
 var mainUIData="<TABLE BORDER=0 width=100% align=center><TR align=left><TD valign=center ALIGN=RIGHT><B>Email&nbsp;Address&nbsp;:</B></TD><TD><INPUT CLASS=\"textinput\" TYPE=\"TEXT\" NAME=\"MAILTO_"+ id +"\" ID=\"MAILTO_"+ id +"\" size=30></TD><TD><INPUT CLASS=\"button\" TYPE=\"BUTTON\" NAME=\"SENDMAIL\" onClick=\"javascript:sendMailRequest(this.form, 'MAILTO_"+ id +"', 'NOTE_"+ id +"', '"+ mailData +"', '"+ mailDivId +"');\" VALUE=\"SEND\">&nbsp;<INPUT CLASS=\"button\" TYPE=\"BUTTON\" NAME=\"CANCEL\" onClick=\"javascript:cancelMailSend('"+mailDivId+"')\" VALUE=\"CANCEL\"></TD></TR><TR align=left><TD valign=center ALIGN=RIGHT><B>Optional&nbsp;Note&nbsp;:</B></TD><TD colspan=2><TEXTAREA class=\"textinput\" NAME=\"NOTE_"+ id +"\" ID=\"NOTE_"+ id +"\" COLS=50></TEXTAREA></TD></TR></TABLE>";
 var nextUIData="</TD><TD class=\"vline\"><img src=\"images/clear.gif\"></TD></TR><TR><TD width=\"100%\" COLSPAN=5><TABLE border=\"0\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\"><TR><TD class=\"hline\" WIDTH=100%></TD></TR></TABLE></TD></TR></TABLE>";
 sendmailui=prevUIData + mainUIData + nextUIData;
 document.getElementById(mailDivId).innerHTML=sendmailui;
}


function cancelMailSend(dealId)
{MainDivId="MAILSENTMSG_" + dealId;
 MailToNameId="NAMETO_" + dealId;
 MailToEmailId="MAILTO_" + dealId;
 MailFromNameId="NAMEFROM_" + dealId;
 MailFromEmailId="MAILFROM_" + dealId;
 OptNoteTxtId="NOTE_" + dealId;

 document.getElementById(MailToNameId).value="";
 document.getElementById(MailToEmailId).value="";
 document.getElementById(MailFromNameId).value="";
 document.getElementById(MailFromEmailId).value="";
 document.getElementById(OptNoteTxtId).value="";
}

function dealInNewWindow(dealFilePath)
{wWidth=screen.width/1.5; wHeight=screen.height/1.5;
 myRef=window.open('/PrintDeal.php?dealfilepath='+dealFilePath,'PrintDeal','screenX=' + wWidth/2 + ',screenY=' + wHeight/2 + ',width=' + wWidth + ',height=' + wHeight + ',resizable=0, scrollbars=1');
}

function stateChanged()
{document.getElementById("txtHint"+seq_name).innerHTML=loadimage1;
 if(xmlHttp.readyState==4){document.getElementById("txtHint"+seq_name).innerHTML=xmlHttp.responseText;}
}

//****AJAX driven TAF - Begins ***
function tell_friend(yymmdd_slashes,fileseqname,yymmddfileseqname)
{var dateArr=yymmdd_slashes.split('/');
 if(dateArr[0]==2007 )
 {if(dateArr[1] >=10)
  {if(dateArr[1]==10)
   {if(dateArr[2]>28){seq_name=yymmddfileseqname;}
    else {seq_name=fileseqname;}
    }
   else{seq_name=yymmddfileseqname;}
  }
 else{seq_name=fileseqname;}
 }
 else
 {if(dateArr[0]>2007){seq_name=yymmddfileseqname;}
  else{seq_name=fileseqname;}
 }

 unique_seq_name=yymmddfileseqname;
 xmlHttp=GetXmlHttpObject();
 if(xmlHttp===null) {alert ("Your browser does not support AJAX!");return;}
 var url="/Includes/new_Includes/DealsPages/tell_friend_ajax.php";
 url=url+"?status=yes";
 url=url+"&yymmdd_slashes="+yymmdd_slashes;
 url=url+"&fileseqname="+fileseqname;
 url=url+"&yymmddfileseqname="+yymmddfileseqname;
 url=url+"&sid="+Math.random();
 xmlHttp.onreadystatechange=stateChanged;
 xmlHttp.open("GET",url,true);
 xmlHttp.send(null);
}

function GetXmlHttpObject()
{var xmlHttp=null;
 try
 {// Firefox, Opera 8.0+, Safari
  xmlHttp=new XMLHttpRequest();
 }
 catch (e)
 {// Internet Explorer
  try
  {xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");}
  catch (e)
  {xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");}
 }
return xmlHttp;
}
//****AJAX driven TAF - Ends ***



/* Start Tell a Friend for Coupons(recent)  */
function stateChanged_tell_coupon_friend()
{if(xmlHttp.readyState==4)
 {document.getElementById("tell_"+coupon_id_fun).innerHTML=xmlHttp.responseText;}
}

function tell_coupon_friend(server_name,coupon_id,merchant_val,coupon_final_link,merchant_name,coupon_title_new,coupon_code_new,exp_date_new, country)
{coupon_final_link=coupon_final_link.replace(/&/g,"ANDPERCENTSYMBOL");
 document.getElementById("tell_"+coupon_id).style.display=(document.getElementById("tell_"+coupon_id).style.display!="none")? "none" : "";

 coupon_id_fun=coupon_id;
 xmlHttp=GetXmlHttpObject();
 if (xmlHttp===null){alert("Your browser does not support AJAX!");return;}
 var url=server_name+"/Includes/new_Includes/DealsPages/tell_friend_coupon_ajax.php";
 url=url+"?status=yes";
 url=url+"&coupon_id="+coupon_id_fun;
 url=url+"&merchant_val="+merchant_val;
 url=url+"&coupon_final_link="+coupon_final_link;
 url=url+"&merchant_name="+merchant_name;
 url=url+"&coupon_title_new="+coupon_title_new;
 url=url+"&coupon_code_new="+coupon_code_new;
 url=url+"&exp_date_new="+exp_date_new;
 url=url+"&country="+country;
 url=url+"&sid="+Math.random();
 xmlHttp.onreadystatechange=stateChanged_tell_coupon_friend;
 xmlHttp.open("GET",url,true);
 xmlHttp.send(null);
}

function stateChanged_ReportWrongLink()
{if(xmlHttp.readyState==4)
 {document.getElementById("tell_"+deal_seq_no_fun).innerHTML=xmlHttp.responseText;}
}

function ReportWrongLink(deal_seq_no,deal_date)
{document.getElementById("tell_"+deal_seq_no).style.display="";
 deal_seq_no_fun=deal_seq_no;
 xmlHttp=GetXmlHttpObject();
 if (xmlHttp===null)
  {
   alert ("Your browser does not support AJAX!");
   return;
  }
  var url="/Includes/new_Includes/DealsPages/report_wrong_link_ajax.php";
  url=url+"?status=yes";
  url=url+"&deal_seq_no="+deal_seq_no;
  url=url+"&deal_date="+deal_date;
  url=url+"&sid="+Math.random();
  xmlHttp.onreadystatechange=stateChanged_ReportWrongLink;
  xmlHttp.open("GET",url,true);
  xmlHttp.send(null);
}

function stateChanged_YestDeal()
{if(xmlHttp.readyState==4)
 {document.getElementById("yest_div").innerHTML=xmlHttp.responseText;}
}

function GetYestDeals()
{xmlHttp=GetXmlHttpObject();
 if(xmlHttp===null)
 {alert ("Your browser does not support AJAX!");return;}
 var url="/YesterdayDeal.php";
 xmlHttp.onreadystatechange=stateChanged_YestDeal;
 xmlHttp.open("GET",url,true);
 xmlHttp.send(null);
}

//End ** for Tell a Friend for Coupons(recent)

function alert_search(msg)
{t_obj=document.SearchForm.searchQuery;
 alert(msg);
 t_obj.value='';
 t_obj.focus();
}

function validate(opt)
{
	country=document.SearchForm.country.value;
	if( document.SearchForm.search_by_deal_or_coupon.value=="Deal" )
	{
		tval=document.SearchForm.searchQuery.value.replace(/^\s+|\s+$/g,"");

		if((tval=="Enter Search Keywords" || tval==="" )  && (opt===0))
		{
			alert_search("Please Enter Keyword To Search");
			return false;
		}
		else
		{
			tval=tval.replace("'","");tval=tval.replace('"','');tval=tval.replace(/ /g,"+");tval=tval.replace(/\//g,"+");tval=tval.replace(/\\/g,"+");tval=tval.replace(/#/g,"ANDPERCENThash");

			if ((tval==="") && (opt==1))
				{window.location.href="/";}
			else
				{if (opt===0) {tval=tval.replace("&","%26"); tval=tval.replace(" ","%20"); document.SearchForm.action="/dealsearch/Controller.php?bargain_search="+tval;}
				if (opt==1)  {if(tval=="Enter Search Keywords"){tval="";} tval=tval.replace("&","%26"); tval=tval.replace(" ","%20"); document.SearchForm.action="/dealsearch/advanced.php?title="+tval;}
				document.SearchForm.submit();
				}
		}
	}
	else
	{
		if(opt==1)
		{
			alert_search("Advanced search is not available for Coupon");
			return false;
		}
		tval=document.SearchForm.searchQuery.value.replace(/^\s+|\s+$/g,"");
		if((tval=="Enter Search Keywords" || tval==="" )  && (opt===0))
		{
			alert_search("Please Enter Keyword To Search");
			return false;
		}
		else
		{
			tval=document.SearchForm.searchQuery.value.replace(/^\s+|\s+$/g,"");
			if ((tval==="") && (opt===0))
				{window.location.href="/";}
			else
			{
				tval=tval.replace(/ /g,"+");
				tval=tval.replace(/\//g,"+");
				tval=tval.replace(/\\/g,"+");
				tval=tval.replace(/#/g,"ANDPERCENThash");
				tval=tval.replace(/&/g,"ANDPERCENTamp;");
				tval=tval.replace(/'/g,"ANDPERCENTsinglequote;");
				tval=tval.replace(/"/g,"ANDPERCENTdoublequote;");
				document.SearchForm.action="/portal/coupons/"+country+"/Controller.php?bargain_search="+tval+"&lmt=1&opt=0&country="+country;
				document.SearchForm.submit();
			}
		}
	}
}

function stateChanged_events_file()
{document.getElementById(place_in_id_temp).innerHTML=loadimage1;
 if(xmlHttp.readyState==4){document.getElementById(place_in_id_temp).innerHTML=xmlHttp.responseText;}
}

function events_file( file_name, place_in_id )
{place_in_id_temp=place_in_id;
 xmlHttp=GetXmlHttpObject();
 if(xmlHttp===null) {alert ("Your browser does not support AJAX!");return;}
 var url="../../include_events_file.php";
 url=url+"?file_name="+file_name;
 url=url+"&sid="+Math.random();
 xmlHttp.onreadystatechange=stateChanged_events_file;
 xmlHttp.open("GET",url,true);
 xmlHttp.send(null);
}

function stateChanged_next_banner()
{document.getElementById("next_banner").innerHTML=loadimage1;
 if(xmlHttp.readyState==4){document.getElementById("next_banner").innerHTML=xmlHttp.responseText;}
}

function next_banner(index,end,h,w)
{xmlHttp=GetXmlHttpObject();
 if(xmlHttp===null){alert("Your browser does not support AJAX!");return;}

 if(current==-1) {current=index;}
 if(current==end) {current=0;}
 else {current++;}
 var url="/Includes/new_Includes/banner_ajax.php";
 url=url+"?next_banner_index="+current;
 url=url+"&h="+h;
 url=url+"&w="+w;
 url=url+"&sid="+Math.random();
 xmlHttp.onreadystatechange=stateChanged_next_banner;
 xmlHttp.open("GET",url,true);
 xmlHttp.send(null);
}

function previous_banner(index,end,h,w)
{xmlHttp=GetXmlHttpObject();
 if(xmlHttp===null)
 {alert("Your browser does not support AJAX!");return;}
 if(current==-1) {current=index;}
 if(current===0) {current=end;}
 else {current--;}
 var url="/Includes/new_Includes/banner_ajax.php";
 url=url+"?next_banner_index="+current;
 url=url+"&h="+h;
 url=url+"&w="+w;
 url=url+"&sid="+Math.random();
 xmlHttp.onreadystatechange=stateChanged_next_banner;
 xmlHttp.open("GET",url,true);
 xmlHttp.send(null);
}

/* Start Related Products  */
var seq_no_temp = '';
function stateChanged_related_products()
{
 document.getElementById('products_'+seq_no_temp).innerHTML=loadimage1;
 if((xmlHttp.readyState== 4) && (xmlHttp.status == 200))
 {
  document.getElementById('products_'+seq_no_temp).innerHTML = xmlHttp.responseText;
 }
}

function related_products(yymmdd_slashes,fileseqname,yymmddfileseqname)
{
	seq_no_temp = yymmddfileseqname;
	xmlHttp=GetXmlHttpObject();
	if(xmlHttp===null){
	alert("Your browser does not support AJAX!");
		return;
	}

	var url ="/Includes/new_Includes/DealsPages/relatedProducts.php";
	url=url+"?status=yes";
	url=url+"&yymmdd_slashes="+yymmdd_slashes;
	url=url+"&fileseqname="+fileseqname;
	url=url+"&yymmddfileseqname="+yymmddfileseqname;
	url=url+"&sid="+Math.random();
	xmlHttp.onreadystatechange=stateChanged_related_products;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

/* End Related Products  */

/* Start Deal Rating */
var deal_seq_no_dealrating = ''
var deal_date_temp = ''
function DealRating(deal_seq_no,deal_date)
{
		deal_seq_no_dealrating = deal_seq_no;
		deal_date_temp = deal_date;
		document.getElementById("tell_"+deal_seq_no_dealrating).style.display="";
		xmlHttp=GetXmlHttpObject();
		if (xmlHttp==null){alert ("Your browser does not support AJAX!");return;}

		var url="/Includes/new_Includes/DealsPages/DealBottomLine.php";
		url=url+"?sequenceNumber="+deal_seq_no;
		url=url+"&dealDate="+deal_date;
		url=url+"&sid="+Math.random();
		xmlHttp.onreadystatechange=stateChanged_DealRating;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
}

function stateChanged_DealRating()
{
	if (xmlHttp.readyState==4)
	{
		document.getElementById("tell_"+deal_seq_no_dealrating).innerHTML=xmlHttp.responseText;
		result_avg_value = document.getElementById("AvgRtg"+deal_seq_no_dealrating).value;
		result_avg(result_avg_value);
	}
}

function result_avg(result_avg_value)
{initialRatingTableValue( deal_seq_no_dealrating, deal_date_temp, result_avg_value)}

var isFinalRating = 0;
var finalRatingValue = "";
var httpRating = false;
var imagePixelSize = 20;
var browser_version= parseInt(navigator.appVersion);
var browser_type = navigator.appName;
var updatedDate;

// This function is called initially when page is loaded. I will display the rating value.It has 3 parameters. (Sequence No, Deal Date, Rating). Parameter raing is fetched from the database.

function initialRatingTableValue(seqNumber, dealDate, rating)
{
	var rating_outof = 5;
	rating_table_value = "";
	rating_table_value = rating_table_value + "<table border=0 bgcolor=#F7F7F7 width=100%><tr>";
	if (browser_type == "Microsoft Internet Explorer" && (browser_version >= 4))
	{rating_table_value = rating_table_value + "<td align=center width=50% valign=bottom><FONT SIZE=1 COLOR=BLUE>Rate this deal</FONT></td><td align=left width=30%><span class=\"unit-rating\">";}
	else{rating_table_value = rating_table_value + "<td align=center valign=bottom width=50%><FONT SIZE=1 COLOR=BLUE >Rate this deal</FONT><td align=left width=30%><div class=\"unit-rating\">";}
	if(rating > 0)
	{rating_table_value = rating_table_value + "<a class='current-rating' href='#' style='width:" + (rating * imagePixelSize) + "px;'>Your rating.</a>";}
	for(i = 1; i <=5 ; i++)
	{rating_table_value = rating_table_value + "<a class=\"r"+i+"-unit\" href=\"#"+i+"\" onMouseOver=\"displayState('"+i+"','"+seqNumber+"','"+dealDate.replace(/-/g,'')+"'); window.status='www.edealinfo.com'; return true;\" onMouseOut=\"displayState('0','"+seqNumber+"','"+dealDate.replace(/-/g,'')+"')\"; onClick=\"ratingRequest('"+i+"','"+seqNumber+"','"+dealDate+"', 'Y')\"; target=\"_self\">"+i+"</a>";}
	if (browser_type == "Microsoft Internet Explorer" && (browser_version >= 4))
	{rating_table_value = rating_table_value + "</span></td>";}
	else{rating_table_value = rating_table_value + "</div></td>";}
	rating_table_value = rating_table_value + "<td  align=left width=15%><div id=\"result_"+dealDate.replace("-","").replace("-","")+seqNumber+"\"></div></td>";
	rating_table_value = rating_table_value + "<td align=left width=15%><div id=\"finalResult_"+dealDate.replace("-","").replace("-","")+seqNumber+"\"></div></td></tr></table>";
	document.getElementById("rating_table_"+dealDate.replace("-","").replace("-","")+seqNumber).innerHTML = rating_table_value;
}

function displayState(id, seqNumber ,dealDate)
{
	if(id == 0)
	{document.getElementById("result_"+dealDate+seqNumber).innerHTML = "";}
	else
	{	var result_val = "";
		switch(id)
		{
			case 1:   result_val = "Poor"; break;
			case 2:   result_val = "Average"; break;
			case 3:   result_val = "Good"; break;
			case 4:   result_val = "Very Good"; break;
			case 5:   result_val = "Excellent"; break;
		}

		if(isFinalRating == 0)
		{document.getElementById("result_"+dealDate+seqNumber).innerHTML = "<font color='red' SIZE=1>"+result_val+"</font>";}
		else
		{document.getElementById("finalResult_"+dealDate+seqNumber).innerHTML = "<font color='blue' SIZE=1>Your Rating: </font><font color='red' SIZE=1>"+finalRatingValue+"</font>";
		 isFinalRating = 0;
		}
	}
}

function ratingRequest(id, seqNo, dealDate, clickFlag)
{
	try
	{	var lastInsertedId = document.getElementById("TXT_LAST_INSERTED_ID_"+dealDate.replace("-","").replace("-","")+seqNo).innerHTML;
		document.getElementById("average_rating_"+dealDate.replace("-","").replace("-","")+seqNo).innerHTML = "<img src='/images/working.gif'><font color='gray' size=1> Processing...</font>";
		xmlHttp = GetXmlHttpObject();
		xmlHttp.open("post","/Includes/new_Includes/DealsPages/insertDealRating.php");
		updatedDate=dealDate.replace("-","").replace("-","");
		xmlHttp.onreadystatechange = receiveRating;
		xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlHttp.send("ID="+escape(id)+"&SEQ_NO="+escape(seqNo)+"&DEAL_DATE="+escape(dealDate)+"&IMG_PXL="+escape(imagePixelSize)+"&CLICK_FLAG="+escape(clickFlag)+"&LAST_INS_ID="+escape(lastInsertedId));
	}
	catch(e)
	{alert("Exception: Request Send Failed !!!!");}
}

// This function responsible for handling the response. And update the DOM contents.

function receiveRating()
{
	var final_result_val = "";
	var rating_outof = 5;
	try
	{	if(xmlHttp.readyState== 4)
		{	if (xmlHttp.status == 200)
			{	var response_t = xmlHttp.responseText;
				var arrayVal = response_t.split("|");
				document.getElementById("rating_table_"+updatedDate+arrayVal[1]).innerHTML =arrayVal[0];
				document.getElementById("finalResult_"+updatedDate+arrayVal[1]).innerHTML = "<font color='blue' size=1>Your Rating: </font><font color='red' size=1>"+arrayVal[3]+"</font>";
				document.getElementById("average_rating_"+updatedDate+arrayVal[1]).innerHTML = "<img src='/images/working.gif'><font color='gray' size=1> Completed.</font>";
				var workingTimer = setTimeout("document.getElementById(\"average_rating_"+updatedDate+arrayVal[1] +"\").innerHTML = \"\";",500);
				setTimeout("document.getElementById(\"average_rating_"+updatedDate+arrayVal[1] +"\").innerHTML = \"<font color='blue' size=1>Average Rating</font>: <font color='red'><B>"+arrayVal[5]+"/"+rating_outof+"</B></font> <font color='black' size=1>(total "+arrayVal[4]+" votes)</font>\";",1000);
				clearTimeout(workingTimer);
				document.getElementById("TXT_LAST_INSERTED_ID_"+updatedDate+arrayVal[1]).value =  arrayVal[6];
			}
		}
	}
	catch(e)
	{alert("Exception: Response Failed !!!!");}
}
/* End of Deal Rating  */
