$(document).ready(function() {
    // do stuff when DOM is ready

    $('#siteContactCountryCode1').click(function(){
        $('#phoneOther').hide();
        $('#phoneUsCanada').show();
        $('#selectStateProvince').attr('disabled', false);
    });

    $('#siteContactCountryCode2').click(function(){
        $('#phoneUsCanada').hide();
        $('#phoneOther').show();
        $('#selectStateProvince').attr('disabled', true);
    });

    // Below JS for tooltips
    $('#tooltip-main-content').hide();
    $('#tooltipmain').bt({
        closeWhenOthersOpen: true,
        trigger: 'click',
        contentSelector: "$('#tooltip-main-content').html()", /*get text of inner content of hidden div*/
        width: 595,
        fill: '#ffffcc',
        strokeWidth: 1,
        strokeStyle: '#ccc',
        spikeLength: 60,
        spikeGirth: 40,
        padding: 0,
        position:'right',
        offsetParent: 'body',
        cornerRadius: 2,
        cssStyles: {background: '#ffffcc'},
        shadow: true,
        shadowOffsetX: 3,
        shadowOffsetY: 3,
        shadowBlur: 8,
        shadowColor: '#ccc',
        shadowOverlap: false,
        noShadowOpts: {strokeStyle: '#ccc', strokeWidth: 2}
    });

    $('#tooltip-ht-content').hide();
    $('#tooltipht').bt({
        closeWhenOthersOpen: true,
        trigger: 'click',
        contentSelector: "$('#tooltip-ht-content').html()", /*get text of inner content of hidden div*/
        width: 380,
        fill: '#ffffcc',
        strokeWidth: 1,
        strokeStyle: '#ccc',
        spikeLength: 40,
        spikeGirth: 30,
        offsetParent: 'body',
        padding: 0,
        position:'right',
        cornerRadius: 2,
        cssStyles: {background: '#ffffcc'},
        shadow: true,
        shadowOffsetX: 3,
        shadowOffsetY: 3,
        shadowBlur: 8,
        shadowColor: 'rgba(0,0,0,.9)',
        shadowOverlap: false,
        noShadowOpts: {strokeStyle: '#999', strokeWidth: 2}
    });

    $('#tooltip-pc-content').hide();
    $('#tooltippc').bt({
        closeWhenOthersOpen: true,
        trigger: 'click',
        contentSelector: "$('#tooltip-pc-content').html()", /*get text of inner content of hidden div*/
        width: 300,
        fill: '#ffffcc',
        strokeWidth: 1,
        strokeStyle: '#ccc',
        spikeLength: 40,
        offsetParent: 'body',
        spikeGirth: 30,
        padding: 0,
        position:'right',
        cornerRadius: 2,
        cssStyles: {background: '#ffffcc'},
        shadow: true,
        shadowOffsetX: 3,
        shadowOffsetY: 3,
        shadowBlur: 8,
        shadowColor: 'rgba(0,0,0,.9)',
        shadowOverlap: false,
        noShadowOpts: {strokeStyle: '#999', strokeWidth: 2}
    });

    $('#tooltip-ts-content').hide();
    $('#tooltipts').bt({
        closeWhenOthersOpen: true,
        trigger: 'click',
        contentSelector: "$('#tooltip-ts-content').html()", /*get text of inner content of hidden div*/
        width: 300,
        fill: '#ffffcc',
        strokeWidth: 1,
        strokeStyle: '#ccc',
        spikeLength: 40,
        spikeGirth: 30,
        padding: 0,
        offsetParent: 'body',
        position:'right',
        cornerRadius: 2,
        cssStyles: {background: '#ffffcc'},
        shadow: true,
        shadowOffsetX: 3,
        shadowOffsetY: 3,
        shadowBlur: 8,
        shadowColor: 'rgba(0,0,0,.9)',
        shadowOverlap: false,
        noShadowOpts: {strokeStyle: '#999', strokeWidth: 2}
    });

    $('#tooltip-op-content').hide();
    $('#tooltipop').bt({
        closeWhenOthersOpen: true,
        trigger: 'click',
        contentSelector: "$('#tooltip-op-content').html()", /*get text of inner content of hidden div*/
        width: 300,
        fill: '#ffffcc',
        strokeWidth: 1,
        strokeStyle: '#ccc',
        spikeLength: 40,
        spikeGirth: 30,
        padding: 0,
        position:'right',
        offsetParent: 'body',
        cornerRadius: 2,
        cssStyles: {background: '#ffffcc'},
        shadow: true,
        shadowOffsetX: 3,
        shadowOffsetY: 3,
        shadowBlur: 8,
        shadowColor: 'rgba(0,0,0,.9)',
        shadowOverlap: false,
        noShadowOpts: {strokeStyle: '#999', strokeWidth: 2}
    });

    $("#tooltipht, #tooltippc, #tooltipts, #tooltipop").click(function(event){
        event.preventDefault();
        event.stopPropagation();
    });
});


    // do stuff when DOM is ready
$(window).unload(function() {
    var SEPARATOR = "#";

    var cookieValue = "";

    function getVal(el){
        return SEPARATOR + (el && el.value && el.value.length > 0 ? el.value.replace(SEPARATOR, ' ') : ' ');
    }

    var firstName = document.signup_form.siteContactFirstName;
    if (firstName && firstName.value) {
        cookieValue += getVal(firstName);
    } else {
        cookieValue += SEPARATOR + ' ';
    }

    var lastname = document.signup_form.siteContactLastName;
    if (lastname && lastname.value) {
        cookieValue += getVal(lastname);
    } else {
        cookieValue += SEPARATOR + ' ';
    }

    var siteName = document.signup_form.siteName;
    if (siteName && siteName.value) {
        cookieValue += getVal(siteName);
    } else {
        cookieValue += SEPARATOR + ' ';
    }

    if (document.signup_form.siteContactCountryCode != null) {
        if (document.signup_form.siteContactCountryCode[0].checked)
            cookieValue += SEPARATOR + 0;
        else if (document.signup_form.siteContactCountryCode[1].checked)
            cookieValue += SEPARATOR + 1;
        else
            cookieValue += SEPARATOR + ' ';
    } else {
        cookieValue += SEPARATOR + ' ';
    }

    if (document.signup_form.siteContactStateCode != null) {
        var stateSelectBox = document.signup_form.siteContactStateCode;
        cookieValue += SEPARATOR + stateSelectBox.options[stateSelectBox.selectedIndex].value;
    } else {
        cookieValue += SEPARATOR + ' ';
    }

    var phone = document.signup_form.siteContactPhone;
    if (phone && phone.value) {
        cookieValue += getVal(phone);
    } else {
        cookieValue += SEPARATOR + ' ';
    }

    var phoneAreaCode = document.signup_form.siteContactPhoneAreaCode;
    if (phoneAreaCode && phoneAreaCode.value) {
        cookieValue += getVal(phoneAreaCode);
    } else {
        cookieValue += SEPARATOR + ' ';
    }

    var phonePrefixCode = document.signup_form.siteContactPhonePrefixCode;
    if (phonePrefixCode && phonePrefixCode.value) {
        cookieValue += getVal(phonePrefixCode);
    } else {
        cookieValue += SEPARATOR + ' ';
    }

    var localRemainder = document.signup_form.siteContactPhoneLocalRemainder;
    if (localRemainder && localRemainder.value) {
        cookieValue += getVal(localRemainder);
    } else {
        cookieValue += SEPARATOR + ' ';
    }

    var phoneInternationalCode = document.signup_form.siteContactPhoneInternationalCode;
    if (phoneInternationalCode && phoneInternationalCode.value) {
        cookieValue += getVal(phoneInternationalCode);
    } else {
        cookieValue += SEPARATOR + ' ';
    }

    var phoneInternationalRemainder = document.signup_form.siteContactPhoneInternationalRemainder;
    if (phoneInternationalRemainder && phoneInternationalRemainder.value) {
        cookieValue += getVal(phoneInternationalRemainder);
    } else {
        cookieValue += SEPARATOR + ' ';
    }

    var email = document.signup_form.siteContactEmail;
    if (email && email.value) {
        cookieValue += getVal(email);
    } else {
        cookieValue += SEPARATOR + ' ';
    }


    var siteURL = document.signup_form.siteURL;
    if (siteURL && siteURL.value) {
        cookieValue += getVal(siteURL);
    } else {
        cookieValue += SEPARATOR + ' ';
    }

    var loginName = document.signup_form.siteOwnerLoginName;
    if (loginName && loginName.value) {
        cookieValue += getVal(loginName);
    } else {
        cookieValue += SEPARATOR + ' ';
    }
    
    if (document.signup_form.siteContactChallengeQuestion != null) {
        var challengeQuestionBox = document.signup_form.siteContactChallengeQuestion;
        cookieValue += SEPARATOR + challengeQuestionBox.options[challengeQuestionBox.selectedIndex].value;
    } else {
        cookieValue += SEPARATOR + ' ';
    }

    var challengeResponse = document.signup_form.siteContactChallengeResponse;
    if (challengeResponse && challengeResponse.value) {
        cookieValue += getVal(challengeResponse);
    } else {
        cookieValue += SEPARATOR + ' ';
    }

    var rc = document.signup_form.rc;
    if (rc && rc.value) {
        cookieValue += getVal(rc);
    } else {
        cookieValue += SEPARATOR + ' ';
    }

    if (null != document.signup_form.productsToAdd) {
        var boxes = document.signup_form.productsToAdd.length;

        var txt = "";
        for (i = 0; i < boxes; i++) {
            if (document.signup_form.productsToAdd[i].checked) {
               cookieValue += SEPARATOR + document.signup_form.productsToAdd[i].value;
            } else {
               cookieValue += SEPARATOR + ' ';
            }
        }
        
    } else {
        // need to add a DELIMITER for every product which might be offered
        cookieValue += SEPARATOR + ' ';
        cookieValue += SEPARATOR + ' ';
        cookieValue += SEPARATOR + ' ';
    }

    if (document.signup_form.siteSendHintsAndTips != null) {
        if (document.signup_form.siteSendHintsAndTips.checked)
            cookieValue += SEPARATOR + document.signup_form.siteSendHintsAndTips.value;
        else
            cookieValue += SEPARATOR + ' ';
    } else {
        cookieValue += SEPARATOR + ' ';
    }

        if (document.signup_form.siteSendCCConnections != null) {
        if (document.signup_form.siteSendCCConnections.checked)
            cookieValue += SEPARATOR + document.signup_form.siteSendCCConnections.value;
        else
            cookieValue += SEPARATOR + ' ';
    } else {
        cookieValue += SEPARATOR + ' ';
    }

    if (document.signup_form.terms_conditions != null) {
        if (document.signup_form.terms_conditions.checked)
            cookieValue += SEPARATOR + document.signup_form.terms_conditions.value;
        else
            cookieValue += SEPARATOR + ' ';
    } else {
        cookieValue += SEPARATOR + ' ';
    }

    var ftdID = document.signup_form.prop_ACCOUNT_FTDID;
    if (ftdID && ftdID.value) {
        cookieValue += getVal(ftdID);
    } else {
        cookieValue += SEPARATOR + ' ';
    }

    var accountID = document.signup_form.accountID;
    if (accountID && accountID.value) {
        cookieValue += getVal(accountID);
    } else {
        cookieValue += SEPARATOR + ' ';
    }

    cookieValue = URLEncode(cookieValue);
    Set_Cookie('signupcookie', cookieValue, '0', '/', location.hostname.substring(location.hostname.indexOf('.')), '');
});