﻿$(document).ready(function() {

    picTrue = new Image(18, 18);
    picTrue.src = "i/validationTrue.gif";

    picFalse = new Image(18, 18);
    picFalse.src = "i/validationFalse.gif";


    $("#Menu").wrap("<div id='MenuBack'><div id='MenuLeft'></div></div>");
    $("#Menu").wrapInner("<div class='Inner'></div>");

    $("h1").wrap("<div class='Title'><div class='TitleLeft'><div class='TitleRight'></div></div></div>");
    $("h2").wrap("<div class='Title'><div class='TitleLeft'><div class='TitleRight'></div></div></div>");


    /* Make the select list clicks work */
    $(".ComboList li a").bind('click', function() {
        var ComboBox = $(this).parents(".ComboBox");
        ComboBox.removeClass("On");
        ComboBox.addClass("Off");

        if ($.browser.msie) {
            if ($.browser.version == "6.0") {
                ComboBox.addClass("ComboBox");
            }
        }

        ComboBox.find(".ComboPanel").slideUp("fast");
        ComboBox.find(".ComboText").text($(this).text());
        validateCombo($(this).text(), $(this).parents(".ComboBox").find(".ComboText").attr("id"));
    })
    
    

    /* Add events to combo boxes */

    /* Get the hover working on the button */

    $(".ComboRight").hover(
            function() {
        $(this).removeClass();
        $(this).addClass("ComboRightHover");
    },
            function() {
        $(this).removeClass();
        $(this).addClass("ComboRight");
    }
        );

    /* Get the panel sliding down and up when you click the button */

    $(".ComboRight").click(function() {

        var ComboBox = $(this).parent(".ComboBox");

        if (ComboBox.is('.Off')) {
            ComboBox.removeClass("Off");
            ComboBox.addClass("On");
            ComboBox.find(".ComboPanel").slideDown("fast");
        }
        else if (ComboBox.is('.On')) {
            ComboBox.removeClass("On");
            ComboBox.addClass("Off");



            ComboBox.find(".ComboPanel").slideUp("fast");
            validateCombo(ComboBox.find(".ComboText").text(), ComboBox.find(".ComboText").attr("id"));
        }

    });

    $(".ComboLeft").click(function() {

        var ComboBox = $(this).parent(".ComboBox");

        if (ComboBox.is('.Off')) {
            ComboBox.removeClass("Off");
            ComboBox.addClass("On");
            ComboBox.find(".ComboPanel").slideDown("fast");
        }
        else if (ComboBox.is('.On')) {
            ComboBox.removeClass("On");
            ComboBox.addClass("Off");
            ComboBox.find(".ComboPanel").slideUp("fast");
            validateCombo(ComboBox.find(".ComboText").text(), ComboBox.find(".ComboText").attr("id"));
        }

    });

    $(".ValidateTextBox").blur(function() {

        msg = isValidTextBox(this, $(this).attr("class"));
        validationImage = "#" + this.id.replace("TXT_", "VI_");

        if (msg != "") {
            $(validationImage).removeAttr("src");
            $(validationImage).attr("src", picFalse.src);
            $(validationImage).show();
        } else {
            $(validationImage).removeAttr("src");
            $(validationImage).attr("src", picTrue.src);
            $(validationImage).show();
        }

    });

    $("#SubmitQuote").click(function() {

        var errors = "";
        if ($("#TXT_yourName").val() == "") {
            errors = "** Please enter your name **";
            displayerror("#TXT_yourName");
        }

        if ($("#TXT_phoneNumber").val() == "") {
            if (errors != "") errors += "<br />";
            errors += "** Please enter your phone number **";
            displayerror("#TXT_phoneNumber");
        }

        if ($("#TXT_emailAddress").val() == "") {
            if (errors != "") errors += "<br />";
            errors += "** Please enter your e-mail address **";
            displayerror("#TXT_emailAddress");
        } else {
            if (!isValidEmail($("#TXT_emailAddress").val())) {
                if (errors != "") errors += "<br />";
                errors += "** Please enter a valid e-mail address **";
                displayerror("#TXT_emailAddress");
            }
        }

        if ($("#TXT_currency").text() == "Please choose...") {
            if (errors != "") errors += "<br />";
            errors += "** Please choose a currency **";
            displayerror("#TXT_currency");
        }

        if ($("#TXT_howMuch").text() == "Please choose...") {
            if (errors != "") errors += "<br />";
            errors += "** Please specify how much you wish to exchange **";
            displayerror("#TXT_howMuch");
        }

        if ($("#TXT_howSoon").text() == "Please choose...") {
            if (errors != "") errors += "<br />";
            errors += "** Please specify how soon you need the currency **";
            displayerror("#TXT_howSoon");
        }

        if (errors != "") {
            $("#Errors").html(errors);
            $("#Errors").slideDown();
        } else {
            submitQuote();
            //Hide all text boxes
            $(".ValidateTextBox").hide();
            $("#Quote").slideUp('slow', function() {
                $("#thankYou").slideDown();
            });
        }
    })

});



var AllowCache = false;

function CacheFix() {
    if (AllowCache == false) {
        return "?" + new Date().getTime().toString();
    } else {
        return "";
    }
}



function submitQuote(){

    var newLocation = "";
    newLocation += "thankyou.aspx?Name=" + $("#TXT_yourName").val();
    newLocation += "&PhoneNumber=" + $("#TXT_phoneNumber").val();
    newLocation += "&EmailAddress=" + $("#TXT_emailAddress").val();
    newLocation += "&Currency=" + $("#TXT_currency").text();
    newLocation += "&HowMuch=" + $("#TXT_howMuch").text();
    newLocation += "&HowSoon=" + $("#TXT_howSoon").text();

    window.location = newLocation;


//    $.get("Handlers/Handler.ashx", {"action": "submitForm", "Name": Name, "PhoneNumber": PhoneNumber, "EmailAddress": EmailAddress, "Currency": Currency, "HowMuch": HowMuch, "HowSoon": HowSoon, "Comments": Comments, "Refresh": new Date().getTime()}, function(data){
//        
//        var Result = data;
//        var CommaPosition = Result.indexOf(",");
//        var QuoteID = Result.substr(0,CommaPosition);
//        var LeadPrice = parseInt(Result.substr(CommaPosition +1)) * 10;    

//        $("#hdn_QuoteID").val(QuoteID);
//        $("#SubmitComments").bind('click', function(){        
//            $.get("Handlers/Handler.ashx", {"action": "submitComments", "QuoteID": QuoteID, "Comments": $("#txt_Comments").val(), "Refresh": new Date().getTime()}, function(){            
//                $("#txt_Comments").hide();
//                $("#comments").slideUp('slow',function(){
//                    $("#FinalMessage").slideDown();
//                });                            
//            })                              
//        })
//        
//        if (LeadPrice > 0) {
//            var pageTracker = _gat._getTracker("UA-4615305-1");
//            pageTracker._initData();
//            pageTracker._trackPageview();

//            pageTracker._addTrans(
//            QuoteID,                                     // Order ID
//            $("#hdn_version").val(),                            // Affiliation
//            LeadPrice,                                    // Total
//            "0",                                     // Tax
//            "0",                                        // Shipping
//            "",                                 // City
//            "",                               // State
//            ""                                       // Country
//            );

//            pageTracker._addItem(
//            QuoteID,                                     // Order ID
//            "",                                     // SKU
//            "Quote",                                  // Product Name 
//            "",                             // Category
//            LeadPrice,                                    // Price
//            "1"                                         // Quantity
//            );

//            pageTracker._trackTrans();
//        }   
//    })            

}









