function isBlank(s)
{
	/*
	 *	Author: Allan L. Chan, Genex
	 *	Description: Check if user has entered data by checking for
	 *		spaces, the enter character or the tab character.
	 *	Input(s):
	 *		s -> form element (i.e. - text box)	
	 *	Output:
	 *		true -> Data entry is blank.
	 *		false -> Data entry exists and is not blank.
	 */
	 
	for(var i = 0; i < s.length; i++)
	{
		var c = s.charAt(i);
		if((c != ' ') && (c != '\n') && (c != '\t')){
			return false;
		}
	}
	
	return true;
	
}


function isEmail(string)
{
	/*
	 *	Author: Allan L. Chan, Genex
	 *	Description: Uses Regular Expression to check if email entered is properly formatted
	 *	Input(s): String from form element (i.e. - text box)
	 *	Output:
	 *		true -> string resembles email format
	 *		false -> string does not fit format of email
	 */
	 
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1){
        return true;
    }else{
        return false;
    }
}


function isError(error_msg)
{
	/*
	 *	Author: Allan L. Chan, Genex
	 *	Description: If error_msg is not an empty string, then send alert to user with error message
	 *	Input(s):
	 *		error_msg -> String of errors on page
	 *	Output:
	 *		true -> There are no errors
	 *		fales -> There were some errors on the page	
	 */
	 
  if(!error_msg)
	{
		return submitFormOnce();
	}

  var msg = "__________________________________________________\n\n";
  msg += "The form was not submitted because of the following error(s).\n";
  msg += "Please correct these error(s) and re-submit.\n";
  msg += "_________________________________________________\n\n";

  if(error_msg)
  {
		msg += "- The following required field(s) have invalid entries:" + error_msg + "\n";
		alert(msg);
		//submitFormOnce(true);
		return false;
  }
}


function isNav()
{
	/*
	 *	Author: Bao Dang, Genex
	 *	Description: Returns whether the user is using Netscape Navigator
	 *	Input(s): None
	 *	Output:
	 *		true -> User's browser is Netscape
	 *		false -> User's browser is not Netscape
	 */
	 
	return (navigator.appName == "Netscape");
}


function isMac()
{
	/*
	 *	Author: Bao Dang, Genex
	 *	Description: Returns whether the user's system is a Macintosh.
	 *	Input(s): None
	 *	Output:
	 *		true -> Macintosh found
	 *		false -> Machine is not a Macintosh
	 */
	 
	return (navigator.appVersion.indexOf("Mac") != -1);
	
}


function isMacPPC()
{
	/*
	 *	Author: Bao Dang, Genex
	 *	Description: Returns whether the user's system is a PowerMac
	 *	Input(s): None
	 *	Output:
	 *		true -> PowerMac found
	 *		false -> Machine is not a PowerMac
	 */
	 
	return (isMac() && (navigator.appVersion.indexOf("PPC") != -1 || navigator.appVersion.indexOf("PowerPC") != -1));
	
}


function isWindows()
{
	/*
	 *	Author: Bao Dang, Genex
	 *	Description: Returns whether the user's operating system is Windows 16-bit
	 *	Input(s): None
	 *	Output:
	 *		true -> Windows found
	 *		false -> Machine is not using Windows
	 */
	 
	return (navigator.appVersion.indexOf("Win") != -1);
	
}


function isWin95NT()
{
	/*
	 *	Author: Bao Dang, Genex
	 *	Description: Returns whether the user's operating system is Windows 9x/NT/2K/XP
	 *	Input(s): None
	 *	Output:
	 *		true -> Windows found
	 *		false -> Machine is not using Windows 9x/NT/2K/XP
	 */
	 
	return (isWindows() && (navigator.appVersion.indexOf("Win16") == -1 && navigator.appVersion.indexOf("Windows 3.1") == -1));
	
}


function openPage()
{
	/*
	 *	Author: Allan L. Chan, Genex
	 *	Description: For opening email article page, get location and
	 * 		page title and then submit form.
	 *	Input(s): None
	 *	Output: None
	 */
	 
	document.frmEmail.action = "/email_article.asp";
	document.frmEmail.txtURL.value = document.location.href;
	document.frmEmail.txtTitle.value = document.title;
	
	document.frmEmail.submit();
	
}


function textCounter(s, maxlimit)
{
	/*
	 *	Author: Jackie Liu, Genex
	 *	Description: Will keep textarea form elements under the maxlimit for character length.
	 *	Input(s):
	 *		s -> form element object (i.e. - textarea)
	 *		maxlimit -> maximum allowable length for character string in this object
	 *	Output: None
	 */
	 
	if(s.value.length > maxlimit){
		s.value = s.value.substring(0, maxlimit);
	}
		
}

function isNumber(s) {
	/*
	 *	Author: Eric Doemelt / Jackie Liu, Genex
	 *	Description: Check if user has entered numberic data by checking for
	 *		spaces, the enter character or the tab character.
	 *	Input(s):
	 *		s -> form element (i.e. - text box)	
	 *	Output:
	 *		true -> Data entry is numberic data.
	 *		false -> Data entry exists and is not numberic.
	 */
	 
	if (s.search(/^\d+$/g) != -1){	// at least one digit
		return true;
	}else{
		return false;
	}
}


function isABA(s)
{
	/*
	 *	Author:  Jackie Liu, Genex
	 *	Description: Check if user has entered valided ABA routing number
	 *	Input(s):
	 *		s -> form element (i.e. - text box)	
	 *	Output:
	 *		true -> Data entry is valid ABA
	 *		false -> Data entry isn invalid ABA
	 */
	
	var atxtABA = new Array();
	
	for (var i = 0; i < s.length; i++)
	{
		atxtABA[i] = s.substring(i, i+1);
	}
	
	atxtABA[0] = atxtABA[0] * 3;
	atxtABA[1] = atxtABA[1] * 7;
	atxtABA[2] = atxtABA[2] * 1;
	atxtABA[3] = atxtABA[3] * 3;
	atxtABA[4] = atxtABA[4] * 7;
	atxtABA[5] = atxtABA[5] * 1;
	atxtABA[6] = atxtABA[6] * 3;
	atxtABA[7] = atxtABA[7] * 7;
	atxtABA[8] = atxtABA[8];
	
	var iSumABA = atxtABA[0] + atxtABA[1] + atxtABA[2] + atxtABA[3] + atxtABA[4] + atxtABA[5] + atxtABA[6] + atxtABA[7];
	var strNewABA = iSumABA + 10;
	
	var strABA = strNewABA.toString();
	var strABALength = strABA.length;
	switch(strABALength)
	{
		case 1 :
			strNewABA = "000" + strNewABA;
			break;
		case 2 :
			strNewABA = "00" + strNewABA;
			break;
		case 3 :
			strNewABA = "0" + strNewABA;
			break;
	}
	
	var strABATemp = (strNewABA.substring(0, 3)) + "0";
	var iNewABA = strABATemp - iSumABA;
	var sDigitABA = iNewABA.toString();
	
	if (sDigitABA.length > 1) {
		sDigitABA = sDigitABA.substring(sDigitABA.length-1, sDigitABA.length);
	}
	
	if (sDigitABA == atxtABA[8])
	{
		return true;
	}
	else
	{
		return false;
	}
}


function popPDF(url,height,width,toolbar,menubar,locationbar,scroll,resize,name)
{
	/*
	 *	Author:  Jackie Liu, Genex
	 *	Description: Popup PDF  file in  a new window
	 *	Input(s):
	 * 		url -> url ref of the PDF file
	 *		height /width -> size of popup window
	 *		toolbar /menubar/locationbar/scroll/resize	->	popup window assets 
	 *		name -> name of popup window
	 *	Output: None
	 */
	
	if (navigator.appName == "Netscape" && !(navigator.plugins["Adobe Acrobat"]))
	{
			parent.location.href = url;
	}
	else
	{
		var spec;
		
		spec = "status=no,toolbar=" + toolbar + ",menubar=" + menubar + ",location=" + locationbar + ",scrollbars=" + scroll + ",resizable=" + resize + ",height=" + height + ",width=" + width;
		var remote = window.open(url, name, spec);
		remote.focus();
	}
}


function popWindow( url, height, width, toolbar, menubar, locationbar, scroll, resize, name )
{
	/*
	 *	Author:  Jackie Liu, Genex
	 *	Description: Popup  document in a new window
	 *	Input(s):
	 * 		url -> url ref of the  file
	 *		height /width -> size of popup window
	 *		toolbar /menubar/locationbar/scroll/resize	->	popup window assets 
	 *		name -> name of popup window
	 *	Output: None
	 */
	var spec;
	
	spec = "status=no,toolbar=" + toolbar + ",menubar=" + menubar + ",location=" + locationbar + ",scrollbars=" + scroll + ",resizable=" + resize + ",height=" + height + ",width=" + width;
	var remote = window.open(url, name, spec);
	remote.focus();
	remote.location.href = url;
}


function UpperCase(str)
{
	/*
	 *	Author:  Jackie Liu, Genex
	 *	Description: Convert input string value to upper case
	 *	Input(s):
	 *		s -> form element (i.e. - text box)	
	 *	Output: None
	 */
	 
	str.value = str.value.toUpperCase();
	
}


var bFormSubmitted=false;
function submitFormOnce(bReset){
	/*
	 *	Author:  Grant Guthrie, Genex
	 *	Description: Prevent a form from being submitted more than once
	 *	Input(s):
	 *		oForm -> form object
	 *	Output: None
	 */
	if(bReset){
		bFormSubmitted=false;
		return;
	}else{
		if (!bFormSubmitted){
			bFormSubmitted=true;

			/** do some UI work here (disable button, show div, etc.) **/

			return true;
		}else{
			//alert('Your submission is in process. Please wait.');
			return false;
		}
	}
}
