// JavaScript Document

var EMPTY				=-1;

var xmlHTTP = false;

// Checking if whether we are using IE 
try 
{
	// If the Javascript version is greater than 5
	xmlHTTP = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (ex)
{
	try 
	{
		// If not then use the older Active X Object
		xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
	}
	catch (ex2)
	{
		// The browser is other than IE
		xmlHTTP = false;
	}
}

//If we are using a non-IE browser, create a javascript instance of the object.
if (!xmlHTTP && typeof XMLHttpRequest != 'undefined') 
{
	xmlHTTP = new XMLHttpRequest();
}


function ascii_value (ch)
{
	var i, h;

	ch=ch.charAt(0);

	for (i=0; i<256; i++)
	{
		h=i.toString(16);
		if (h.length==1)
			h="0"+h;

		h="%"+h;
		h=unescape(h);
		if (h==c)
			break;
	}
	return i;
}

// Function for validating a form by object name
function ValidateFormByName(frm)
{
	isblank=false;
	for (cnt=0; cnt<frm.length && (!isblank); cnt++)
	{
		objName=frm.elements[cnt].name;
		
		if(objName.substring(0, 3)=="cmb" && frm.elements[cnt].value==EMPTY)
			isblank=true;
		else if(objName.substring(0, 3)!="emp" && frm.elements[cnt].value=="")
			isblank=true;
	}		
	
	if (isblank)
		return (--cnt);
	else
		return EMPTY;
}

// Function for validating form by object ID
function ValidateFormByID(frm)
{
	isblank=false; 
	for (cnt=0; cnt<frm.length && (!isblank); cnt++)
	{
		objName=frm.elements[cnt].id;
		if(objName.substring(0, 3)=="lst" && frm.elements[cnt].value==EMPTY)
			isblank=true;
		else if(objName.substring(0, 3)!="emp" && frm.elements[cnt].value=="")
			isblank=true;
	}		
	
	if (isblank)
		return (--cnt);
	else
		return EMPTY;
}

// Funtion for verifying an Email Address
function isEmailAddress(strEmailAddress)
{
	objEmailAddress = document.getElementById (strEmailAddress);
	
	EmailAddress	= objEmailAddress.value;
	
	if (EmailAddress.indexOf("@")<0 || EmailAddress.indexOf(".")<0)
		return false;
	else
		return true;
}

// Function for matching the two password given
function isValueMatch(strNameFirst, strNameSecond)
{
	// Retrieving Object Referenes
	objFirst 		= document.getElementById(strNameFirst);
	objSecond 		= document.getElementById(strNameSecond);

	strFirstValue	= objFirst.value;
	strSecondValue	= objSecond.value;
	
	if (strFirstValue!=strSecondValue)
		return false;
	else
		return true;
}

function verifyDelete (url, id, pgno, identifier)
{
	if (confirm("You are about to delete this information.\nDo you wish to continue?"))
		document.location= url + "?md=rm&" + identifier + "=" + id + "&pgno=" + pgno;
}

function gotoPage (txtid, url)
{
 	txtObj = document.getElementById(txtid);
	
	if (txtObj.value==0)
		return;
	
	document.location = url + "?pgno=" + txtObj.value;
}

function winkRow (strrowname)
{
	objRow = document.getElementById(strrowname);
	
	objRow.style.display = (objRow.style.display=="none" ? "block" : "none");
}

// For implementing Ajax
function MakePostRequest (serverPage, objID, frm)
{
	var strQueryString="";
	var obj = document.getElementById(objID);
	
	// Creating a QueryString for PostMethod
	for (cnt=0; cnt<frm.length; cnt++)
		strQueryString = strQueryString + frm.elements[cnt].name + "=" + frm.elements[cnt].value + "&";
		
	xmlHTTP.open("POST", serverPage, true);
	xmlHTTP.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	xmlHTTP.setRequestHeader("Content-length", strQueryString.length);
	xmlHTTP.setRequestHeader("Connection", "close");
	
	xmlHTTP.onreadystatechange = function() 
	{
		// alert(xmlHTTP.readyState + ' and Status is ' + xmlHTTP.status);
		if (xmlHTTP.readyState == 4 && xmlHTTP.status == 200)
		{
			// alert(obj.name);
			// alert(xmlHTTP.responseText);
			obj.innerHTML = xmlHTTP.responseText;
		}
	}
	xmlHTTP.send(strQueryString);
}

function MakeGetRequest(serverPage, objID)
{
	var obj = document.getElementById(objID);
		
	xmlHTTP.open("GET", serverPage, true);
	xmlHTTP.onreadystatechange = function() 
	{
		// alert(xmlHTTP.readyState + ' and Status is ' + xmlHTTP.status);
		if (xmlHTTP.readyState == 4 && xmlHTTP.status == 200)
		{
			// alert(obj.name);
			// alert(xmlHTTP.responseText);
			obj.innerHTML = xmlHTTP.responseText;
		}
	}
	xmlHTTP.send(null);
}