﻿var currentRating;
var currentPage;
function ratePagePath() {
	var strHandlerPath = '/handlers/Rating.ashx';
	strHandlerPath+='?v='+currentRating+'&p='+currentPage;
	return strHandlerPath;
}
function ratePage(thisRating,thisPage){
    if(thisRating != null){
       currentRating=thisRating;
       currentPage=thisPage;
       InvokeAshxRating();
   }
}

////////////////////////////////////////////////////////
/* Invite Dedication AJAX functions */
////////////////////////////////////////////////////////

var fRatingCallback = function() {
	var intMaxResponseLength = 300;			//Max allowable chars in response.
	var bCatchConnectionErrors = false;		//For development, keep false.				
	
	
	//Custom error message in the event of failure.
	var errormsgHTML = 'An error occurred while processing the request.';
	
	if (xmlhttp.readyState==4) {	//If OK...
		try {
			////////////////////////////////////////////////////////
			var strResponse = xmlhttp.responseText; //Do something with the response.
			////////////////////////////////////////////////////////
			
			//no need to do anything here
			
		}
		catch (e) {
			//Put any error handling here.
			var strErrorExplanation = 'There was a problem handling the response. \n'
			var strStatusText = 'Status Text: ' + xmlhttp.statusText + '\n'
			var strError = 'Error: ' + e.toString();
			//alert(strErrorExplanation + strStatusText + strError);
            alert(strStatusText);
		}
	}
}

function InvokeAshxRating() {
    
	var strHttpCommandType = 'GET';
	var strHandlerPath = ratePagePath(); 
	//If asynchronous, set to true. Prevents page from hanging during ashx error.
	var bAsynch = true;	
    
    
	//////////////////////////////////////////////////////////////
	//Initialize the XmlHttpRequest, Set the callback function, make the request.
	//////////////////////////////////////////////////////////////
	InitXmlHttp();
	xmlhttp.onreadystatechange = fRatingCallback;
	xmlhttp.open(strHttpCommandType, strHandlerPath, bAsynch);
	xmlhttp.send(null);	//If command is GET, set to 'null'.
	//////////////////////////////////////////////////////////////
	
}

//////////////////////////////////////////////////////////////////
//Ajax Handler function.
//////////////////////////////////////////////////////////////////

function InitXmlHttp() {
	// Attempt to initialize xmlhttp object
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e) {
		// Try to use different activex object
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (E) {
			xmlhttp = false;
		}
	}
	// If not initialized, create XMLHttpRequest object
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {     
		xmlhttp = new XMLHttpRequest();
	}
}
