// JavaScript Document

var EMPTY				=-1;

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=='chkElect' || objName=='ttlElect')
		{
			isblank=false;
		}
		else
		{
			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 two strings
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 winkBlock (strrowname)
{
	objRow = document.getElementById(strrowname);
	
	objRow.style.display = (objRow.style.display=="none" ? "block" : "none");
}
