function _CF_onError(form_object, input_object, object_value, error_message)   {
	alert(error_message);
       	return false;	
}

function _CF_Selected(obj) {
	x = 0;
	for (i=0; i < obj.length; i++)
	{
		if (obj.options[i].selected)
			x = x+ 1;
	}	
	return x;
}

// has Value function
function _CF_hasValue(obj, obj_type) {	

    if (obj_type == "TEXT" || obj_type == "PASSWORD") {
	    	if (obj.value.length == 0) 
	      		return false;
	    	else 
	      		return true;
    	}
    else if (obj_type == "SELECT")
	{
        for (i=0; i < obj.length; i++)
	    	{
		if (obj.options[i].selected)
			if (obj.options[i].value.length == 0)
				return false;
			else	
				return true;
		}

       	return false;	
	}
    else if (obj_type == "SINGLE_VALUE_RADIO" || obj_type == "SINGLE_VALUE_CHECKBOX")
	{

		if (obj.checked)
			return true;
		else
       		return false;	
	}
    else if (obj_type == "RADIO" || obj_type == "CHECKBOX")
	{

        for (i=0; i < obj.length; i++)
	    	{
		if (obj[i].checked)
			return true;
		}

       	return false;	
	}
}


//check euro date function
function _CF_checkeurodate(object_value) {

    //Returns true if value is a eurodate format or is NULL
    //otherwise returns false	
    if (object_value.length == 0)
        return true;

    //Returns true if value is a date in the dd/mm/yyyy format
	isplit = object_value.indexOf('/');

	if (isplit == -1)
	{
		isplit = object_value.indexOf('.');
	}

	if (isplit == -1 || isplit == object_value.length)
		return false;

    sMonth = object_value.substring(0, isplit);
	monthSplit = isplit + 1;
	isplit = object_value.indexOf('/', monthSplit);

	if (isplit == -1)
	{
		isplit = object_value.indexOf('.', monthSplit);
	}

	if (isplit == -1 ||  (isplit + 1 )  == object_value.length)
		return false;

    sDay = object_value.substring((sMonth.length + 1), isplit);
	sYear = object_value.substring(isplit + 1);
	
	if (!_CF_checkinteger(sMonth) || 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 (!_CF_checkrange(sYear, 1900, 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
		return true;
}

// get the Valid Birth date
function _CF_validBirthDate() {

	var today = new Date();	
	var curDate = new Date(today.setYear(new Date().getFullYear()-10));
	var curDt = (curDate.getMonth()+1) + '/' + curDate.getDate() + '/' + (curDate.getFullYear());	
	
	return curDt;
}


// Check the birth date field validity
function _CF_checkbirthdate(object_value) {

    //Returns true if value is a date in the dd/mm/yyyy format
	isplitStr = object_value.indexOf('/');
	if (isplitStr == -1)
	{
		isplitStr = object_value.indexOf('.');
	}

    sMnth = object_value.substring(0, isplitStr);
	monthSplitStr = isplitStr + 1;
	isplitStr = object_value.indexOf('/', monthSplitStr);

	if (isplitStr == -1)
	{
		isplitStr = object_value.indexOf('.', monthSplitStr);
	}

    sDy = object_value.substring((sMnth.length + 1), isplitStr);
	sYr = object_value.substring(isplitStr + 1);	
	var birthDate = new Date(sYear, sMonth-1, sDay);
	var today = new Date();	
	var curDate = _CF_validBirthDate();

	//if year is less than 10 years then return false
	if(Date.parse(curDate) > Date.parse(birthDate))
	{
		return true;
	}	
	else
	{
		return false;
	}
}

// Check Day function
function _CF_checkday(checkYear, checkMonth, checkDay){
	maxDay = 31;

	if (checkMonth == 4 || checkMonth == 6 ||
			checkMonth == 9 || checkMonth == 11)
		maxDay = 30;
	else
	if (checkMonth == 2)
	{
		if (checkYear % 4 > 0)
			maxDay =28;
		else
		if (checkYear % 100 == 0 && checkYear % 400 > 0)
			maxDay = 28;
		else
			maxDay = 29;
	}

	return _CF_checkrange(checkDay, 1, maxDay); //check day
}



// Check Integer Function
function _CF_checkinteger(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;
}


// Check number Range function
function _CF_numberrange(object_value, min_value, max_value)    {
    // check minimum
    if (min_value != null)
	{
        if (object_value < min_value)
		return false;
	}

    // check maximum
    if (max_value != null)
	{
	if (object_value > max_value)
		return false;
	}
	
    //All tests passed, so...
    return true;
}


// Check number function
function _CF_checknumber(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 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;
}


// Check Range Function
function _CF_checkrange(object_value, min_value, max_value) {
    //if value is in range then return true else return false

    if (object_value.length == 0)
        return true;


    if (!_CF_checknumber(object_value))
	{
	return false;
	}
    else
	{
	return (_CF_numberrange((eval(object_value)), min_value, max_value));
	}
	
    //All tests passed, so...
    return true;
}


// Check Phone Format Function
function _CF_checkphone(object_value) {
    if (object_value.length == 0)
        return true;
		
    if (object_value.length != 12)
        return false;

	// check if first 3 characters represent a valid area code
    if (!_CF_checknumber(object_value.substring(0,3)))
		return false;
    else
	if (!_CF_numberrange((eval(object_value.substring(0,3))), 100, 1000))
		return false;

	// check if area code/exchange separator is either a'-' or ' '
	if (object_value.charAt(3) != "-" && object_value.charAt(3) != " ")
        return false;

	// check if  characters 5 - 7 represent a valid exchange
    if (!_CF_checknumber(object_value.substring(4,7)))
		return false;
    else
	if (!_CF_numberrange((eval(object_value.substring(4,7))), 100, 1000))
		return false;
	
	// check if exchange/number separator is either a'-' or ' '
	if (object_value.charAt(7) != "-" && object_value.charAt(7) != " ")
        return false;

	// make sure last for digits are a valid integer
	if (object_value.charAt(8) == "-" || object_value.charAt(8) == "+")
        return false;
	else
	{
		return (_CF_checkinteger(object_value.substring(8,12)));
	}
}


// Check Zip code format Function
function _CF_checkzip(object_value)    {
    if (object_value.length == 0)
        return true;
		
    if (object_value.length != 5 && object_value.length != 10)
        return false;

	// make sure first 5 digits are a valid integer
	if (object_value.charAt(0) == "-" || object_value.charAt(0) == "+")
        return false;

	if (!_CF_checkinteger(object_value.substring(0,5)))
		return false;

	if (object_value.length == 5)
		return true;
	
	// make sure

	// check if separator is either a'-' or ' '
	if (object_value.charAt(5) != "-" && object_value.charAt(5) != " ")
        return false;

	// check if last 4 digits are a valid integer
	if (object_value.charAt(6) == "-" || object_value.charAt(6) == "+")
        return false;

	return (_CF_checkinteger(object_value.substring(6,10)));
}



function _CF_checkssc(object_value){
	var white_space = " -+.";
	var ssc_string="";
	var check_char;


    if (object_value.length == 0)
        return true;

    if (object_value.length != 11)
        return false;

	// make sure white space is valid
	if (object_value.charAt(3) != "-" && object_value.charAt(3) != " ")
        return false;

	if (object_value.charAt(6) != "-" && object_value.charAt(6) != " ")
        return false;

	 
	// squish out the white space
	for (var i = 0; i < object_value.length; i++)
	{
		check_char = white_space.indexOf(object_value.charAt(i))
		if (check_char < 0)
			ssc_string += object_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_checkinteger(ssc_string))
		return false;

	return true;

    }
	
function isEmailAddress(emailStr) {

	/* The following pattern is used to check if the entered e-mail address
	   fits the user@domain format.  It also is used to separate the username
	   from the domain. */
	var emailPat=/^(.+)@(.+)$/
	/* The following string represents the pattern for matching all special
	   characters.  We don't want to allow special characters in the address. 
	   These characters include ( ) < > @ , ; : \ " . [ ]    */
	var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
	/* The following string represents the range of characters allowed in a 
	   username or domainname.  It really states which chars aren't allowed. */
	var validChars="\[^\\s" + specialChars + "\]"
	/* The following pattern applies if the "user" is a quoted string (in
	   which case, there are no rules about which characters are allowed
	   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
	   is a legal e-mail address. */
	var quotedUser="(\"[^\"]*\")"
	/* The following pattern applies for domains that are IP addresses,
	   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
	   e-mail address. NOTE: The square brackets are required. */
	var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
	/* The following string represents an atom (basically a series of
	   non-special characters.) */
	var atom=validChars + '+'
	/* The following string represents one word in the typical username.
	   For example, in john.doe@somewhere.com, john and doe are words.
	   Basically, a word is either an atom or quoted string. */
	var word="(" + atom + "|" + quotedUser + ")"
	// The following pattern describes the structure of the user
	var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
	/* The following pattern describes the structure of a normal symbolic
	   domain, as opposed to ipDomainPat, shown above. */
	var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")
	
	
	/* Finally, let's start trying to figure out if the supplied address is
	   valid. */
	
	/* Begin with the coarse pattern to simply break up user@domain into
	   different pieces that are easy to analyze. */
	var matchArray=emailStr.match(emailPat)
	if (matchArray==null) {
	  /* Too many/few @'s or something; basically, this address doesn't
	     even fit the general mould of a valid e-mail address. */
		//alert("Email address seems incorrect (check @ and .'s)")
		return false;
	}
	var user=matchArray[1]
	var domain=matchArray[2]
	
	// See if "user" is valid 
	if (user.match(userPat)==null) {
	    // user is not valid
	    //alert("The username doesn't seem to be valid.")
	    return false;
	}
	
	/* if the e-mail address is at an IP address (as opposed to a symbolic
	   host name) make sure the IP address is valid. */
	var IPArray=domain.match(ipDomainPat)
	if (IPArray!=null) {
	    // this is an IP address
		  for (var i=1;i<=4;i++) {
		    if (IPArray[i]>255) {
		        //alert("Destination IP address is invalid!")
			return false;
		    }
	    }
	    return true;
	}
	
	// Domain is symbolic name
	var domainArray=domain.match(domainPat)
	if (domainArray==null) {
		//alert("The domain name doesn't seem to be valid.")
	    return false;
	}
	
	/* domain name seems valid, but now make sure that it ends in a
	   three-letter word (like com, edu, gov) or a two-letter word,
	   representing country (uk, nl), and that there's a hostname preceding 
	   the domain or country. */
	
	/* Now we need to break up the domain to get a count of how many atoms
	   it consists of. */
	var atomPat=new RegExp(atom,"g")
	var domArr=domain.match(atomPat)
	var len=domArr.length
	if (domArr[domArr.length-1].length<2 || 
	    domArr[domArr.length-1].length>3) {
	   // the address must end in a two letter or three letter word.
	   //alert("The address must end in a three-letter domain, or two letter country.")
	   return false;
	}
	
	// Make sure there's a host name preceding the domain.
	if (len<2) {
	   //var errStr="This address is missing a hostname!"
	   //alert(errStr)
	   return false;
	}
	
	// If we've gotten this far, everything's valid!
	return true;
}
//  End -->

// Check if value passed is a short date
function _CF_checkshortdate(object_value){
    //Returns true if value is a eurodate format or is NULL
    //otherwise returns false	

    if (object_value.length == 0)
        return true;
     
    //Returns true if value is a date in the dd/yyyy format
	isplit = object_value.indexOf('/');

	if (isplit == -1)
	{
		isplit = object_value.indexOf('.');
	}

	if (isplit == -1 || isplit == object_value.length)
		return false;

    sMonth = object_value.substring(0, isplit);	
    sYear = object_value.substring((isplit + 1));
    
     if(sYear.length != 4)
    		return false;
	else
	if (!_CF_checkinteger(sMonth)) //check month
		return false;
	else
	if (sMonth ==0) //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 (!_CF_checkrange(sYear, 1900, null)) //check year
		return false;
	else
	if (sYear ==0) //check year
		return false;
	else
		return true;
    }

function _CF_radioValue(obj)
	{
    for (var i=0; i<obj.length; i++) {
      if (obj[i].checked) {
         return obj[i].value;
      }
    }
    return obj.value;
}


// Check USMLE format function
function _CF_checkusmle(object_value)  {
	var white_space = " -+.";
	var ssc_string="";
	var check_char;


    if (object_value.length == 0)
        return true;

    if (object_value.length != 11)
        return false;

	// make sure white space is valid
	if (object_value.charAt(1) != "-" && object_value.charAt(3) != " ")
        return false;

	if (object_value.charAt(5) != "-" && object_value.charAt(6) != " ")
        return false;

	if (object_value.charAt(9) != "-" && object_value.charAt(6) != " ")
       return false;	
	 
	// squish out the white space
	for (var i = 0; i < object_value.length; i++)
	{
		check_char = white_space.indexOf(object_value.charAt(i))
		if (check_char < 0)
			ssc_string += object_value.substring(i, (i + 1));
	}	

	// if all white space return error
    if (ssc_string.length != 8)
        return false;
	 
	 	
	// make sure number is a valid integer
	if (!_CF_checkinteger(ssc_string))
		return false;

	return true;

}	
	
// Check Credit card number function	
function _CF_checkcreditcard(object_value)    {
	var white_space = " -";
	var creditcard_string="";
	var check_char;


    if (object_value.length == 0)
        return true;

	// squish out the white space
	for (var i = 0; i < object_value.length; i++)
	{
		check_char = white_space.indexOf(object_value.charAt(i))
		if (check_char < 0)
			creditcard_string += object_value.substring(i, (i + 1));
	}	

	// if all white space return error
    if (creditcard_string.length == 0)
        return false;
	 
	 	
	// make sure number is a valid integer
	if (creditcard_string.charAt(0) == "+")
        return false;

	if (!_CF_checkinteger(creditcard_string))
		return false;

    // now check mod10

	var doubledigit = creditcard_string.length % 2 == 1 ? false : true;
	var checkdigit = 0;
	var tempdigit;

	for (var i = 0; i < creditcard_string.length; i++)
	{
		tempdigit = eval(creditcard_string.charAt(i))

		if (doubledigit)
		{
			tempdigit *= 2;
			checkdigit += (tempdigit % 10);

			if ((tempdigit / 10) >= 1.0)
			{
				checkdigit++;
			}

			doubledigit = false;
		}
		else
		{
			checkdigit += tempdigit;
			doubledigit = true;
		}
	}	
	return (checkdigit % 10) == 0 ? true : false;
}
	

//Check if CVV value entered is numbers only	
function _CF_checkcvv(object_value)
{
	var white_space1 = " -";
	var cvv_string="";
	var check_char1;
	
    if (object_value.length == 0)
        return true;

	// squish out the white space
	for (var i = 0; i < object_value.length; i++)
	{
		check_char1 = white_space1.indexOf(object_value.charAt(i))
		if (check_char1 < 0)
		{
			cvv_string += object_value.substring(i, (i + 1));
		}
	}	

	// if all white space return error
    if (cvv_string.length == 0 || cvv_string.length < 3)
        return false;	 
	 	
	// make sure number is a valid integer
	if (cvv_string.charAt(0) == "+")
     {   return false;		}

	if (!_CF_checkinteger(cvv_string))
	{		return false;				}

	// if all the if statements are not true then it is an integer.	
  	return true;
}

// Removes leading and ending whitespaces
function trim( str ) 
{
      str = this != window? this : str;
      return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
}

// Pops a window with user defined url, page title, and window features
function popWin(theUrl, theTitle, theFeatures) {
	if(theUrl && theUrl != '')
	{
		window.open(theUrl, theTitle, theFeatures);
	}
}
	

// Set State Function
function setState(country_select, state_select, baseurl) {
		var selectedCountry;
		selectedCountry = country_select.options[country_select.selectedIndex].value;
		stateField = eval("document.forms[0]." + state_select);
		frames.HIDDEN_IFRAME.location.href = '';
		
		frames.HIDDEN_IFRAME.location.replace = function(location) {this.iframe.src = location;}
				
		if (selectedCountry != "USA"){
			stateField.length = 0;
			stateField.options[0] = new Option("Foreign", "FR");
			stateField.options.selectedIndex = 0;
		} 
		else {
			stateField.length = 0;
			stateField.options[0] = new Option("Please wait...", "", true, true);
			var url = baseurl  + "&country="  +  escape(selectedCountry) + "&field=" + escape(state_select) ;
			frames.HIDDEN_IFRAME.location.href = url;
		}
}


// Compare two short dates function
// returns result in boolean value. 
// if date1 is greater than or equal to date2 - returns true, else returns false;
function compareshortdates(date1, date2)
{	
	var result;
		
	if (date1.substring(1,2) == '/')
		date1 = '0' + date1;

	if (date2.substring(1,2) == '/')
		date2 = '0' + date2;
		
	var dt1yr	= date1.substring(3, date1.length);
	var dt2yr	= date2.substring(3, date2.length);		
	var dt1mnth = date1.substring(0, 2);
	var dt2mnth = date2.substring(0, 2);
		
	if (dt1yr > dt2yr) {
		result  = true;
	}
	else if(dt1yr == dt2yr){
		if(dt1mnth > dt2mnth || dt1mnth == dt2mnth) 		
			result = true;
		else if (dt1mnth < dt2mnth) 
			result = false;
	}	
	else
			result = false;
	
	return result;
}

// Compare two short dates function
// returns result in boolean value. 
// if date1 is equal to date2 - returns true, else returns false;
function equalShortdates(date1, date2)
{
	if (date1.substring(1,2) == '/')
		date1 = '0' + date1;

	if (date2.substring(1,2) == '/')
		date2 = '0' + date2;
		
	var dt1yr	= date1.substring(3, date1.length);
	var dt2yr	= date2.substring(3, date2.length);		
	var dt1mnth = date1.substring(0, 2);
	var dt2mnth = date2.substring(0, 2);
	
	if (dt1yr == dt2yr) {
		if (dt1mnth == dt2mnth)
			return true;
		else
			return false;
	}
	else 
		return false;
}

// Compare two short dates function
// returns result in boolean value. 
// if date1 is greater than or equal to date2 - returns true, else returns false;
function comparedates(date1, date2)
{	
	var result;
				
	if (date1.substring(1,2) == '/')
		date1 = '0' + date1;

	if (date2.substring(1,2) == '/')
		date2 = '0' + date2;
		
	var dt1yr	= date1.substring(6, date1.length);
	var dt2yr	= date2.substring(6, date2.length);		
	var dt1mnth = date1.substring(0, 2);
	var dt2mnth = date2.substring(0, 2);
	var dt1day = date1.substring(3, 5);
	var dt2day = 	date2.substring(3, 5);
	
	if (dt1yr > dt2yr) {
		result  = true;
	}
	else if(dt1yr == dt2yr){
		if(dt1mnth > dt2mnth ) 		
			result = true;		
		else if (dt1mnth < dt2mnth) 
			result = false;
		else if(dt1mnth == dt2mnth){
			if (dt1day > dt2day || dt1day == dt2day)
				result = true;
			else
				result = false;
		}			
	}	
	else
			result = false;
	
	return result;
}