﻿var usaStates = new Array("Select a State", "AL", "AK", "AS", "AZ", "AR", "CA", "CO", "CT", "DE", "DC", "FL", "GA", "HI", "ID", "IL", "IN", "IA", "KS", "KY", "LA", "ME", "MD", "MA", "MI", "MN", "MS", "MO", "QC", "MT", "NE", "NV", "NH", "NM", "NJ", "NY", "NC", "ND", "OH", "OK", "ON", "OR", "PA", "PR", "RI", "SC", "SD", "TN", "TX", "UT", "VA", "VI", "VT", "WA", "WI", "WV", "WY", "AB", "BC", "MB", "NB", "NL", "NT", "NS", "NU", "ON", "PE", "QC", "SK", "YT");
var canadaProvinces = new Array("Select a Province", "Alberta", "British Columbia", "Manitoba", "New Brunswick", "Newfoundland and Labrador", "Nova Scotia", "Northwest Territory", "Nunavut", "Ontario", "Prince Edward Island", "Quebec", "Saskatchewan", "Yukon");

$(document).ready(function() {

    setTimeout(function() { $("#liveadmin img").attr("src", "images/startChatSmall.png").show() }, 1000);

    $(".printLinkSolutions").hover(function() {
        $(".printPageLink").html('Print this Page');
        return false;
    },
    function() {
        $(".printPageLink").html('');
        return false;
    });
    $(".emailLinkSolutions").hover(function() {
        $(".printPageLink").html('Email this Page');
        return false;
    },
    function() {
        $(".printPageLink").html('');
        return false;
    });
    $(".openLinkSolutions").hover(function() {
        $(".printPageLink").html('Add to Favorites');
        return false;
    },
    function() {
        $(".printPageLink").html('');
        return false;
    });

    $("#btnSubmit").click(function() {
        $("#btnSubmit").addClass("btnLoading");
        if (ValidateContactUsInfo()) {
            if (typeof $.jmsajax == 'function') {
                $.jmsajax({
                    url: window.location.pathname,
                    method: "btnSubmit_Click",
                    data: {
                        info: fillContactUsInfo()
                    },
                    success: function(res) {
                        $("#btnSubmit").removeClass("btnLoading");
                        if (res) {
                            window.showModalDialog("Controls/ThankYou.html", "ThankYou", "dialogHeight: 400px; dialogWidth: 600px; center: Yes; scroll: No; resizable: No;");
                        } else {
                            $('#txtInfo').html("Error when sending Email. Please check your Email address and try again!");
                        }
                    },
                    error: function() {
                        $("#btnSubmit").removeClass("btnLoading");
                        alert("Error when sending Email. Please try again!");
                    }
                });
            }
        }
    });
    $("#btnSubmitNewsletter").click(function() {
        $("#btnSubmitNewsletter").addClass("btnLoading");
        $('#txtNewsletterInfo').html("");
        var index = window.location.pathname.lastIndexOf('/');
        var path = window.location.pathname.slice(0, index + 1) + 'Controls/Subscription.aspx';
        if (typeof $.jmsajax == 'function') {
            $.jmsajax({
                url: path,
                method: "btnSubmitNewsletter_Click",
                data: {
                    email: $("#txtNewsletter").val()
                },
                success: function(res) {
                    $("#btnSubmitNewsletter").removeClass("btnLoading");
                    if (res) {
                        $('#txtNewsletterInfo').html("Successfully subscription!");
                    } else {
                        $('#txtNewsletterInfo').html("Error when subscribing. Please try again!");
                    }
                },
                error: function() {
                    $("#btnSubmitNewsletter").removeClass("btnLoading");
                    alert("Error when subscribing. Please try again!");
                }
            });
        }
    });
    $("#cmbCountry").change(function() {
        obj = document.getElementById('cmbState');
        obj.options.length = 0;
        switch ($(this).val()) {
            case 'USA':
                AddUSAStates();
                $('#stateText').html("State");
                $('#zipText').html("Zip");
                break;
            case 'CA':
                for (keyVar in canadaProvinces) {
                    AddSelectOption(obj, canadaProvinces[keyVar], canadaProvinces[keyVar], false);
                }
                $('#stateText').html("Province");
                $('#zipText').html("Postal Code");
                break;
        }
    });
    if (window.location.pathname.indexOf('ContactUs.aspx') > 0) {
        AddUSAStates();
    }
});

function addToFavorites() {
    if (window.sidebar) { // Mozilla Firefox Bookmark
        window.sidebar.addPanel(document.title, location.href, "");
    } else if (window.external) { // IE Favorite
        window.external.AddFavorite(location.href, document.title);
    }
    else if (window.opera && window.print) { // Opera Hotlist
        return true;
    }
}
function emailFriend() {
    var width = 600;
    var height = 400;
    var left = parseInt((screen.availWidth / 2) - (width / 2));
    var top = parseInt((screen.availHeight / 2) - (height / 2));
    window.open("Controls/EmailFriend.aspx?link=" + window.location, "EmailFriend", "menubar=0,resizable=0,width=" + width + ",height=" + height + ",left=" + left + ",top=" + top);
}
function AddUSAStates() {
    obj = document.getElementById('cmbState');
    obj.options.length = 0;
    for (keyVar in usaStates) {
        AddSelectOption(obj, usaStates[keyVar], usaStates[keyVar], false);
    }
}
function AddSelectOption(selectObj, text, value, isSelected) {
    if (selectObj != null && selectObj.options != null) {
        selectObj.options[selectObj.options.length] = new Option(text, value, false, isSelected);
    }
}
function fillContactUsInfo() {
    var contactUsInfo = {}; 
    contactUsInfo.FirstName = $('#txtFirstName').val();
    contactUsInfo.LastName = $('#txtLastName').val();
    contactUsInfo.Company = $('#txtCompany').val();
    contactUsInfo.Email = $('#txtEmail').val();
    contactUsInfo.Telephone = $('#txtTelephone').val();
    contactUsInfo.Country = $('#cmbCountry').val();
    contactUsInfo.Address = $('#txtAddress').val();
    contactUsInfo.City = $('#txtCity').val();
    contactUsInfo.State = $('#cmbState').val();
    contactUsInfo.Zip = $('#txtZip').val();
    contactUsInfo.Comments = $('#txtComments').val();
    contactUsInfo.IsVideoTrib = $('#chkVideoTribute').is(':checked');
    contactUsInfo.IsLjCandle = $('#chkLJCandle').is(':checked');
    contactUsInfo.IsWebDev = $('#chkWebsiteDevelopment').is(':checked');
    contactUsInfo.IsHOrnam = $('#chkHolidayOrnaments').is(':checked');
    contactUsInfo.IsLjStationery = $('#chkLJStationery').is(':checked');
    contactUsInfo.IsEasyPrint = $('#chkEasyPrint').is(':checked');
    contactUsInfo.IsConsulting = $('#chkConsulting').is(':checked');
    contactUsInfo.IsOther = $('#chkOther').is(':checked'); 
    contactUsInfo.IsMarketingServices = $('#chkMarketingServices').is(':checked');
    contactUsInfo.IsWebcasting = $('#chkWebcasting').is(':checked');
    return contactUsInfo;
}
function ValidateContactUsInfo() {
    if ($('#txtFirstName').val() == '' || $('#txtLastName').val() == '' || $('#txtCompany').val() == '' || $('#txtEmail').val() == '' || $('#txtTelephone').val() == '' || $('#txtAddress').val() == '' || $('#txtCity').val() == '' || $('#cmbState').val() == 'Select a State' || $('#cmbState').val() == 'Select a Province' || $('#txtZip').val() == '') {
        $("#btnSubmit").removeClass("btnLoading");
        $('#txtInfo').html("Please fill all required fields!");
        return false;
    }
    $('#txtInfo').html("");
    return true;
}