// This document has the following parts:
// 1. Set footer links for EN and JP environments	-- removed
// 2. Update display of elements in the shopping cart	
// 3. Hide tagged FAQ classes, make them available for hide/show toggle
// 4. Manage display of links in left Column 1 *pending* -- removed

//Can be loaded when ready


$(window).load(function(){

    var themeLang=($('body').is('#_en'))?'en':'jp';	

    // 2. Update display of elements in the shopping cart	; this file is in setDisplayOfShippingToNone.js;	
    $('table.CartContents a.EstimateShippingLink').parent().parent().css('display','none');

    // 3. Hide tagged FAQ classes, make them available for hide/show toggle
    $('.FAQ_Answer').hide();								 
    $('.FAQ_Container .FAQ_Question').toggle(
        function(){
            $(this).next('.FAQ_Answer').fadeIn();
            $(this).addClass('Close');
        },
        function(){
            $(this).next('.FAQ_Answer').fadeOut();
            $(this).removeClass('Close');   
        }
        );

    //from : common.js
    $('.InitialFocus').focus();
    /*need to check if we need it , we may remove it and use css instead*/
    $('table.Stylize tr:even').addClass('Odd');
    $('table.Stylize tr:even').addClass('Even');
    $('table.Stylize tr:first-child').addClass('First');
    $('table.Stylize tr:last-child').addClass('Last');
    $('table.Stylize tr td:odd').addClass('Odd');
    $('table.Stylize tr td:even').addClass('Even');

    $('.TabContainer .TabNav li').click(function() {
        $(this).parent('.TabNav').find('li').removeClass('Active');
        $(this).parents('.TabContainer').find('.TabContent').hide();
        $(this).addClass('Active');
        $(this).parents('.TabContainer').find('#TabContent'+this.id).show();
        $(this).find('a').blur();
        return false;
    });

    $(".ProductList1 li").click(function(e){
        //pkg:conflict is fixed
        if(!($(e.target).is('a')))
        {
            window.location.href = $('.title a', this).attr('href');
        }
    });

    if($('.wineRatingWrap').length){
        $('.wineRatingWrap').each(function() {
            $(this).find(".wineRatingInfo a").hover(
                function() {
                    $(this).parent().parent().find(".wineRatingInfo ."+ themeLang).css('display','block');
                },
                function() {
                    $(this).parent().parent().find(".wineRatingInfo ."+ themeLang).css('display','none');
                }
                );
        });
    }

    if($('p.thumb > a').length)
    {
        $('p.thumb > a').lightBox({
            imageLoading:'/javascript/jquery/plugins/lightbox/images/lightbox-ico-loading.gif',
            imageBtnClose:'/javascript/jquery/plugins/lightbox/images/lightbox-btn-close.gif',
            overlayBgColor:'#f7f3dd'
        });
    }
    $(".fetch-shipping-button").live('click', function(event) {
        code = $(this).attr('class').replace('fetch-shipping-button','');
        code = $.trim(code);
        
        $(this)
        .parents('.AccountOrderStatusItem')
        .find('.fetch-shipping-container')
        .load('remote.php?w=fetchShippingStatus&id='+code);
        /*
        $.get('remote.php?w=fetchShippingStatus&id='+code, function(data) {
            console.log(data);
        });
        */
        event.preventDefault();
    });

    
});
var config = {
    ShopPath : '%%GLOBAL_ShopPath%%', 
    AppPath : '%%GLOBAL_AppPath%%'
};

/*
$(window).error(function(errorMeaage, fileName, lineNumber){
console.log(errorMeaage+'::'+fileName+'::'+lineNumber);
});
*/
//Siva:Master Error handler. Emails Error from production.
window.onerror = function(desc,page,line,chr){
    var jserrorMsg = 'IwineError: JavaScript error occurred! \n'
    +'\nErrorDesc: \t'+desc+"\n"
    +'\nPageAddr: \t'+page+"\n"
    +'\nLine: \t'+line+"\n"
    +'\nChar: \t'+chr+"\n";
    var brwData="";
    brwData += "--> BCodeName:[" + navigator.appCodeName + "]"+"\n";
    brwData += "BrowName:[" + navigator.appName + "]"+"\n";
    brwData += "BrowVer:[" + navigator.appVersion + "]"+"\n";
    brwData += "CookiesEnabled:[" + navigator.cookieEnabled + "]"+"\n";
    brwData += "Platform:[" + navigator.platform + "]"+"\n";
    brwData += "User-agentHeader:[" + navigator.userAgent + "]"+"\n";

    return true;
}

function zipButton()
{
    $(".iw_prefecture").attr('size','1');

    var themeLang   =($('body').is('#_en'))?'en':'jp';
    var zipButton   = '住所の検索';

    if(themeLang != "jp"){
        zipButton = 'Search Address';
    }


    $(".iw_zipcode").each(function(index){
        var p = $(this).parent();
        if(p.find('.zipBtn').length == 0)
        {
            var zipBtn = $('<input/>').attr({
                type:'button',
                'class':'zipBtn',
                value: zipButton
            });
            p.append(zipBtn);
        }
    });

    $("dd").delegate(".zipBtn", "click", function(event){
        var parent = $(this).parent();
        var parentForm = $(this).parents('form');
        var zipcode = parent.find('.iw_zipcode').val();
        //console.log(zipcode);
        $.post(
            "/zipcode.php",
            {
                zip: zipcode,
                lang:themeLang
            },
            function (data){
                if(data.status)
                {
                    parentForm.find('.iw_prefecture').val(data.prefecture)
                    parentForm.find('.iw_suburb').val(data.city)
                    parentForm.find('.iw_addr1').val(data.addr)
                }
                else{
            //alert("error");
            //console.log("error");
            }
            },"json");

        //event.stopPropagation();
        //event.preventDefault();
        return;
    });
}
/*
 * auther : Pramendra Gupta 
 * side navigation 
 * show children branch if exits else root item
 */
$(document).ready(function() {

    if($(".parent-node .active .children").length > 0)
    $('.parent-node .active .children').each(function(index) {
        
        $(this).parent().siblings().hide();
        
    });

});
