function initializeArray(){
	aryErrors = new Array();
}
function addErr(e2add){
	nextIndex = aryErrors.length;
	aryErrors[nextIndex] = e2add;
}

function trim(str){ 
    var whiteSpaces = new Array(' ', '\t', '\n'); //array of space, tab and new line 
    for(var i=0; i<whiteSpaces.length; i++){ 
        str = str.split(whiteSpaces[i]); // remove white spaces 
        str = str.join(''); 
    } 
    return str; 
}

function isEmail(eml) {
	// make sure search function is available
	if(eml.search){
		if (eml.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) {return true;}
		else {return false;}
		}
	else{return true;}
}

function hasSpecChar(fld){
	arySpecChars = "<>%*#";
	for(i = 0; i < fld.length; i++){
		for(j = 0; j < arySpecChars.length; j++){
			if(fld.indexOf(arySpecChars.charAt(j)) != -1){
				return true;
				break;
			}
		}
	}
	return false;
}

function hasErrors(){
	if(aryErrors.length < 1){
		return false;
	}
	else{
		errString = "==============================================\nYour form cannot be submitted as entered.\nPlease correct the following issues:\n==============================================\n";
		for(i = 0; i < aryErrors.length; i++){
			errString = errString + "- " + aryErrors[i] + "\n";
		}
		alert(errString);
		return true;
	}
}

function fixPhone(phn){
	_out = "()-. "; // replace this
	_in = ""; // with this
	_temp = "" + phn; // temporary holder
	
	for(i = 0; i < _out.length; i++){
		while (_temp.indexOf(_out.charAt(i))>-1) {
			_pos= _temp.indexOf(_out.charAt(i));
			_temp = "" + (_temp.substring(0, _pos) + _in + _temp.substring((_pos + _out.charAt(i).length), _temp.length));
		}
	}
	//_temp = trim(_temp);
return _temp;
}

function isValidPhoneNumber(s)
{  
    return (isInteger(s) && s.length == 10); //digitsInUSPhoneNumber)
}

function isInteger(s)

{   var i;

    if (!isEmpty(s)){

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;}
}

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function reformat (s)

{   var arg;
    var sPos = 0;
    var resultString = "";

    for (var i = 1; i < reformat.arguments.length; i++) {
       arg = reformat.arguments[i];
       if (i % 2 == 1) resultString += arg;
       else {
           resultString += s.substring(sPos, sPos + arg);
           sPos += arg;
       }
    }
    return resultString;
}

function popHelp(pageUrl){
	winHandle = window.open(pageUrl, "helpWin", "width=400,height=375,border=0,status=0,location=0,scrollbars=1");
}

function isFloat (s){
	var i;
    var seenDecimalPoint = false;

    if(isEmpty(s)){
		return false;}

    if (s == ".") return false;

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if ((c == ".") && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }
    // All characters are numbers.
    return true;
}

function isDollar(s){
	if(!isFloat(s)){
		return false;}
		
	s_length = s.length;
	if(s_length < 4 || s.charAt(s_length - 3) != "."){
		return false;}
	return true;
}

function jsDateDiff(f_start, f_end, f_interval, f_rounding ) {

    var iOut = 0;
    
    // Create 2 error messages, 1 for each argument. 
    var f_startMsg = "Check the f_start Date and f_end Date\n"
        f_startMsg += "must be a valid date format.\n\n"
		f_startMsg += f_start + "\n";
		f_startMsg += f_end + "\n\n";
        f_startMsg += "Please try again." ;		
    var f_intervalMsg = "Sorry the dateAdd function only accepts\n"
        f_intervalMsg += "d, h, m OR s f_intervals.\n\n"
        f_intervalMsg += "Please try again." ;

    var bufferA = Date.parse( f_start ) ;
    var bufferB = Date.parse( f_end ) ;
    	
    // check that the f_start parameter is a valid Date. 
    if ( isNaN (bufferA) || isNaN (bufferB) ) {
        alert( f_startMsg ) ;
        return null ;
    }
	
    // check that an f_interval parameter was not numeric. 
    if ( f_interval.charAt == 'undefined' ) {
        // the user specified an incorrect f_interval, handle the error. 
        alert( f_intervalMsg ) ;
        return null ;
    }
    
    var number = bufferB-bufferA ;
    
    // what kind of add to do? 
    switch (f_interval.charAt(0))
    {
        case 'd': case 'D': 
            iOut = parseInt(number / 86400000) ;
            if(f_rounding) iOut += parseInt((number % 86400000)/43200001) ;
            break ;
        case 'h': case 'H':
            iOut = parseInt(number / 3600000 ) ;
            if(f_rounding) iOut += parseInt((number % 3600000)/1800001) ;
            break ;
        case 'm': case 'M':
            iOut = parseInt(number / 60000 ) ;
            if(f_rounding) iOut += parseInt((number % 60000)/30001) ;
            break ;
        case 's': case 'S':
            iOut = parseInt(number / 1000 ) ;
            if(f_rounding) iOut += parseInt((number % 1000)/501) ;
            break ;
        default:
        // If we get to here then the f_interval parameter
        // didn't meet the d,h,m,s criteria.  Handle
        // the error. 		
        alert(f_intervalMsg) ;
        return null ;
    }    
    return iOut ;
}
function LaunchExternalWin(fUrl,fWidth,fHeight,fParams,fName){
	if(fWidth == "") {fWidth = 600;}
	if(fHeight == "") {fHeight = 400;}
	if(fParams == ''){fParams = ',scrollbars=1';}
	if(fName == ""){fName = "winLoad" + Math.round(Math.random()*1000);}
	
	fWinL = (screen.width - fWidth) / 2;
	fWinT = (screen.height - fHeight) / 2;
	fParams += ",top="+fWinT+",left="+fWinL;
	
	window.open(fUrl, fName, 'width='+fWidth+',height='+fHeight+fParams);
}
function ValidateNumeric()
{
	var keyCode = window.event.keyCode;
	if (keyCode > 57 || keyCode < 48) 
	{ 
		alert('This field allows numeric entry only.');
		window.event.returnValue = false;
	}
}