﻿// mobile
//if (navigator.userAgent.indexOf('iPhone') != -1) {
//    addEventListener("load", function () {
//        setTimeout(hideURLbar, 0);
//    }, false);
//}

//function hideURLbar() {
//  //  window.scrollTo(0, 1);
//}

function AjaxLoginFacebook(pc, pl) {

      $.ajax({
           type: "POST",
           url: "/ajax/UtilsAjax.aspx",
           // dataType: 'json',
           data: {
               task: 'facebookconnect',
               c: pc,
               l: pl
           },
           success: function (data) {
             var obj = $.parseJSON(data);

             if (obj['success'] == 1) {
                 window.location.reload();
             }
             else {
                
             }
           }

       });

}

function MobileScrollToContent() {
    if (document.getElementById('header') != null && document.getElementById('main_menu') != null) {
        if (document.getElementById('leftzone') != null) {
            scrollTo(0, document.getElementById('header').scrollHeight + document.getElementById('main_menu').scrollHeight + document.getElementById('leftzone').scrollHeight)
        } else {
            scrollTo(0, document.getElementById('header').scrollHeight + document.getElementById('main_menu').scrollHeight)
        }
    }
}

//*//

$(document).ready(function () {
  //  $('.required').each(function (index) {
     //   if ($('label[for="' + $(this).attr('id') + '"]').match("*$") != "*")
    //        $('label[for="' + $(this).attr('id') + '"]').append('&nbsp;*');
       // else
       //     ;
    //});

    $("a.tooltip[title]").tooltip(
			{
			    showURL: false,
			    track: true,
			    top: 10,
			    left: 5,
			    showBody: ": "
			}
		);

});

jQuery.fn.center = function () {

    return this.each(function () {
        var element = jQuery(this), win = jQuery(window);
        centerElement();
        jQuery(window).bind('resize', function () {
            centerElement();
        });


        function centerElement() {
            var elementWidth, elementHeight, windowWidth, windowHeight, X2, Y2;
            elementWidth = element.outerWidth();
            elementHeight = element.outerHeight();
            windowWidth = win.width();
            windowHeight = win.height();
            X2 = (windowWidth / 2 - elementWidth / 2) + "px";
            Y2 = (windowHeight / 2 - elementHeight / 2) + "px";
            jQuery(element).css({
                'left': X2,
                'top': Y2,
                'position': 'fixed'
            });
        } //centerElement function
    });
}


/*
jQuery.fn.center = function () {
this.css("position", "absolute");
this.css("top", ($(window).height() - this.height()) / 2 + $(window).scrollTop() + "px");
this.css("left", ($(window).width() - this.width()) / 2 + $(window).scrollLeft() + "px");

return this;
}
*/
/****************************************************************************/
//                          skin dropdownlist
/****************************************************************************/
$(document).ready(function () {
    // select element styling
    $('select.customdropdown').each(function () {
        var title = $(this).attr('title');
        if ($('option:selected', this).val() != '') title = $('option:selected', this).text();
        $(this)
					.css({ 'z-index': 10, 'opacity': 0, '-khtml-appearance': 'none' })
					.after('<span class="customdropdown">' + title + '</span>')
					.change(function () {
					    val = $('option:selected', this).text();
					    $(this).next().text(val);
					})
    });

});

/****************************************************************************/

/********************** Auto Hide Mobile Top Nav ****************************/

$(document).ready(function () {
    if ($('.mobile #homeWrapper').length) {
        $('.mobile #megadd').css('display', 'block'); 
    }
});

/****************************************************************************/

/********************** MEGA DROP DOWN *************************************/


var constMaxSiteWidth = 0;

function MegaDDMouseIn(elem) {
    var dropDownDiv = $(this).find('div');
    dropDownDiv.stop().fadeTo(200, .95).show();

    if (dropDownDiv.length > 0) {
        if (/_done123456$/.test($(this).find('div').attr("id")) == false) {
            
            var marginLeftRight = parseInt($(this).find('div').css("padding-left")) + parseInt($(this).find('div').css("padding-right"));

            var widthDrop = ($(this).find('div>ul').outerWidth(true) * $(this).find('div>ul').length) + marginLeftRight;
           

            if (widthDrop > constMaxSiteWidth)
                widthDrop = constMaxSiteWidth - marginLeftRight;

            dropDownDiv.css('width', widthDrop);

            var headerOffsetRight = ($('#header').offset().left + constMaxSiteWidth);


            var elemOffsetRight = ($(this).offset().left + $(this).find('div').outerWidth(true));

            if (elemOffsetRight > headerOffsetRight) {
                var move = elemOffsetRight - headerOffsetRight;
                dropDownDiv.css('left', -move);
            }

            $(this).find('div').attr("id", $(this).find('div').attr("id") + "_done123456");

        }


    }
}
function MegaDDMouseOut(elem) {
    $(this).find("div").stop().fadeTo(200, 0, function () {
        $(this).hide();
    });
}

function GenerateTopMenu() {

    constMaxSiteWidth = $('#header').width();

    $("div#megadd>ul>li").hover(MegaDDMouseIn, MegaDDMouseOut);
    $("div#megadd>ul>li>div").css({ opacity: 0 });
   
        $("div#megadd>ul>li[subid]").each(
                    function (index) {
                        var subid = $(this).attr("subid");

                        var wrapUl = !$("#" + subid).children(":first-child").is("ul");
                        var wrapLi = !$("#" + subid).children(":first-child").children(":first-child").is("li");

                        if (wrapLi == true)
                            $("#" + subid).children(":first-child").wrap("<li />");
                        if (wrapUl == true)
                            $("#" + subid).children(":first-child").wrap("<ul />");

                        $(this).append($("#" + subid));
                    });

        var liWidth = 0;
        var visibleWidth = 0;
        
        $("div#megadd>ul>li").each(function () {
            if (constMaxSiteWidth < (liWidth + $(this).outerWidth(true))) {
                $(this).css('display', 'none');
            }
            else {
                 visibleWidth += $(this).outerWidth(true)-10;
             //   console.log($(this).innerWidth() );
            }
            liWidth += $(this).outerWidth(true);
        });

      //  alert(visibleWidth);
        if (visibleWidth < constMaxSiteWidth) {

            //alert(visibleWidth);

             var pad =   ((((constMaxSiteWidth - visibleWidth) / $("div#megadd>ul>li:visible").length)) / 2);
             var padFloor = Math.floor(pad);
             var padRest = (pad - padFloor) * $("div#megadd>ul>li:visible").length * 2;
             //alert("padRest:" + padFloor + Math.floor(padRest));

             $("div#megadd>ul>li>a").css("padding-left", padFloor).css("padding-right", padFloor);
             //var orig = (pad * $("div#megadd>ul>li:visible").length * 2) - ( visibleWidth);
             var lastElem = padFloor + Math.floor(padRest)-2;
           //  alert(lastElem);
             $("div#megadd>ul>li:visible:last>a").css("padding-right", lastElem);
            //$("div#megadd>ul>li:visible:last>a").css("padding-left", pad - 1);
        }


        $("div#megadd").css("visibility", "visible"); 
 
}


/********************************************************************/

/* ************************************* BAG MANAGMENT  **************************************/


var _timeout;
function ShowPopupAddToBag() {
    
    $("#popupAddToBag").fadeIn("fast");
    $("#popupAddToBag").width($("#popupAddToBag #link1AddToBag").outerWidth(true) + $("#popupAddToBag #link2AddToBag").outerWidth(true) + 40);
    $("#popupAddToBag").center();
    clearTimeout(_timeout);
    _timeout = setTimeout('HidePopupAddToBag()', 4000);
    return false;
}

function HidePopupAddToBag() {
    $("#popupAddToBag").fadeOut("fast");
}

function addToBagV2(sku, id, qty, idCountry, idLang, gotobag, showpopup) {

    createCookie('ecomBag' + idCountry + '_' + sku, qty + '^1^p^' + id, 30);
    if (gotobag == true) {
        document.location.href = '/ecomBag.aspx?c=' + idCountry + '&l=' + idLang;
    }
    if (showpopup == true) {
        ShowPopupAddToBag();
    }

    updateEcombagTotalProducts();

    return false;
}



function updateEcombagTotalProducts() {
    var country = $("#spEcombagTotalProducts").attr("country");
    var total = 0;
    if (country != undefined) {
        var cookName = 'ecomBag' + country + '_';
        var cookContent = document.cookie, cookEnd, i, j;

        for (i = 0, c = cookContent.length; i < c; i++) {
            j = i + cookName.length;

            if (cookContent.substring(i, j) == cookName) {
                cookEnd = cookContent.indexOf(";", j);
                if (cookEnd == -1) {
                    cookEnd = cookContent.length;
                }
                var skuContent = cookContent.substring(j, cookEnd).split('=');
                if (skuContent.length == 2) {
                    var ContentTab = skuContent[1].split('^');
                    if (ContentTab.length > 0)
                        total += new Number(ContentTab[0]);
                }

            }

        }
    }
    $("#spEcombagTotalProducts").html(total);
}

$(document).ready(function () {
    updateEcombagTotalProducts();
});
/*
function addToBag(sku, price, id) {
if (arguments.length == 3) {
//sku,price,id
createCookie('ecomBag19_' + arguments[0], '1^1^p^' + arguments[2], 30);
} else {
//sku,price,id,qty
createCookie('ecomBag19_' + arguments[0], arguments[3] + '^1^p^' + arguments[2], 30);
}
document.location.href = '/ecomBag.aspx?c=19&l=1';
}*/
/********************************************************************/

/************************************** COOKIES *************************************/
function createCookieMinutes(name, value, minutes) {
    if (minutes) {
        var date = new Date();
        date.setTime(date.getTime() + (minutes * 60 * 1000));
        var expires = '; expires=' + date.toGMTString();
    }
    else var expires = '';
    document.cookie = name + '=' + value + expires + '; path=/';
}

function createCookie(name, value, days) {
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
        var expires = '; expires=' + date.toGMTString();
    }
    else var expires = '';
    document.cookie = name + '=' + value + expires + '; path=/';
}


function WriteCookie(name, value, expdate) {
    var argv = WriteCookie.arguments;
    var argc = WriteCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path = (argc > 3) ? argv[3] : null;
    var domain = (argc > 4) ? argv[4] : null;
    var secure = (argc > 5) ? argv[5] : false;

    var date = new Date();
    date.setTime(date.getTime() + (30 * 24 * 60 * 60 * 1000));
    expires = 1;

    if (expdate != null) date = expdate;
    document.cookie = name + "=" + escape(value) +
    ((expires == null) ? "" : ("; expires=" + date.toUTCString())) +
    ((path == null) ? "" : ("; path=" + path)) +
    ((domain == null) ? "" : ("; domain=" + domain)) +
    ((secure == true) ? "; secure" : "");
}

function getCookieVal(offset) {
    var endstr = document.cookie.indexOf(";", offset);
    if (endstr == -1) endstr = document.cookie.length;
    return unescape(document.cookie.substring(offset, endstr));
}

function ReadCookie(name) {
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while (i < clen) {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg) return getCookieVal(j);
        i = document.cookie.indexOf(" ", i) + 1;
        if (i == 0) break;
    }
    return null;
}

function DeleteCookie(name) {
    date = new Date;
    date.setFullYear(date.getFullYear() - 1);
    WriteCookie(name, 'ko', date);
}

function eraseCookie(name) {
    createCookie(name, "", -1);
    document.location.href = document.location.href;
}

function eraseCookieNoRefresh(name) {
    createCookie(name, "", -1);
}



/********************************************************************/

/* ********************************** POP UP LOADING **************************************/


function showLoading() {
   // var showDiv = function () {
        $("#popupLoading").center();
        $("#popupLoading").fadeIn("fast");
    //}
    //setTimeout(showDiv, 50);
    }
function showLoadingWithMask() {
    $("#globalMask").css({ "opacity": "0.5" }).fadeIn("fast");
    showLoading();
}

function hideLoading() {
    $("#globalMask").fadeOut("fast");
    $("#popupLoading").fadeOut("fast");
    //  $('#popupLoading').removeClass('fixed');
}

/********************************************************************/

/********************** SEARCH ***************************/
function goSearchpage(defaultValue, c, l) {
    if (document.getElementById('searchfield').value.length > 0 && document.getElementById('searchfield').value != defaultValue) {
        location.href = "/Search.aspx?search='" + encodeURI(document.getElementById('searchfield').value) + "'&c=" + c + "&l=" + l;
    }
}
function searchPress(e, defaultValue, c, l) {
    if (e.keyCode == 13)
        goSearchpage(defaultValue, c, l);
}

function disableEnterKey(e) {
    var key;
    if (window.event)
        key = window.event.keyCode; //IE
    else
        key = e.which; //firefox
    return (key != 13);
}

/**************************************************************************/

/********************** FROM FO.js ***************************/

function ChangeUrl() {
    location.href = document.forms[0].ListeUrl.options[document.forms[0].ListeUrl.selectedIndex].value;
}


function changeSecTab(tab) {
    document.getElementById('divSecType').style.display = 'none';
    document.getElementById('divSecRange').style.display = 'none';
    document.getElementById(tab).style.display = 'block';
    //TODO : write cookie : active TAB
}

/**************************************************************************/
function TextAreaCheckLength(txtArea, limit, spanToRefresh) {

    var realLength = txtArea.val().length;
    var length = txtArea.val().replace(/\r/ig, "").length;

    if (length > limit) {
        var tail = length - limit;
        //length = 500;
        txtArea.val(txtArea.val().substring(0, realLength - tail));
    }
    spanToRefresh.html(limit - length);
}

function formatPrice(culture, total, ctrl) {
    $.ajax({
        type: "POST",
        url: "/ajax/ecombag_ajax.aspx",
        data: "task=formatprice&price=" + total + "&culture=" + culture,
        success: function (msg) {
            ctrl.html(msg);
        }
    });
}

function ManageReadMoreButton(readmorelink, elemContent, elemExpand) {
    var originalSize = elemExpand.height();

    if (elemContent.outerHeight(true) > (elemExpand.height() + readmorelink.height() + 5)) {
        readmorelink.click(function (e) {
            e.preventDefault();
            if (ReadMoreButtonAnimate(elemExpand, elemContent, originalSize, readmorelink) == true) {
                //   $("#fadeimg").fadeOut(400);
                $("#fadeimg").hide();
            }
            else {
                //$("#fadeimg").fadeIn(400);
                $("#fadeimg").show();
            }
            /*
            $("#imgBLUp").fadeOut(400);
            $("#imgBLDown").fadeIn(400);
            */
        });
    }
    else {
        readmorelink.hide();
        $("#fadeimg").hide();
        elemExpand.height(elemExpand.height() + readmorelink.height());
    }
}

function ReadMoreButtonAnimate(fromElem, totalElem, originalHeight, readmorelink) {

    if (fromElem.height() > originalHeight) {
       
        readmorelink.find(".imgBLDown").fadeIn(400);
        readmorelink.find(".imgBLUp").fadeOut(400);

        fromElem.animate({ height: originalHeight }, 400, function () {
            //imgElem.attr("src", "/img/OCC/new/moreBTN.png");
          
        });
        return false;

    }
    else {
        readmorelink.find(".imgBLUp").fadeIn(400);
        readmorelink.find(".imgBLDown").fadeOut(400);

        fromElem.animate({ height: totalElem.css("height") }, 400, function () {
            //imgElem.attr("src", "/img/OCC/new/lessBTN.png");
        
        });
        return true;
    }
}


function ReadMoreButton(elemDisplay, readmorelink) {
    if (elemDisplay.is(":hidden")) {
        readmorelink.find(".imgBLUp").fadeIn(400);
        readmorelink.find(".imgBLDown").fadeOut(400);

        elemDisplay.slideDown(700, "linear", function () {
        //    imgButton.attr("src", "/img/OCC/new/lessBTN.png");

        });

    }
    else {
        readmorelink.find(".imgBLDown").fadeIn(400);
        readmorelink.find(".imgBLUp").fadeOut(400);
        
        elemDisplay.slideUp(600, "linear", function () {
          //  imgButton.attr("src", "/img/OCC/new/moreBTN.png");

        });

    }
}


/******************************************************************************/

/*********************        VALIDATION                      **************************/

$(document).ready(function () {
    $("#aspnetForm").validate({
        onsubmit: false
        , errorClass: 'validationerror'
        , validClass: 'validationvalid'
    });

    $('.validationGroup .causesValidation').click(DefaultValidateGroup);

    $.extend($.validator.messages, {
        required: '<img src="/img/error-anim.gif"/>'
        , email: '<img src="/img/error-anim.gif"/>'
        , minlength: '<img src="/img/error-anim.gif"/>'
        , equalTo: '<img src="/img/error-anim.gif"/>'
        , number: '<img src="/img/error-anim.gif"/>'
        , digits: '<img src="/img/error-anim.gif"/>'
    });
});

function GetDefaultValidationResultWithoutHidden(elem) {
    var isValid = true;

    elem.find(':input').each(function (i, item) {
        if ($(item).is(":hidden") == false) {
            if (!$(item).valid())
                isValid = false;
        }
    });

    return isValid;
}

function GetDefaultValidationResult(elem) {
    var isValid = true;

    elem.find(':input').each(function (i, item) {
        if (!$(item).valid())
            isValid = false;
    });

    return isValid;
}

function DefaultValidateGroup(evt) {

    isValid = GetDefaultValidationResult($(this).parents('.validationGroup'));

    if (!isValid)
        evt.preventDefault();
    else
        showLoading();
}



/************************************************************************/

/*********************       EQUALIZE                    ***********************/
function GlobalEqualizeElements() {
    $('[equalize]').each(function () {
        if (/_done123456$/.test($(this).attr("equalize")) == false) {


            var curEqualize = $(this).attr("equalize");
            var allCurEqualize = $('[equalize="' + curEqualize + '"]');
            if (allCurEqualize.length > 1) {
                var height = 0;
                var reset = $.browser.msie && $.browser.version < 7 ? "1%" : "auto";
                var oldHeight = allCurEqualize.css("height");

                allCurEqualize.css("height", reset);

                allCurEqualize.each(function () {
                    height = Math.max(height, this.offsetHeight);
                });

                allCurEqualize.css("height", height);

                allCurEqualize.each(function () {
                    var h = this.offsetHeight;
                    if (h > height)
                        $(this).css("height", height - (h - height));
                });
            }
            allCurEqualize.attr("equalize", curEqualize + "_done123456");

        }
    });

    $(".equalizeDivGroup").each(function () {
        var height = 0;
        var reset = $.browser.msie && $.browser.version < 7 ? "1%" : "auto";

        $(this).find(".equalizeDiv").css("height", reset);

        $(this).find(".equalizeDiv").each(function (i) {
            height = Math.max(height, this.offsetHeight);
        });

        $(this).find(".equalizeDiv").css("height", height);

        $(this).find(".equalizeDiv").each(function (i) {
            var h = this.offsetHeight;
            if (h > height)
                $(this).css("height", height - (h - height));
        });
    });
}

$(document).ready(function () {
    GlobalEqualizeElements();
});

/*-------------------------------------------------------------------- */
/********************** MENU LEFT BEGIN *********************************/

function GenerateMenuleft() {
    // if ($("#menuleft").height() > $(window).height() - 160 && $("#menuleft ul").length > 1) {
    var isSub = $("#menuleft ul>li:nth-child(2)").length;
    if ($("#menuleft ul").length > 5 || $("#menuleft ul").length == 0 || isSub == 0) {
       
       var ulTopVisible = $("#menuleft .selected").parent();
       var ulTopVisibleChildsLength = ulTopVisible.find("li:nth-child(2)").length;

        if ($("#superCatName").length > 0) {
            var newul = "<ul>" + $("#superCatName").html();
            $("#menuleft ul li:first-child").each(function (index, Element) {

                if (ulTopVisibleChildsLength == 0 && $(this).hasClass("selected"))
                    newul += "<li class='selected'>" + $(this).html() + "</li>";
                else
                    newul += "<li>" + $(this).html() + "</li>";
            })

            newul += "</ul>";

            if (ulTopVisibleChildsLength == 0)
                $("#menuleft ul").detach();
            else
                $("#menuleft ul").not(ulTopVisible).detach();

            $("#menuleft").append(newul);

            if (ulTopVisible.length == 0 ) {
                $("#menuleft ul>li:first-child").addClass("selected");
            }

            $("#superCatName").detach();
        }
        
    }
    
    $("#menuleft ul>li:first-child").addClass("title");
    $("#menuleft").css("visibility", "visible");
}


/********************** MENU LEFT END *********************************/

/********************** BOTTOM LAYER BEGIN *********************************/

var BottomLayerBreak = 0;
var currentBottomLayerDisplayed = 0;
var BottomLayerPosition = 0;

var BottomLayertotalHeight = 20;
var BottomLayerIntervalIdentifier;
var BottomLayerHeightEachItemTab = new Array();

function BottomLayerMove() {
    if (BottomLayerPosition == 0) {
        if (BottomLayerHeightEachItemTab[currentBottomLayerDisplayed] > 20) {
            StopRotationBottomLayer();

            $("#BottomLayer .imgBLUp").fadeOut( 400);
            $("#BottomLayer .imgBLDown").fadeIn( 400);

            BottomLayerBreak = 1;

            $("#BottomLayer").animate({ height: BottomLayerHeightEachItemTab[currentBottomLayerDisplayed] }, 400, function () {
                BottomLayerPosition = 1;
            });
        }
    }
    else {

        $("#BottomLayer .imgBLUp").fadeIn(400);
        $("#BottomLayer .imgBLDown").fadeOut( 400);


        $("#BottomLayer").animate({ height: 25 }, 400, function () {
            BottomLayerPosition = 0;
            BottomLayerBreak = 0;

            LaunchRotationBottomLayer();
        });
    }
}

function BottomLayerUpFixed() {
    if (currentBottomLayerDisplayed != 0) {
        $("#bottomLayerElem_" + currentBottomLayerDisplayed).insertBefore($("#bottomLayerElem_0"));
    }
    $("#ContentBottomLayer>div").css("position", "static").css("display", "");
}

function BottomLayerClose() {
    $("#BottomLayer").animate({ height: 0 }, 400);
    createCookieMinutes('hidebottomlayer', '1', 5);
}


function BottomLayerShowNext() {
    if (BottomLayerBreak == 0 && $("#bottomLayerElem_1").length > 0) {
        var nextBottomLayerDisplayed = currentBottomLayerDisplayed + 1;
        if ($("#bottomLayerElem_" + nextBottomLayerDisplayed).length == 0)
            nextBottomLayerDisplayed = 0;


        $("#bottomLayerElem_" + currentBottomLayerDisplayed).fadeOut(200, function () { $("#bottomLayerElem_" + nextBottomLayerDisplayed).fadeIn(400); });
        
        currentBottomLayerDisplayed = nextBottomLayerDisplayed;
        if (BottomLayerHeightEachItemTab[currentBottomLayerDisplayed] > 20) {
            $("#linkUpBottomLayer").fadeIn( 400);
        }
        else {
            $("#linkUpBottomLayer").fadeOut( 400);
        }
    }
}

function LaunchRotationBottomLayer() {
   BottomLayerIntervalIdentifier = setInterval(BottomLayerShowNext, 5000);
}

function StopRotationBottomLayer() {
    clearInterval(BottomLayerIntervalIdentifier);
}

function  InitBottomLayer(){
  //  $("#linkUpBottomLayer").hide();
    $(".main_content").css("margin-bottom", "40px");

    BottomLayertotalHeight = 0;
    var ContentBottomLayerCount = 0;

    $("#ContentBottomLayer>div").each(function (i, item) {
        BottomLayerHeightEachItemTab.push($(item).outerHeight(true));
        ContentBottomLayerCount++;
    });

    $("#BottomLayerCennterContent").height(BottomLayertotalHeight);

    if (BottomLayerHeightEachItemTab[currentBottomLayerDisplayed] > 20) {
        $("#linkUpBottomLayer").fadeIn(200);
    }
    if (ContentBottomLayerCount > 1) {
        LaunchRotationBottomLayer();
    }
}

$(window).load(function () {
    InitBottomLayer();
});



/********************** BOTTOM LAYER END *********************************/



/********************** FAQ BEGIN ******************************************/

$(document).ready(function () {
    if ($(".FAQQuestion").length > 0 && $(".FAQAnswer").length > 0) {
        $(".FAQQuestion").click(function () {

            $('.FAQAnswer').slideUp(350);

            if ($(this).next('.FAQAnswer').css('display') == 'none') {
                $(this).next().slideDown(350);
            }
            return false;
        });
    }
});

/********************** FAQ END ******************************************/

/********************** NEWSLETTER POPUP******************************************/


var CanHideNewsletterAuto = true;
var UrlNewsletterPopupPage = "";
var DefaultEmailValNewsletterPopup = "";
$(document).ready(function () {
    $("#NewsletterPopupEmail").focus(function (event) {
        if (CanHideNewsletterAuto == true) {
            $("#NewsletterPopupEmail").val("");
        }
        CanHideNewsletterAuto = false;
    });
    $("#NewsletterPopupValid").click(function (event) {
        CanHideNewsletterAuto = false;
        if (GetDefaultValidationResult($("#NewsletterPopup"))) {
            HideNewsletterPopup(false);
            document.location.href = CanHideNewsletterAuto + $("#NewsletterPopup").val();

        }
        else
            event.preventDefault();
    });
});

function ShowNewsletterPopup(url) {
    
    if (url != "" && $.cookie('NewsletterPopupCookie') == null) {
        UrlNewsletterPopupPage = url;
        $("#globalMask").css({ "opacity": "0.5" }).show();
        $("#NewsletterPopup").center().show();
        setTimeout("HideNewsletterPopupAuto()", 35000);
    }
}

function HideNewsletterPopupAuto() {
    if (CanHideNewsletterAuto == true)
        HideNewsletterPopup(true);
}

function HideNewsletterPopup(auto) {
    $("#globalMask").css({ "opacity": "0" }).hide();
    $("#NewsletterPopup").hide();
    if(auto == false)
       $.cookie('NewsletterPopupCookie', 'true', { expires: 30});
}
/********************** NEWSLETTER POPUP END ******************************************/

function AustraliaIsStateZipCodeValid(zip, state) {
    var allArray = new Array();
    allArray["ACT"] = new Array(200, 221, 2600, 2601, 2602, 2603, 2604, 2605, 2606, 2607, 2608, 2609, 2610, 2612, 2614, 2615, 2616, 2617, 2618, 2620, 2900, 2901, 2902, 2903, 2904, 2905, 2906, 2911, 2912, 2913, 2914, 2611);
    allArray["NSW"] = new Array(1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, 1020, 1021, 1022, 1023, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039, 1040, 1041, 1042, 1043,
                                    1044, 1045, 1046, 1100, 1101, 1105, 1106, 1107, 1108, 1109, 1110, 1112, 1113, 1114, 1115, 1116, 1117, 1118, 1119, 1120, 1121, 1122, 1123, 1124, 1125, 1126, 1127, 1128, 1129, 1130, 1131, 1132, 1133, 1134, 1135, 1136, 1137, 1138, 1139, 1140, 1141, 1142, 1143, 1144, 1145, 1146, 1147, 1148, 1149, 1150, 1151, 1152, 1153, 1154, 1155, 1156, 1157, 1158, 1159, 1160, 1161, 1162, 1163, 1164,
                                    1165, 1166, 1167, 1168, 1169, 1170, 1171, 1172, 1173, 1174, 1175, 1176, 1177, 1178, 1179, 1180, 1181, 1182, 1183, 1184, 1185, 1186, 1187, 1188, 1189, 1190, 1191, 1192, 1193, 1194, 1195, 1196, 1197, 1198, 1199, 1200, 1201, 1202, 1203, 1204, 1205, 1206, 1207, 1208, 1209, 1210, 1211, 1212, 1213, 1214, 1215, 1216, 1217, 1218, 1219, 1220, 1221, 1222, 1223, 1224, 1225,
                                    1226, 1227, 1228, 1229, 1230, 1231, 1232, 1233, 1234, 1235, 1236, 1237, 1238, 1239, 1240, 1291, 1292, 1293, 1294, 1295, 1296, 1297, 1298, 1299, 1300, 1311, 1312, 1313, 1314, 1315, 1316, 1317, 1318, 1319, 1320, 1321, 1322, 1323, 1324, 1325, 1326, 1327, 1328, 1329, 1330, 1331, 1332, 1333, 1334, 1335, 1340, 1350, 1355, 1360, 1391, 1401, 1416, 1419, 1420, 1421, 1422, 1423, 1424, 1425, 1426, 2620,
                                    1427, 1428, 1429, 1430, 1435, 1440, 1445, 1450, 1455, 1460, 1465, 1466, 1470, 1475, 1480, 1481, 1484, 1485, 1487, 1490, 1493, 1495, 1499, 1515, 1560, 1565, 1570, 1582, 1585, 1590, 1595, 1597, 1602, 1630, 1635, 1639, 1640, 1655, 1658, 1660, 1670, 1671, 1675, 1680, 1685, 1690, 1691, 1692, 1693, 1694, 1695, 1696, 1697, 1698, 1699, 1700, 1701, 1710, 1712, 1715, 1730, 1740, 1741, 1750, 1755, 1765,
                                    1771, 1781, 1790, 1797, 1800, 1805, 1811, 1816, 1819, 1825, 1826, 1830, 1831, 1835, 1848, 1851, 1860, 1871, 1875, 1885, 1888, 1890, 1891, 1900, 1902, 2000, 2001, 2002, 2004, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027, 2028, 2029, 2030, 2031, 2032, 2033, 2034, 2035, 2036, 2037, 2038, 2039, 2040, 2041, 2042, 2043,
                                    2044, 2045, 2046, 2047, 2048, 2049, 2050, 2051, 2052, 2055, 2057, 2058, 2059, 2060, 2061, 2062, 2063, 2064, 2065, 2066, 2067, 2068, 2069, 2070, 2071, 2072, 2073, 2074, 2075, 2076, 2077, 2079, 2080, 2081, 2082, 2083, 2084, 2085, 2086, 2087, 2088, 2089, 2090, 2091, 2092, 2093, 2094, 2095, 2096, 2097, 2099, 2100, 2101, 2102, 2103, 2104, 2105, 2106, 2107, 2108, 2109, 2110, 2111, 2112, 2113, 2114,
                                    2115, 2116, 2117, 2118, 2119, 2120, 2121, 2122, 2123, 2124, 2125, 2126, 2127, 2128, 2129, 2130, 2131, 2132, 2133, 2134, 2135, 2136, 2137, 2138, 2139, 2140, 2141, 2142, 2143, 2144, 2145, 2146, 2147, 2148, 2150, 2151, 2152, 2153, 2154, 2155, 2156, 2157, 2158, 2159, 2160, 2161, 2162, 2163, 2164, 2165, 2166, 2167, 2168, 2170, 2171, 2172, 2173, 2174, 2175, 2176, 2177, 2178, 2179, 2190, 2191,
                                    2192, 2193, 2194, 2195, 2196, 2197, 2198, 2199, 2200, 2203, 2204, 2205, 2206, 2207, 2208, 2209, 2210, 2211, 2212, 2213, 2214, 2216, 2217, 2218, 2219, 2220, 2221, 2222, 2223, 2224, 2225, 2226, 2227, 2228, 2229, 2230, 2231, 2232, 2233, 2234, 2250, 2251, 2252, 2256, 2257, 2258, 2259, 2260, 2261, 2262, 2263, 2264, 2265, 2267, 2278, 2280, 2281, 2282, 2283, 2284, 2285, 2286, 2287, 2289, 2290, 2291,
                                    2292, 2293, 2294, 2295, 2296, 2297, 2298, 2299, 2300, 2302, 2303, 2304, 2305, 2306, 2307, 2308, 2309, 2310, 2311, 2312, 2314, 2315, 2316, 2317, 2318, 2319, 2320, 2321, 2322, 2323, 2324, 2325, 2326, 2327, 2328, 2329, 2330, 2331, 2333, 2334, 2335, 2336, 2337, 2338, 2339, 2340, 2341, 2342, 2343, 2344, 2345, 2346, 2347, 2348, 2350, 2351, 2352, 2353, 2354, 2355, 2356, 2357, 2358, 2359, 2360, 2361,
                                    2365, 2369, 2370, 2371, 2372, 2379, 2380, 2381, 2382, 2386, 2387, 2388, 2390, 2395, 2396, 2397, 2398, 2399, 2400, 2401, 2402, 2403, 2404, 2405, 2406, 2408, 2409, 2410, 2411, 2415, 2420, 2421, 2422, 2423, 2424, 2425, 2426, 2427, 2428, 2429, 2430, 2431, 2439, 2440, 2441, 2442, 2443, 2444, 2445, 2446, 2447, 2448, 2449, 2450, 2452, 2453, 2454, 2455, 2456, 2460, 2462, 2463, 2464, 2465, 2466, 2469,
                                    2470, 2471, 2472, 2473, 2474, 2475, 2476, 2477, 2478, 2479, 2480, 2481, 2482, 2483, 2484, 2485, 2486, 2487, 2488, 2489, 2490, 2500, 2502, 2505, 2506, 2508, 2515, 2516, 2517, 2518, 2519, 2520, 2522, 2525, 2526, 2527, 2528, 2529, 2530, 2533, 2534, 2535, 2536, 2537, 2538, 2539, 2540, 2541, 2545, 2546, 2548, 2549, 2550, 2551, 2555, 2556, 2557, 2558, 2559, 2560, 2563, 2564, 2565, 2566, 2567, 2568,
                                    2569, 2570, 2571, 2572, 2573, 2574, 2575, 2576, 2577, 2578, 2579, 2580, 2581, 2582, 2583, 2584, 2585, 2586, 2587, 2588, 2590, 2594, 2611, 2619, 2621, 2622, 2623, 2624, 2625, 2626, 2627, 2628, 2629, 2630, 2631, 2632, 2633, 2640, 2641, 2642, 2643, 2644, 2645, 2646, 2647, 2648, 2649, 2650, 2651, 2652, 2653, 2655, 2656, 2658, 2659, 2660, 2661, 2663, 2665, 2666, 2668, 2669, 2671, 2672, 2675, 2678,
                                     2680, 2681, 2700, 2701, 2702, 2703, 2705, 2706, 2707, 2708, 2710, 2711, 2712, 2713, 2714, 2715, 2716, 2717, 2720, 2721, 2722, 2725, 2726, 2727, 2729, 2730, 2731, 2732, 2733, 2734, 2735, 2736, 2737, 2738, 2739, 2745, 2747, 2748, 2749, 2750, 2751, 2752, 2753, 2754, 2755, 2756, 2757, 2758, 2759, 2760, 2761, 2762, 2763, 2765, 2766, 2767, 2768, 2769, 2770, 2773, 2774, 2775, 2776, 2777, 2778, 2779,
                                      2780, 2782, 2783, 2784, 2785, 2786, 2787, 2790, 2791, 2792, 2793, 2794, 2795, 2796, 2797, 2798, 2799, 2800, 2803, 2804, 2805, 2806, 2807, 2808, 2809, 2810, 2818, 2820, 2821, 2823, 2824, 2825, 2827, 2828, 2829, 2830, 2831, 2832, 2833, 2834, 2835, 2836, 2839, 2840, 2842, 2843, 2844, 2845, 2846, 2847, 2848, 2849, 2850, 2852,
                                    2864, 2865, 2866, 2867, 2868, 2869, 2870, 2871, 2873, 2874, 2875, 2876, 2877, 2878, 2879, 2880, 2890, 2891, 2898, 2899, 3644, 4375, 4383, 2618, 3691, 3707, 4380);
    allArray["NT"] = new Array(800, 801, 804, 810, 811, 812, 813, 814, 815, 820, 821, 822, 828, 829, 830, 831, 832, 834, 835, 836, 837, 838, 839, 840, 841, 845, 846, 847, 850, 851, 852, 853, 854, 860, 861, 862, 870, 871, 872, 880, 881, 885, 886, 906, 907, 909, 4825);
    allArray["QLD"] = new Array(4000, 4001, 4002, 4003, 4004, 4005, 4006, 4007, 4008, 4009, 4010, 4011, 4012, 4013, 4014, 4017, 4018, 4019, 4020, 4021, 4022, 4025, 4029, 4030, 4031, 4032, 4034, 4035, 4036, 4037, 4051, 4053, 4054, 4055, 4059, 4060, 4061, 4064, 4065, 4066, 4067,
                                    4068, 4069, 4070, 4072, 4073, 4074, 4075, 4076, 4077, 4078, 4101, 4102, 4103, 4104, 4105, 4106, 4107, 4108, 4109, 4110, 4111, 4112, 4113, 4114, 4115, 4116, 4117, 4118, 4119, 4120, 4121, 4122, 4123, 4124, 4125, 4127, 4128, 4129, 4130, 4131, 4132, 4133, 4151,
                                    4152, 4153, 4154, 4155, 4156, 4157, 4158, 4159, 4160, 4161, 4163, 4164, 4165, 4169, 4170, 4171, 4172, 4173, 4174, 4178, 4179, 4183, 4184, 4205, 4207, 4208, 4209, 4210, 4211, 4212, 4213, 4214, 4215, 4216, 4217, 4218, 4219, 4220, 4221, 4222, 4223, 4224, 4225, 4226, 4227, 4228, 4229, 4230, 4270, 4271, 4272, 4275, 4280, 4285, 4287, 4300,
                                    4301, 4303, 4304, 4305, 4306, 4307, 4309, 4310, 4311, 4312, 4313, 4340, 4341, 4342, 4343, 4344, 4345, 4346, 4347, 4350, 4352, 4353, 4354, 4355, 4356, 4357, 4358, 4359, 4360, 4361, 4362, 4363, 4364, 4365, 4370, 4371, 4372, 4373, 4374, 4376, 4377, 4378, 4380, 4381, 4382, 4384, 4385, 4387, 4388, 4390, 4400, 4401, 4402, 4403, 4404, 4405, 4383, 4385,
                                    4406, 4407, 4408, 4410, 4411, 4412, 4413, 4415, 4416, 4417, 4418, 4419, 4420, 4421, 4422, 4423, 4424, 4425, 4426, 4427, 4428, 4454, 4455, 4461, 4462, 4465, 4467, 4468, 4470, 4471, 4472, 4474, 4475, 4477, 4478, 4479, 4480, 4481, 4482, 4486, 4487, 4488, 4489, 4490, 4491, 4492, 4493, 4494, 4496, 4497, 4498, 4500, 4501, 4502, 4503, 4504,
                                    4505, 4506, 4507, 4508, 4509, 4510, 4511, 4512, 4514, 4515, 4516, 4517, 4518, 4519, 4520, 4521, 4550, 4551, 4552, 4553, 4554, 4555, 4556, 4557, 4558, 4559, 4560, 4561, 4562, 4563, 4564, 4565, 4566, 4567, 4568, 4569, 4570, 4571, 4572, 4573, 4574, 4575, 4580, 4581, 4600, 4601, 4605, 4606, 4608, 4610, 4611, 4612, 4613, 4614, 4615, 4620,
                                    4621, 4625, 4626, 4627, 4630, 4650, 4655, 4659, 4660, 4662, 4670, 4671, 4673, 4674, 4676, 4677, 4678, 4680, 4694, 4695, 4697, 4699, 4700, 4701, 4702, 4703, 4704, 4705, 4706, 4707, 4709, 4710, 4711, 4712, 4713, 4714, 4715, 4716, 4717, 4718, 4719, 4720, 4721, 4722, 4723, 4724, 4725, 4726, 4727, 4728, 4730, 4731, 4732, 4733, 4735, 4736,
                                    4737, 4738, 4739, 4740, 4741, 4742, 4743, 4744, 4745, 4746, 4750, 4751, 4753, 4754, 4756, 4757, 4798, 4799, 4800, 4801, 4802, 4803, 4804, 4805, 4806, 4807, 4808, 4809, 4810, 4811, 4812, 4813, 4814, 4815, 4816, 4817, 4818, 4819, 4820, 4821, 4822, 4823, 4824, 4825, 4828, 4829, 4830, 4849, 4850, 4852, 4854, 4855, 4856, 4857, 4858, 4859,
                                    4860, 4861, 4865, 4868, 4869, 4870, 4871, 4872, 4873, 4874, 4875, 4876, 4877, 4878, 4879, 4880, 4881, 4882, 4883, 4884, 4885, 4886, 4887, 4888, 4890, 4891, 4895, 9000, 9001, 9002, 9005, 9007, 9008, 9009, 9010, 9013, 9015, 9016, 9017, 9018, 9019, 9020, 9021, 9022, 9023, 9250, 9464, 9726, 9728, 9729, 9943, 9944);
    allArray["SA"] = new Array(5000, 5001, 5005, 5006, 5007, 5008, 5009, 5010, 5011, 5012, 5013, 5014, 5015, 5016, 5017, 5018, 5019, 5020, 5021, 5022, 5023, 5024, 5025, 5031, 5032, 5033, 5034, 5035, 5037, 5038, 5039, 5040, 5041, 5042, 5043, 5044, 5045, 5046, 5047, 5048, 5049, 5050, 5051, 5052, 5061, 5062, 5063, 5064,
                                    5065, 5066, 5067, 5068, 5069, 5070, 5071, 5072, 5073, 5074, 5075, 5076, 5081, 5082, 5083, 5084, 5085, 5086, 5087, 5088, 5089, 5090, 5091, 5092, 5093, 5094, 5095, 5096, 5097, 5098, 5106, 5107, 5108, 5109, 5110, 5111, 5112, 5113, 5114, 5115, 5116, 5117, 5118, 5120, 5121, 5125, 5126, 5127, 5131, 5132, 5133, 5134, 5136, 5137, 5138, 5139, 5140, 5141, 5142, 5144, 5150, 5151, 5152, 5153,
                                    5154, 5155, 5156, 5157, 5158, 5159, 5160, 5161, 5162, 5163, 5164, 5165, 5166, 5167, 5168, 5169, 5170, 5171, 5172, 5173, 5174, 5201, 5202, 5203, 5204, 5210, 5211, 5212, 5213, 5214, 5220, 5221, 5222, 5223, 5231, 5232, 5233, 5234, 5235, 5236, 5237, 5238, 5240, 5241, 5242, 5243, 5244, 5245, 5246, 5250, 5251, 5252, 5253, 5254, 5255, 5256, 5259, 5260, 5261, 5262, 5263, 5264, 5265, 5266,
                                    5267, 5268, 5269, 5270, 5271, 5272, 5273, 5275, 5276, 5277, 5278, 5279, 5280, 5290, 5291, 5301, 5302, 5303, 5304, 5306, 5307, 5308, 5309, 5310, 5311, 5320, 5321, 5322, 5330, 5331, 5332, 5333, 5340, 5341, 5342, 5343, 5344, 5345, 5346, 5350, 5351, 5352, 5353, 5354, 5355, 5356, 5357, 5360, 5371, 5372, 5373, 5374, 5381, 5400, 5401, 5410, 5411, 5412, 5413, 5414, 5415, 5416, 5417, 5418,
                                    5419, 5420, 5421, 5422, 5431, 5432, 5433, 5434, 5440, 5451, 5452, 5453, 5454, 5455, 5460, 5461, 5462, 5464, 5470, 5471, 5472, 5473, 5480, 5481, 5482, 5483, 5485, 5490, 5491, 5493, 5495, 5501, 5502, 5510, 5520, 5521, 5522, 5523, 5540, 5550, 5552, 5554, 5555, 5556, 5558, 5560, 5570, 5571, 5572, 5573, 5575, 5576, 5577, 5580, 5581, 5582, 5583, 5600, 5601, 5602, 5603, 5604, 5605,
                                    5606, 5607, 5608, 5609, 5630, 5631, 5632, 5633, 5640, 5641, 5642, 5650, 5651, 5652, 5653, 5654, 5655, 5660, 5661, 5670, 5671, 5680, 5690, 5700, 5710, 5720, 5722, 5723, 5724, 5725, 5730, 5731, 5732, 5733, 5734, 5800, 5810, 5839, 5860, 5861, 5862, 5863, 5864, 5865, 5866, 5867, 5868, 5869, 5870, 5871, 5872, 5873, 5874, 5875, 5876, 5877, 5878, 5879, 5880, 5881, 5882, 5883, 5884, 5885,
                                    5886, 5887, 5888, 5889, 5890, 5891, 5892, 5893, 5894, 5895, 5896, 5897, 5898, 5899, 5900, 5901, 5902, 5903, 5904, 5920, 5942, 5950, 5960, 872);
    allArray["TAS"] = new Array(7000, 7001, 7002, 7004, 7005, 7006, 7007, 7008, 7009, 7010, 7011, 7012, 7015, 7016, 7017, 7018, 7019, 7020, 7021, 7022, 7023, 7024, 7025, 7026, 7027, 7030, 7050, 7051, 7052, 7053, 7054, 7055, 7109, 7112, 7113, 7116, 7117, 7119, 7120, 7139, 7140, 7150, 7151, 7155, 7162, 7163, 7170, 7171,
                                    7172, 7173, 7174, 7175, 7176, 7177, 7178, 7179, 7180, 7182, 7183, 7184, 7185, 7186, 7187, 7190, 7209, 7210, 7211, 7212, 7213, 7214, 7215, 7216, 7248, 7249, 7250, 7252, 7253, 7254, 7255, 7256, 7257, 7258, 7259, 7260, 7261, 7262, 7263, 7264, 7265, 7267, 7268, 7270, 7275, 7276, 7277, 7290, 7291, 7292, 7300, 7301, 7302, 7303, 7304, 7305, 7306, 7307, 7310, 7315, 7316, 7320, 7321, 7322,
                                    7325, 7330, 7331, 7466, 7467, 7468, 7469, 7470, 7800, 7802, 7803, 7804, 7805, 7806, 7807, 7808, 7809, 7810, 7811, 7812, 7813, 7814, 7823, 7824, 7827, 7828, 7829, 7845, 7850, 7901, 7902, 7903, 7904, 7905, 7906, 7907, 7908, 7909, 7915, 7916, 7917, 7918, 7919, 7920, 7921, 7922, 7923);
    allArray["VIC"] = new Array(3000, 3001, 3002, 3003, 3004, 3005, 3006, 3008, 3010, 3011, 3012, 3013, 3015, 3016, 3018, 3019, 3020, 3021, 3022, 3023, 3024, 3025, 3026, 3027, 3028, 3029, 3030, 3031, 3032, 3033, 3034, 3036, 3037, 3038, 3039, 3040, 3041, 3042, 3043, 3044, 3045, 3046, 3047, 3048, 3049, 3050, 3051, 3052, 3053, 3054, 3055, 3056, 3057, 3058, 3059, 3060, 3061, 3062, 3063, 3064, 3065, 3066, 3067, 3068,
                                    3070, 3071, 3072, 3073, 3074, 3075, 3076, 3078, 3079, 3081, 3082, 3083, 3084, 3085, 3086, 3087, 3088, 3089, 3090, 3091, 3093, 3094, 3095, 3096, 3097, 3099, 3101, 3102, 3103, 3104, 3105, 3106, 3107, 3108, 3109, 3110, 3111, 3113, 3114, 3115, 3116, 3121, 3122, 3123, 3124, 3125, 3126, 3127, 3128, 3129, 3130, 3131, 3132, 3133, 3134, 3135, 3136, 3137, 3138, 3139, 3140, 3141, 3142, 3143, 3144,
                                     3145, 3146, 3147, 3148, 3149, 3150, 3151, 3152, 3153, 3154, 3155, 3156, 3158, 3159, 3160, 3161, 3162, 3163, 3164, 3165, 3166, 3167, 3168, 3169, 3170, 3171, 3172, 3173, 3174, 3175, 3176, 3177, 3178, 3179, 3180, 3181, 3182, 3183, 3184, 3185, 3186, 3187, 3188, 3189, 3190, 3191, 3192, 3193, 3194, 3195, 3196, 3197, 3198, 3199, 3200, 3201, 3202, 3204, 3205, 3206, 3207, 3211, 3212, 3214, 3215,
                                     3216, 3217, 3218, 3219, 3220, 3221, 3222, 3223, 3224, 3225, 3226, 3227, 3228, 3230, 3231, 3232, 3233, 3235, 3236, 3237, 3238, 3239, 3240, 3241, 3242, 3243, 3249, 3250, 3251, 3254, 3260, 3264, 3265, 3266, 3267, 3268, 3269, 3270, 3271, 3272, 3273, 3274, 3275, 3276, 3277, 3278, 3279, 3280, 3281, 3282, 3283, 3284, 3285, 3286, 3287, 3289, 3292, 3293, 3294, 3300, 3301, 3302, 3303, 3304, 3305,
                                     3309, 3310, 3311, 3312, 3314, 3315, 3317, 3318, 3319, 3321, 3322, 3323, 3324, 3325, 3328, 3329, 3330, 3331, 3332, 3333, 3334, 3335, 3337, 3338, 3340, 3341, 3342, 3345, 3350, 3351, 3352, 3353, 3354, 3355, 3356, 3357, 3360, 3361, 3363, 3364, 3370, 3371, 3373, 3374, 3375, 3377, 3378, 3379, 3380, 3381, 3384, 3385, 3387, 3388, 3390, 3391, 3392, 3393, 3395, 3396, 3400, 3401, 3402, 3407, 3409,
                                     3412, 3413, 3414, 3415, 3418, 3419, 3420, 3423, 3424, 3427, 3428, 3429, 3430, 3431, 3432, 3433, 3434, 3435, 3437, 3438, 3440, 3441, 3442, 3444, 3446, 3447, 3448, 3450, 3451, 3453, 3458, 3460, 3461, 3462, 3463, 3464, 3465, 3467, 3468, 3469, 3472, 3475, 3477, 3478, 3480, 3482, 3483, 3485, 3487, 3488, 3489, 3490, 3491, 3494, 3496, 3498, 3500, 3501, 3502, 3505, 3506, 3507, 3509, 3512, 3515,
                                     3516, 3517, 3518, 3520, 3521, 3522, 3523, 3525, 3527, 3529, 3530, 3531, 3533, 3537, 3540, 3542, 3544, 3546, 3549, 3550, 3551, 3552, 3554, 3555, 3556, 3557, 3558, 3559, 3561, 3562, 3563, 3564, 3565, 3566, 3567, 3568, 3570, 3571, 3572, 3573, 3575, 3576, 3579, 3580, 3581, 3583, 3584, 3585, 3586, 3588, 3589, 3590, 3591, 3594, 3595, 3596, 3597, 3599, 3607, 3608, 3610, 3612, 3614, 3616, 3617,
                                     3618, 3619, 3620, 3621, 3622, 3623, 3624, 3629, 3630, 3631, 3632, 3633, 3634, 3635, 3636, 3637, 3638, 3639, 3640, 3641, 3643, 3646, 3647, 3649, 3658, 3659, 3660, 3661, 3662, 3663, 3664, 3665, 3666, 3669, 3670, 3671, 3672, 3673, 3675, 3676, 3677, 3678, 3682, 3683, 3685, 3687, 3688, 3689, 3690, 3691, 3694, 3695, 3697, 3698, 3699, 3700, 3701, 3704, 3705, 3707, 3708, 3709, 3711, 3712, 3713,
                                     3714, 3715, 3717, 3718, 3719, 3720, 3722, 3723, 3724, 3725, 3726, 3727, 3728, 3730, 3732, 3733, 3735, 3736, 3737, 3738, 3739, 3740, 3741, 3744, 3746, 3747, 3749, 3750, 3751, 3752, 3753, 3754, 3755, 3756, 3757, 3758, 3759, 3760, 3761, 3762, 3763, 3764, 3765, 3766, 3767, 3770, 3775, 3777, 3778, 3779, 3781, 3782, 3783, 3785, 3786, 3787, 3788, 3789, 3791, 3792, 3793, 3795, 3796, 3797, 3799,
                                     3800, 3802, 3803, 3804, 3805, 3806, 3807, 3808, 3809, 3810, 3812, 3813, 3814, 3815, 3816, 3818, 3820, 3821, 3822, 3823, 3824, 3825, 3831, 3832, 3833, 3835, 3840, 3841, 3842, 3844, 3847, 3850, 3851, 3852, 3853, 3854, 3856, 3857, 3858, 3859, 3860, 3862, 3864, 3865, 3869, 3870, 3871, 3873, 3874, 3875, 3878, 3880, 3882, 3885, 3886, 3887, 3888, 3889, 3890, 3891, 3892, 3893, 3895, 3896, 3898,
                                     3900, 3902, 3903, 3904, 3909, 3910, 3911, 3912, 3913, 3915, 3916, 3918, 3919, 3920, 3921, 3922, 3923, 3925, 3926, 3927, 3928, 3929, 3930, 3931, 3933, 3934, 3936, 3937, 3938, 3939, 3940, 3941, 3942, 3943, 3944, 3945, 3946, 3950, 3951, 3953, 3954, 3956, 3957, 3958, 3959, 3960, 3962, 3964, 3965, 3966, 3967, 3971, 3975, 3976, 3977, 3978, 3979, 3980, 3981, 3984, 3987, 3988, 3990, 3991, 3992,
                                     3995, 3996, 8001, 8002, 8003, 8004, 8005, 8006, 8007, 8008, 8009, 8010, 8011, 8012, 8015, 8045, 8051, 8060, 8061, 8066, 8069, 8070, 8071, 8102, 8103, 8107, 8108, 8111, 8120, 8205, 8383, 8386, 8388, 8390, 8393, 8394, 8396, 8399, 8576, 8627, 8873, 3644);

    allArray["WA"] = new Array(6000, 6001, 6003, 6004, 6005, 6006, 6007, 6008, 6009, 6010, 6011, 6012, 6014, 6015, 6016, 6017, 6018, 6019, 6020, 6021, 6022, 6023, 6024, 6025, 6026, 6027, 6028, 6029, 6030, 6031, 6032, 6033, 6034, 6035, 6036, 6037, 6038, 6041, 6042, 6043, 6044, 6050, 6051, 6052, 6053, 6054, 6055, 6056, 6057, 6058, 6059, 6060, 6061, 6062, 6063, 6064, 6065, 6066, 6067, 6068, 6069, 6070, 6071, 6072,
                                    6073, 6074, 6076, 6077, 6078, 6079, 6081, 6082, 6083, 6084, 6090, 6100, 6101, 6102, 6103, 6104, 6105, 6106, 6107, 6108, 6109, 6110, 6111, 6112, 6121, 6122, 6123, 6124, 6125, 6126, 6147, 6148, 6149, 6150, 6151, 6152, 6153, 6154, 6155, 6156, 6157, 6158, 6159, 6160, 6161, 6162, 6163, 6164, 6165, 6166, 6167, 6168, 6169, 6170, 6171, 6172, 6173, 6174, 6175, 6176, 6180, 6181, 6182, 6207,
                                    6208, 6209, 6210, 6211, 6213, 6214, 6215, 6218, 6220, 6221, 6223, 6224, 6225, 6226, 6227, 6228, 6229, 6230, 6231, 6232, 6233, 6236, 6237, 6239, 6240, 6243, 6244, 6251, 6252, 6253, 6254, 6255, 6256, 6258, 6260, 6262, 6271, 6275, 6280, 6281, 6282, 6284, 6285, 6286, 6288, 6290, 6302, 6304, 6306, 6308, 6309, 6311, 6312, 6313, 6315, 6316, 6317, 6318, 6320, 6321, 6322, 6323, 6324, 6326,
                                    6327, 6328, 6330, 6331, 6332, 6333, 6335, 6336, 6337, 6338, 6341, 6343, 6346, 6348, 6350, 6351, 6352, 6353, 6355, 6356, 6357, 6358, 6359, 6361, 6363, 6365, 6367, 6368, 6369, 6370, 6372, 6373, 6375, 6383, 6384, 6385, 6386, 6390, 6391, 6392, 6393, 6394, 6395, 6396, 6397, 6398, 6401, 6403, 6405, 6407, 6409, 6410, 6411, 6412, 6413, 6414, 6415, 6418, 6419, 6420, 6421, 6422, 6423, 6424,
                                    6425, 6426, 6427, 6428, 6429, 6430, 6431, 6432, 6433, 6434, 6436, 6437, 6438, 6440, 6442, 6443, 6445, 6446, 6447, 6448, 6450, 6452, 6460, 6461, 6462, 6463, 6465, 6466, 6467, 6468, 6470, 6472, 6473, 6475, 6476, 6477, 6479, 6480, 6484, 6485, 6487, 6488, 6489, 6490, 6501, 6502, 6503, 6504, 6505, 6506, 6507, 6509, 6510, 6511, 6512, 6513, 6514, 6515, 6516, 6517, 6518, 6519, 6521, 6522,
                                    6525, 6528, 6530, 6531, 6532, 6535, 6536, 6537, 6556, 6558, 6560, 6562, 6564, 6566, 6567, 6568, 6569, 6571, 6572, 6574, 6575, 6603, 6605, 6606, 6608, 6609, 6612, 6613, 6614, 6616, 6620, 6623, 6625, 6627, 6628, 6630, 6631, 6632, 6635, 6638, 6639, 6640, 6642, 6646, 6701, 6705, 6707, 6710, 6711, 6712, 6713, 6714, 6716, 6718, 6720, 6721, 6722, 6725, 6726, 6728, 6731, 6733, 6740, 6743,
                                    6751, 6753, 6754, 6758, 6760, 6762, 6765, 6770, 6798, 6799, 6800, 6803, 6809, 6817, 6820, 6827, 6830, 6831, 6832, 6837, 6838, 6839, 6840, 6841, 6842, 6843, 6844, 6845, 6846, 6847, 6848, 6849, 6850, 6865, 6872, 6892, 6900, 6901, 6902, 6903, 6904, 6905, 6906, 6907, 6909, 6910, 6911, 6912, 6913, 6914, 6915, 6916, 6917, 6918, 6919, 6920, 6921, 6922, 6923, 6924, 6925, 6926, 6929, 6931,
                                    6932, 6933, 6934, 6935, 6936, 6937, 6938, 6939, 6940, 6941, 6942, 6943, 6944, 6945, 6946, 6947, 6951, 6952, 6953, 6954, 6955, 6956, 6957, 6958, 6959, 6960, 6961, 6963, 6964, 6965, 6966, 6967, 6968, 6969, 6970, 6979, 6980, 6981, 6982, 6983, 6984, 6985, 6986, 6987, 6988, 6989, 6990, 6991, 6992, 6997, 872);
    if (allArray[state] != undefined) {
        for (var i = 0; i < allArray[state].length; i++) {
            if (allArray[state][i] == zip)
                return true;
        }
    }
    return false;
}

function BrazilIsStateZipCodeValid(zip, state) {
    var allArray = new Array();
    allArray["AC"] = "6";
    allArray["AL"] = "5";
    allArray["AP"] = "6";
    allArray["AM"] = "6";
    allArray["BA"] = "4";
    allArray["CE"] = "6";
    allArray["DF"] = "7";
    allArray["ES"] = "2";
    allArray["GO"] = "7";
    allArray["MA"] = "6";
    allArray["MT"] = "7";
    allArray["MS"] = "7";
    allArray["MG"] = "3";
    allArray["PA"] = "6";
    allArray["PB"] = "5";
    allArray["PR"] = "8";
    allArray["PE"] = "5";
    allArray["PI"] = "6";
    allArray["RJ"] = "2";
    allArray["RN"] = "5";
    allArray["RS"] = "9";
    allArray["RO"] = "7";
    allArray["RR"] = "6";
    allArray["SC"] = "8";


    allArray["SE"] = "4";
    allArray["TO"] = "7";

    if (state == "SP" && (zip == "1" || zip == "0")) {
        return true;
    }
    if (allArray[state] != undefined && allArray[state] == zip) {
        return true;
    }
    return false;
}


//post with data passed as params and redirect
//path : url to post to
//params is a JSON collection of key/value pair as follow : var parameter = {'key1','param1':'key2','value2':'key3','value3'}
function post_to_url(path, params, method) {
    //default method is post
    method = method || "post";

    var form = document.createElement("form");
    form.setAttribute("method", method);
    form.setAttribute("action", path);

    for (var key in params) {
        var hiddenField = document.createElement("input");
        hiddenField.setAttribute("type", "hidden");
        hiddenField.setAttribute("name", key);
        hiddenField.setAttribute("value", params[key]);

        form.appendChild(hiddenField);
    }

    document.body.appendChild(form);
    form.submit();
}

//   ############################################################
//							Facebook Rules 
//   ############################################################

$(document).ready(function () {

    if (top != self && document.documentElement.clientWidth <= 760) {

        var cssObj = {
            'backgroundColor': '#FFF !important',
            'backgroundImage': 'none !important'
        }
        $("html").css(cssObj);

        // HomePage modification
        var homeLeftFb = $('#homeLeftFacebookOffer');
        var homeRightFb = $('#homeRightFacebookOffer');
        
        if (homeLeftFb.length > 0) {
            $("homeLeft").html().replaceWith(homeLeftFb.html());
        }
        if (homeRightFb.length > 0) {
            $("homeRight").html().replaceWith(homeRightFb.html());
        }
        else{
            var alternateContent = $('#homeLeft object img');
            var alternateContentLink = $('#homeLeft object a');

            if (alternateContentLink.length > 0) {
                $('#homeLeft object').hide();
                $('#homeLeft').append(alternateContentLink);
            }
            else if (alternateContent.length > 0) {
                $('#homeLeft object').hide();
                $('#homeLeft').append(alternateContent);
            }

            var alternateRightContent = $('#homeRight object img');
            var alternateRightContentLink = $('#homeRight object a');

            if (alternateRightContentLink.length > 0) {
                $('#homeRight object').hide();
                $('#homeRight').append(alternateRightContentLink);
            }
            else if (alternateRightContent.length > 0) {
                $('#homeRight object').hide();
                $('#homeRight').append(alternateRightContent);
            }
        }

        setTimeout("GenerateTopMenu()", 300);

        FB.init({
            appId: '275368459143160',
            status: true, // check login status
            cookie: true, // enable cookies to allow the server to access the session
            xfbml: true, // parse XFBML
            oauth: true // enables OAuth 2.0
        });

        function resize() {
            if ($.browser.webkit) {
                FB.Canvas.setSize({ height: $(document.body).height() + 30 });
            } else {
                FB.Canvas.setSize({ height: document.body.scrollHeight + 30 });
            }
        }
        setTimeout(resize, 500);
        FB.Canvas.setAutoResize(true);
    }
});

function shareFbThumbnail(page) {
    window.open(page, 'Facebook', 'width=500, height=400');
};

