// JScript source code

function change_focus(x_length,fld_to_check,fld_to_focus)
{
	if(fld_to_check.value.length >= x_length)
	{
		fld_to_focus.focus();
	}
}

function is_numbers(str_val)
{
	validChars = "0123456789"; 
	for(var i = 0;i < str_val.length;i++){ 
		if (validChars.indexOf(str_val.charAt(i)) == -1)
			return false;}
	return true;
}

function is_password(str_val)
{
	validChars  = "abcdefghijklmnopqrstuvwxyz"; 
    validChars += "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 
    validChars += "0123456789";
    if(str_val.length < 6)
		return false;
	for(var i = 0;i < str_val.length;i++){ 
		if (validChars.indexOf(str_val.charAt(i)) == -1)
			return false;}
	return true;
}

function fis_email(str_val) {
	if ((str_val.indexOf(".") > 2) && (str_val.indexOf("@") > 0))
		return true;
	else
		return false;
}

function is_email(str_val){	
	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(str_val))
		return true;
	else{
		return false;
	}	
}

function isallwhite(strText)
{
	a = 0;
	cr="";
	var white=" ";
	while (a < (strText.length))
	{
		cr = strText.substring(a,a+1);
		if (white.indexOf(cr) == -1)
			return false;
		a++;
	}
	return true;
}

function pwd_step1(form)
{
	if ((isallwhite(form.fld_email.value)) == true){
		alert("You must enter an E-mail Address."); 
		form.fld_email.focus();
		form.fld_email.select();
		return false;
	}
}

function pwd_step2(form)
{
	if ((isallwhite(form.fld_secret_answer.value)) == true){
		alert("You must enter a Secret Answer."); 
		form.fld_secret_answer.focus();
		form.fld_secret_answer.select();
		return false;
	}
}

function validate(form)
{
	if ((isallwhite(form.fld_firstname.value)) == true){
		alert("You must enter a first name."); 
		form.fld_firstname.focus();
		form.fld_firstname.select();
		return false;
	}
	if ((isallwhite(form.fld_lastname.value)) == true){
		alert("You must enter a last name."); 
		form.fld_lastname.focus();
		form.fld_lastname.select();
		return false;
	}
	if ((isallwhite(form.fld_address.value)) == true){
		alert("You must enter a street address."); 
		form.fld_address.focus();
		form.fld_address.select();
		return false;
	}
	if ((isallwhite(form.fld_city.value)) == true){
		alert("You must enter a city."); 
		form.fld_city.focus();
		form.fld_city.select();
		return false;
	}
	if (form.fld_state.options[form.fld_state.selectedIndex].value == 0){
		alert("You must select a state.");
		form.fld_state.focus();
		return false;
	}
	if (((isallwhite(form.fld_zip5.value)) == true) || (is_numbers(form.fld_zip5.value) == false) || (form.fld_zip5.value.length < 5)){
		alert("You must enter a 5-digit zip code."); 
		form.fld_zip5.focus();
		form.fld_zip5.select();
		return false;
	}
	if (((isallwhite(form.fld_zip4.value)) == false) && ((is_numbers(form.fld_zip4.value) == false) || (form.fld_zip4.value.length < 4))){
		alert("Your 'Zip + 4' zip code must be in the format #####-####."); 
		form.fld_zip4.focus();
		form.fld_zip4.select();
		return false;
	}
	if (((isallwhite(form.fld_phone1.value)) == true) || (is_numbers(form.fld_phone1.value) == false) || (form.fld_phone1.value.length < 3)){
		alert("You must enter a phone number in the format ###-###-####."); 
		form.fld_phone1.focus();
		form.fld_phone1.select();
		return false;
	}
	if (((isallwhite(form.fld_phone2.value)) == true) || (is_numbers(form.fld_phone2.value) == false) || (form.fld_phone2.value.length < 3)){
		alert("You must enter a phone number in the format ###-###-####."); 
		form.fld_phone2.focus();
		form.fld_phone2.select();
		return false;
	}
	if (((isallwhite(form.fld_phone3.value)) == true) || (is_numbers(form.fld_phone3.value) == false) || (form.fld_phone3.value.length < 4)){
		alert("You must enter a phone number in the format ###-###-####."); 
		form.fld_phone3.focus();
		form.fld_phone3.select();
		return false;
	}
	if (((isallwhite(form.fld_fax1.value)) == false) || ((isallwhite(form.fld_fax2.value)) == false) || ((isallwhite(form.fld_fax3.value)) == false)){
		if (((isallwhite(form.fld_fax1.value)) == true) || (is_numbers(form.fld_fax1.value) == false) || (form.fld_fax1.value.length < 3)){
			alert("Your fax number must be in the format ###-###-####."); 
			form.fld_fax1.focus();
			form.fld_fax1.select();
			return false;
		}
		if (((isallwhite(form.fld_fax2.value)) == true) || (is_numbers(form.fld_fax2.value) == false) || (form.fld_fax2.value.length < 3)){
			alert("Your fax number must be in the format ###-###-####."); 
			form.fld_fax2.focus();
			form.fld_fax2.select();
			return false;
		}
		if (((isallwhite(form.fld_fax3.value)) == true) || (is_numbers(form.fld_fax3.value) == false) || (form.fld_fax3.value.length < 4)){
			alert("Your fax number must be in the format ###-###-####."); 
			form.fld_fax3.focus();
			form.fld_fax3.select();
			return false;
		}
	}
	if (isallwhite(form.fld_email.value) == true){
		alert("You must enter an E-mail Address."); 
		form.fld_email.focus();
		form.fld_email.select();
		return false;
	}
	else {
		if (is_email(form.fld_email.value) == false){
			alert("The e-mail address you've entered is invalid."); 
			form.fld_email.focus();
			form.fld_email.select();
			return false;
		}
	}
	if (isallwhite(form.fld_pwd.value) == true){
		alert("You must enter a Password."); 
		form.fld_pwd.focus();
		form.fld_pwd.select();
		return false;
	}
	else{
		if (is_password(form.fld_pwd.value) == false){
			alert("The password you choose must be at least 6 characters long and may be comprised of only numbers and letters (both uppercase and lowercase)."); 
			form.fld_pwd2.value = "";
			form.fld_pwd.value = "";
			form.fld_pwd.focus();
			form.fld_pwd.select();
			return false;
		}
		if (form.fld_pwd.value != form.fld_pwd2.value){
			alert("The passwords you've entered do not match."); 
			form.fld_pwd2.value = "";
			form.fld_pwd.value = "";
			form.fld_pwd.focus();
			form.fld_pwd.select();
			return false;
		}
	}
	if (form.fld_sel_secretquestionid.options[form.fld_sel_secretquestionid.selectedIndex].value == 0){
		alert("Please select a Password Question.");
		form.fld_sel_secretquestionid.focus(); 
		return false;
	}
	if (isallwhite(form.fld_secret_answer.value) == true){
		alert("You must enter a Secret Answer."); 
		form.fld_secret_answer.focus();
		form.fld_secret_answer.select();
		return false;
	}
	if (form.fld_account_type[0].checked == true){
		if ((isallwhite(form.fld_deanum.value) == true) || (form.fld_deanum.value.length != 9)){
			alert("You must enter a valid 9-character DEA Number."); 
			form.fld_deanum.focus();
			form.fld_deanum.select();
			return false;
		}
		if (form.fld_sponsor_id1.options[form.fld_sponsor_id1.selectedIndex].value == 0){
			alert("You must indicate a Sponsor #1. If you enter the name of the sponsor manually, please be sure to select 'OTHER' from the drop-down list.");
			form.fld_sponsor_id1.focus(); 
			return false;
		}
		if (form.fld_sponsor_id1.options[form.fld_sponsor_id1.selectedIndex].value == 1){
			if (isallwhite(form.fld_sponsor_other1.value) == true){
				alert("You selected 'OTHER' for Sponsor #1. Please indicate the name of the sponsor in the text field to the right."); 
				form.fld_sponsor_other1.focus();
				form.fld_sponsor_other1.select();
				return false;
			}
		}
		if (form.fld_sponsor_id2.options[form.fld_sponsor_id2.selectedIndex].value == 0){
			alert("You must indicate a Sponsor #2. If you enter the name of the sponsor manually, please be sure to select 'OTHER' from the drop-down list.");
			form.fld_sponsor_id2.focus(); 
			return false;
		}
		if (form.fld_sponsor_id2.options[form.fld_sponsor_id2.selectedIndex].value == 1){
			if (isallwhite(form.fld_sponsor_other2.value) == true){
				alert("You selected 'OTHER' for Sponsor #2. Please indicate the name of the sponsor in the text field to the right."); 
				form.fld_sponsor_other2.focus();
				form.fld_sponsor_other2.select();
				return false;
			}
		}
		if (form.fld_sponsor_id3.options[form.fld_sponsor_id3.selectedIndex].value == 0){
			alert("You must indicate a Sponsor #3. If you enter the name of the sponsor manually, please be sure to select 'OTHER' from the drop-down list.");
			form.fld_sponsor_id3.focus(); 
			return false;
		}
		if (form.fld_sponsor_id3.options[form.fld_sponsor_id3.selectedIndex].value == 1){
			if (isallwhite(form.fld_sponsor_other3.value) == true){
				alert("You selected 'OTHER' for Sponsor #3. Please indicate the name of the sponsor in the text field to the right."); 
				form.fld_sponsor_other3.focus();
				form.fld_sponsor_other3.select();
				return false;
			}
		}
	}
	else{
		if (form.fld_companyid.options[form.fld_companyid.selectedIndex].value == 0){
			alert("You must indicate a Company/Organization Affiliation. If you enter the name of the company/organization affiliation manually, please be sure to select 'OTHER' from the drop-down list.");
			form.fld_companyid.focus(); 
			return false;
		}
		if (form.fld_companyid.options[form.fld_companyid.selectedIndex].value == 1){
			if (isallwhite(form.fld_company_other.value) == true){
				alert("You selected 'OTHER' for Company/Organization Affiliation. Please indivate the name of the company/organization affiliation in the text field to the right."); 
				form.fld_company_other.focus();
				form.fld_company_other.select();
				return false;
			}
		}
	}
	if (form.fld_accept_terms_yn.checked == false){
		alert("You must indicate your acceptance of and agreement to the Terms of Use in order to continue."); 
		return false;
	}
	if (form.fld_accept_privacy_yn.checked == false){
		alert("You must indicate your acceptance of and agreement to the Privacy Policy in order to continue."); 
		return false;
	}
}

function validate_profile(form)
{
	if ((isallwhite(form.fld_firstname.value)) == true){
		alert("You must enter a first name."); 
		form.fld_firstname.focus();
		form.fld_firstname.select();
		return false;
	}
	if ((isallwhite(form.fld_lastname.value)) == true){
		alert("You must enter a last name."); 
		form.fld_lastname.focus();
		form.fld_lastname.select();
		return false;
	}
	if ((isallwhite(form.fld_address.value)) == true){
		alert("You must enter a street address."); 
		form.fld_address.focus();
		form.fld_address.select();
		return false;
	}
	if ((isallwhite(form.fld_city.value)) == true){
		alert("You must enter a city."); 
		form.fld_city.focus();
		form.fld_city.select();
		return false;
	}
	if (form.fld_state.options[form.fld_state.selectedIndex].value == 0){
		alert("You must select a state.");
		form.fld_state.focus();
		return false;
	}
	if (((isallwhite(form.fld_zip5.value)) == true) || (is_numbers(form.fld_zip5.value) == false) || (form.fld_zip5.value.length < 5)){
		alert("You must enter a 5-digit zip code."); 
		form.fld_zip5.focus();
		form.fld_zip5.select();
		return false;
	}
	if (((isallwhite(form.fld_zip4.value)) == false) && ((is_numbers(form.fld_zip4.value) == false) || (form.fld_zip4.value.length < 4))){
		alert("Your 'Zip + 4' zip code must be in the format #####-####."); 
		form.fld_zip4.focus();
		form.fld_zip4.select();
		return false;
	}
	if (((isallwhite(form.fld_phone1.value)) == true) || (is_numbers(form.fld_phone1.value) == false) || (form.fld_phone1.value.length < 3)){
		alert("You must enter a phone number in the format ###-###-####."); 
		form.fld_phone1.focus();
		form.fld_phone1.select();
		return false;
	}
	if (((isallwhite(form.fld_phone2.value)) == true) || (is_numbers(form.fld_phone2.value) == false) || (form.fld_phone2.value.length < 3)){
		alert("You must enter a phone number in the format ###-###-####."); 
		form.fld_phone2.focus();
		form.fld_phone2.select();
		return false;
	}
	if (((isallwhite(form.fld_phone3.value)) == true) || (is_numbers(form.fld_phone3.value) == false) || (form.fld_phone3.value.length < 4)){
		alert("You must enter a phone number in the format ###-###-####."); 
		form.fld_phone3.focus();
		form.fld_phone3.select();
		return false;
	}
	if (((isallwhite(form.fld_fax1.value)) == false) || ((isallwhite(form.fld_fax2.value)) == false) || ((isallwhite(form.fld_fax3.value)) == false)){
		if (((isallwhite(form.fld_fax1.value)) == true) || (is_numbers(form.fld_fax1.value) == false) || (form.fld_fax1.value.length < 3)){
			alert("Your fax number must be in the format ###-###-####."); 
			form.fld_fax1.focus();
			form.fld_fax1.select();
			return false;
		}
		if (((isallwhite(form.fld_fax2.value)) == true) || (is_numbers(form.fld_fax2.value) == false) || (form.fld_fax2.value.length < 3)){
			alert("Your fax number must be in the format ###-###-####."); 
			form.fld_fax2.focus();
			form.fld_fax2.select();
			return false;
		}
		if (((isallwhite(form.fld_fax3.value)) == true) || (is_numbers(form.fld_fax3.value) == false) || (form.fld_fax3.value.length < 4)){
			alert("Your fax number must be in the format ###-###-####."); 
			form.fld_fax3.focus();
			form.fld_fax3.select();
			return false;
		}
	}
	if (isallwhite(form.fld_email.value) == true){
		alert("You must enter an E-mail Address."); 
		form.fld_email.focus();
		form.fld_email.select();
		return false;
	}
	else {
		if (is_email(form.fld_email.value) == false){
			alert("The e-mail address you've entered is invalid."); 
			form.fld_email.focus();
			form.fld_email.select();
			return false;
		}
	}
}

function validate_login(form)
{
	if (isallwhite(form.fld_uname.value) == true){
		alert("You must enter a User Name."); 
		form.fld_uname.focus();
		form.fld_uname.select();
		return false;
	}
	if (isallwhite(form.fld_pwd.value) == true){
		alert("You must enter a Password."); 
		form.fld_pwd.focus();
		form.fld_pwd.select();
		return false;
	}
}

function valid_account(form)
{
	
	if (isallwhite(form.fld_email.value) == true){
		alert("You must enter an E-mail Address."); 
		form.fld_email.focus();
		form.fld_email.select();
		return false;
	}
	else {
		if (is_email(form.fld_email.value) == false){
			alert("The e-mail address you've entered is invalid."); 
			form.fld_email.focus();
			form.fld_email.select();
			return false;
		}
	}
	if (isallwhite(form.fld_pwd.value) == false){
		if (is_password(form.fld_pwd.value) == false){
			alert("The new password you choose must be at least 6 characters long and may be comprised of only numbers and letters (both uppercase and lowercase)."); 
			form.fld_pwd2.value = "";
			form.fld_pwd.value = "";
			form.fld_pwd.focus();
			form.fld_pwd.select();
			return false;
		}
		if (form.fld_pwd.value != form.fld_pwd2.value){
			alert("The passwords you've entered do not match."); 
			form.fld_pwd2.value = "";
			form.fld_pwd.value = "";
			form.fld_pwd.focus();
			form.fld_pwd.select();
			return false;
		}
	}
	if ((isallwhite(form.fld_deanum.value) == true) || (form.fld_deanum.value.length != 9)){
		alert("You must enter a valid 9-character DEA Number."); 
		form.fld_deanum.focus();
		form.fld_deanum.select();
		return false;
	}
	if (form.fld_sel_secretquestionid.options[form.fld_sel_secretquestionid.selectedIndex].value == 0){
		alert("You must select a Password Question.");  
		return false;
	}
	if (isallwhite(form.fld_secret_answer.value) == true){
		alert("You must enter a Secret Answer."); 
		form.fld_secret_answer.focus();
		form.fld_secret_answer.select();
		return false;
	}
}

function validate_cpass(form)
{
	if (isallwhite(form.fld_oldpwd.value) == true){
		alert("You must enter your Current Password."); 
		form.fld_oldpwd.focus();
		form.fld_oldpwd.select();
		return false;
	}
	if (isallwhite(form.fld_pwd.value) == true){
		alert("You must enter a New Password."); 
		form.fld_pwd.focus();
		form.fld_pwd.select();
		return false;
	}
	else{
		if (is_password(form.fld_pwd.value) == false){
			alert("The password you choose must be at least 6 characters long and may be comprised of only numbers and letters (both uppercase and lowercase)."); 
			form.fld_pwd2.value = "";
			form.fld_pwd.value = "";
			form.fld_pwd.focus();
			form.fld_pwd.select();
			return false;
		}
		if (form.fld_pwd.value != form.fld_pwd2.value){
			alert("The passwords you've entered do not match."); 
			form.fld_pwd2.value = "";
			form.fld_pwd.value = "";
			form.fld_pwd.focus();
			form.fld_pwd.select();
			return false;
		}
	}
}

function launchReferAF(){
     FB.ui(
   {
     method: 'stream.publish',
     message: 'I just got FREE Roadside Assistance from Insure on the Spot!',
             attachment: {
               name: 'Sign Up Now!',
               caption: 'Insure on the Spot',
               description: (
                 'We specialize in low cost auto insurance, and although we ' +
                 'give good drivers a discount, we insure everyone. ' +
                 'Sign up today and refer to a friend to have Roadside Assistance ' +
                 'added to your policy for FREE!'
               ),
               href: 'http://budurl.com/rx2x'
             },
             user_message_prompt: 'Share your thoughts about Insure on the Spot'
   },
   function(response) {
     if (response && response.post_id) {
       //alert('Post was published.');
       document.getElementById('rafthanks').style.display = "block";
       window.location = "#tbox"
     } else {
      //alert('Post was not published.');
      alert('Facebook appears to be experiencing some technical difficulties. Please try again.');
     }
   }
 );
}

/*
window.fbAsyncInit = function() {
        var out = document.getElementById('out');
        FB.init({appId: '141278882578423', status: true, cookie: true,
                 xfbml: true});

        function launchReferAF(){
             FB.ui(
           {
             method: 'stream.publish',
             message: 'I just got FREE Roadside Assistance from Isure on the Spot!',
             attachment: {
               name: 'Sign Up Now!',
               caption: 'Insure on the Spot',
               description: (
                 'We specialize in low cost auto insurance, and although we ' +
                 'give good drivers a discount, we insure everyone. ' +
                 'Sign up today and refer to a friend to have Roadside Assistance ' +
                 'added to your policy for FREE!'
               ),
               href: 'http://www.insureonthespot.com'
             },                       
             action_links: [
               { text: 'Code', href: 'http://www.insureonthespot.com' }
             ],
             user_message_prompt: 'Share your thoughts about Insure on the Spot'
           },
           function(response) {
             if (response && response.post_id) {
              // alert('Post was published.');
             } else {                                         
              // alert('Post was not published.');
             }
           }
         );
        }
                                                                                            
};
*/
/*
      (function() {
        var e = document.createElement('script');
        e.type = 'text/javascript';
        e.src = document.location.protocol +
          '//connect.facebook.net/en_US/all.js';
        e.async = true;
        document.getElementById('fb-root').appendChild(e);
      }());
*/