﻿
//Award points to the user by point id.
function $Award(pointid, catid) {
   //alert('Inside Award fxn! pointid=' + pointid + ' and pointcatid=' + catid);
   
   //See if the values are valid so we can add points.
	if (pointid.toString.length > 0 && 
		catid.toString.length > 0 && 
		IsNumeric(pointid) && 
		IsNumeric(catid)) {

		//alert('got past initial comparisons');

		var strHttpCommandType = 'GET';
		var strHandlerPath = '/mycorner/handlers/Points.ashx' 
		strHandlerPath += '?pointid=' + pointid;
		strHandlerPath += '&pointcatid=' + catid;
		strHandlerPath += '&m=addpointsbyidandcatid';
		
		var bAsynch = true;	
		InitXmlHttp();
		xmlhttp.onreadystatechange = $AwardCallback;
		xmlhttp.open(strHttpCommandType, strHandlerPath, bAsynch);
		
		
		//alert('$Award strHandlerPath is: ' + strHandlerPath);
		
		xmlhttp.send(null);
	}
	else {
		return;
	}
}

//We don't necessarily need this function to do anything...it's the callback for
//the $Award (points) function.
var $AwardCallback = function() {
	var intMaxResponseLength = 300;			
	var bCatchConnectionErrors = false;					
	
	var errormsgHTML = '$AwardCallback: An error occurred while processing the request.';
	var successmsgHTML = 'You have earned points.';
	
	if (xmlhttp.readyState==4) {	//If OK...
		try {
			////////////////////////////////////////////////////////
			var strResponse = xmlhttp.responseText; //Do something with the response.
			////////////////////////////////////////////////////////
			
			if (strResponse.length > intMaxResponseLength && bCatchConnectionErrors) {
				//If the length of the response exceeds the max, it's an error. Probably a 404 error.
				//Uncomment to show error
				//alert(errormsgHTML);
			}
			else {
				//The response length is good. Proceed with the callback execution.
				//alert(successmsgHTML);
			}
		}
		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);
			//Display friendly failure message.
			//alert(errormsgHTML);
		}
	}
}

