﻿// JScript File

 /*************************************************
        Validates that only alpha-numeric characters and spaces are entered
        **************************************************/
        function NumericKeyPress(passedEvent)
        {
            //only alpha-numeric characters are allowed - first character must not be a number
            var objEvent = (passedEvent==null)? window.event: passedEvent;//for mozilla compatibility
            var keyCode = (navigator.appName == "Netscape")? objEvent.which: objEvent.keyCode;
        	
            if(keyCode < 30)
	            return;
            if((keyCode>=48 && keyCode<59))
	            return true;
            else 
	            return false;
        	
        }
            
        /*************************************************
        Validates that only alpha-numeric characters are entered
        **************************************************/
        function AlphaNumericKeypress(passedEvent)
        {
	        //only alpha-numeric characters are allowed - first character must not be a number
	        var objEvent = (passedEvent==null)? window.event: passedEvent;//for mozilla compatibility
	        var keyCode = (navigator.appName == "Netscape")? objEvent.which: objEvent.keyCode;
        	
            if((keyCode >= 97 && keyCode <=122) || (keyCode >= 65 && keyCode <=90) || (keyCode == 8) || (keyCode == 0))
		        return true;
	        else 
		        return false;
        	
        }
        
        /*************************************************
        Validates that Special Characters are not allowed except "-" and "_"
        **************************************************/
        function SpecialCharacterNotAllowed(passedEvent)
        {
            var objEvent = (passedEvent==null)? window.event: passedEvent;//for mozilla compatibility
            var keyCode = (navigator.appName == "Netscape")? objEvent.which: objEvent.keyCode;
            if(((keyCode>=33 && keyCode<=47) || (keyCode>=58 && keyCode<=64) || (keyCode>=91 && keyCode<=96) || (keyCode>=123 && keyCode<=126)) && keyCode!=45 && keyCode!=95)
                return false;
            else
                return true;
        }

/***************************************************************************************************
SendAJAXRequest:  Use this function to send AJAX requests to a predefined server side ASHX handler
functionName - The name of server side function to be called - this function is actually some server side code block that returns data
queryString - querystring to be sent to server side function 
callBackFunction - 
	the client side function that will be called when data comes from server side;  Get data in XML format from http.responseXML or in text 
	format from http.responseText, depending upon the way you are returning data from your server side block

	Put the following status check in your client side function
			if (http.readyState != 4 || http.status != 200 )
				return;


***************************************************************************************************/
var http = null;//HTTP object
function SendAJAXRequest(functionName, queryString, callBackFunction)
{
    if(navigator.appName != "Netscape")
		http = new ActiveXObject("Microsoft.xmlhttp");
	else
		http = new XMLHttpRequest();
	var root = window.location.pathname.split("/")[1];alert(root);
	var strAjaxPath = strAppPath+"AJAXFunctions.ashx?Function="+functionName+"&"+queryString;
	//http.open("GET", "/"+root+"/AJAXFunctions.ashx?Function="+functionName+"&"+queryString, true); 
	http.open("GET", strAjaxPath, true); 
	http.onreadystatechange = callBackFunction;
	http.send(null);	
}

/********************************************************************************************
Basic Ajax function for Help page to get the keywords.
********************************************************************************************/
    function myAjax()
    {        
        var keyword = document.getElementById("txtHelpText").value;

        ParameterList="keyword="+keyword;//Sending Data Using Make String   
                 
        var ajax;
        try
        {                
            ajax = new XMLHttpRequest();// Firefox, Opera, and the like                
        }
        catch (e)
        {
            try
            {
             ajax= new ActiveXObject("Msxm12.XMLHTTP");//Internet Exploder?
            }
            catch (e)
            {
                try
                {
                   ajax = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (e)
                {
                    alert("Don't bother, your browser doesnt support AJAX");
                }
            }
        }
        var root = window.location.pathname.split("/")[1];
        ajax.open('POST','/'+root+"/AJAXFunctions.ashx?Function=GetHelplist&"+ParameterList, 'true'); //First Argument Method Of Transfer Data,Second Argument Page Name,...
        ajax.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        ajax.setRequestHeader("Content-length",  ParameterList.length);//Sending Data Len
        ajax.setRequestHeader("Connection", "close");
        ajax.send(ParameterList);//Send Data To Specific Page
        ajax.onreadystatechange  = function()
         { 
           if(ajax.readyState  == 4)
             { 
                var Separator1 = "<tr>";
                var Separator2 = "<td>";
                var i = 0;
                var keywords = ajax.responseText.split(Separator1);
                document.getElementById("lstHelp").selectedIndex = -1;
                document.getElementById("lstHelp").options.length = 0;
                for (i = 0; i < keywords.length - 1 ; i++)
                {
                    var values = keywords[i].split(Separator2);
                    var opt = document.createElement("OPTION");
                    opt.text = values[0];
                    opt.value = values[1];
                    document.getElementById("lstHelp").options.add(opt);
                    document.getElementById("lstHelp").options[0].selected = true;
                }
                document.getElementById("lstHelp").selectedIndex = 0;
                SetDescription();
             }
         };          
      }
          
    function SetDescription()
    {
        var lstbox = document.getElementById("lstHelp");
        if(lstbox.selectedIndex >= 0)
        {
            var desc = lstbox.options[lstbox.selectedIndex].value;
            document.getElementById("tdLabel").innerHTML = desc;
        }
}
