// ****************************** Validate.js ************************************
// This file has functions to validate field values on the client side before submiting.
// Most of these methods are accessed from the ValidateForm() function invoked in OnSubmit of
// any form.
// ****************************** Validate.js ************************************

function trim(userInput)
{
	var iEnd, iStart, bLoop, cChar, sTrimmed;

	iEnd = userInput.length - 1;
	iStart = 0;
	bLoop = true;

	cChar = userInput.charAt(iStart);
	while ((iStart < iEnd) && ((cChar == "\n") || (cChar == "\r") || (cChar == "\t") || (cChar == " ")))
	{
		iStart ++;
		cChar = userInput.charAt(iStart);
	}

	cChar = userInput.charAt(iEnd);
	while ((iEnd >= 0) && ((cChar == "\n") || (cChar == "\r") ||
                        (cChar == "\t") || (cChar == " ")))
	{
		iEnd --;
		cChar = userInput.charAt(iEnd);
	}

	if (iStart < iEnd)
	{
		sTrimmed = userInput.substring(iStart, iEnd + 1);
	} 
	else if(iStart == iEnd) 
	{
		sTrimmed = userInput;
	}
	else
	{
		sTrimmed = "";
	}

	return sTrimmed;	
}

function SetValue(name){						
	var arg= name + "=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while(i<clen){
		var j=i+alen;
		if (document.cookie.substring(i,j)==arg){
			var endstr=document.cookie.indexOf(";",j);
			if (endstr==-1)
				endstr=document.cookie.length;
			return unescape(document.cookie.substring(j, endstr));
		}
		i= document.cookie.indexOf(" ", i) +1;
		if (i==0) break;
	}
	return null;
}

function SetCookie(name, value, expiresOld){
	var now= new Date();
	var expires = new Date(now.getTime() + 1000 * 60 * 60 * 24 * 30);
	document.cookie= name+ "=" + escape (value) + "; expires=" +expires.toGMTString();
}

function CheckString(sCheckString){
	strCheck	= new String(sCheckString);
	bCheck="True";
	for (i=0; i < strCheck.length; i++){
		CheckChar=strCheck.charCodeAt(i);
		if ((CheckChar >= 33 && CheckChar <= 38) || (CheckChar >= 42 && CheckChar <= 43) || (CheckChar >= 58 && CheckChar <= 62) || (CheckChar >= 91 && CheckChar < 95) || (CheckChar >= 123 && CheckChar <= 126))
		{
			bCheck="False";
		}
	}
	if (bCheck=="False"){
		return false;
	}
	else{
		return true;
	}
}

function CheckAddString(sCheckString)
{
	strCheck	= new String(sCheckString);
	bCheck="True";
	for (i=0; i < strCheck.length; i++){
		CheckChar=strCheck.charCodeAt(i);
		if ((CheckChar > 39 && CheckChar <= 45) || (CheckChar == 47))
		{
			bCheck="False";
		}
	}
	if (bCheck=="False"){
		return false;
	}
	else{
		return true;
	}
}

function OpenHelpWindow(sHelpFile)
{
	var shelpFileLoc	= "TWKBHelp/" + sHelpFile;
	if (top.SoffrontHelp && !top.SoffrontHelp.closed){
		top.SoffrontHelp.close();
	}

 	var WindowWidth	= parseInt(screen.width * 0.521);
 	var WindowHeight= parseInt(screen.height* 0.464);
 	var WindowTop	= parseInt((screen.height-WindowHeight)/2);
 	var WindowLeft= parseInt((screen.width-WindowWidth)/2);
	top.SoffrontHelp = window.open(shelpFileLoc,"SoffrontHelp","Height="+WindowHeight+",Width="+WindowWidth+",top="+WindowTop+",left="+WindowLeft+",toolbar=yes,titlebar=no,scrollbars=yes,resizable=yes");
	top.SoffrontHelp.focus();	
}
