﻿// JScript File

// JScript File

var xmlhttp;
var addWebPageHistoryURL = "./addWebPageHistory.aspx?";

function addWebPageHistory(idName,applicationID,webPageID,webPageEventTypeID)
{
    
    //This is a more efficient and faster means of building/concatenating together a list of name value pairs
    var aParams = new Array();
    aParams.push(encodeNameAndValue("idName",idName));
    aParams.push(encodeNameAndValue("applicationID",applicationID));
    aParams.push(encodeNameAndValue("webPageID",webPageID));
    aParams.push(encodeNameAndValue("webPageEventTypeID",webPageEventTypeID));
    var sNameValuePairs = aParams.join("&");
    var url = addWebPageHistoryURL; 
    
    getHTTPRequestObject();
    
    if(xmlhttp)
    {
        xmlhttp.open("POST", url + sNameValuePairs, true);
        xmlhttp.onreadystatechange = postCallback;
        xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
        xmlhttp.send(sNameValuePairs);
    }

}

function getHTTPRequestObject()
{

    if (window.ActiveXObject)
    {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if (window.XMLHttpRequest)
    {
        xmlhttp = new XMLHttpRequest();
    }

}


function encodeNameAndValue(sName, sValue)
{
    var sParam = encodeURIComponent(sName);
    sParam += "=";
    sParam += encodeURIComponent(sValue);
    return sParam;
}

function postCallback(response)
{
             
    if(xmlhttp.readyState == 4)
    {             
  
        if(xmlhttp.status == 200)
        {
                
                            //read the response headers
            /*                            
            var sHeaders = xmlhttp.getAllResponseHeaders();
            var aHeaders = sHeaders.split(/\r?\n/);
            
            for (var i = 0; i < aHeaders.length; i++)
            {
                alert(aHeaders[i]);
            }
            */
 
             eval('var objResults = ' + xmlhttp.responseText);
            
            for (var i = 0; i < objResults.Results.pageHitThreshold.length; i++)
            {
                var hitCount = objResults.Results.pageHitThreshold[i].hitCount; 
                  
                if (hitCount > 0)
                {
                    alert("You have exceeded the page hit threshold.");
                }            
            }           
            
            
        }
        
    }
    
}



