/**************************************************************************************/
//		FUNCTION:		IsEmpty
//		PARAMETERS:		
//			f:Form Field Name
//			minLen: minimum required length;
//			maxLen: maximum required length
//		CALLS:
//			TrimLeft (str AS String)			
//		RETURNS:
//			true:	 If the fields has a zero-lenght value or null value
//			false: 	If the field has some value.
/**************************************************************************************/
function IsEmpty (f, minLen, maxLen) {
	var OK = false;
		
	if (f.value == null)
		OK = true;
	else {
		var val = TrimLeft(f.value);
		var strLen = val.length;
	
               if (strLen == 0)
			 OK = true;
		else {
			if ((minLen > 0) && (strLen < minLen))
				 OK = true;
			if  ((maxLen > 0) && (strLen > maxLen))
				 OK = true;
		}
	}
			
	return(OK);
}


function IsLength (f, minLen, maxLen) {
	var OK = false;
	if (f.value == null)
		 OK = true;
	else {
		var val = TrimLeft(f.value);
		var strLen = val.length;
		
		if (strLen == 0)
			OK = true;
		else {
			if ((minLen > 0) && (strLen < minLen))
				OK = true;
			if  ((maxLen > 0) && (strLen > maxLen))
				OK = true;
		}
	}
			
	return(OK);
}
/**************************************************************************************/
//		FUNCTION:			CheckDate
//		PARAMETERS:		
//								fld1:	List of options in the <select name="MONTH"></select> 
//								fld2:	List of options in the <select name="DAY"></select>
//								fld3:	List of options in the <select name="YEAR"></select>
//		RETURNS:		
//			true: If the fields has a zero-lenght value or null value
/**************************************************************************************/
function CheckDate(fld1, fld2, fld3) {
	var OK = true;
	
	var maxDays = 31;
	var m = parseInt(fld1.options[fld1.options.selectedIndex].value);
	var y = parseInt(fld3.options[fld3.options.selectedIndex].value)
	
	if (m==4 || m==6 || m==9 || m==11) maxDays = 30;
	else if (m==2) {
		if (y % 4 > 0) maxDays = 28;
		else if (y % 100 == 0 && y % 400 > 0) maxDays = 28;
        else maxDays = 29;
	}
	
	for (var i=0; i<fld2.options.length; fld2.options[i++] = null) ;
	for (var i=0; i<maxDays; i++) fld2.options[i] = new Option (i+1, i+1, false, false)
	
	fld2.options[0].selected = true;
	
	return (OK)	
}
/*********************************************************************************
*	FUNCTION:		newWindow
*	PARAMETERS:
		doc: 	Document to open in the new window
		hite: 	Height of the new window
		wide:	Width of the new window
		bars:	1-Scroll bars = YES 0-Scroll Bars = NO
		resize 	1-Resizable = YES 0-Resizable = NO
*	CALLS:	NONE
*	RETURNS:		New window instance
**********************************************************************************/
function newWindow (doc, hite, wide, bars, resize) {
	var winNew="newWindow";
	var opt="toolbar=0,location=0,directories=0,status=0,menubar=0,";
	opt+=("scrollbars="+bars+",");
	opt+=("resizable="+resize+",");
	opt+=("width="+wide+",");
	opt+=("height="+hite);
	winHandle=window.open(doc,winNew,opt);
	
	return;
}





/*********************************************************************************
*	FUNCTION:		IsDigit
*	PARAMETER:		Any Chracter
*	CALLS			isEmpty to check the NULL
*	RETURNS:		TRUE if the passed chracter is a digit, otherwise FALSE
**********************************************************************************/
function IsDigit(theNum) {
	var OK = false;
	var theMask = '0123456789';
	
	if (theMask.indexOf(theNum) != -1) OK = true;
	
        return(OK);
}
/*********************************************************************************
*	FUNCTION:		IsInt
*	PARAMETER:		
*		f:	The form field name
*	RETURNS:		TRUE if the passed parameter is an integer, otherwise FALSE
*	CALLS:			IsDigit
**********************************************************************************/
function IsInt (f) {
	var OK = false;
	
	if (!IsEmpty(f)) {
		var f_Val = f.value;
	
		for (var i=0; i<f_Val.length; i++) {
			OK = IsDigit(f_Val.substring(i,i+1));
			if (!OK) break;
		}

	}

	return(OK);
}
/*********************************************************************************
*	FUNCTION:		isReal
*	PARAMETER:		theStr	AS String 
							decLen	AS Integer (how many digits after period)
*	RETURNS:		TRUE if theStr is a float, otherwise FALSE
*	CALLS:			isInt
**********************************************************************************/
function IsReal (f, decLen) {
	var OK = false;
		
	if (!IsEmpty(f)) {
		if (IsInt(f)) OK = true;
		else {
			var theStr = f.value;
			var dot1st = theStr.indexOf('.');
			var dot2nd = theStr.lastIndexOf('.');
		
			if ((dot1st == dot2nd) && (dot1st > 0)) {
				var intPart = theStr.substring(0, dot1st);
				var decPart = theStr.substring(dot2nd+1);
				
				for (var i=0; i<intPart.length; i++) {
					OK = IsDigit(intPart.substring(i,i+1));
					if (!OK) break;
				}
				
				if (OK) 
					for (var i=0; i<decPart.length; i++) {
						OK = IsDigit(decPart.substring(i,i+1));
						if (!OK) break;
					}
			}
		}
	}
	
	return (OK);
}
/*********************************************************************************
*	FUNCTION:		TrimLeft (str)
*		Trims the left spaces of a string	
*	PARAMETER:		str	AS String 
*	RETURNS:		the trimed string
**********************************************************************************/
function TrimLeft (str) {
	var pos = -1;

	if (str.length > 0) 
		while (str.substring(++pos, pos+1) == " ");
	else pos = 0;
			
	return (str.substring(pos, str.length));
}
/*********************************************************************************
*	FUNCTION:		tickSession (timeRemains, redirectURL)
*		Counts the number of remaining seconds of SessionTimeout and redirect to the specified 
*		as the session times out.
*	PARAMETER:		timeRemains	AS int, the ramaining number of seconds
*					redirectURL AS String, the URL to be redirectd as the session expires
*	RETURNS:		NOTHING
**********************************************************************************/
function tickSession(timeRemains, redirectURL) {	
	var timeOut = timeRemains
	var str = "This session expires in " + parseInt(timeOut/60) + " minutes, " + parseInt(timeOut%60) + " seconds."

	winDesktop.status = str;
		
	timeOut--;
	
	if (timeOut <= 0) winDesktop.location = redirectURL;
	else winDesktop.setTimeout("tickSession("+timeOut+",'"+redirectURL+"')",1000);
	
	return;
}
/*********************************************************************************
*	FUNCTION:		tickSession (timeRemains, redirectURL)
*		Counts the number of remaining seconds of SessionTimeout and redirect to the specified 
*		as the session times out.
*	PARAMETER:		timeRemains	AS int, the ramaining number of seconds
*					redirectURL AS String, the URL to be redirectd as the session expires
*	RETURNS:		NOTHING
**********************************************************************************/
function closeAfter(winHandle, timeClose)   {	
	var timeOut = timeClose;
	var str = "This window will close after " + timeClose + " seconds.";
	
	winHandle.status = str;
	timeOut--;

	if (timeOut <= 0) alert ("CLOSING"); //winHandle.close();
	else closeAfter(winHandle, timeOut);
	//winHandle.setTimeout("closeAfter("+winHandle + "," + timeOut + ")",1000);
	
	return;
}
/*********************************************************************************
*	FUNCTION:		opens a new window and return the window handler;
*		newURL: 	the new location to open;
*		winName: 	the window name
*		winHeight:	 Height of the new window in pixels
*		winWidth:	Width of the window i pixels
*		posLeft:		postion of the window from left of the screen	
*		posTop:		postion of the window from top of the screen 
**********************************************************************************/
function openDialog(newURL, winName, winHeight, winWidth, posLeft, posTop)
{	
	var winHandel;
	var winOptions = "";
	
	winOptions += "width=" + winWidth + ",height=" + winHeight +",left=" + posLeft + ",top=" + posTop;
	winOptions += ",toolbar=0,menubar=0,scrollbars=1,resizable=0,status=0,location=0;directories=0";
	
	winHandel = window.open(newURL, winName, winOptions);
	
	return 	(winHandel);
}
/*********************************************************************************
*		FUNCTION:		returns true if the str contains a space
**********************************************************************************/
function hasSpace (str) {
	var space_found = false;
	var cnt = 0;
	
		
	
	while ((!space_found) && (cnt < str.length)) {
		if (str.charAt(cnt++) ==' ') space_found = true;
		 
	}
	
	return (space_found);
}
/*********************************************************************************
*		FUNCTION:		returns true if the str contains a special chracter
**********************************************************************************/
function hasInvalidCh (str) {
	var invalid_found = false;
	var cnt = 0;
	var loChars = "abcdefghijklmnopqrstuvwxyz ";
	var upChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ ";
	var digits = "0123456789";
		
	while ((!invalid_found) && (cnt < str.length)) {
		ch = str.charAt(cnt++);
		if (!((loChars.indexOf(ch) > -1) || (upChars.indexOf(ch) > -1) || (digits.indexOf(ch) > -1)))
			invalid_found = true;
	}
	
	return (invalid_found);
}
/*


*/

/*

Start of new function
*/

function hasInvalidname (str) {
	
        var invalid_found = false;
	var cnt = 0;
	var loChars = "abcdefghijklmnopqrstuvwxyz";
	var upChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var digits = "-. ";
	
	while ((!invalid_found) && (cnt < str.length)) {
		ch = str.charAt(cnt++);
		if (!((loChars.indexOf(ch) > -1) || (upChars.indexOf(ch) > -1) || (digits.indexOf(ch) > -1)))
			invalid_found = true;
	}
	
	return (invalid_found);
}

/*

*/

function IsCharacter (str) {
	
        var invalid_found = false;
	var cnt = 0;
	var loChars = "abcdefghijklmnopqrstuvwxyz";
	var upChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	
	
	while ((!invalid_found) && (cnt < str.length)) {
		ch = str.charAt(cnt++);
		if (!((loChars.indexOf(ch) > -1) || (upChars.indexOf(ch) > -1)))
			invalid_found = true;
	}
	
	return (invalid_found);
}
/*


*/
function hasInvalidaddress (str) {
	
        var invalid_found = false;
	var cnt = 0;
	var loChars = "abcdefghijklmnopqrstuvwxyz";
	var upChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var digits = "0123456789";		
	var extrachars = "-.#/, ";
	
	while ((!invalid_found) && (cnt < str.length)) {
		ch = str.charAt(cnt++);
		if (!((loChars.indexOf(ch) > -1) || (upChars.indexOf(ch) > -1) || (digits.indexOf(ch) > -1) || (extrachars.indexOf(ch) > -1)))
			invalid_found = true;
	}
	
	return (invalid_found);
}


function hasInvalidDescription (str) {
	
        var invalid_found = false;
	var cnt = 0;
	var loChars = "abcdefghijklmnopqrstuvwxyz";
	var upChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	var digits = "0123456789";		
	var extrachars = "-., ";
	
	while ((!invalid_found) && (cnt < str.length)) {
		ch = str.charAt(cnt++);
		if (!((loChars.indexOf(ch) > -1) || (upChars.indexOf(ch) > -1) || (digits.indexOf(ch) > -1) || (extrachars.indexOf(ch) > -1)))
			invalid_found = true;
	}
	
	return (invalid_found);
}




function IsEmail (theStr) {
	var atIndex = theStr.indexOf('@');
	var dotIndex = theStr.indexOf('.', atIndex);
	var flag = true;
	theSub = theStr.substring(0, dotIndex+1)

	if ((atIndex < 1)||(atIndex != theStr.lastIndexOf('@'))||(dotIndex < atIndex + 2)||(theStr.length <= theSub.length)) 
	{	flag = false; }
	else { flag = true; }
	
	return(!flag);
}




function IsUrl (theStr) {
		
	var dotIndex = theStr.indexOf('.');
	var flag = true;
	theSub = theStr.substring(0, dotIndex+1)

	if ((dotIndex < 1)||(theStr.length <= theSub.length)) 
	{	flag = false; }
	else { flag = true; }
	
	return(!flag);
}









function hasDigitOnly (str) {
	var invalid_found = false;
	var cnt = 0;
	var digits = "1234567890-";
	if (str.length == 0)  	invalid_found = false;
	else
	{
	while ((!invalid_found) && (cnt < str.length)) {
		ch = str.charAt(cnt++);
		if (!((digits.indexOf(ch) > -1)))
			invalid_found = true;
	}
	}
	return (invalid_found);
}

function hasDigit(str) {
	var invalid_found = false;
	var cnt = 0;
	var digits = "1234567890";
	if (str.length == 0)  	invalid_found = false;
	else
	{
	while ((!invalid_found) && (cnt < str.length)) {
		ch = str.charAt(cnt++);
		if (!((digits.indexOf(ch) > -1)))
			invalid_found = true;
	}
	}
	return (invalid_found);
}

/*********************************************************************************
*		FUNCTION:		showDialog(theURL, theHeight, theWidth);
**********************************************************************************/
function showDialog (theMessage, theHeight, theWidth) {
	var theURL 		= "about:blank";
	var theTop		= Math.ceil((600 - theHeight) / 2);
	var theLeft		= Math.ceil((800 - theWidth) / 2);
	
	var strOption 	= "width="+theWidth+",height="+theHeight+",top="+theTop+",left="+theLeft+",status=no,toolbar=no,location=no,directories=no,menubar=no,scrollbars=yes,resizable=no,statusbar=no";
	var winDialog 	= self.open(theURL, "winAlert", strOption);

	with (winDialog.document) {
		open();
		write('<html><head><title>'+theMessage.title+'</title></head>');
		write('<body bgcolor="#669966" text="#ffffff" onresize="self.resizeTo('+(theWidth+5)+','+(theHeight+10)+'); self.moveTo('+theLeft+','+theTop+');" onblur="self.focus();">');
		write('<form><table border="0" cellpadding="0" cellspacing="0" style="top-margin: 2px">');
		write('<tr><td><div align="left" style="font-family: courier new; font-size: 14pt; font-weight: bold">'+theMessage.heading+'</div></td></tr>');
		write('<tr><td><hr size="3"></td></tr>');
		write('<tr><td><div style="font-family: courier new; font-size: 10pt; font-weight: normal">'+theMessage.detail+'</div></td></tr>');
		write('<tr><td><hr size="2"></td></tr>');
		write('<tr><td><div align="center"><input name="cmdClose" type="Button" value="CLOSE" style="font-family: courier new; font-size: 8pt; font-weight: bold; width: 200px" onclick="self.close();"></div></td></tr>');
		write('<tr><td><hr size="2"></td></tr>');
		write('</table></form>');
		write('</body>');
		write('</html>');
		close();
	}
	
	return (true);
}

/**************************************************************************************/
//	EOF
/**************************************************************************************/



function isNotEmpty(String) {
   // Return false if "string" is empty or all blank
  if (String.length == 0) {return (false);}
  for (var i=0; i < String.length; i++) {
    if (String.substring(i,i+1) != " ") {return (true);}
  }
  return (false);
}