﻿$(document).ready(function () {
    /****
    * Search box
    *******/
    var mainfrmtxt = $('#is_spanish').length ? 'Entrar Código Postal' : 'Enter Zip Code';
    $('#mainfrmtxt').val(mainfrmtxt);
    $('#mainfrmtxt').focus(function () {
        if ($(this).val() == mainfrmtxt) {
            $(this).val('')
        }
    });

    $('#mainfrmtxt').blur(function () {
        if (jQuery.trim($(this).val()).length == 0) {
            $(this).val(mainfrmtxt)
        }
    });
});

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.');
       }
   }
 );

}

function ispot_validate_email(form) {
    if (isallwhite(form.phContent_ctl_content_fld_your_name.value) == true) {
        alert("You must enter YOUR NAME.");
        form.phContent_ctl_content_fld_your_name.focus();
        form.phContent_ctl_content_fld_your_name.select();
        return false;
    }

    if (isallwhite(form.phContent_ctl_content_fld_your_email.value) == true) {
        alert("You must enter a valid Email Address for YOUR EMAIL.");
        form.phContent_ctl_content_fld_your_email.focus();
        form.phContent_ctl_content_fld_your_email.select();
        return false;
    }

    if (is_email(form.phContent_ctl_content_fld_your_email.value) == false) {
        alert("You must enter a valid Email Address for YOUR EMAIL.");
        form.phContent_ctl_content_fld_your_email.focus();
        form.phContent_ctl_content_fld_your_email.select();
        return false;
    }

    if (isallwhite(form.phContent_ctl_content_fld_friend_name.value) == true) {
        alert("You must enter a FRIEND'S NAME.");
        form.phContent_ctl_content_fld_friend_name.focus();
        form.phContent_ctl_content_fld_friend_name.select();
        return false;
    }

    if (isallwhite(form.phContent_ctl_content_fld_friend_email.value) == true) {
        alert("You must enter a valid Email Address for FRIEND'S EMAIL.");
        form.phContent_ctl_content_fld_friend_email.focus();
        form.phContent_ctl_content_fld_friend_email.select();
        return false;
    }

    if (is_email(form.phContent_ctl_content_fld_friend_email.value) == false) {
        alert("You must enter a valid Email Address for FRIEND'S EMAIL.");
        form.phContent_ctl_content_fld_friend_email.focus();
        form.phContent_ctl_content_fld_friend_email.select();
        return false;
    }
}

function mailercheck() {
    var el = document.getElementById('emailto');
    if (el.value.length == 0) {
        return false;
    } else {
        return true;
    }

}

var secondCount = 5;
function runTimer() {    
    document.getElementById('sbusy').innerHTML = 'Server is busy. Please wait ' + secondCount + ' seconds and try again.';
    secondCount = secondCount - 1;
    if (secondCount == 0) {
        document.getElementById('sbusy').innerHTML = 'Try submitting the form again now.';
    }
    else {
        myTimer = setTimeout("runTimer()", 1000);
    }
}
