function GetBrowser()
{
	var xmlHTTP =null;
	try 
	{
		//firefox ,sarfari,opera;
		xmlHTTP   = new XMLHttpRequest();
	}
	catch (e)
	{
		//FOR IE
		try
		{
			xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");	
		}
		catch (E)
		{
			xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");			
		}
	}
	return xmlHTTP;
}

function showOverRating(imgId){
	var im=1;
	for(im = 1; im<=imgId; im++){
		document.getElementById("img"+im).src='yellow_star_17_16.gif'/*tpa=http://assets.chemistdirect.co.uk/include/validationscript/images/yellow_star_17_16.gif*/;
		document.getElementById("img"+im).alt='Click to rate';
		document.getElementById("img"+im).title='Click to rate';
	}
}
function showOutRating(imgId,ratingId,typerate){
	var im=1;
	//alert(ratingId);
	var cnt = 0;
	for(im = 1; im<=5; im++){
		if(im <= ratingId)
		{
			
			document.getElementById("img"+im).src=document.getElementById("orange_star_type").value;
			
			
		}
		else
		{
			cnt++;
			if(cnt == 1 && typerate == 'double')
				document.getElementById("img"+im).src=document.getElementById("orange_halfsquare_type").value;
			else
				document.getElementById("img"+im).src='grey_star_17_16.gif'/*tpa=http://assets.chemistdirect.co.uk/include/validationscript/images/grey_star_17_16.gif*/;
		}
	}
}
function showOverRatingRev(imgId){
	
	var im=1;
	for(im = 1; im<=imgId; im++){
		document.getElementById("imgr"+im).src='yellow_star_17_16.gif'/*tpa=http://assets.chemistdirect.co.uk/include/validationscript/images/yellow_star_17_16.gif*/;
	}
}
function showOutRatingRev(imgId,ratingId){
	var im=1;
	//alert(ratingId);
	for(im = 1; im<=5; im++){
		if(im <= ratingId)
		{
			document.getElementById("imgr"+im).src=document.getElementById("orange_star_type").value;
		}
		else
		{
			document.getElementById("imgr"+im).src='grey_star_17_16.gif'/*tpa=http://assets.chemistdirect.co.uk/include/validationscript/images/grey_star_17_16.gif*/;
		}
	}
}
function showOverRatingBar(imgId,type){
	var im=1;
	for(im = 1; im<=imgId; im++){
		document.getElementById("img"+type+im).src='yellow_square.gif'/*tpa=http://assets.chemistdirect.co.uk/include/validationscript/images/yellow_square.gif*/;
	}
}
function showOutRatingBar(imgId,type){
	var im=1;
	var vote = document.getElementById('rating11').value;
	
	for(im = 1; im<=imgId; im++){
		if(im <= vote)
		{
			document.getElementById("img"+type+im).src=document.getElementById("orange_square_type").value;
		}
		else
		{
			document.getElementById("img"+type+im).src='gray_square.gif'/*tpa=http://assets.chemistdirect.co.uk/include/validationscript/images/gray_square.gif*/;
		}
	}
}

function showOverRatingVideo(imgId,vCNT){
	var im=1;
	for(im = 1; im<=imgId; im++){
		document.getElementById("img_video_"+vCNT+"_"+im).src='yellow_star_17_16.gif'/*tpa=http://assets.chemistdirect.co.uk/include/validationscript/images/yellow_star_17_16.gif*/;
		document.getElementById("img_video_"+vCNT+"_"+im).alt='Click to rate';
		document.getElementById("img_video_"+vCNT+"_"+im).title='Click to rate';
	}
}
function showOutRatingVideo(imgId,ratingId,vCNT){
	var im=1;
	
	for(im = 1; im<=5; im++){
		if(im <= ratingId)
			document.getElementById("img_video_"+vCNT+"_"+im).src=document.getElementById("orange_star_type").value;
		else
			document.getElementById("img_video_"+vCNT+"_"+im).src='grey_star_17_16.gif'/*tpa=http://assets.chemistdirect.co.uk/include/validationscript/images/grey_star_17_16.gif*/;
	}
}

function doUpdateProductRating(prodId, vote){
	
		var pb_type=document.getElementById("pb_set").value;
		url = "http://assets.chemistdirect.co.uk/include/validationscript/product_rating_update.php";
		var param ="prodid="+prodId+"&vote="+vote+"&type=product&pb_type="+pb_type;
		//alert(param);
		var xmlhttp =  new GetBrowser();
		xmlhttp.open('POST', url, true);                      
		
		/* The callback function */
		//document.getElementById('div_rating').style.display='';
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
			
			var objDetails = xmlhttp.responseText;
			//alert(objDetails);
			if(objDetails != null){
				splitObjDetails = objDetails.split('|-|');
				 	document.getElementById("rating").innerHTML=splitObjDetails[0];
 					document.getElementById("rated").innerHTML = splitObjDetails[1];
					document.getElementById("revmsg").innerHTML='Thanks for rating, click to write a quick review.';
					//document.getElementById("reviewDiv").innerHTML=splitObjDetails[0];
			}
					
			}
		}                  
		
		/* Send the POST request */
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlhttp.send(param);	
}

function doUpdateProductRatingFromReviewNew(prodId, vote, calledpage){
	
		//alert(calledpage);return false;
		var pb_type=document.getElementById("pb_set").value;
		url = "http://assets.chemistdirect.co.uk/include/validationscript/product_rating_update_new.php";
		var param ="prodid="+prodId+"&vote="+vote+"&type=product&pb_type="+pb_type;
		//alert(param);
		var xmlhttp =  new GetBrowser();
		xmlhttp.open('POST', url, true);                      
		
		/* The callback function */
		//document.getElementById('div_rating').style.display='';
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
			
			var objDetails = xmlhttp.responseText;
			//alert(objDetails);
			if(objDetails != null){
				splitObjDetails = objDetails.split('|-|');
				 	
					if(calledpage==1)
					{
					document.getElementById("rating").innerHTML=splitObjDetails[0];
 					document.getElementById("rated").innerHTML = splitObjDetails[1];
					document.getElementById("revmsg").innerHTML='Thanks for your review';
					}else
					{
						document.getElementById("hideType").innerHTML='done';
						}
					//document.getElementById("reviewDiv").innerHTML=splitObjDetails[0];
			}
					
			}
		}                  
		
		/* Send the POST request */
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlhttp.send(param);	
}

function doUpdateProductRating_multiple(prodId, vote){
	
		url = "http://assets.chemistdirect.co.uk/include/validationscript/product_rating_update.php";
		var param ="prodid="+prodId+"&vote="+vote+"&type=product";
		//alert(param);
		var xmlhttp =  new GetBrowser();
		xmlhttp.open('POST', url, true);                      
		
		/* The callback function */
		//document.getElementById('div_rating').style.display='';
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
			
			var objDetails = xmlhttp.responseText;
			//alert(objDetails);
			if(objDetails != null){
				//alert(objDetails);
				splitObjDetails = objDetails.split('|-|');
				
				//alert(splitObjDetails);
				 	document.getElementById(prodId+"rating").innerHTML=splitObjDetails[0];
					if(splitObjDetails[1].replace('customers rated this','') > 1)
					{
 						document.getElementById(prodId+"_cust_cnt").innerHTML =  trimAll(splitObjDetails[1].replace('customers rated this',''))+' Ratings';
					}
					else
					{
 						document.getElementById(prodId+"_cust_cnt").innerHTML =  trimAll(splitObjDetails[1].replace('customers rated this',''))+' Rating';
					}
				}
					
			}
		}                  
		
		/* Send the POST request */
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlhttp.send(param);	
	
}
function doUpdateVideoRating(videoId, vote,vCNT){
	
		var pb_type=document.getElementById("pb_set").value;
		url = "http://assets.chemistdirect.co.uk/include/validationscript/product_rating_update.php";
		var param ="videoid="+videoId+"&vote="+vote+"&type=video&pb_type="+pb_type;
		//alert(param);
		var xmlhttp =  new GetBrowser();
		xmlhttp.open('POST', url, true);                      
		
		/* The callback function */
		//document.getElementById('div_rating').style.display='';
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
			
			var objDetails = xmlhttp.responseText;
			//alert(objDetails);
			if(objDetails != null){
					document.getElementById("rateVideo"+vCNT).innerHTML=objDetails;
					document.getElementById("revvideomsg"+vCNT).style.display='';
					document.getElementById("revvideomsg"+vCNT).innerHTML='<span class="floatl text13">Thanks for rating</span>';
			}
					
			}
		}                  
		
		/* Send the POST request */
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlhttp.send(param);	
	
}
function doLoadProductRating(prodid,type){

	if(document.getElementById('url_type'))
		var url_type = document.getElementById('url_type').value;
		
	if(type == 0)
	{
		var divname = 'reviewdiv';
		var rating = '';
		document.getElementById(divname).style.height = '';
		document.getElementById(divname).style.overflow = 'hidden';
	}
	else if(type == 1)
	{
		var divname = 'ratingDiv';
		var rating = document.getElementById('rating11').value;
	}

	if(document.getElementById("pb_set"))
		var pb_type=document.getElementById("pb_set").value;
	
	if(document.getElementById('no_review') != null || document.getElementById('no_review') != undefined)
		var no_review='yes';
	else
		var no_review='no';
		
		var url = "http://assets.chemistdirect.co.uk/include/validationscript/write_a_review.php";
		var param ="prodid="+prodid+"&type="+type+"&rate="+rating+"&no_review="+no_review+"&pb_type="+pb_type+"&url_type="+url_type;
		//alert(url);
		var xmlhttp =  new GetBrowser();
		xmlhttp.open('POST', url, true);   
		/* The callback function */
		//document.getElementById('div_rating').style.display='';
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
			var objDetails = xmlhttp.responseText;
			
			/*alert(objDetails);
			return false;*/
			if(objDetails != null){
				if(document.getElementById('no_review') != null || document.getElementById('no_review') != undefined)
				{
					document.getElementById('no_review').style.display='';
				}
				if(document.getElementById('rating_revcnt') != null || document.getElementById('rating_revcnt') != undefined)
				{
					document.getElementById('rating_revcnt').innerHTML = rating+' / 5';
				}
				document.getElementById(divname).innerHTML = objDetails;
				document.getElementById('fname').focus();
				
			}
					
			}
			//alert(xmlhttp.readyState);
		}                  
		
		/* Send the POST request */
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlhttp.send(param);	
}

function doLoadProductRating1(prodid,type){

	if(document.getElementById('url_type'))
		var url_type = document.getElementById('url_type').value;
		
	if(type == 0)
	{
		var divname = 'reviewdiv';
		var rating = '';
		document.getElementById(divname).style.height = '';
		document.getElementById(divname).style.overflow = 'hidden';
	}
	else if(type == 1)
	{
		var divname = 'ratingDiv';
		var rating = document.getElementById('rating11').value;
	}
	if(document.getElementById("pb_set"))
		var pb_type=document.getElementById("pb_set").value;
	
	if(document.getElementById('no_review') != null || document.getElementById('no_review') != undefined)
		var no_review='yes';
	else
		var no_review='no';
		
		var url = "http://assets.chemistdirect.co.uk/include/validationscript/write_a_review.php";
		var param ="prodid="+prodid+"&type="+type+"&rate="+rating+"&no_review="+no_review+"&pb_type="+pb_type+"&url_type="+url_type;
		var xmlhttp =  new GetBrowser();
		xmlhttp.open('POST', url, true);   
		/* The callback function */
		//document.getElementById('div_rating').style.display='';
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
			var objDetails = xmlhttp.responseText;
			
			//alert(objDetails);
			//return false;
			if(objDetails != null)
			{
				if(document.getElementById('no_review') != null || document.getElementById('no_review') != undefined)
				{
					document.getElementById('no_review').style.display='';
				}
				if(document.getElementById('rating_revcnt') != null || document.getElementById('rating_revcnt') != undefined)
				{
					document.getElementById('rating_revcnt').innerHTML = rating+' / 5';
				}
					document.getElementById(divname).innerHTML = objDetails;
					document.getElementById('fname').focus();
				
			}
					
			}
			//alert(xmlhttp.readyState);
		}                  
		
		/* Send the POST request */
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlhttp.send(param);	
}

function doUpdateProductRating1(prodId, vote){
	
	//alert(prodId+" && "+vote);
	var pb_type=document.getElementById("pb_set").value;
		url = "http://assets.chemistdirect.co.uk/include/validationscript/product_rating_update.php";
		var param ="prodid="+prodId+"&vote="+vote+"&type=product&pb_type="+pb_type;
		//alert(param);
		var xmlhttp =  new GetBrowser();
		xmlhttp.open('POST', url, true);                      
		
		/* The callback function */
		//document.getElementById('div_rating').style.display='';
		xmlhttp.onreadystatechange = function() {
			if (xmlhttp.readyState == 4) {
			
			var objDetails = xmlhttp.responseText;
			//alert(objDetails);
			if(objDetails != null){
				splitObjDetails = objDetails.split('|-|');
				 	document.getElementById("rating").innerHTML=splitObjDetails[0];
 					document.getElementById("rated").innerHTML = splitObjDetails[1];
					document.getElementById("revmsg").innerHTML='Thanks for rating, click to write a quick review.';
					//document.getElementById("reviewDiv").innerHTML=splitObjDetails[0];
			}
					
			}
		}                  		
		/* Send the POST request */
		xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		xmlhttp.send(param);	
}
