var popUpTemplate;
var valid = false;
var isTemplatePresent = false;
var isInsured = false;
var isPopupTriggered = false;
var isSignup = false;

function triggerValidation() {
    //alert("asdfS");
    $(".submit input, .submit-inner input, .submit-express input").click(function (event) {
        var imgSubmit = false; var submitExpressInterest = false; var submitContactUs = false;

        if ($(".request-a-quote").length == 0 && $(this).attr("id") == "imgSubmit") //on click of submit image on home page.
            imgSubmit = true;
        else if ($(this).attr("id") == "submitExpressInterest")
            submitExpressInterest = true;
        else if ($(this).attr("id") == "submitContactUs")
            submitContactUs = true;

        if (!isTemplatePresent) {
            $("body").append(popUpTemplate);
            isTemplatePresent = true;
        }

        if (($(".contact-us").length > 0)) {

            /* Validation */
            var bFirstName = validateNameField($("#firstName").val(), 'First Name');
            var bSurName = validateNameField($("#surName").val(), 'Surname');
            var bSubject = validateNameField($("#subject").val(), 'Subject');
            var bEmail = validateEmailField($("#yourEmail").val()) && ($("#yourEmail").val() != 'Your email address');
            var bBrief = validateNameField($("#briefMessage").val(), '');

            if (!bFirstName || !bSurName || !bSubject || !bEmail || !bBrief) {
                errorPopup();
                return false;
            } else {
                handleSubmitContact();
            }

            /*
            $(".form-mid input:text,.form-mid textarea").not(":button, :submit, :reset, :hidden, :checkbox").each( function() {
            if((($(this).val() == 'First Name') || ($(this).val() == 'Surname') || ($(this).val() == 'Your email address') || ($(this).val() == 'Subject') || ($(this).val() == '')) ){
            //alert("Attr:-"+$(this).attr("name")+$(this).val());
            //alert($("#item_type").val());
            errorPopup();
            return false;
            }else{
            $(".express-itr").removeShadow();
            $(".err-box").removeShadow();
            if(($("#yourEmail").val() != 'Your email address') && (valid == false)){
            email_address = $('#yourEmail');           
            email_regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;           
            if(!email_regex.test(email_address.val())){
            errorPopup();
            return false;						
            }else{
            valid = true;                                                                                      

          
            }
            }else{
            if((valid)){
            if(submitContactUs)
            {
            handleSubmitContact();
            submitContactUs= false;
            }

            //thankYouPopup();
            }else{
            valid = false;
            errorPopup();
            return false;
            }
            }
            }
            });*/
        } else if (($(".request-a-quote").length > 0)) {
            var validateFileds = new Array();
            var highlightInvalidFileds = new Array();

            var bFirstName = validateNameField($("#firstName").val(), 'First Name');
            var bSurName = validateNameField($("#surName").val(), 'Surname');
            var bPhoneNumber = validatePhoneNumberField($("#yourPhone").val());
            var bMobileNumber = validatePhoneNumberField($("#yourMobile").val());
            var bEmail = validateEmailField($("#yourEmail").val());
            var bItemType = validateSelectBoxField($("#item_type").val());
            var bBrief = validateNameField($("#briefMessage").val(), '');

            var bIfYes = true;
            if ($("#yes_insured_btn")[0].checked == true) {
                bIfYes = validateNameField($("#ifyes").val(), '');
                if (!bIfYes) {
                    validateFileds[validateFileds.length] = fieldPrompts["ifyes"];
                    highlightInvalidFileds[highlightInvalidFileds.length] = "#ifyes";
                }
            }

            if (!bFirstName) {
                validateFileds[validateFileds.length] = fieldPrompts["firstName"];
                highlightInvalidFileds[highlightInvalidFileds.length] = "#firstName";
            }

            if (!bSurName) {
                validateFileds[validateFileds.length] = fieldPrompts["surName"];
                highlightInvalidFileds[highlightInvalidFileds.length] = "#surName";
            }

            if (($("#yourPhone").val() == "Your phone number") && (($("#yourMobile").val()) == "Your mobile number")) {
                validateFileds[validateFileds.length] = fieldPrompts["phoneMobile"];
                highlightInvalidFileds[highlightInvalidFileds.length] = "#yourPhone";
                highlightInvalidFileds[highlightInvalidFileds.length] = "#yourMobile";
            } else if (($("#yourPhone").val() == "Your phone number") && (!bMobileNumber)) {
                validateFileds[validateFileds.length] = fieldPrompts["invalidMobile"];
                highlightInvalidFileds[highlightInvalidFileds.length] = "#yourMobile";
            } else if (($("#yourMobile").val() == "Your mobile number") && (!bPhoneNumber)) {
                validateFileds[validateFileds.length] = fieldPrompts["invalidPhone"];
                highlightInvalidFileds[highlightInvalidFileds.length] = "#yourPhone";
            } else if (!bPhoneNumber && !bMobileNumber) {
                validateFileds[validateFileds.length] = fieldPrompts["invalidPhone"];
                highlightInvalidFileds[highlightInvalidFileds.length] = "#yourPhone";
                validateFileds[validateFileds.length] = fieldPrompts["invalidMobile"];
                highlightInvalidFileds[highlightInvalidFileds.length] = "#yourMobile";
            } else if (bPhoneNumber && !bMobileNumber) {
                validateFileds[validateFileds.length] = fieldPrompts["invalidMobile"];
                highlightInvalidFileds[highlightInvalidFileds.length] = "#yourMobile";
            } else if (!bPhoneNumber && bMobileNumber) {
                validateFileds[validateFileds.length] = fieldPrompts["invalidPhone"];
                highlightInvalidFileds[highlightInvalidFileds.length] = "#yourPhone";
            } else {
                $("#yourPhone, #yourMobile").removeClass("invalidField");
            }

            if (($("#yourEmail").val()) == "Your email address") {
                validateFileds[validateFileds.length] = fieldPrompts["yourEmail"];
                highlightInvalidFileds[highlightInvalidFileds.length] = "#yourEmail";
            } else if (!bEmail) {
                validateFileds[validateFileds.length] = fieldPrompts["invalidEmail"];
                highlightInvalidFileds[highlightInvalidFileds.length] = "#yourEmail";
            }

            if (!bItemType) {
                validateFileds[validateFileds.length] = fieldPrompts["item_type"];
                highlightInvalidFileds[highlightInvalidFileds.length] = "#item_type";
            }

            if (!bBrief) {
                validateFileds[validateFileds.length] = fieldPrompts["briefMessage"];
                highlightInvalidFileds[highlightInvalidFileds.length] = "#briefMessage";
            }
            /*email_address = $('#yourEmail');
            email_regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
            $(".form-mid input:text, .form-mid textarea, #item_type_tovalidate").not(":button, :submit, :reset, :hidden, :checkbox ,#noFileSelected, #item_type1, #yourMobile, #yourPhone").each(function (i) {
            $(".err-box").removeShadow();
            //alert(i+""+$(this).attr("name"));
            if (($(this).val() == 'First Name') || ($(this).val() == 'Surname') || ($(this).val() == 'Your email address') || 
            ($("#item_type").val() == "0") || ($(this).val() == "") || ($("#yes_insured_btn").is(':checked'))) {
            if (($(this).attr("title") == $(this).val())) {
            if (!($(this).next().val() == "0")) {
            if (($(this).attr("title"))) {
            validateFileds[validateFileds.length] = fieldPrompts[$(this).attr("name")];
            highlightInvalidFileds[highlightInvalidFileds.length] = "#" + $(this).attr("id");
            }
            } else if ((($(this).next().val() == "0")) && (i == 3)) {
            validateFileds[validateFileds.length] = fieldPrompts["item_type"];
            highlightInvalidFileds[highlightInvalidFileds.length] = "#item_type_tovalidate";
            }
            }
            if ((!email_regex.test(email_address.val())) && ($("#yourEmail").val() != 'Your email address') && (i == 2)) {
            validateFileds[validateFileds.length] = fieldPrompts["invalidEmail"];
            highlightInvalidFileds[highlightInvalidFileds.length] = "#" + $(this).attr("id");
            }/*
            if ($("#yourPhone").val() != "Your phone number" && (i == 3)) {
            validateFileds[validateFileds.length] = fieldPrompts["invalidPhone"];
            highlightInvalidFileds[highlightInvalidFileds.length] = "#" + $(this).attr("id");
            }
            if ($("#yourMobile").val() != "Your mobile number" && (i == 4)) {
            validateFileds[validateFileds.length] = fieldPrompts["invalidMobile"];
            highlightInvalidFileds[highlightInvalidFileds.length] = "#" + $(this).attr("id");
            }
            if ($("#briefMessage").val() == "" && i==4) {
            validateFileds[validateFileds.length] = fieldPrompts[$(this).attr("name")];
            highlightInvalidFileds[highlightInvalidFileds.length] = "#" + $(this).attr("id");
            }
            //alert(i+" 11 "+$(this).attr("name"))
            if (($("#yes_insured_btn").is(':checked')) && ($("#ifyes").val() == "") && (i == 5)) {
            validateFileds[validateFileds.length] = fieldPrompts["ifyes"];
            highlightInvalidFileds[highlightInvalidFileds.length] = "#ifyes";
            }
            }
            });
            if (($("#yourPhone").val() == 'Your phone number') && ($("#yourMobile").val() == 'Your mobile number')) {
            validateFileds[validateFileds.length] = fieldPrompts["phoneMobile"];
            } else if ((($("#yourPhone").val() != 'Your phone number') || ($("#yourMobile").val() != 'Your mobile number'))) {
            $("#yourPhone, #yourMobile").removeClass("invalidField");
            }*/

            if ($("#uploadIE").val() != "") {
                var result = triginpfunIE();
                if (!result) {
                    validateFileds[validateFileds.length] = fieldPrompts["invalidFileFormat"];
                    
                } //event.preventDefault();
            }
            if ($("#upload").val() != "") {
                var result = triginpfun();
                if (!result) {
                    validateFileds[validateFileds.length] = fieldPrompts["invalidFileFormat"];
                }
            }
            if (validateFileds.length == 0) {
                //customPopup("Thank You!", "A representative from Suttons &amp; Robertsons<br/> will promptly contact you within 24hours.", "");
                //isPopupTriggered = false;
				return true;
            } else {
                customPopup("Error!", "Please enter the following missing information and <strong>\"SUBMIT\"</strong> the form",

                validateFileds.join("<br/>"));
                highlightInvalidFields(highlightInvalidFileds);
                isPopupTriggered = true;
                if ($.browser.webkit) {
                    $("#yourPhone").addClass("invalidField");
                    $("#yourMobile").addClass("invalidField");
                    $("#item_type_tovalidate").addClass("invalidField");
                }
                event.preventDefault();
            }
        } else {

            var bFirstName = validateNameField($("#firstName").val(), 'First Name');
            var bSurName = validateNameField($("#surName").val(), 'Surname');
            var bPhoneNumber = validatePhoneNumberField($("#yourPhone").val());
            var bEmail = validateEmailField($("#yourEmail").val());
            var bItemType = validateSelectBoxField($("#item_type").val());

            if (!bFirstName || !bSurName || !bPhoneNumber || !bEmail || !bItemType || ($("#yourEmail").val() == 'Your email address') || ($("#yourPhone").val() == "Your phone number")) {
                errorPopup();
                event.preventDefault();
                valid = false;
                return false;
            } else {
                if (imgSubmit) {
                    handleSubmitRequest();
                    imgSubmit = false;
                }
                else if (submitExpressInterest) {
                    handleExpressInterest();
                    submitExpressInterest = false;
                }
            }


            /* $("#popup input:text, .form-mid input:text, .form-mid-inner input:text").not(":button, :submit, :reset, :hidden, :checkbox").each(function () {
            if ((($(this).val() == 'First Name') || ($(this).val() == 'Surname') || ($(this).val() == 'Your email address') || ($(this).val() == 'Your phone number')) || ($("#item_type").val() == "0")) {
            errorPopup();
            event.preventDefault(); valid = false;
            return false;
            } else {
            $(".express-itr").removeShadow();
            $(".err-box").removeShadow();
            if (($("#yourEmail").val() != 'Your email address') && (valid == false)) {
            email_address = $('#yourEmail');
            email_regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
            if (!email_regex.test(email_address.val())) {
            errorPopup();
            event.preventDefault(); valid = false;
            return false;
            } else {
            valid = true;
            }
            } else {
            if ((valid)) {
            //thankYouPopup();
            if (imgSubmit) {
            handleSubmitRequest();
            imgSubmit = false;
            }
            else if (submitExpressInterest) {
            handleExpressInterest();
            submitExpressInterest = false;
            }

            } else {
            valid = false;
            errorPopup();
            event.preventDefault();
            return false;
            }
            }
            }
            });*/
        }

    });
}
function errorPopup(msg) {

    if (msg == null)
        msg = "Some information is missing. Please enter your information into all fields and click the <strong>\"SUBMIT\"</strong> button.";
    if (!isTemplatePresent) {
        $("body").append(popUpTemplate);
        isTemplatePresent = true;
    }
    $("#popup").fadeOut("fast");

    if (($(".online-quote, .online-quote-inner, .contact-us, .request-a-quote").length > 0)) {
        loadPopup("backgroundPopup", "thank_you_error");
    }
    $("#thank_you_error").fadeIn("fast");
    $('#close_butn').unbind('click');
    $('#bottom_lnk').unbind('click');
    $("#error_desc").html("");
    $("#header_message").html("Error!");
    $("#message_desc").html(msg);
    $("#bottom_lnk").html("Return to form");
    $('#close_butn,#bottom_lnk').bind('click', function () {
        $(".err-box").removeShadow();
        $("#thank_you_error").fadeOut("fast");
        if (($(".online-quote, .online-quote-inner,.contact-us, .request-a-quote").length > 0)) {
            disablePopup("backgroundPopup", "thank_you_error");
        }
        $("#popup").fadeIn("fast");
    });
    centerPopup("backgroundPopup", "thank_you_error");
    $(".err-box").dropShadow();
    return false;
}

function customErrorPopup(customTitle, customMessage) {
    if (!isTemplatePresent) {
        $("body").append(popUpTemplate);
        isTemplatePresent = true;
    }

    $("#popup").fadeOut("fast");

    if (($(".online-quote, .online-quote-inner, .contact-us, .request-a-quote").length > 0)) {
        loadPopup("backgroundPopup", "thank_you_error");
    }
    $("#thank_you_error").fadeIn("fast");
    $('#close_butn').unbind('click');
    $('#bottom_lnk').unbind('click');
    $("#header_message").html(customTitle);
    $("#error_desc").html("");
    $("#message_desc").html(customMessage);
    $("#bottom_lnk").html("Return to form");
    $('#close_butn,#bottom_lnk').bind('click', function () {
        $(".err-box").removeShadow();
        $("#thank_you_error").fadeOut("fast");
        if (($(".online-quote, .online-quote-inner,.contact-us, .request-a-quote").length > 0)) {
            disablePopup("backgroundPopup", "thank_you_error");
            //$('.online-quote form, .online-quote-inner form, .contact-us form, .request-a-quote form, .express-itr').get(0).reset();
            //$('.jquery-selectbox-currentItem').text("Please select");
            $(".err-box").removeShadow();
            //$("#email input").val('Your email address');
            valid = false;
        }
        $("#popup").fadeIn("fast");
    });
    centerPopup("backgroundPopup", "thank_you_error");
    $(".err-box").dropShadow();
    return false;
}

function thankYouPopup(isContactUs) {
    if (!isTemplatePresent) {
        $("body").append(popUpTemplate);
        isTemplatePresent = true;
    }

    $("#popup").fadeOut("fast");
    if (($(".online-quote, .online-quote-inner, .contact-us, .request-a-quote").length > 0)) {
        loadPopup("backgroundPopup", "thank_you_error");
    }
    $("#thank_you_error").fadeIn("fast");
    $('#close_butn').unbind('click');
    $('#bottom_lnk').unbind('click');
    $("#header_message").html("Thank You!"); 
    if ($("#thankYouiFrame").length == 0) {
        if (isContactUs)
            $("#thankYouFrame").append("<iframe id=\"thankYouiFrame\" src=\"/thankYou3.html\"></iframe>");
        else
            $("#thankYouFrame").append("<iframe id=\"thankYouiFrame\" src=\"/thankYou2.html\"></iframe>");
    }

    $("#message_desc").html("A representative from Suttons &amp; Robertsons<br/> will promptly contact you within 24 hours.");
    $("#bottom_lnk").html("Return to site");
    $('#close_butn, #bottom_lnk').bind('click', function () {
        $("#thank_you_error").fadeOut("fast");
$("#thankYouFrame").empty();
        disablePopup("backgroundPopup", "thank_you_error");
        $('.online-quote form, .online-quote-inner form, .contact-us form, .request-a-quote form, .express-itr form').get(0).reset();
        $("#noFileSelected").removeClass("fileimg");
        $('.jquery-selectbox-currentItem').text("Please select");
        $(".err-box").removeShadow();
        $("#email input").val('Your email address');
        valid = false;
    });
    centerPopup("backgroundPopup", "thank_you_error");
    $(".err-box").dropShadow();
    return false;
}

function customPopup(title, customMessage, customDesc) {
    if (title == "Thank You!") {
        //$("#error_desc").remove();
        $("#error_desc").html("");
    if ($("#thankYouiFrame").length == 0) $("#thankYouFrame").append("<iframe id=\"thankYouiFrame\" src=\"/thankYou.html\"></iframe>");
        //document.getElementById("error_desc").innerHTML = "";
        $("#error_desc").css({ "margin": "0", "font-size": "0" });
        $("#bottom_lnk").html("Return to site");
    } else {
        $("#message_desc").next().append("<p class=\"err-desc\" id=\"error_desc\"></p>");
        $("#error_desc").css({ "margin": "4px 0 16px 0", "font-size": "14px" });
        $("#bottom_lnk").html("Return to form");
    }
    $(".err-box").removeShadow();
    $("#thank_you_error").removeShadow();
    $("#popup").fadeOut("fast");
    if (($(".online-quote, .online-quote-inner, .contact-us, .request-a-quote").length > 0)) {
        loadPopup("backgroundPopup", "thank_you_error");
    }
    $("#thank_you_error").fadeIn("fast");
    $('#close_butn').unbind('click');
    $('#bottom_lnk').unbind('click');
    $("#header_message").html(title);
    if (customMessage != "") {
        $("#message_desc").html(customMessage);
    }
    if (customDesc != "") {
        $("#error_desc").html(customDesc);
    }
    $('#close_butn, #bottom_lnk').bind('click', function () {
        if (title == "Thank You!") {
            $("#thank_you_error").fadeOut("fast");
            disablePopup("backgroundPopup", "thank_you_error");
            $("#thankYouFrame").empty();
            $('.online-quote form, .online-quote-inner form, .contact-us form, .request-a-quote form').get(0).reset();
            $("#noFileSelected").removeClass("fileimg");
	        $('.jquery-selectbox-currentItem').text("Please select");
            $("#item_type").val("0");
            $(".err-box").removeShadow();
            $("#email input").val('Your email address');
            $("#ifyes").addClass("disabled-button");
            $("#ifyes").attr("disabled", "disabled");
        } else {
            $("#thank_you_error").fadeOut("fast");
            if (($(".online-quote, .online-quote-inner,.contact-us, .request-a-quote").length > 0)) {
                disablePopup("backgroundPopup", "thank_you_error");
                $("#thank_you_error").removeShadow();
            }
            $("#popup").fadeIn("fast");
        }
    });
    centerPopup("backgroundPopup", "thank_you_error");
    $(".err-box").dropShadow();
    return false;
}


function validatePhone(refToApply) {
    $("#" + refToApply).bind('keydown', function (e) {
        var key = e.charCode || e.keyCode || 0;
        var ctrlKey = e.ctrlKey;
        var shiftKey = e.shiftKey;
        var keychar = String.fromCharCode(key);
		var length = $(this)[0].value.length;
        if (!ctrlKey && /*!shiftKey &&*/ ((key == 8 || key == 9 || key == 46 || key == 35 || key == 36 || (key >= 37 && key <= 40)) /* backspace, end, begin, top, bottom, right, left, del, tab */ || ((key >= 48 && key <= 57) && !shiftKey) || (key >= 96 && key <= 105))) { /* 0-9 */
		if (length == 11 && ((key >= 48 && key <= 57) || (key >= 96 && key <= 105))) {
                e.preventDefault();
            } else {
            return;
			}
        } else {
            e.preventDefault();
        }
    });

    $("#" + refToApply).bind('contextmenu', function (e) {
        return false;
    });
}


function validateEmail(refToApply) {
    $("#" + refToApply).bind('keypress', function (e) {
        var key = e.charCode || e.keyCode || 0;
        var keychar = String.fromCharCode(key);
        //console.log(keychar + " - " + key);
        if (((key == 8 || key == 9 || key == 32 || key == 35 || key == 36 || (key >= 37 && key <= 40)) && e.charCode == 0) /* backspace, end, begin, top, bottom, right, left, del, tab */ || (key >= 48 && key <= 57) || (key >= 65 && key <= 90) || key == 45 || key == 95 || /* key == 36 ||*/key == 46 || (key == 64) || (key >= 97 && key <= 122)) { /* 0-9a-zA-Z */
            return;
        } else {
            e.preventDefault();
        }
    });
}
function validateName(refToApply) {
    $("#" + refToApply).bind('keypress', function (e) {
        var key = e.charCode || e.keyCode || 0;
        var keychar = String.fromCharCode(key);
        //console.log(keychar + " - " + key);
        if (((key == 8 || key == 9 || key == 35 || key == 36 || (key >= 37 && key <= 40)) && e.charCode == 0) /* backspace, end, begin, top, bottom, right, left, del, tab */ || key == 46 || key == 32 || (key >= 48 && key <= 57) || (key >= 65 && key <= 90) || (key >= 97 && key <= 122)) {

            /* 0-9a-zA-Z & . (dot) */
            return;
        } else {
            e.preventDefault();
        }
    });
}
$(document).ready(function () {

var UserName= new String("SandRLondon") ;
 url = 'http://api.twitter.com/1/statuses/user_timeline/' + UserName+ '.json?callback=?';
            $.getJSON(url, function (tweet) {
                var text = tweet[0].text;
                var formatText = twitterLinks(text);
                $("#last-tweet").html(formatText);
            });


     $('#briefMessage').bind({
        keyup: function () {
            var max = 500;
            if ($(this).val().length > max) {
                $(this).val($(this).val().substr(0, max));
            }
        },
        keypress: function () {
            var max = 500;
            if ($(this).val().length > max) {
                $(this).val($(this).val().substr(0, max));
            }
        }
    });

    hightlightNavigationItem();

    $(".form-mid input, .form-mid-inner input, .form-mid textarea, .form-mid-inner textarea, #email input").not(".form-mid input:radio[@name='yesinsured']").each(function () {
        var nameOfField = $(this).attr("name");
        $(this).attr("id", nameOfField);
        if (nameOfField == "phone" || nameOfField == "yourPhone" || nameOfField == "yourMobile") {
            //$(this).attr("maxlength", "11");
        } else if (nameOfField == "firstName" || nameOfField == "surName") {
            $(this).attr("maxlength", "30");
        } else if (nameOfField == "briefMessage") {
            $(this).attr("maxlength", "500");
        }
        else if (nameOfField == "ifyes") {
            $(this).attr("maxLength", "10");
        }
        else if (nameOfField == "yourEmail") {
            $(this).attr("maxLength", "50");
        }
    });

    /****** Custom Select boxes *******/
    $("#item_type").selectbox().bind('change', function () {
        $("<div>Value of #item_type changed to: " + $(this).val() + "<\/div>").appendTo('#item_type .demoTarget').fadeOut(5000, function () {
            $(this).remove();
        });
    });
    $("#item_type1").selectbox().bind('change', function () {
        $("<div>Value of #item_type1 changed to: " + $(this).val() + "<\/div>").appendTo('#item_type1 .demoTarget').fadeOut(5000, function () {
            $(this).remove();
        });
    });

    /****** Enabling active/inactive states of Navigation *******/
    $("#nav dd").mouseover(function () {
        $(this).addClass("active");
    });
    $("#nav dd").mouseout(function () {
        if ($.browser.msie) {
            if (!($(this).hasClass("active"))) {
                //alert("false");
            }
        }
        $(this).removeClass("active");

    });
    $(".cs_leftBtn img, .cs_rightBtn img").mouseover(function () {
        var image = $(this).attr("src");
        if (image.indexOf("prev") > 1) {
            $(this).attr("src", "/images/prev-mo.jpg");
        } else {
            $(this).attr("src", "/images/next-mo.jpg");
        }

    });
    $(".cs_leftBtn img, .cs_rightBtn img").mouseout(function () {
        var image = $(this).attr("src");
        if (image.indexOf("prev") > 1) {
            $(this).attr("src", "/images/prev.jpg");
        } else {
            $(this).attr("src", "/images/next.jpg");
        }

    });

    /****** Header - Right most Menu modification  *******/
    if ($.browser.msie) {
        $("#nav dd:eq(3) dl dd:eq(1)").next().addClass("ie7-fix");
    }
    if ($.browser.webkit) {
        $("#nav").css({ "width": "955px" });
    }

    if ($.browser.msie) {
        $('input').bind('focus', function () {
            $(this).addClass('ieFocus');
        }).bind('blur', function () {
            $(this).removeClass('ieFocus');
        });
        $('textarea').bind('focus', function () {
            $(this).addClass('ieFocus');
        }).bind('blur', function () {
            $(this).removeClass('ieFocus');
        });
    }

    var browserMozilla = $.browser.mozilla;
    var browserWebkit = $.browser.webkit;
    var browserSafari = $.browser.safari || $.browser.webkit;
    var browserMsie = $.browser.msie;
    var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome');
    var is_safari = navigator.userAgent.toLowerCase().indexOf('safari') > -1;


    if ((navigator.appVersion.indexOf("Mac") != -1) && (browserMozilla)) {
        $("#nav dd a span.active-menu").css({ "top": "-8px" });
        $("#company_info_container #company_info p.live-chat").addClass("live-chat-mac-mozilla");
        $("#company_info_container #company_info p.tel").addClass("telephone-mac-mozilla");
        $("#store_info dl dd p.store-map a").addClass("view-map-mac-mozilla");
        $("#store_info dl dd p.store-map span").addClass("view-map-mac-mozilla");
        $("#partners_img").css({ "height": "616px" });
        $("#inner_left_container #meet_the_staff h5").css({ "font-family": "'Optima Regular',Verdana,Arial,sans-serif" });
        $("#pripol_img").css({ "height": "9577px" });
        $("#shop_img").css({ "height": "1652px" });
        $("#pawnbrokingserv_img").css({ "height": "598px" });
        $("#loans_img").css({ "height": "626px" });
        $("#how_much_img").css({ "height": "468px" });
        $("#sellyour_rolexwatch_img").css({ "height": "510px" });
        $("#sellyour_philippewatch_img").css({ "height": "474px" });
        $("#sellyour_omegawatch_img").css({ "height": "474px" });
        $("#sellyour_breitlingwatch_img").css({ "height": "492px" });
        $("#sellyour_watch_img").css({ "height": "456px" });
        $("#sellyour_cartierwatch_img").css({ "height": "456px" });
        $(".mini-center-needhelpbox").css({ "padding-left": "7px" });
        $(".mini-need-helpbox4middle").css({ "padding-left": "8px" });
        $(".helpbox-extra4middle").css({ "padding-left": "14px" });
        $(".helpbox-extra-temp").css({ "padding-left": "37px" });
        $("#affiliations_img").css({ "height": "500px" });
        $("#sitemap_img").css({ "height": "1264px" });
        $("#faqs_img").css({ "height": "3310px" });
        $("#raq_img").css({ "height": "732px" });
        $("#pawnbroking_img").css({ "height": "1156px" });
        $(".livechatcont1").css({ "margin-left": "26px","margin-top": "-15px" });
        $(".livechatfix").css({ "margin-top": "7px" });
        $(".live-chat-rect").css({ "margin-left": "23px" });
        $("dl#nav dd dl dd dl dd").css({ "width": "178px" });
        $(".pawn-need-help-box .livechatcont1 p").css({ "padding-left":"22px"});
        
		if(navigator.userAgent.indexOf("3.6")>0) {
			$("#shop_box_medium .livechatcont1 p").css({ "margin-left": "-9px" ,"padding-left" : "0px"});
			$(".pawn-need-help-box .livechatcont1 p").css({ "margin-left": "-9px" ,"padding-left" : "0px !important"});
			$(".icon-lc").css({ "margin-top": "7px" });
			$(".live-chat-rect p").css({ "margin-left": "-6px"}); 
		}
    }
    
    if ((navigator.appVersion.indexOf("Mac") != -1)) {
        $("#right_container #receive_updates").css({ "margin": "14px 0 23px 0" });
        $(".spacer").css({ "height": "89px" });
    }
    
    if ((navigator.appVersion.indexOf("Mac") != -1) && (browserWebkit)) {
        $("#company_info_container #company_info p.live-chat").addClass("live-chat-mac-webkit");
        $("#company_info_container #company_info p.tel").addClass("telephone-mac-webkit");
       	//$("#pawnbroking_img").css({ "height": "940px" });
        $(".icon").css({ "margin-top": "-2px" });
        $(".partners-right-img").css({ "height": "520px !important" });
        $(".watches-spacer").css({ "height": "101px !important" });
        $(".gold-spacer").css({ "height": "68px !important" });
        $("#jewellery_right div.faqs-right-bg").css({ "height": "212px !important" });
        $(".diamonds-spacer").css({ "height": "104px !important" });
        $("#pawnbrokingserv_img").css({ "height": "590px" });
        $("#contus_img").css({ "height": "1301px" });
        $(".livechatfix").css({ "margin-top": "7px" });
        $(".livechatcont1").css({ "margin-left": "26px", "margin-top": "-15px" });
        $(".expert-valuations-right").css({ "height": "347px !important" });
        $("#shop_box .livechatcont").css({ "margin-left": "8px !important", "margin-top": "-9px !important" });
        $(".live-chat-rect").css({ "margin-left": "26px", "margin-top": "-8px" });
		$(".helpbox-extra-temp").css({ "padding-left": "37px" });
		$(".pawn-need-help-box .livechatcont1 p").css({ "padding-left":"23px !important"});
		$("#shop_box .livechatcont p").css({ "margin-right": "6px !important" });
    }
 

    if ((navigator.appVersion.indexOf("Win") != -1) && ((is_chrome == -1) && (browserSafari || is_safari) )) {
        //$("#btm_lnks dd.icon").css({"margin-top":"-20px"});
        $("#shop_img").css({ "height": "1629px" });
        $("#partners_img").css({ "height": "619px !important" });
        $("#pawnbrokingserv_img").css({ "height": "590px" });
        $("#loans_img").css({ "height": "563px !important" });
        $("#how_much_img").css({ "height": "461px !important" });
        $("#loans_img").css({ "height": "563px !important" });
        $("#how_much_img").css({ "height": "461px !important" });
        $("#sellyour_rolexwatch_img").css({ "height": "496px !important" });
        $("#sellyour_philippewatch_img").css({ "height": "442px !important" });
        $("#sellyour_omegawatch_img").css({ "height": "478px !important" });
        $("#sellyour_watch_img").css({ "height": "424px !important" });
        $("#sellyour_breitlingwatch_img").css({ "height": "478px !important" });
        $("#sellyour_cartierwatch_img").css({ "height": "424px !important" });
        $(".mini-center-needhelpbox").css({ "padding-left": "9px !important" });
        $(".mini-need-helpbox4middle").css({ "padding-left": "10px !important" });
        $(".helpbox-extra4middle").css({ "padding-left": "16px !important" });
        $("#affiliations_img").css({ "height": "526px !important" });
        $("#sitemap_img").css({ "height": "1166px !important" });
        $("#pripol_img").css({ "height": "9702px !important" });
        $("#contus_img").css({ "height": "1546px !important" });
        $("#faqs_img").css({ "height": "3317px !important" });
        $("#raq_img").css({ "height": "716px !important" });
        //$("#pawnbroking_img").css({"height":"1145px !important"});
        $("#raq_img").css({ "height": "744px !important" });
       	//$(".livechatcont").css({ "margin-top": "-7px", "margin-left": "7px" });
        $(".lc-fix").css({ "margin-left": "-10px !important" });
        $(".lc-mid").css({ "margin-left": "-10px !important" });
        $(".imgtxtboxbottom").css({ "margin-bottom": "-11px !important" });
        $(".mini-center-needhelpbox_sell").css({ "margin-bottom": "8px !important" });
		$(".mini-center-needhelpbox_sell").css({ "padding-bottom": "0px !important" });
		$(".mini-need-helpbox4middle_sf").css({ "padding-left": "0px !important" });
		$(".sendmail-sell-watch-fix").css({ "padding-left": "0px !important" });
		$(".live-chat-rect").css({ "margin-left": "14px !important" });
		$(".lpChatTextLink").css({ "margin-left": "-2px !important" });
		$(".tel-sell-watch-fix").css({ "padding-left": "7px !important" });
		$(".icon-lc").css({ "margin-top": "5px !important" });
		$(".helpbox-extra-temp").css({ "padding-left": "37px" });

    }
    
    if ((navigator.appVersion.indexOf("Win") != -1) && ((is_chrome >= -1) && (browserSafari || is_safari) )) {
        $(".livechatcont").css({ "margin-top": "-6px", "margin-left": "8px" });
        $(".lc-fix").css({ "margin-left": "-2px !important" });
        $(".lc-mid").css({ "margin-left": "-2px !important" });
        $(".need-help-saf-chro-fix").css({"padding-bottom":"8px !important"});
        $(".need-help-loans-watches-saf-chro-fix").css({"padding-bottom":"20px !important"});
        $(".live-chat").css({ "margin-right": "17px !important" });
        $(".icon-saf").css({ "margin-top": "1px !important" });
		$("#shop_box_medium .livechatcont1 p").css({ "padding-left": "17px" });
		$("#shop_box_rq .livechatcont1 p").css({ "padding-left": "17px" });
		$(".pawn-need-help-box .livechatcont1 p").css({ "padding-left": "20px  !important" });
		$("#shop_box .livechatcont p").css({ "margin-right": "7px" });
    }
    
	if ((navigator.appVersion.indexOf("Win") != -1) && ((is_chrome > -1))) {
		$(".icon-lc").css({ "margin-top": "0px !important" });
        $(".icon").css({ "margin-top": "1px" });

	}
	
    if ((navigator.appVersion.indexOf("Mac") != -1) && ((browserWebkit))) {
        $("#partners_img").css({ "height": "607px !important" });
        $("#contus_img").css({ "height": "1546px !important" });
        $("#sitemap_img").css({ "height": " 1016px !important" });
        $("#shop_img").css({ "height": "1629px" });
        $("#loans_img").css({ "height": "563px !important" });
        $("#how_much_img").css({ "height": "461px !important" });
        $("#sellyour_rolexwatch_img").css({ "height": "496px !important" });
        $("#sellyour_philippewatch_img").css({ "height": "442px !important" });
        $("#sellyour_omegawatch_img").css({ "height": "460px !important" });
        $("#sellyour_breitlingwatch_img").css({ "height": "478px !important" });
        $("#sellyour_watch_img").css({ "height": "424px !important" });
        $("#sellyour_cartierwatch_img").css({ "height": "442px !important" });
        $(".mini-center-needhelpbox").css({ "padding-left": "9px !important" });
        $(".mini-need-helpbox4middle").css({ "padding-left": "10px !important" });
        $(".helpbox-extra4middle").css({ "padding-left": "16px !important" });
        $("#affiliations_img").css({ "height": "492px !important" });
        $("#sitemap_img").css({ "height": "1212px !important" });
        $("#pripol_img").css({ "height": "9444px !important" });
        $("#faqs_img").css({ "height": "3251px !important" });
        $("#raq_img").css({ "height": "716px !important" });
        $("#pawnbroking_img").css({ "height": "1165px !important" });
		$("#pawnbroking_img_ev").css({ "height": "347px !important" });
        $("#raq_img").css({ "height": "739px !important" });
    }
    if ((navigator.appVersion.indexOf("Win") != -1) && (browserWebkit)) {
        $("#company_info_container #company_info p.live-chat").addClass("live-chat-win-webkit");
        $("#company_info_container #company_info p.tel").addClass("telephone-win-webkit");
        $("#shop_img").css({ "height": "1646px" });
        //$(".icon").css({ "margin-top": "-2px" });
      	//$(".icon-lc").css({ "margin-top": "5px !important" });
    }
    if ((navigator.appVersion.indexOf("Win") != -1) && (browserMozilla) || (browserMsie)) {
        $("#left_container").addClass("leftcont");
    }

    if ((navigator.appVersion.indexOf("Mac") != -1) && (browserWebkit)) {
        $("#left_container dl.online-quote .form-mid").addClass("form-bottom-mac-webkit");
    }

    if ((navigator.appVersion.indexOf("Win") != -1) && (browserMozilla)) {
        $("#inner_left_container dl.partners_cont:first").addClass("partners_cont_fix");
		$(".livechatfix").css({ "margin-top": "6px" });
		$(".pawn-need-help-box .livechatcont1 p").css({ "margin-left": "3px","padding-left" : "0px !important" });
		$("#shop_box_medium .livechatcont1 p").css({ "padding-left": "17px" });
		$("#shop_box_rq .livechatcont1 p").css({ "padding-left": "17px" });
		$("#shop_box .live-chat-rect").css({ "margin-left": "18px" });
		$("#faqs_img").css({ "height": "3292px" });
		$("#affiliations_img").css({ "height": "528px" });
		$("#sitemap_img").css({ "height": "1168px" });
		$(".helpbox-lnksclr .livechatfix img").css({ "margin-top": "-1px" });

		if(navigator.userAgent.indexOf("3.6")>0) {
			$("#shop_box_medium .livechatcont1 p").css({ "margin-left": "-12px" ,"padding-left" : "0px"});
			$(".pawn-need-help-box .livechatcont1 p").css({ "margin-left": "-12px" ,"padding-left" : "0px !important"});
			$("#faqs_img").css({ "height": "3311px" });
			$(".icon-lc").css({ "margin-top": "7px" });
		}
	}

    $(".hover").hover(
	  function () {
	  	var imgSrc = $(this).attr("src");
	    imgSrc = imgSrc.split("/");
	    imgSrc = imgSrc[2].split(".");
 		imgSrc= imgSrc[0].split("-");
	    $(this).attr("src", "/images/" + imgSrc[0] + "-mo." + "jpg");
	  },

	  function () {
	      var imgSrc = $(this).attr("src");
	      imgSrc = imgSrc.split("/");
	      imgSrc = imgSrc[2].split(".");
	      imgSrc = imgSrc[0].split("-");
	      $(this).attr("src", "/images/" + imgSrc[0] + "." + "jpg");
	  }
	);

    $('.cust-ipf').live("click", function (e) {
        $('#upload').click();
        e.preventDefault();
    });

    var versionn = $.browser.version
    if ($.browser.msie) {
        $("#iExplorer").css({ "display": "block" });
        $("#otherBrowsers").css({ "display": "none" });
    } else {
        $("#iExplorer").css({ "display": "none" });
        $("#otherBrowsers").css({ "display": "block" });
    }
    if (($.browser.mozilla) || ($.browser.opera)) {
        $("#upload").addClass("mozillaOpera");

    } else {
        $("#upload").addClass("otherBrowsers");
    }
    $(".enableifyes").addClass("mid-msg-ro");
    $("#ifyes").addClass("disabled-button");
    $("#ifyes").attr("disabled", "disabled"); // Make read-only	
    try {
        var getParent = $("#ref_id_pawnbroking_shop").parent().attr("id");
        $("#" + getParent).addClass("shop_left_container");
    } catch (err) { }

    $("#yes_insured_btn").click(function () {
        validatePhone("ifyes");
    });



    validateName("firstName");
    validateName("surName");
    validateEmail("yourEmail");
    validatePhone("yourPhone");
    validatePhone("yourMobile");
    validateEmail("receiveEmailUpdates");
    triggerValidation();

    if (($("#popup").length > 0) || ($(".online-quote, .online-quote-inner, .contact-us, .request-a-quote, .vol-layout-container").length > 0)) {
        $("body").append("<div id=\"backgroundPopup\"></div>");
    }


    popUpTemplate = "<div id=\"thank_you_error\">" + "<dl class=\"err-box\">" + "<dd class=\"form-top\"></dd>" + "<dd class=\"form-mid\">" + "<dl>" + "<dd><span class=\"close\" id=\"close_butn\"><a href=\"javascript:void(0)\">X</a></span></dd>" + "<dd class=\"err-box-desc\">" + "<h2 id=\"header_message\"></h2>" + "<p class=\"err-img\"><img src=\"/images/meet-the-staff." + "png\" width=\"200\" height=\"40\" alt=\"\" /></p>" + "<p class=\"err-msg\" id=\"message_desc\"></p>" + "<p class=\"err-desc\" id=\"error_desc\"></p>" + "<p class=\"txtlnks retn-to-formlnk\"><img src=\"/images/arrow." + "png\" class=\"icon\" width=\"7\" height=\"7\" alt=\"\" /> &nbsp;<a href=\"javascript:void(0)\" id=\"bottom_lnk\"></a></p>" + "</dd>" + "</dl>" + "</dd>" + "</dl>" + "<div id=\"thankYouFrame\" style=\"display:none;\"></div>" + "</div>";

    $("#sign_up").click(function () {
        if (!isTemplatePresent) {
            $("body").append(popUpTemplate);
            isTemplatePresent = true;
        }
        //alert($("#email input").val());
        //$(".form-mid input:text, ").not(":button, :submit, :reset, :hidden, :checkbox").each( function() {
        if (($("#email input").val() == 'Your email address')) {
            errorPopup("Please enter a valid email address <br/>and click the <strong>\"Sign Up\"</strong> link.");
            return false;
        } else {
            $(".err-box").removeShadow();
            if (($("#email input").val() != 'Your email address') && (valid == false)) {
                email_address = $('#email input');
                 email_regex = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.([a-z][a-z]+)|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i;
                /*email_regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;*/
                if (!email_regex.test(email_address.val())) {
                    errorPopup("Please enter a valid email address and click the <strong>\"Sign Up\"</strong> link.");
                    //alert("if email");
                    return false;
                } else {
                    //alert("else email");
                    valid = true;
                    //thankYouPopup();
                    handleSignUp();
                    valid = false;
                }
            }
        }
        //});
    });

    $("#frmRequestQuote #briefMessage, #frmRequestQuote input, #frmRequestQuote select").live("blur", function () {
        var getBriefMessVal = $(this).val();
        getBriefMessVal = jQuery.trim(getBriefMessVal);
        $(this).val(getBriefMessVal);

        email_address = $('#yourEmail');
        email_regex = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.([a-z][a-z]+)|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i;
        //email_regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
        if (!isSignup) {
            setTimeout(function () {
                if (isPopupTriggered) {
                    if (($("#firstName").val() != "First Name")) {
                        $("#firstName").removeClass("invalidField");
                    } else {
                        $("#firstName").addClass("invalidField");
                    }
                    if (($("#surName").val() != "Surname")) {
                        $("#surName").removeClass("invalidField");
                    } else {
                        $("#surName").addClass("invalidField");
                    }

                    if (($("#subject").val() != "Subject")) {
                        $("#subject").removeClass("invalidField");
                    } else {
                        $("#subject").addClass("invalidField");
                    }

                    if (($("#briefMessage").val() != "")) {
                        $("#briefMessage").removeClass("invalidField");
                    } else {
                        $("#briefMessage").addClass("invalidField");
                    }

                    if (($("#yourEmail").val() != "Your email address") && (email_regex.test(email_address.val()))) {
                        $("#yourEmail").removeClass("invalidField");
                    } else {
                        $("#yourEmail").addClass("invalidField");
                    }

                    /*if (($("#yourPhone").val() != "Your phone number") && (!isNaN($("#yourPhone").val()))) {
                    $("#yourPhone").removeClass("invalidField");
                    } else {
                    $("#yourPhone").addClass("invalidField");
                    }
                    if (($("#yourMobile").val() != "Your mobile number") && (!isNaN($("#yourMobile").val()))) {
                    $("#yourMobile").removeClass("invalidField");
                    } else {
                    $("#yourMobile").addClass("invalidField");
                    }*/

                    var bPhoneNumber = validatePhoneNumberField($("#yourPhone").val());
                    var bMobileNumber = validatePhoneNumberField($("#yourMobile").val());

                    if (($("#yourPhone").val() == "Your phone number") && (($("#yourMobile").val()) == "Your mobile number")) {
                        $("#yourPhone").addClass("invalidField");
                        $("#yourMobile").addClass("invalidField");
                    } else if (($("#yourPhone").val() == "Your phone number") && (!bMobileNumber)) {
                        $("#yourMobile").addClass("invalidField");
                        $("#yourPhone").removeClass("invalidField");
                    } else if (($("#yourMobile").val() == "Your mobile number") && (!bPhoneNumber)) {
                        $("#yourPhone").addClass("invalidField");
                        $("#yourMobile").removeClass("invalidField");
                    } else if (!bPhoneNumber && !bMobileNumber) {
                        $("#yourPhone").addClass("invalidField");
                        $("#yourMobile").addClass("invalidField");
                    } else if (bPhoneNumber && !bMobileNumber) {
                        $("#yourMobile").addClass("invalidField");
                        $("#yourPhone").removeClass("invalidField");
                    } else if (!bPhoneNumber && bMobileNumber) {
                        $("#yourPhone").addClass("invalidField");
                        $("#yourMobile").removeClass("invalidField");
                    } else {
                        $("#yourPhone, #yourMobile").removeClass("invalidField");
                    }

                    if (($("#item_type").val() != "0")) {
                        $("#item_type_tovalidate").removeClass("invalidField");
                    } else {
                        $("#item_type_tovalidate").addClass("invalidField");
                    }
                }
            }, 10);
        } else {
            if (($("#receiveEmailUpdates").val() != "Your email address") && (email_regex.test($("#receiveEmailUpdates").val()))) {
                $("#receiveEmailUpdates").removeClass("invalidField");
            } else {
                $("#receiveEmailUpdates").addClass("invalidField");
            }
            isSignup = false;
        }
    });

    $("#yourMobile, #yourPhone").live("blur", function () {
        var key;
        var extractedNos = new Array();
        for (i = 0; i < ($(this).val().length); i++) {
            var key = $(this).val().charCodeAt(i)
            if ((key >= 48 && key <= 57)) {
                extractedNos[extractedNos.length] = $(this).val().charAt(i);
            }
        }
        var finalExtratedNos = "";
        for (i = 0; i < extractedNos.length; i++) {
            finalExtratedNos = finalExtratedNos + extractedNos[i];
        }
        $(this).val(finalExtratedNos);
    });

    $(".item-0, .item-1, .item-2, .item-3, .item-4, .item-5, .item-6, .item-7, .item-8").live("click", function () {
        if ($(".request-a-quote").length > 0) {
            var currentSelection = $("#item_type_tovalidate").text();
            if (isPopupTriggered) {
                if (currentSelection == "Please select") {
                    $("#item_type_tovalidate").addClass("invalidField");
                } else {
                    $("#item_type_tovalidate").removeClass("invalidField");
                }
            }
        }
    });
    $("#frmRequestQuote #item_type").prev().attr("id", "item_type_tovalidate");
    //$("#item_type1").prev().attr("id","item_type_tovalidate1");

});

function triginpfun() {
    var fName = $("#upload").val();
    var fileType = fName.split('.')[fName.split('.').length - 1]
    fileType = fileType.toLowerCase();
    $("#noFileSelected").attr("title", fName + " ");
    $("#noFileSelected").addClass("fileimg");
    $("#noFileSelected").val(fName);
    /*$('#noFileSelected').attr("readonly", "readonly");*/
    if (fileType != 'jpg' && fileType != 'gif' && fileType != 'png' && fileType != 'jpeg') {
        //errorPopup('File extensions supported are JPG, GIF and PNG.');
        return false;
    }

    return true;
}

function setFileName() {
    var fName = $("#upload").val();
    if (navigator.userAgent.toLowerCase().indexOf('chrome') != -1) {
        var fName = fName.substr(fName.lastIndexOf("\\") + 1);
    }
    $("#noFileSelected").attr("title", fName + " ");
    $("#noFileSelected").addClass("fileimg");
    $("#noFileSelected").val(fName);
    /*$('#noFileSelected').attr("readonly", "readonly");*/
}

function triginpfunIE() {
    var fName = $("#uploadIE").val();
    var fileType = fName.split('.')[fName.split('.').length - 1]
    fileType = fileType.toLowerCase();
    if (fileType != 'jpg' && fileType != 'gif' && fileType != 'png' && fileType != 'jpeg') {
        errorPopup('File extensions supported are JPG, GIF and PNG.');
        return false;
    }
    return true;
}

$("input:radio[@name='ifyes']").change(function () {
    if ($("input:radio[@name='ifyes']:checked").val() == 'Yes') {
        $(".enableifyes").removeClass("mid-msg-ro");
        $("#ifyes").removeClass("if-yesfoc");
        $("#ifyes").removeAttr("disabled"); // Make read-write 
        $("#ifyes").removeClass("disabled-button");
    }
    else {
        $(".enableifyes").addClass("mid-msg-ro");
        $("#ifyes").addClass("if-yesfoc");
        $("#ifyes").val('');
        $("#ifyes").removeClass('invalidField');
        $("#ifyes").attr("disabled", "disabled"); // Make read-only
        $("#ifyes").addClass("disabled-button");
    }
});

/****** 'prompt' Message for text boxes *******/
$(function () {
    $(".propmt").each(function () {
        $tb = $(this);
        if ($tb.val() != this.title) {
            $tb.removeClass("prompt");
        }
    });

    $(".prompt").focus(function () {
        $tb = $(this);
        if ($tb.val() == this.title) {
            $tb.val("");
            $tb.removeClass("prompt");
        }
    });

    $(".prompt").blur(function () {
        $tb = $(this);
        if ($.trim($tb.val()) == "") {
            $tb.val(this.title);
            $tb.addClass("prompt");
        }
    });
});
$('#ques_tt').mouseover(function () {
    $(this).attr("src", "/images/request-a-quote-ques-mo.jpg");
});
$('#ques_tt').mouseout(function () {
    $(this).attr("src", "/images/request-a-quote-ques.jpg");
});
/****** Image Slider with 'Fade' effect *******/
$(window).load(function () {
    try {
        $('#slider').nivoSlider({
            effect: 'fade', //Specify sets like: 'sliceDownRight','sliceDownLeft','sliceUpRight','sliceUpLeft','sliceUpDown','sliceUpDownLeft','fold','fade','slideInRight','slideInLeft'
            slices: 15,
            animSpeed: 1000, //Slide transition speed
            pauseTime: 20000,
            startSlide: 0, //Set starting Slide (0 index)
            directionNav: false, //Next & Prev
            directionNavHide: false, //Only show on hover
            controlNav: true, //1,2,3...
            controlNavThumbs: false, //Use thumbnails for Control Nav
            controlNavThumbsFromRel: false, //Use image rel for thumbs
            controlNavThumbsSearch: '.jpg', //Replace this with...
            controlNavThumbsReplace: '_thumb.jpg', //...this in thumb Image src
            keyboardNav: true, //Use left & right arrows
            pauseOnHover: true, //Stop animation while hovering
            manualAdvance: false //Force manual transitions
        });
    } catch (e) { }
});

/****** Image gallery Slider with effects *******/

$(function () {
    try {
        $('#one').ContentSlider({
            width: '573px',
            height: '518px',
            speed: 800,
            easing: 'easeInOutQuart' // swing, easeInQuad, easeOutQuad, easeInOutQuad, easeInCubic, easeOutCubic, easeInOutCubic, easeInQuart, easeOutQuart, easeInOutQuart, easeInQuint, easeOutQuint, easeInOutQuint, easeInSine, easeOutSine, easeInOutSine, easeInExpo, easeOutExpo, easeInOutExpo, easeInCirc, easeOutCirc, easeInOutCirc, easeInElastic, easeOutElastic, easeInOutElastic, easeInBack, easeOutBack, easeInOutBack, easeInBounce, easeOutBounce, easeInOutBounce
        });
    } catch (e) { }
});


/****** Store Slider with effects *******/

$(function () {
    try {
        $('#storeslider').anythingSlider({
                // Appearance
                width               : null,      // Override the default CSS width
                height              : null,      // Override the default CSS height
                resizeContents  	: false,     // If true, solitary images/objects in the panel will expand to fit the viewport

                // Navigation
                startPanel          : 1,         // This sets the initial panel
                hashTags            : true,      // Should links change the hashtag in the URL?
                buildArrows         : false,     // If true, builds the forwards and backwards buttons
                buildNavigation     : false,     // If true, builds a list of anchor links to link to each panel
                navigationFormatter : null,      // Details at the top of the file on this use (advanced use)
                forwardText         : "&raquo;", // Link text used to move the slider forward (hidden by CSS, replaced with arrow image)
                backText            : "&laquo;", // Link text used to move the slider back (hidden by CSS, replace with arrow image)

                // Slideshow options
                autoPlay            : false,     // This turns off the entire slideshow FUNCTIONALY, not just if it starts running or not
                startStopped        : false,     // If autoPlay is on, this can force it to start stopped
                pauseOnHover        : true,      // If true & the slideshow is active, the slideshow will pause on hover
                resumeOnVideoEnd    : true,      // If true & the slideshow is active & a youtube video is playing, it will pause the autoplay until the video has completed
                stopAtEnd           : false,     // If true & the slideshow is active, the slideshow will stop on the last page
                playRtl             : false,     // If true, the slideshow will move right-to-left
                startText           : "Start",   // Start button text
                stopText            : "Stop",    // Stop button text
                delay               : 3000,      // How long between slideshow transitions in AutoPlay mode (in milliseconds)
                animationTime       : 600,       // How long the slideshow transition takes (in milliseconds)
                easing              : "swing"    // Anything other than "linear" or "swing" requires the easing plugin
            });
    } catch (e) { }
});

$("ss_la").click(function(){$('#storeslider').data('AnythingSlider').goBack();});
$("ss_ra").click(function(){$('#storeslider').data('AnythingSlider').goForward();});


function hightlightNavigationItem() {
    var url = ['about-us', 'pawnbroking-services', 'shop'];
    var urlPathArray = document.location.pathname.split('/');
    if (urlPathArray.length > 1) {
        $.each(url, function (index, value) {
            var urlPath = urlPathArray[1];
            urlPath = urlPath.toLowerCase();

            switch (urlPath) {
                case 'about-us':
                    $("#nav dd:eq(1)").attr("class", "current-page");
                    break;
                case 'pawnbroking-services':
                    $("#nav dd:eq(3)").attr("class", "current-page");
                    break;
                case 'shop':
                    $("#nav dd:eq(12)").attr("class", "current-page");
                    break;
            }
        });
    }
}

function highlightInvalidFields(getInvalidFields) {
    for (i = 0; i < getInvalidFields.length; i++) {
        $(getInvalidFields[i]).addClass("invalidField");
    }
}

var fieldPrompts = {
    //PERSONAL INFO
    "firstName": "Please enter your First Name."
    , "surName": "Please enter your Surname."
    , "yourEmail": "Please enter  your Email id."
	, "invalidEmail": "Please enter valid Email id."
    , "yourPhone": "Please enter your Phone number."
	, "invalidPhone": "Please enter your valid Phone number."
	, "yourMobile": "Please enter your Mobile number."
	, "invalidMobile": "Please enter your valid Mobile number."
    , "item_type": "Please select the Item Type."
	, "subject": "Please enter the Subject."
	, "briefMessage": "Please enter the Brief Description."
	, "ifyes": "Please enter Insured amount."
	, "phoneMobile": "Please enter Phone number or Mobile number."
    , "invalidFileFormat" : "File extensions supported are JPG, GIF and PNG."
};

/*
* Condition : It shouldn't be empty, It shouldn't be defaultValue
*/
function validateNameField(p_Value, p_DefaultValue) {
    var sValue = p_Value, sDefaultValue = p_DefaultValue;

    if ((sValue == "") || (sValue == sDefaultValue)) {
        return false;
    } else {
        return true;
    }
}

function validateEmailField(p_value) {
    var sValue = p_value;
     var email_regex = /^[-a-z0-9~!$%^&*_=+}{\'?]+(\.[-a-z0-9~!$%^&*_=+}{\'?]+)*@([a-z0-9_][-a-z0-9_]*(\.[-a-z0-9_]+)*\.([a-z][a-z]+)|([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}))(:[0-9]{1,5})?$/i;
    //var email_regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;

    if (!(email_regex.test(sValue))) {
        return false;
    } else {
        return true;
    }
}

function validatePhoneNumberField(p_iValue) {
    var iValue = p_iValue;

    if (iValue.length < 9) {
        return false;
    } else {
        return true;
    }
}

function twitterLinks(text) 
	{     
	var base_url = 'http://twitter.com/';   // identica: 'http://identi.ca/'     
	var hashtag_part = 'search?q=#';        // identica: 'tag/'     
	var mention_part = '';              	// identica: ''     // convert URLs into links     
	text = text.replace(/(>|<a[^<>]+href=['"])?(https?:\/\/([-a-z0-9]+\.)+[a-z]{2,5}(\/[-a-z0-9!#()\/?&.,]*[^ !#?().,])?)/gi,
	function ($0, $1, $2) {             
		return ($1 ? $0 : '<a href="' + $2 + '" >' + $2 + '</a>');
	});     // convert protocol-less URLs into links
	
	text = text.replace(/(:\/\/|>)?\b(([-a-z0-9]+\.)+[a-z]{2,5}(\/[-a-z0-9!#()\/?&.]*[^ !#?().,])?)/gi,
	function ($0, $1, $2) {            
		return ($1 ? $0 : '<a href="http://' + $2 + '">' + $2 + '</a>');
	});     // convert @mentions into follow links
	
	text = text.replace(/(:\/\/|>)?(@([_a-z0-9\-]+))/gi,
	function ($0, $1, $2, $3) { 
		return ($1 ? $0 : '<a href="' + base_url + mention_part + $3 + '" title="Follow ' + $3 + '" >@' + $3 + '</a>');
	});     // convert #hashtags into tag search links
	
	text = text.replace(/(:\/\/|>)?(\#([_a-z0-9\-]+))/gi,
	function ($0, $1, $2, $3) { 
		return ($1 ? $0 : '<a href="' + base_url + hashtag_part + $3 + '" title="Search tag: ' + $3 + '" >#' + $3 + '</a>'); });
	return text;
} 

function validateSelectBoxField(p_sValue) {
    var sValue = p_sValue;

    if (sValue == "0" || sValue == "") {
        return false;
    } else {
        return true;
    }
}
