﻿//CONTACT FORM FUNCTIONS
//======================
//validates the contact form
function validateContactForm() {
    var isFormValid = true;
    //Step # 1 : Restart the output message label.
    document.getElementById('ctl00_ContentPlaceHolder1_uiContactView_ucContactBox_vsContactForm').innerHTML = "* Required fields.";

    //Step # 2 : Determine the Fields by reverse order.
    //Validate Subject
    if (!(isCheckBoxValid("ctl00_ContentPlaceHolder1_uiContactView_ucContactBox_DdlContactSubject"))) {
        isFormValid = false;
    }

    //Validate Email
    if (!(isEmailValid("ctl00_ContentPlaceHolder1_uiContactView_ucContactBox_txtEmail"))) {
        isFormValid = false;
    }

    //Validate Phone
    if (!(isNameValid("ctl00_ContentPlaceHolder1_uiContactView_ucContactBox_txtPhone", 1))) {
        isFormValid = false;
    }

    //Validate Last Name
    if (!(isNameValid("ctl00_ContentPlaceHolder1_uiContactView_ucContactBox_txtName", 1))) {
        isFormValid = false;
    }

    //Step # 3 : Determine display of notification and errors.
    if (isFormValid) {
        $('#ctl00_ContentPlaceHolder1_uiContactView_ucContactBox_btnSend')
        .hide();
        $('#ContactLoader')
        .show();
        $('#ContactLoader').removeClass("notDisplayed");
        sleep(500);
        return true;
    }
    else {
        document.getElementById('ctl00_ContentPlaceHolder1_uiContactView_ucContactBox_vsContactForm').innerHTML =
         "* Required fields.";
        return false;
    }
}

//CONTACT INPUT ENTER EVENT
//==========================
function GetKeyPressForContactTextBox(inField, e) {
    var charCode;

    if (e && e.which) {
        charCode = e.which;
    } else if (window.event) {
        e = window.event;
        charCode = e.keyCode;
    }

    if (charCode == 13) {
        document.getElementById("ctl00_ContentPlaceHolder1_uiContactView_ucContactBox_btnSend").click();
    }
}

//FLASH PRINTER
//=============
function getSwf(id, divName, width, height, wmode, src, bgcolor) {
    var divName = document.getElementById(divName);
    var obj = '<OBJECT id="' + id
    + '" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="' +
     width + '" height="' + height
     + '" style="z-index:0;" ><PARAM NAME="movie" VALUE="' + src + '"><PARAM NAME="wmode" VALUE="' +
      wmode + '"><PARAM NAME="quality" VALUE="high"><param name="bgcolor" value="' + bgcolor + '"><EMBED style="z-index:0;" wmode="' + wmode
       + '" quality="high" src="' + src + '"  width="' + width + '" height="' + height
        + '" bgcolor="' + bgcolor
         + '" TYPE="application/x-shockwave-flash" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer"></EMBED></OBJECT>';
    divName.innerHTML = obj;
}


//REGISTER FUNCTIONS
//==================
//validate the register form
function validateRegisterForm() {
    
    var isFormValid = true;
    //Step # 1 : Clean the output message label.
    document.getElementById('ctl00_ContentPlaceHolder1_uiRegister_lblVsRegister').innerHTML = "";

    //Step # 2 : Determine the Fields of the billing information by reverse order.

    //Validate Country
    if (!(isCheckBoxValid("ctl00_ContentPlaceHolder1_uiRegister_DdlCountry"))) {
        isFormValid = false;
    }
    else {
        if (document.getElementById('ctl00_ContentPlaceHolder1_uiRegister_DdlCountry').value == 265) {
            if (!(isCheckBoxValid("ctl00_ContentPlaceHolder1_uiRegister_DdlState"))) 
                isFormValid = false;
        }
        else if(document.getElementById('ctl00_ContentPlaceHolder1_uiRegister_DdlCountry').value == 303) {
            if (!(isCheckBoxValid("ctl00_ContentPlaceHolder1_uiRegister_DdlProvince"))) 
                isFormValid = false;
        }
    }

    //Validate Verify Password
    if (!(isNameValid("ctl00_ContentPlaceHolder1_uiRegister_txtPasswordVerify", 1))) {
        isFormValid = false;
    }

    //Validate Password
    if (!(isNameValid("ctl00_ContentPlaceHolder1_uiRegister_txtPassword", 1))) {
        isFormValid = false;
    }

     //Validate Verify = password
    var jqueryId = "#ctl00_ContentPlaceHolder1_uiRegister_txtPassword";
    var jqueryId2 = "#ctl00_ContentPlaceHolder1_uiRegister_txtPasswordVerify";
    if (document.getElementById('ctl00_ContentPlaceHolder1_uiRegister_txtPassword').value != document.getElementById('ctl00_ContentPlaceHolder1_uiRegister_txtPasswordVerify').value)
    {
        isFormValid = false;
        $(jqueryId).addClass("fieldError");
        $(jqueryId2).addClass("fieldError");
    }
    else
    {
        if ((document.getElementById('ctl00_ContentPlaceHolder1_uiRegister_txtPassword').value != "")&&
        (document.getElementById('ctl00_ContentPlaceHolder1_uiRegister_txtPasswordVerify').value != "")){
            $(jqueryId).removeClass("fieldError");
            $(jqueryId2).removeClass("fieldError");
        }
    }


    //Validate Email
    if (!(isEmailValid("ctl00_ContentPlaceHolder1_uiRegister_txtEmail"))) {
        isFormValid = false;
    }

    //Validate Phone
    if (!(isNameValid("ctl00_ContentPlaceHolder1_uiRegister_txtPhone", 1))) {
        isFormValid = false;
    }

    //Validate Last Name
    if (!(isNameValid("ctl00_ContentPlaceHolder1_uiRegister_txtLastName", 1))) {
        isFormValid = false;
    }
    //Validate First Name
    if (!(isNameValid("ctl00_ContentPlaceHolder1_uiRegister_txtFirstName", 1))) {
        isFormValid = false;
    }

    //Step # 3 : If the Method type is credit then we need to validate

    //Step # 4 : Determine display of notification and errors.
    if (isFormValid) {
        return true;
    }
    else {
        document.getElementById('ctl00_ContentPlaceHolder1_uiRegister_lblVsRegister').innerHTML +=
         "* Please Fill the required Fields.";
        return false;
    }
}

//update state display
function updateStateDisplay() {
    document.getElementById('ctl00_ContentPlaceHolder1_uiRegister_pnlStateBox').style.display = 'none';
    document.getElementById('ctl00_ContentPlaceHolder1_uiRegister_pnlProvinceBox').style.display = 'none';
    if (document.getElementById('ctl00_ContentPlaceHolder1_uiRegister_DdlCountry').value == 265)
        document.getElementById('ctl00_ContentPlaceHolder1_uiRegister_pnlStateBox').style.display = 'block';
    if (document.getElementById('ctl00_ContentPlaceHolder1_uiRegister_DdlCountry').value == 303)
        document.getElementById('ctl00_ContentPlaceHolder1_uiRegister_pnlProvinceBox').style.display = 'block';
}

//SEARCH BOX FUNCTIONS
//====================
function updateSubCategoryDropDownForSearch() {
    //Clean the select options in the current sub category Drop down
    $('#ctl00_ucSearchBox_DdlSubCategories option').remove();

    //Add the standard "By Sub Category" element
    $('#ctl00_ucSearchBox_DdlSubCategories').append('<option id="0">By Sub Category</option>');

    //Iterate on the mainCategoriesCollection Array
    var i;
    for (i = 0; i < mainCategoriesCollection.length; i++) {
        //If the fatherId suits the selected id,
        if (mainCategoriesCollection[i].FatherId == $('#ctl00_ucSearchBox_DdlCategories').val()) {
            //Add the element to the sub category list
            var syntax = "<option value=" + mainCategoriesCollection[i].Id + ">" + mainCategoriesCollection[i].Name + "</option>";
            $('#ctl00_ucSearchBox_DdlSubCategories').append(syntax);
        }
    }
}


//SEARCH BOX CMS ENTER EVENT
//==========================
function GetKeyPressForCmsSearchTextBox(e) {
    var Key;

    if (window.event)        // IE
    {
        Key = window.event.keyCode;
    }
    else if (e.which) // Netscape/Firefox/Opera
    {
        Key = e.which
    }

    if ((Key == 13)) {
        validateSearchForm();
    }
}

//validate the search form
function validateSearchForm() {
    var language = $('#langLocator').html();
    var result = true;
    if (
    ($('#search_text').val() == "Search")
    || ($('#search_text').val() == "")
    ) {
        result = false;
    }
    else {
        window.location = "/SearchResults.aspx?q=" + $('#search_text').val() + "&language=" + language;
    }

}

//PRODUCT FORM FUNCTION
//=====================
//Validates the product form
function validateProductForm() {
    document.getElementById('ctl00_ContentPlaceHolder1_uiProductForm_lblVs').innerHTML =
     "";
    if (isValidInput())
        return true;
    document.getElementById('ctl00_ContentPlaceHolder1_uiProductForm_lblVs').innerHTML =
     "Please Fill required fields";
    return false;
}

//Validates the drop downs
function isValidInput() {

    //DROP DOWNS
    var elms =
        $('#ctl00_ContentPlaceHolder1_uiProductForm_pnlProductFeatures select');
    var result = true;
    elms.each
   (
       function () {
           var elm = $(this);
           var elmId = elm.attr("Id").substring(43);
           $('#ctl00_ContentPlaceHolder1_uiProductForm_lbl' + elmId).removeClass('red');
           if (elm.val() == 0) {
               result = false;
               $('#ctl00_ContentPlaceHolder1_uiProductForm_lbl' + elmId).addClass('red');
           }
       }
   );

   //TEXT BOXES
   var elms =
        $('#ctl00_ContentPlaceHolder1_uiProductForm_pnlProductFeatures input:text');
    elms.each
   (
       function () {
           var elm = $(this);
           var elmId = elm.attr("Id").substring(43);
           $('#ctl00_ContentPlaceHolder1_uiProductForm_lbl' + elmId).removeClass('red');
           if (elm.val() == "") {
               result = false;
               $('#ctl00_ContentPlaceHolder1_uiProductForm_lbl' + elmId).addClass('red');
           }
       }
   );


    return result;
}

//calculate the attached price for an element id.
function getPriceForElement(attachedSelectedId) {
    var attachedPrice = 0;
    var i;
    for (i = 0; i < FeatureValuesCollection.length; i++) {
        //If the required id is in the collection
        if (FeatureValuesCollection[i].Id == attachedSelectedId) {
            //Get the new attached price
            attachedPrice = FeatureValuesCollection[i].Value;
        }
    }
    //return the attached price
    return attachedPrice;
}

//calculate the added price
function CalculateAddedPrice(containerId) {
    //Get all of the elements in the container that are drop downs
    var elms = $('#'+containerId+' select');
    var totalAttachedPrice = 0;
    parseFloat(totalAttachedPrice);

    //Iterate on the elements and attach the added price
    elms.each
    (
        function () {
            var elm = $(this);
            totalAttachedPrice += parseFloat(getPriceForElement(elm.val()));
        }
    );
        return totalAttachedPrice;
    }

//updates the elements for the product price
    function CalculateProductFormTotals() {
        //Get the base price.
        var basePrice = $('#ctl00_ContentPlaceHolder1_uiProductForm_lblBasePricePerUnit').html();
        parseFloat(basePrice);

        //get the new added price
        var newPrice = parseFloat(basePrice) + 
        parseFloat(CalculateAddedPrice("ctl00_ContentPlaceHolder1_uiProductForm_pnlProductFeatures"));

        //update the price label value
        document.getElementById('ctl00_ContentPlaceHolder1_uiProductForm_lblPricePerUnit').innerHTML = newPrice;

        //call the update amount function
        updateTotalPriceLabel();
    }


//FORM FUNCTIONS
//==============
//validates textbox field by the char length as a minimum 
//required fields
function isNameValid(id, charLength) {
    var jqueryId = "#" + id;
    if (document.getElementById(id).value.length > charLength) {
        $(jqueryId).removeClass("fieldError");
        return true;
    }
    else {
        $(jqueryId).addClass("fieldError");
        $(jqueryId).focus();
        return false;
    }
}
//Validates the email field
function isEmailValid(id) {
    var jqueryId = "#" + id;
    var filter = /^[\w-]+(\.[\w-]+)*@[\w-]+(\.[\w-]+){1,4}$/;
    if (filter.test(document.getElementById(id).value)) {
        $(jqueryId).removeClass("fieldError");
        return true;
    }
    else {
        $(jqueryId).addClass("fieldError");
        $(jqueryId).focus();
        return false;
    }
}

//validates that the check box has a non default value
function isCheckBoxValid(id) {
    var jqueryId = "#" + id;
    if ($(jqueryId).val() == "0") {
        $(jqueryId).addClass("fieldError");
        $(jqueryId).focus();
        return false;
    }
    else {
        $(jqueryId).removeClass("fieldError");
        return true;
    }
}




//SEO FUNCTIONS
//=============

//REDIRECT THE USER VIA JAVASCRIPT TO KEEP THE STRENGTH OF ANOTHER LINK
function JSLink(url, target) {
    if (target == 0) {
        document.location.href = url;
    }
    else {
        window.open(url);
    }
}

//CART FUNCTIONS
//==========================
//validate the cart form
function validateCartForm() {
    document.getElementById('ctl00_ContentPlaceHolder1_uiCart_lblVSCart').innerHTML = "";
    if (!isCheckBoxValid('ctl00_ContentPlaceHolder1_uiCart_DdlDeliveryTypes')) {
        document.getElementById('ctl00_ContentPlaceHolder1_uiCart_lblVSCart').innerHTML =
     'Please Select a delivery Method';
        return false;
    }
    return true;
}

//Check that the creditContainer is hidden, if the phoneOrder radio button is checked.
function CheckForPhoneCheck() {
    if (document.getElementById("ctl00_ContentPlaceHolder1_uiOrderForm_radPhone").checked)
        switchToOrderPhone();
}

//Set Credit Elements to default values for the order phone.
function switchToOrderPhone() {
    document.getElementById("ctl00_ContentPlaceHolder1_uiOrderForm_txtCardNumber").value = "4580111133334444";
    document.getElementById("ctl00_ContentPlaceHolder1_uiOrderForm_txtCardCVV").value = "000";
    document.getElementById("ctl00_ContentPlaceHolder1_uiOrderForm_txtCardOwnerName").value = "בוצעה הזמנה טלפונית";
    document.getElementById("ctl00_ContentPlaceHolder1_uiOrderForm_txtCardOwnerId").value = "בוצעה הזמנה טלפונית";
    document.getElementById("ctl00_ContentPlaceHolder1_uiOrderForm_creditContainer").style.display = "none";
    
}


//Set Credit Elements to default values for the order phone.
function switchToOrderCredt() {
    document.getElementById("ctl00_ContentPlaceHolder1_uiOrderForm_txtCardNumber").value = "";
    document.getElementById("ctl00_ContentPlaceHolder1_uiOrderForm_txtCardCVV").value = "";
    document.getElementById("ctl00_ContentPlaceHolder1_uiOrderForm_txtCardOwnerName").value = "";
    document.getElementById("ctl00_ContentPlaceHolder1_uiOrderForm_txtCardOwnerId").value = "";
    document.getElementById("ctl00_ContentPlaceHolder1_uiOrderForm_creditContainer").style.display = "block";
}


//Updates the per unit price label.
function CalculateUnitPriceForCart(dropDownId,cartLineId) {
    //Step 1: get the value of the changed element.
    var AddedElementPriceToUnitPrice = PriceDictionary[parseInt(document.getElementById(dropDownId).value)];
    //Step 2: calculate the new currnet unit price.
    document.getElementById("unitPrice_" + cartLineId).innerHTML =
            parseInt(document.getElementById("baseUnitPrice_" + cartLineId).innerHTML) +
            AddedElementPriceToUnitPrice;
    //Step 3: Update the total price.
    updateTotalPriceForCartLine(cartLineId);
}

function updateTotalPriceForCartLine(cartLineId) {
    //Step 1: get the value of the quantity:
    var currentQuantity = parseInt(document.getElementById("quantity_" + cartLineId).value);
    //Step 2: get the value of the price per product:
    var currentPricePerUnit = parseInt(document.getElementById("unitPrice_"+cartLineId).innerHTML);
    //Step 3: Set the total price into the total price label:
    document.getElementById("totalPrice_" + cartLineId).innerHTML = currentQuantity * currentPricePerUnit;
}

//SHARE BAR FUNCTIONS
//===================

//FACEBOOK
function shareFacebook(url) {
    var urlToGo = "http://www.facebook.com/sharer.php?u=" + url;
    window.open(urlToGo, "FacebookShare", "height=436", "width=635", "left=200", "top=100", "location=no", "menubar=no", "resizable=yes",
 "scrollbars=yes", "status=no", "titlebar=no", "toolbar=no");
}

//BOOKMARK
function shareBookMark(title, url) {
    if (window.sidebar) window.sidebar.addPanel(title, url, "");
    else if (window.opera && window.print) {
        var elem = document.createElement('a');
        elem.setAttribute('href', url); elem.setAttribute('title', title); elem.setAttribute('rel', 'sidebar'); elem.click();
    }
    else if (document.all) window.external.AddFavorite(url, title);
}

//REDIRECT TO PRINT FREINDLY PAGE
function sharePrint(url) {
    window.open(url, "",
 "height=800, width=1024, left=200, top=100, location=no, menubar=no, resizable=yes, scrollbars=yes, status=no, titlebar=no, toolbar=YES");
}

//SHARE A FRIEND
function shareWithAFriend(url) {
    window.open(url, "",
"height=400, width=550, left=200, top=100, location=no, menubar=no, resizable=yes, scrollbars=yes, status=no, titlebar=no, toolbar=no");
}

//POP FUNCTIONS
//=============
//SHOWS AN ELEMENT
function ShowPop(id) {
    var popId = "pop" + id;
    document.getElementById(popId).style.display = "block";
}

//HIDES EN ELEMENT
function HidePop(id) {
    var popId = "pop" + id;
    document.getElementById(popId).style.display = "none";
}

//UI Functions
function colorIcon(id, src) {
    document.getElementById(id).src = src;
}


//PRODUCTS FUNCTIONS
//==================
    //Updates the per unit price label.
        function CalculateUnitPrice(dropDownId) {
            //Step 1: get the value of the changed element.
            var AddedElementPriceToUnitPrice = PriceDictionary[parseInt(document.getElementById(dropDownId).value)];
            //Step 2: calculate the new currnet unit price.
            document.getElementById("ctl00_ContentPlaceHolder1_uiProductForm_lblPricePerUnit").innerHTML =
            parseInt(document.getElementById("ctl00_ContentPlaceHolder1_uiProductForm_lblBasePricePerUnit").innerHTML) +
            AddedElementPriceToUnitPrice;
            //Step 3: Update the total price.
            updateTotalPriceLabel();
        }

    //Updates the total price label.
    function updateTotalPriceLabel() {
        //Step 1: get the value of the quantity:
        var currentQuantity = parseInt(document.getElementById("ctl00_ContentPlaceHolder1_uiProductForm_DdlQuantity").value);
        //Step 2: get the value of the price per product:
        var currentPricePerUnit = parseInt(document.getElementById("ctl00_ContentPlaceHolder1_uiProductForm_lblPricePerUnit").innerHTML);
        //Step 3: Set the total price into the total price label:
        document.getElementById("ctl00_ContentPlaceHolder1_uiProductForm_lblTotalPrice").innerHTML = currentQuantity * currentPricePerUnit;
    }

    //Updates the final price label.
    function updateFinalPrice() {
        //Step 1: get the value of the delivery price:
        var deliveryPrice = parseInt(document.getElementById("ctl00_ContentPlaceHolder1_uiCart_DdlDeliveryTypes").value);
        //Step 2: get the value of the price per product:
        var cartTotalPriceBeforeDelivery = parseInt(document.getElementById("ctl00_ContentPlaceHolder1_uiCart_lblCartMiddleSum").innerHTML);
        //Step 3: Set the total price into the total price label:
        document.getElementById("ctl00_ContentPlaceHolder1_uiCart_lblCartFinalPrice").innerHTML = deliveryPrice + cartTotalPriceBeforeDelivery;
    }

    //Adds a cart line through usage of AJAX and WCF
    function AddToCartViaAjax(sessionId) {
        //Step 1: Prepare all the variables to send to the WCF web service.
        var cmsId = document.getElementById("ctl00_ContentPlaceHolder1_uiProductForm_lblProductCmsId").innerHTML;
        var color = document.getElementById("ctl00_ContentPlaceHolder1_uiProductForm_DdlColorChoice").value;
        var size = document.getElementById("ctl00_ContentPlaceHolder1_uiProductForm_DdlSizeChoice").value;
        var type = document.getElementById("ctl00_ContentPlaceHolder1_uiProductForm_DdlTypeChoice").value;
        var quantity = document.getElementById("ctl00_ContentPlaceHolder1_uiProductForm_DdlQuantity").value;
        //Step 2: Prepare the Ajax Object and send the request.
        var xmlhttp;
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        }
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
       xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("ctl00_ContentPlaceHolder1_uiProductForm_lblAddToCartLineSpan").innerHTML = '<img src=\"Resources/Store/AddToCartDoneButton.png\" alt=\"המוצר בסל\"/>';
                document.getElementById("ctl00_ucPersonalZone_cartLineLink").innerHTML = xmlhttp.responseText;
            }
        }
        var wcfUrl = "WebServices/ShoppingService.svc/AddCartLine?cmsId=" + cmsId + "&color=" + color + "&size=" + size + "&type=" + type + "&quantity=" + quantity + "&sessionId=" + sessionId;
        xmlhttp.open("GET", wcfUrl, true);
        xmlhttp.send();


    }

    //Upates a cart via AJAX and WCF
    function updateCartLine(cartLineId,cartId,isRefresh) {
        
        //Step 1: Prepare all the variables to send to the WCF web service.
        var color = document.getElementById("color_"+cartLineId).value;
        var size = document.getElementById("size_"+cartLineId).value;
        var type = document.getElementById("type_"+cartLineId).value;
        var quantity = document.getElementById("quantity_"+cartLineId).value;
        wcfUrl = "WebServices/ShoppingService.svc/UpdateCartLine?cartLineId=" + cartLineId + "&color=" + color + "&size=" + size + "&type=" + type +
         "&quantity=" + quantity + "&sessionId=" + cartId;

        //Step 2: Prepare the Ajax Object and send the request.
        var xmlhttp;
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        }
        else {// code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
       xmlhttp.onreadystatechange = function () {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("updateSpan_" + cartLineId).src = "/Resources/Cart/updateCartLineDoneButton.png";
                document.getElementById("ctl00_ucPersonalZone_cartLineLink").innerHTML = xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET", wcfUrl, true);
        xmlhttp.send();
        //if (isRefresh)
           // location.href = "/cms.aspx?nameUrl=Cart";
    }

    //Removes a cart line via AJAX and WCF
    function removeCartLine(cartLineId) {
        if (confirm("Are you sure you wish to remove this product?")) {
            var xmlhttp;
            if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp = new XMLHttpRequest();
            }
            else {// code for IE6, IE5
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            xmlhttp.onreadystatechange = function () {
                if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                    //Update where we at.
                    location.href = "/cms.aspx?nameUrl=Cart";
                }
            }
            var wcfUrl = "WebServices/ShoppingService.svc/RemoveCartLine?cartLineId="+cartLineId;
            xmlhttp.open("GET", wcfUrl, false);
            xmlhttp.send();
            
           
        }//End confirmation check
    }

    //ORDER FORM FUNCTIONS
    //====================
    function validateOrderForm() {
        var isFormValid = true;
        //Step # 1 : Clean the output message label.
        document.getElementById('ctl00_ContentPlaceHolder1_uiOrderForm_orderFormVs').innerHTML = "";

        //Step # 2 : Determine the Fields of the billing information by reverse order.

        //Validate Terms of use
        if (!($('#ctl00_ContentPlaceHolder1_uiOrderForm_chkTerms').is(":checked"))) {
            document.getElementById('ctl00_ContentPlaceHolder1_uiOrderForm_orderFormVs').innerHTML = "* Please Accept the Terms of use.</br>";
            isFormValid = false;
        }

        //Validate Zip
        if (!(isNameValid("ctl00_ContentPlaceHolder1_uiOrderForm_txtZip", 1)))
            isFormValid = false;

        //Validate Country
        if (!(isCheckBoxValid("ctl00_ContentPlaceHolder1_uiOrderForm_DdlCountryId"))) {
            isFormValid = false;
        }
        else {
            if (document.getElementById('ctl00_ContentPlaceHolder1_uiOrderForm_DdlCountryId').value == 265) {
                if (!(isCheckBoxValid("ctl00_ContentPlaceHolder1_uiOrderForm_DdlState")))
                    isFormValid = false;
            }
            else if (document.getElementById('ctl00_ContentPlaceHolder1_uiOrderForm_DdlCountryId').value == 303) {
                if (!(isCheckBoxValid("ctl00_ContentPlaceHolder1_uiOrderForm_DdlProvince")))
                    isFormValid = false;
            }
        }

        //Validate City
        if (!(isNameValid("ctl00_ContentPlaceHolder1_uiOrderForm_txtCity", 1))) {
            isFormValid = false;
        }

        //Validate Address
        if (!(isNameValid("ctl00_ContentPlaceHolder1_uiOrderForm_txtAddress", 1))) {
            isFormValid = false;
        }

        //Validate Email
        if (!(isEmailValid("ctl00_ContentPlaceHolder1_uiOrderForm_txtEmail"))) {
            isFormValid = false;
        }

        //Validate Phone
        if (!(isNameValid("ctl00_ContentPlaceHolder1_uiOrderForm_txtPhone", 1))) {
            isFormValid = false;
        }

        //Validate Last Name
        if (!(isNameValid("ctl00_ContentPlaceHolder1_uiOrderForm_txtLast", 1))) {
            isFormValid = false;
        }
        //Validate First Name
        if (!(isNameValid("ctl00_ContentPlaceHolder1_uiOrderForm_txtFirstName", 1))) {
            isFormValid = false;
        }

        //Step # 3 : If the Method type is credit then we need to validate
        if ($('#ctl00_ContentPlaceHolder1_uiOrderForm_radCreditCard').is(":checked")) {

                //Validate Credit Number
            if (!(isNameValid("ctl00_ContentPlaceHolder1_uiOrderForm_txtCardNumber", 7))) {
                document.getElementById('ctl00_ContentPlaceHolder1_uiOrderForm_orderFormVs').innerHTML += 
                "* Please Enter at least 7 digits in Card Number.</br>";
                    isFormValid = false;
                }
                else {

                    //Validate Credit Number as number
                    if (!(isNumber(document.getElementById('ctl00_ContentPlaceHolder1_uiOrderForm_txtCardNumber').value))) {
                        isFormValid = false;
                        document.getElementById('ctl00_ContentPlaceHolder1_uiOrderForm_orderFormVs').innerHTML += "* Please Enter a numeric input in Card Number.</br>";
                        $('#ctl00_ContentPlaceHolder1_uiOrderForm_txtCardNumber').addClass("fieldError");
                        $('#ctl00_ContentPlaceHolder1_uiOrderForm_txtCardNumber').focus();
                    }
                    else {
                        $('#ctl00_ContentPlaceHolder1_uiOrderForm_txtCardNumber').remove("fieldError");
                    }

                }

                //Validate Credit Type
                if (!(isCheckBoxValid("ctl00_ContentPlaceHolder1_uiOrderForm_DdlCreditType"))) {
                    isFormValid = false;
                }

                //Validate First Name on card
                if (!(isNameValid("ctl00_ContentPlaceHolder1_uiOrderForm_txtCreditFirstName", 1))) {
                    isFormValid = false;
                }

                //Validate Last Name on card
                if (!(isNameValid("ctl00_ContentPlaceHolder1_uiOrderForm_txtCreditLastName", 1))) {
                    isFormValid = false;
                }

                //Validate CVV
                if (!(isNameValid("ctl00_ContentPlaceHolder1_uiOrderForm_txtCreditCvv", 2))) {
                    isFormValid = false;
                }
                else {
                    //Validate Credit Number as number
                    if (
                        !(
                        isNumber(
                        document.getElementById('ctl00_ContentPlaceHolder1_uiOrderForm_txtCreditCvv').value
                        )
                        )) {
                        isFormValid = false;
                        document.getElementById('ctl00_ContentPlaceHolder1_uiOrderForm_orderFormVs').innerHTML +=
                 "* Please Enter a numeric input in CVV.</br>";
                        $('#ctl00_ContentPlaceHolder1_uiOrderForm_txtCreditCvv').addClass("fieldError");
                        $('#ctl00_ContentPlaceHolder1_uiOrderForm_txtCreditCvv').focus();
                    }
                    else {
                        $('#ctl00_ContentPlaceHolder1_uiOrderForm_txtCreditCvv').remove("fieldError");
                    }
                }

                

                //Validate Expiration Date
                var d1 = new Date();
                var d2 = new Date(Number($('#ctl00_ContentPlaceHolder1_uiOrderForm_DdlYear').val()), Number($('#ctl00_ContentPlaceHolder1_uiOrderForm_DdlMonth').val()), 24, 1, 1, 1);
                //Check month
                if (d1 > d2) {
                    $('#ctl00_ContentPlaceHolder1_uiOrderForm_DdlMonth').addClass("fieldError");
                    $('#ctl00_ContentPlaceHolder1_uiOrderForm_DdlYear').addClass("fieldError");
                    isFormValid = false;
                }
                else {
                    $('#ctl00_ContentPlaceHolder1_uiOrderForm_DdlMonth').removeClass("fieldError");
                    $('#ctl00_ContentPlaceHolder1_uiOrderForm_DdlYear').removeClass("fieldError");
                }
            }
            //Step # 4 : Determine display of notification and errors.
            if (isFormValid) {
                return true;
            }
            else {
                document.getElementById('ctl00_ContentPlaceHolder1_uiOrderForm_orderFormVs').innerHTML +=
         "* Please Fill the required Fields.";
                return false;
            }
        }


        //update state display
        function updateOrderFormStateDisplay() {
            document.getElementById('ctl00_ContentPlaceHolder1_uiOrderForm_pnlStateBox').style.display = 'none';
            document.getElementById('ctl00_ContentPlaceHolder1_uiOrderForm_pnlProvinceBox').style.display = 'none';
            if (document.getElementById('ctl00_ContentPlaceHolder1_uiOrderForm_DdlCountryId').value == 265)
                document.getElementById('ctl00_ContentPlaceHolder1_uiOrderForm_pnlStateBox').style.display = 'block';
            if (document.getElementById('ctl00_ContentPlaceHolder1_uiOrderForm_DdlCountryId').value == 303)
                document.getElementById('ctl00_ContentPlaceHolder1_uiOrderForm_pnlProvinceBox').style.display = 'block';
        }


        //Shows/Hides the credit box dependent on payment method selected value
        function updateCreditBoxDisplay() {
            if ($('#ctl00_ContentPlaceHolder1_uiOrderForm_radCreditCard').is(":checked"))
                $('#creditCardBox').slideDown();
            else
                $('#creditCardBox').slideUp();
        }


    //GENERAL USABILITY
    var numb = '0123456789';
    var lwr = 'abcdefghijklmnopqrstuvwxyz';
    var upr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';

    function isValid(parm, val) {
        if (parm == "") return true;
        for (i = 0; i < parm.length; i++) {
            if (val.indexOf(parm.charAt(i), 0) == -1) return false;
        }
        return true;
    }

    function isNumber(parm) { return isValid(parm, numb); }
    function isLower(parm) { return isValid(parm, lwr); }
    function isUpper(parm) { return isValid(parm, upr); }
    function isAlpha(parm) { return isValid(parm, lwr + upr); }
    function isAlphanum(parm) { return (parm, lwr + upr + numb); } 
