
//<!--

function _CF_onError(form_object, input_object, object_value, error_message)
    {
	alert(error_message);
		input_object.focus();
       	return false;	
    }

function _CF_hasValue(obj, obj_type)
    {
    if (obj_type == "TEXT")
	{
    	if (obj.value.length == 0) 
      		return false;
    	else 
      		return true;
    	}
    else if (obj_type == "SELECT")
	{
        if (obj.value == "null")
			return false;
		else		
       	return true;	
	}
    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;	
	}
	}

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;
    }

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
    }

/*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_checkform(_CF_this)
    {
    if  (!_CF_hasValue(_CF_this.fname, "TEXT" )) 
        {
        if  (!_CF_onError(_CF_this, _CF_this.fname, _CF_this.fname.value, "Please enter your First Name"))
            {
            return false; 
            }
        }
    if  (!_CF_hasValue(_CF_this.lname, "TEXT" )) 
        {
        if  (!_CF_onError(_CF_this, _CF_this.lname, _CF_this.lname.value, "Please enter your Last Name"))
            {
            return false; 
            }
        }
    if  (!_CF_hasValue(_CF_this.address, "TEXT" )) 
        {
        if  (!_CF_onError(_CF_this, _CF_this.address, _CF_this.address.value, "Please enter your Address"))
            {
            return false; 
            }
        }

    if  (!_CF_hasValue(_CF_this.city, "TEXT" )) 
        {
        if  (!_CF_onError(_CF_this, _CF_this.city, _CF_this.city.value, "Please enter your City"))
            {
            return false; 
            }
        }

    if  ((!_CF_hasValue(_CF_this.state1, "SELECT" )) && (document.form.country.value == 'us'))
        {
        if  (!_CF_onError(_CF_this, _CF_this.state1, _CF_this.state1.value, "Please select your state"))
            {
            return false; 
            }
        }
    if  ((!_CF_hasValue(_CF_this.zip, "TEXT" )) && (document.form.country.value == 'us'))
        {
        if  (!_CF_onError(_CF_this, _CF_this.zip, _CF_this.zip.value, "Please enter a valid Zip Code"))
            {
            return false; 
            }
        }

    /*if  (!_CF_checkzip(_CF_this.zip.value))
        {
        if  (!_CF_onError(_CF_this, _CF_this.zip, _CF_this.zip.value, "Please enter a valid Zip Code"))
            {
            return false; 
            }
        }

    if  (!_CF_hasValue(_CF_this.phone1, "TEXT" )) 
        {
        if  (!_CF_onError(_CF_this, _CF_this.phone1, _CF_this.phone1.value, "Please enter your Phone Number"))
            {
            return false; 
            }
        }

    if  (!_CF_checkinteger(_CF_this.phone1.value))
        {
        if  (!_CF_onError(_CF_this, _CF_this.phone1, _CF_this.phone1.value, "Please enter your Phone Number"))
            {
            return false; 
            }
        }

    if  (!_CF_hasValue(_CF_this.phone2, "TEXT" )) 
        {
        if  (!_CF_onError(_CF_this, _CF_this.phone2, _CF_this.phone2.value, "Please enter your Phone Number"))
            {
            return false; 
            }
        }

    if  (!_CF_checkinteger(_CF_this.phone2.value))
        {
        if  (!_CF_onError(_CF_this, _CF_this.phone2, _CF_this.phone2.value, "Please enter your Phone Number"))
            {
            return false; 
            }
        }

    if  (!_CF_hasValue(_CF_this.phone3, "TEXT" )) 
        {
        if  (!_CF_onError(_CF_this, _CF_this.phone3, _CF_this.phone3.value, "Please enter your Phone Number"))
            {
            return false; 
            }
        }

    if  (!_CF_checkinteger(_CF_this.phone3.value))
        {
        if  (!_CF_onError(_CF_this, _CF_this.phone3, _CF_this.phone3.value, "Please enter your Phone Number"))
            {
            return false; 
            }
        }

	if  (!_CF_hasValue(_CF_this.email, "TEXT" )) 

        {

        if  (!_CF_onError(_CF_this, _CF_this.email, _CF_this.email.value, "Please enter your email address"))
            {
            return false; 
            }
        }
*/
    if  (!_CF_hasValue(_CF_this.placepurchased, "TEXT" )) 
        {
        if  (!_CF_onError(_CF_this, _CF_this.placepurchased, _CF_this.placepurchased.value, "Please enter where the product was purchased"))
            {
            return false; 
            }
        }

    if  (!_CF_hasValue(_CF_this.citypurchased, "TEXT" )) 
        {
        if  (!_CF_onError(_CF_this, _CF_this.citypurchased, _CF_this.citypurchased.value, "Please enter where the product was purchased"))
            {
            return false; 
            }
        }

    if  (!_CF_hasValue(_CF_this.model, "TEXT" )) 
        {
        if  (!_CF_onError(_CF_this, _CF_this.model, _CF_this.model.value, "Please enter the model"))
            {
            return false; 
            }
        }
	
	if((document.form.country.value != 'us') && (document.form.state2.value == '')) {
		alert("Please enter you state or province.");
		document.form.state2.focus();
		document.form.state2.blur();
		document.form.state2.select();
		return false
	}
	
	if(document.form.satisfied[3].checked == true && (document.form.email.value.length == 0)){
		var notSat = confirm("You have indicated that you are dissatisfied, would you like us to contact you?");
		
		if(notSat){
			document.form.email.focus();
			document.form.email.blur();
			document.form.email.select();
			
			return false;
		}
	}

    return true;
    }

function validateemail(element) {
 	if (element.lastIndexOf('.') > element.lastIndexOf('@')){
 		return true;
 	}
	else{
    	alert("Please enter a valid email address");
		document.form.email.focus();
		document.form.email.blur();
		document.form.email.select();
	}
}

//-->

