function _CF_checkinteger(object_value){
/*
|| BEGIN FUNCTIONDOC ||
|| PROPERTIES ||
    Function Name:          _CF_checkinteger
    Date Created:           
    Author:                 Sandra Clark, 2001, Shayna Productions, all rights reserved.
    Last Modified:      
    
|| RESPONSIBILITIES ||
    I return true if the value passed to me is an integer value or is NULL
    
|| PARAMETERS REQUIRED ||
    object_value        value to be tested.
    
|| RETURNS ||
    true        value is an integer or NULL
    false       value is not an integer nor NULL

|| NOTES ||
    Adapted from ColdFusion CFForm Validation Routines      
    
|| END FUNCTIONDOC ||
*/
//---------------------------------------------------------------------------------------------
    if (object_value.length == 0)
        return true;

    //Returns true if value is an integer defined as
    //   having an optional leading + or -.
    //   otherwise containing only the characters 0-9.
    var decimal_format = ".";
    var check_char;

    //The first character can be + -  blank or a digit.
    check_char = object_value.indexOf(decimal_format)
    //Was it a decimal?
    if (check_char < 1)
        return _CF_checknumber(object_value);
    else
        return false;
    }
//--------------------------------------------------------------------------------------------------    
function isInteger(obj){
/*
|| BEGIN FUNCTIONDOC ||
|| PROPERTIES ||
    Function Name:          isInteger()
    Date Created:           
    Author:                 Sandra Clark, 2001, Shayna Productions, all rights reserved.
    Last Modified:      
    
|| RESPONSIBILITIES ||
    I check to see if an object passed to me has a value that is an Integer.
    If not, I pop up a message box.
    
|| PARAMETERS REQUIRED ||
        obj                 Object whose value needs to be checked.
|| RETURNS ||
    true if object's value is an integer
    
|| END FUNCTIONDOC ||
*/
//---------------------------------------------------------------------------------------------

// Validates whether an object is an Integer.
    var msg = '';
    var success;
    
    success = _CF_checkinteger(obj.value);
    
    if (!success || obj.value == ''){
        alert('Item is not an Integer. Please re-enter.');
        obj.value='0';
        obj.focus();
    }
    
    return success;


}
//--------------------------------------------------------------------------------------------------
function ssncheck(objssn)
// checks Social Security Number for proper inputting. If
// numbers only are input, adds hyphens to correct area.
{
    if (!checkssn(objssn)){
        alert('Social Security Number must be in format xxx-xx-xxxx');
        objssn.value="";
        objssn.focus()
        return false;
    } else
        return true;
}
//==================================================================================================
function _CF_checkssninteger(object_value)
    {
    //Returns true if value is a number or is NULL
    //otherwise returns false
        
    if (object_value.length == 0)
        return true;

    //Returns true if value is an integer defined as
    //   having an optional leading + or -.
    //   otherwise containing only the characters 0-9.
    var decimal_format = ".";
    var check_char;

    //The first character can be + -  blank or a digit.
    check_char = object_value.indexOf(decimal_format)
    //Was it a decimal?
    if (check_char < 1)
    return _CF_checknumber(object_value);
    else
    return false;
    }
//==================================================================================================
function checkssn(object_value)
// Checks Social Security number and formats it correctly.
    {
    var white_space = " -+.";
    var ssc_string="";
    var check_char;
    

    if (object_value.value.length == 0)
        return true;
    
    if (object_value.value.length == 9){
    // make sure number is a valid integer
        if (!_CF_checkssninteger(object_value.value)){
            return false;
        } else {
            // incorporate dashes at position 
            // 3 and 6
            var sub1 = object_value.value.substring(0,3)
            var sub2 = object_value.value.substring(3,5)
            var sub3 = object_value.value.substring(5,10)
            object_value.value = sub1 + "-" + sub2 + "-" + sub3
            return object_value.value;
        }
    }

    if (object_value.value.length != 11)
        return false;
        
    // make sure white space is valid
    if (object_value.value.charAt(3) != "-" && object_value.value.charAt(3) != " ")
        return false;

    if (object_value.value.charAt(6) != "-" && object_value.value.charAt(6) != " ")
        return false;

     
    // squish out the white space
    for (var i = 0; i < object_value.value.length; i++)
    {
        check_char = white_space.indexOf(object_value.value.charAt(i))
        if (check_char < 0)
            ssc_string += object_value.value.substring(i, (i + 1));
    }   

    // if all white space return error
    if (ssc_string.length != 9)
        return false;
     
        
    // make sure number is a valid integer
    if (!_CF_checkssninteger(ssc_string))
        return false;

    return true;

}
//==================================================================================================
function datecheck(valDate){
// =================================================================================================
// Programmer:              Sandra Clark    
//
// Description:             Checks date validation. If ok, passes through, otherwise,
//                          shows alert box.
// =================================================================================================
    datevalid = 'True';
    if (!checkdate(valDate)){
        if (datevalid == 'True'){
            alert('Date must be in the form MM/DD/YYYY');
            valDate.value = '';
            valDate.focus();
            return false;
        } else 
            alert('Date is not valid, please re-enter.');
            valDate.value = '';
            valDate.focus();
            return false;   
    } else 
        return true;         
}
//--------------------------------------------------------------------------------------------------
function timecheck(valTime){
// =================================================================================================
// Programmer:              Sandra Clark    
//
// Description:             Checks date validation. If ok, passes through, otherwise,
//                          shows alert box.
// =================================================================================================
    timevalid = true;
    if (!IsValidTime(valTime.value)){
        if (timevalid){
            alert('Time must be in the form HH:MM:SS AM/PM');
            valTime.value = '';
            valTime.focus();
            return false;
        } else 
            alert('Time is not valid, please re-enter.');
            valTime.value = '';
            valTime.focus();
            return false;
    } else 
        return true;         
}
//--------------------------------------------------------------------------------------------------
function checkdate(object_value){
// =================================================================================================
// Programmer:          Adapted from Cold Fusion CF Form Validation Routines        
//
// Description:         Returns true if value is a date format or is NULL otherwise returns false   
// =================================================================================================
    if (object_value.value.length == 0)
        return true;

    //Returns true if value is a date in the mm/dd/yyyy format
    isplit = object_value.value.indexOf('/');

    if (isplit == -1 || isplit == object_value.length)
        return false;

    sMonth = object_value.value.substring(0, isplit);
    isplit = object_value.value.indexOf('/', isplit + 1);

    if (isplit == -1 || isplit == object_value.value.length)
        return false;

    sDay = object_value.value.substring((sMonth.length + 1), isplit);

    sYear = object_value.value.substring(isplit + 1);

    if (!_CF_checkinteger(sMonth)) //check month
        return false;
    else
    if (!_CF_checkrange(sMonth, 1, 12)) //check month
        return false;
    else
    if (!_CF_checkinteger(sYear)) //check year
        return false;
    else
    if (!checkyearlen(sYear)) // check to make sure year has 4 digits
        return false;
    else
        newYear=checkyearlen(sYear);
    if (!_CF_checkrange(sYear, 0, null)) //check year
        return false;
    else
    if (!_CF_checkinteger(sDay)) //check day
        return false;
    else
    if (!_CF_checkday(sYear, sMonth, sDay)) // check day
        return false;
    else
        if (sMonth.length == 1 && sMonth <= 9){
            sMonth = '0'+ sMonth.toString();
        } 
        if (sDay.length == 1 & sDay <= 9){
            sDay = '0' + sDay.toString();
        }
        object_value.value = sMonth + "/" + sDay + "/" + newYear;
        return object_value.value;
    }
//--------------------------------------------------------------------------------------------------
function _CF_checkinteger(object_value){
// =================================================================================================
// Programmer:              Adapted from ColdFusion CFForm Validation Routines  
//
// Description:             Returns true if value is a number or is NULL otherwise returns false    
// =================================================================================================
    if (object_value.length == 0)
        return true;

    //Returns true if value is an integer defined as
    //   having an optional leading + or -.
    //   otherwise containing only the characters 0-9.
    var decimal_format = ".";
    var check_char;

    //The first character can be + -  blank or a digit.
    check_char = object_value.indexOf(decimal_format)
    //Was it a decimal?
    if (check_char < 1)
    return _CF_checknumber(object_value);
    else
    return false;
    }
//--------------------------------------------------------------------------------------------------
function _CF_checknumber(object_value){
// =================================================================================================
// Programmer:          Adapted from ColdFusion CF Form Validation Routines     
//
// Description:         Returns true if value is a number or is NULL otherwise returns false
// =================================================================================================
    if (object_value.length == 0)
        return true;

    //Returns true if value is a number defined as
    //   having an optional leading + or -.
    //   having at most 1 decimal point.
    //   otherwise containing only the characters 0-9.
    var start_format = " .+-0123456789";
    var number_format = " .0123456789";
    var check_char;
    var decimal = false;
    var trailing_blank = false;
    var digits = false;

    //The first character can be + - .  blank or a digit.
    check_char = start_format.indexOf(object_value.charAt(0))
    //Was it a decimal?
    if (check_char == 1)
        decimal = true;
    else if (check_char < 1)
        return false;
        
    //Remaining characters can be only . or a digit, but only one decimal.
    for (var i = 1; i < object_value.length; i++)
    {
        check_char = number_format.indexOf(object_value.charAt(i))
        if (check_char < 0)
            return false;
        else if (check_char == 1)
        {
            if (decimal)        // Second decimal.
                return false;
            else
                decimal = true;
        }
        else if (check_char == 0)
        {
            if (decimal || digits)  
                trailing_blank = true;
        // ignore leading blanks

        }
            else if (trailing_blank)
            return false;
        else
            digits = true;
    }   
    //All tests passed, so...
    return true
    }

//--------------------------------------------------------------------------------------------------
function _CF_checkrange(object_value, min_value, max_value){
// =================================================================================================
// Programmer:              Adapted from ColdFusion Validation Routines 
//
// Description:             if value is in range then return true else return false
// =================================================================================================
    if (object_value.length == 0)
        return true;


    if (!_CF_checknumber(object_value))
    {
    datevalid = 'False';
    return false;
    }
    else
    {
    return (_CF_numberrange((eval(object_value)), min_value, max_value));
    }
    
    //All tests passed, so...
    return true;
    }
//--------------------------------------------------------------------------------------------------
function checkemail(e){
// parameter 'e' is value of object.

// Email Validation. Written by PerlScriptsJavaScripts.com

ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";

for(i=0; i < e.length ;i++){
if(ok.indexOf(e.charAt(i))<0){ 
return (false);
}	
} 

if (document.images) {
re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
if (!e.match(re) && e.match(re_two)) {
return (-1);		
} 
}

}
//--------------------------------------------------------------------------------------------------
function _CF_numberrange(object_value, min_value, max_value){
// =================================================================================================
// Programmer:          Adapted from ColdFusion CFForm Validation Routines      
//
// Description:         makes sure object_value falls between min and max
// =================================================================================================
    // check minimum
    if (min_value != null)
    {
        if (object_value < min_value){
            datevalid = 'False';
            return false;
        }
    }

    // check maximum
    if (max_value != null)
    {
    if (object_value > max_value){
        datevalid = 'False';
        return false;
    }
    }
    
    //All tests passed, so...
    return true;
    }
//--------------------------------------------------------------------------------------------------
function checkyearlen(lenyear){
// =================================================================================================
// Programmer:          Description:
//  Sandra Clark        Y2K Function.
//                      if year is 4 digits, return it, otherwise, if it is 2 digits, determine 
//                      which century it should be in using the pivotyear variables and add those 
//                      two digits to the year to make a 4 digit year.
//  Vicky (10/02/01)    comment out the else block statements. return false if the use didn't 
//                      enter the exact 4 digits year.
// =================================================================================================

    // 
    if (lenyear.length == 4) {
        return lenyear;
    } else {
        return false; 
        /*
        if (lenyear.length ==2){
            if ((lenyear > pivotyearmin)  && (lenyear <=pivotyearmax)){
                var xyear = earlycentury;
            }   else {
                var xyear = latercentury;
            }
            lenyear= xyear + lenyear
            return lenyear;
        }
    */
    }
        
}
//--------------------------------------------------------------------------------------------------
function _CF_checkday(checkYear, checkMonth, checkDay){
// =================================================================================================
// Programmer:              Adapted from Cold Fusion CFForm Validation Routins  
//
// Description:             Checks day to assure valid date. Checks for Leap year too.
// =================================================================================================
    maxDay = 31;
    var intMonth = parseInt(checkMonth);
    var intYear = parseInt(checkYear);
    
    if (intMonth == 4 || intMonth == 6 ||
            intMonth == 9 || intMonth == 11)
        maxDay = 30;
    else
    if (intMonth == 2)                  // Checks for Leap Year
    {
        if (intYear % 4 > 0)
            maxDay =28;
        else
        if (intYear % 100 == 0 && intYear % 400 > 0)
            maxDay = 28;
        else
            maxDay = 29;
    }
        return _CF_checkrange(checkDay, 1, maxDay); //check day
    }


/*/--------------------------------------------------------------------------------------------------
function checkemail(sourcefield, returnmsg){
// =================================================================================================
// Programmer:      Sandra Clark            
//
// Description:     Validates email address
//
// Parameters:
//                  sourcefield:    email field
//                  returnmsg:      Boolean, return a message or just true/false
// =================================================================================================
    var str=sourcefield.value
    var filter=/^.+@.+\..{2,3}$/
    if (filter.test(str))
        testresults=true;
    else{
        if (returnmsg){
            alert("Please input a valid email address!");
        }
        testresults=false;
    }
    return (testresults);
}*/
//--------------------------------------------------------------------------------------------------
function validateUSZIP(sourcefield, returnmsg) {
// =================================================================================================
// Programmer:      Sandra Clark            
//
// Description:     Validates US Zipcodes
//
// Parameters:
//                  sourcefield:    ZipCode field
//                  returnmsg:      Boolean, return a message or just true/false
// =================================================================================================

    var valid = "0123456789-";
    var hyphencount = 0;

    if (sourcefield.value.length!=5 && sourcefield.value.length!=10) {
        if (returnmsg)
            alert("Please enter your 5 digit or 5 digit+4 zip code.");
        return false;
    }
    for (var i=0; i < sourcefield.value.length; i++) {
        temp = "" + sourcefield.value.substring(i, i+1);
        if (temp == "-") 
            hyphencount++;
        if (valid.indexOf(temp) == "-1") {
            if (returnmsg)
                alert("Invalid characters in your zip code.  Please try again.");
                
            return false;
        }
      }
    if ((hyphencount > 1) || ((sourcefield.value.length==10) && ""+ sourcefield.value.charAt(5)!="-")) {
        if (returnmsg)
            alert("The hyphen character should be used with a properly formatted 5 digit+four zip code, like '12345-6789'.   Please try again.");
        return false;
   }

  return true;
}
//--------------------------------------------------------------------------------------------------
function validateCanadianZip(sourcefield, returnmsg) {
// =================================================================================================
// Programmer:      Sandra Clark            
//
// Description:     Validates Canadian Postal Codes.
//
// Parameters:
//                  sourcefield:    Postal Code field
//                  returnmsg:      Boolean, return a message or just true/false
// =================================================================================================
    // if there happens to be a space in the field, get rid of it.
    var newstring = "";
    for (index = 0; index < sourcefield.value.length; index++){
        if (sourcefield.value.charAt(index) != " ")
            newstring = newstring + sourcefield.value.charAt(index);
    }
    if (newstring.search(/^([A-Za-z][0-9][A-Za-z][0-9][A-Za-z][0-9]$)/) != -1) {
        return true;
    } else {
        if (returnmsg){
            alert("Invalid Postal Code!");
        }
        return false;
    }
}
//-------------------------------------------------------------------------------------------------
function ckrequiredinput(source, field, msgstring) {
//==================================================================================================
//Programmer:       Vicky (Yen) Ngo
//
//Description:      This function check to see if the user enter all the input that are required.
//
//History Date:     "10/12/2001" initial creation.
//
// Parameters:      source - form's name.
//                  ckfield (scope=string) - form field name need to check if the content is empty or not.
//                  msgstring (scope=string) - message to out put this ckfield is empty.
//==================================================================================================
        newfield = eval('source.'+field);
        if (newfield.value == ''){
            alert(msgstring);
            return false;
        }
        return true;
}//end ckrequiredinput function
//--------------------------------------------------------------------------------------------------------


function IsValidTime(timeStr) {
//==================================================================================================
//Programmer:       Sandeep Tamhankar (stamhankar@hotmail.com) 
//
//Description:      Checks if time is in HH:MM:SS AM/PM format.
//                  The seconds and AM/PM are optional.
//
//History Date:     11/30/2001 initial creation.
//
// Parameters:      timeStr - Time to be validated.
//==================================================================================================
// 
 if(timeStr.length >0){
        var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;
        
        var matchArray = timeStr.match(timePat);
        if (matchArray == null) {
            return false;
        }
        hour = matchArray[1];
        minute = matchArray[2];
        second = matchArray[4];
        ampm = matchArray[6];
        
        if (second=="") { second = null; }
        if (ampm=="") { ampm = null }
        
        if (hour < 0  || hour > 23) {
            return false;
        }
        if (hour <= 12 && ampm == null) {
            if (confirm("Please indicate which time format you are using.  OK = Standard Time, CANCEL = Military Time")) {
                return false;
           }
        }
        if  (hour > 12 && ampm != null) {
            return false;
        }
        if (minute<0 || minute > 59) {
            return false;
        }
        if (second != null && (second < 0 || second > 59)) {
            return false;
        }
        return true;
    } else {
        return true;
    }
}
//*-------------------------------------------------------------------------------------------------
function checkTextLength(objItem, len, fieldname){
//  obj_value = form.field.value
// len = maximum length of field.
    var nCount = 0;
    var szObjItem = objItem.value;
    nCount = GetNewLineCount( szObjItem );
    if ((objItem.value.length+nCount) > len){
        var overlength = objItem.value.length + nCount - len;
        var msg = fieldname + ' too long. Can only be ' + len + ' in length. Currently it is ' + overlength + ' characters too long.';
        alert(msg);
        return false;
    } 
        return true;
}

//*-------------------------------------------------------------------------------------------------
function dateCompare(strDate1, strDate2){
// returns -1 if date1 < date2
// returns 0 if date1 = date2
// returns 1 if date1 > date2

    var newDate1 = strDate1.split("/");
    var newDate2 = strDate2.split("/");
    
    var Date1 = new Date(newDate1[2], newDate1[0]-1, newDate1[1]);
    var Date2 = new Date(newDate2[2], newDate2[0]-1, newDate2[1]);
    
    if (Date1 < Date2){
        return -1;
    } else if (Date1 > Date2){
        return 1;
    } else {
        return 0;
    }
        


}

//==================================================================================================
//  Programmer:     Tung Phan
//  Date:           09/20/2002    
//  Usage:          Count the number of new line in the string. 
//==================================================================================================
function GetNewLineCount( StrObj )
{
    var nCount = 0;
    var mystr = StrObj;
    var iIdx  = 0;

    while ( mystr.charAt(iIdx) != '' ) {
        if (mystr.charCodeAt(iIdx) == 10) {
            nCount++;
        }
        iIdx++;
    }
    return nCount;
}



var regCaZip = new RegExp(/A9A 9A9/);
var regExText = new RegExp(/A-Za-z0-9/);
var regExEmail = new RegExp(/^[a-zA-Z_0-9-'\+~]+(\.[a-zA-Z_0-9-'\+~]+)*@([a-zA-Z_0-9-]+\.)+[a-zA-Z]{2,7}/);
var regExNonDig = new RegExp(/\D/);
var regExDig = new RegExp(/\d/);
var regExPhone = new RegExp(/^[2-9]\d{2}-\d{3}-\d{4}$/);

function chkText(fld, req)
{
	if(req)
	{
		if(!$(fld).val() == '')
		{
			if(!(regExText.test($(fld).val())))
				return false;
		}
	}
	else
	{
		if($(fld).val() != '')
		{
			if(!(regExText.test($(fld).val())))
				return false;		
		}
	}
	
	return true;	
}

function chkEmail(fld, req)
{
	if(req)
	{
		if(!$(fld).val() == '')
		{
			if(!(regExEmail.test($(fld).val())))
				return false;		
		}
	}
	else
	{
		if($(fld).val() != '')
		{
			if(!(regExEmail.test($(fld).val())))
				return false;		
		}
	}
	
	return true;	
}

function chkNumber(fld, req)
{
	if(req)
	{
		if(!$(fld).val() == '')
		{
			if(regExDig.test($(fld).val()))
				return false;		
		}
	}
	else
	{
		if($(fld).val() != '')
		{
			if(regExDig.test($(fld).val()))
				return false;		
		}
	}
	
	return true;	
}

function chkZip(cntry, zip, st)
{
	var found = false;
	for(i = 0; i < CanStates.length; i++)
	{
		if(st == CanStates[i])
			found = true;
	}

	if(cntry != '' && zip.length > 0)
	{
		if(cntry == 'CA' && found)
		{
			if((zip.length == 6 || zip.length == 7) && regExCaZip.test(zip))
			return false;
		}

		if(cntry == 'US' && !found)		
		{
			if((zip.length == 5 || zip.length == 10) && regExDig.test(zip))
				return false;
		}
	}
	
	return true;

} 

function chkPhoneNbr(fld1,fld2,req)
{
	

	var phnNbr = $(fld1).val() + $(fld2).val();
	phnNbr = phnNbr.replace(/[\D]/g,"");

	if(req)
	{
		if(phnNbr != '')
		{
			if(phnNbr.length == 10)			
				return false;
		}
	}
	else
	{
		if(phnNbr != '')
		{
			if(phnNbr.length == 10)
				return false;
		}
	}
	
	return true;
}





