var LastOpenSubmenu = "";
function DataLangLoaded(data){
  

    
    jQuery('#text_langWarning').html(data['text']);
    jQuery('#cancel_Rem_action').html(data['linkCancel']);
    jQuery('#OK_Rem_action').html(data['linkOK']);
    jQuery('#warningLabel').html(data['warningLabel']);
    jQuery('#lng').val(data['lng']);
   
    
}

function showWarningLangBox(id){
  
    DataUrl = '/ajax/common/loadLangData.php';
    jQuery('body').append(' <div id="lang_info_dialog" class="lang_pop_up" style="display: none"></div>');
    jQuery('#lang_info_dialog').html('<div id="pop_up_container" style="color: #808080" align="center"><br/><img src="/images/icons/yellow_alert.gif"    /><div id="warningLabel" style="color:#000;font-size:18px;">Warning</div><div id="text_langWarning">Sorry,not possible to change your region while completing a purchase. Select OK to complete your purchase or CANCEL to change your region and go back to the shop.</div><div class="btn_Rem"><a href="#" id="OK_Rem_action">OK</a></div> <div class="btn_Rem"><a href="/index.php?lng='+id+'" id="cancel_Rem_action">Cancel</a></div></div>');
    jQuery('html, body').animate({
        scrollTop:0
    }, 'slow', function(){
        jQuery('#lang_info_dialog').fadeIn();
    });
    
    jQuery('#OK_Rem_action').click(function(){
        jQuery('#lang_info_dialog').fadeOut();
    });
    //Load data
    jQuery.post(DataUrl,null,DataLangLoaded,"json");
    
}


function changeLang(id){
    var currentURL = window.location.toString();
    var newURL = '';

    //Remove ending anchors
    currentURL = currentURL.replace(/#.*$/,'');

    if(currentURL.match(/\/index\.php/))
        if(currentURL.match(/(?:\?|\&)lng=[\-a-z]{2,5}(?:\&|$)/))
            newURL = currentURL.replace(/lng=[\-a-z]{2,5}/i,'lng='+id);
        else if(currentURL.match(/index\.php\?.*=/))
            newURL = currentURL+'&lng='+id;
        else
            newURL = currentURL+'?lng='+id;
    else
        newURL = 'index.php?lng='+id;
    if(!currentURL.match(/\/index\.php/) && currentURL.match(/-[a-z]{2,5}$/))
        newURL   = currentURL.replace(/-[a-z\-]{2,5}/,"-"+id );
    else
    if(currentURL.match(/\/products\/terr/) || currentURL.match(/\/products\/aero/))
        newURL   = currentURL+'-'+id;
    document.location = newURL;
    
}

function topMenuOver(id){
    if(LastOpenSubmenu!=''){
        document.getElementById(LastOpenSubmenu).style.display = 'none';
    }
    if(id!="-1"){
        submenu = document.getElementById(id);
        submenu.style.display = 'block';
        LastOpenSubmenu = id;
    }
}

function NewWindow(mypage, myname, w, h) {
    var winl = (screen.width - w  ) / 2;
    var wint = (screen.height - h - 60 ) / 2;
    winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',location=no,scrollbars=no,status=no';
    win = window.open(mypage, myname, winprops)
    if (parseInt(navigator.appVersion) >= 4) {
        win.window.focus();
    }
}

function showPromoPopup(){
    if (! window.focus)return true;
    var href;
    var windowname = 'Motorshow';
    href= "motorshow.html";
    window.open(href, windowname, 'width=260,height=445,scrollbars=no');
    return false;
}

function updateOrderStatus(url,msg){
    var r=confirm(msg);
    if (r==true)
        window.location.replace(url);

}

