    //url for GA tracking
    var track_addtocart_url     = "/addcart";
    var track_addtocartpopup_url= "/addtocart_popup";
    var track_invoice_validate  = "/checkout/validate_invoice";
    var track_checkout_submit   = "/checkout/submit";
    var miniBasketTimeout;
    var run_scroll = false;
    var tab_referer = 1;
    var email_addr  = "";

    function getId(str){
            var str = str.split("_");

            return str[1].toUpperCase();
    }

    function dimScreenCheckout(div_id, opac){
        var wW = $(window).width();
        var wH = $(document).height();

        if(div_id != "" && $("#"+div_id)){
            wH = Math.max($(document).height(),pY+$("#"+div_id).height());
        }

        if(opac == "")opac = "0.7";

        if(!$("#dim-bg").is(":visible")){
            $('body').prepend("<div id='dim-bg'></div>");
            $('#dim-bg').css({display:'block',opacity: opac, 'width':wW+'px','height':wH+'px'});
        }
    }

    function dimScreen(div_id, opac){
        var wW = $(window).width();
        var wH = $(document).height();

        if(div_id != "" && $("#"+div_id)){
            wH = Math.max($(document).height(),pY+$("#"+div_id).height());
        }

        if(opac== "")opac = "0.7";

        if(!$("#dim-bg").is(":visible")){
            $('body').prepend("<div id='dim-bg'></div>");
            $('#dim-bg').css({display:'block',opacity: opac, 'width':wW+'px','height':wH+'px','position':'absolute','z-index':9998,'background':'#000'});
            $("#dim-bg").click(function(){
                hideMiniBasket();
            })
        }
    }

    function removeDim(){

        if($("#cvc_popup") && $("#cvc_popup").is(":visible")){
            $("#cvc_popup").slideUp();
        }

        if($("#what_is_this_cardtype") && $("#what_is_this_cardtype").is(":visible")){
            $("#what_is_this_cardtype").slideUp();
        }

        if($("#newsletter_what_popup") && $("#newsletter_what_popup").is(":visible")){
            $("#newsletter_what_popup").slideUp();
        }

        $("#dim-bg").fadeOut("fast", function(){
            $("#dim-bg").remove();
        });

    }

    function backToTop() {
        var x1 = x2 = x3 = 0;
        var y1 = y2 = y3 = 0;

        if (document.documentElement) {
            x1 = document.documentElement.scrollLeft || 0;
            y1 = document.documentElement.scrollTop || 0;
        }

        if (document.body) {
            x2 = document.body.scrollLeft || 0;
            y2 = document.body.scrollTop || 0;
        }

        x3 = window.scrollX || 0;
        y3 = window.scrollY || 0;

        var x = Math.max(x1, Math.max(x2, x3));
        var y = Math.max(y1, Math.max(y2, y3));

        window.scrollTo(Math.floor(x / 2), Math.floor(y / 2));

        if (x > 0 || y > 0) {
            window.setTimeout("backToTop()", 25);
        }
    }


    function removeItemMini(input_id){
        item_id = getId(input_id);

        updateItemActionP(item_id, 0, "addTo");

    }

    function updateItemMini(input_id){ 
        item_id = getId(input_id);
        quantity = $("#inputmini_"+item_id).val();

        updateItemActionP(item_id, quantity, "addTo");

    }

    function updateMainBasket(){ // use if change quantity in mini basket @ basket page - temp
        var url = site_url + "basket/basket_ajax";

           $.ajax({
            type:"POST",
            url:url,
            dataType:"text",
            success: function(html){
                $("#basket_content").html(html)
            }
        })
    }

    function addItemToBasketAll(input_id, quantity){ 
        item_id = getId(input_id);

        updateItemActionP(item_id, quantity, "addMore");

    }

    function update_minisum(){
        total_item = $("#total_item_p").val();
        total_price = $("#total_price_p").val();
        $("#header_items").html(total_item);
        $("#header_price").html(total_price);
    }
    function showMiniBasket(autohide){

        dimScreen("", 0.7);
        $("#mini_basket").slideDown("slow");

        if(autohide == true){
            miniBasketTimeout=setTimeout(hideMiniBasket,10000);

            $("#mini_basket").bind("mouseenter",function(){
                clearTimeout(miniBasketTimeout);
            }).bind("mouseleave",function(){
                miniBasketTimeout=setTimeout(hideMiniBasket,10000);
            });
        }

    }

    function hideMiniBasket(){

        clearTimeout(miniBasketTimeout);

        removeDim();

        $("#mini_basket").slideUp("fast");

        if(miniBasketTimeout){
            clearTimeout(miniBasketTimeout);
        }
    }

    function updateItemActionP(item_id, quantity, action){ 
        var url = site_url + "basket/add_from_product"+"/"+item_id + "/" + quantity + "/" + action;
        var total_item = 0;
        var total_price = 0;
        var mini_basket_sum = "";
        //var item = msg_item;//tungnt comment
           $.ajax({
            type:"POST",
            url:url,
            dataType:"text",
            success: function(html){
                $("#mini_basket").html(html);
                bind_event_update_minibasket();
                update_minisum();
                if(total_item > 1)item = msg_items;
                if($("#basket_content").length > 0){
                    updateMainBasket();
                }
            }
        })
    }

    function show_popup(title,text,popupY){
    	if($("#popup-box").css('display') != 'none') return false;
        if($("#c_subject")){
            $("#c_subject").hide();
        }
        $('html, body').animate({scrollTop:0}, 'fast');//scroll to top
        var wW = $(window).width();
        var wH = $(window).height();
        var pW = $("#newsletter-box").width();        //Width of the popup
        var pX = (wW-pW)/2;    //X coodinate of the popup
        var pY = 117;

        //var pY = ((popupY!=null)&&(parseInt(popupY)+''!='NaN'))?parseInt(popupY):250;    //Y coodinate of the popup
        var wH = Math.max($(document).height(),pY+$("#popup-box").height());



        $("#popup-title").html(title);
        $("#popup-text").html(text);
        $('body').prepend("<div id='popup-bg'></div>");
        $('#popup-bg').css({display:'block',opacity: 0.7, 'width':wW+'px','height':wH+'px'});
        //$("#popup-box").css({display:'block',top:pY+'px',left:pX+'px',width:pW+'px'});
        $("#popup-box").css({display:'block'});
        set_popup_at_center("#popup-box",9999);
        $("#close-link, #close-image, #popup-bg").click(function(){
            hide_popup();
        })
    }

    function hide_popup() {
        if($("#c_subject")){
            $("#c_subject").show();
        }

        $("#popup-box").css('display','none');
        $("#popup-bg").css('display','none');
        $("#popup-bg").remove();
    }

    /*
    Set an element HTML at the center of the screen
    Params: string of class or id; OR an jquery object of element
    */
    function set_popup_at_center(elementPopup, zindex){
        var wW = $(window).width();
        var wH = $(window).height();
        var pW = $(elementPopup).width();
        var pH = $(elementPopup).height();
        var pX = (pW >= wW) ? 0 : (wW-pW)/2;    //X coodinate of the popup
        var pY = (pH >= wH) ? 0 : (wH-pH)/2;    //Y coodinate of the popup
        $(elementPopup).css({'left':pX,'top':pY,'z-index':zindex});
    }

    function format_price(price,currency){
        html = '';
        price = isNaN(price) ? 0 : price;
        currency_decimal_point = (typeof currency.currency_decimal_point != 'undefined') ? currency.currency_decimal_point : 0;
        currency_sign_before = (typeof currency.currency_sign_before != 'undefined' && currency.currency_sign_before !='') ? currency.currency_sign_before+'&nbsp;' : '';
        currency_sign_after = (typeof currency.currency_sign_after != 'undefined' && currency.currency_sign_after !='') ? '&nbsp;'+currency.currency_sign_after : '';
        currency_float_point = typeof currency.currency_float_point != 'undefined' ? currency.currency_float_point : '';
        new_price = number_format(price, currency_decimal_point);
        int_part = Math.floor(new_price);
        float_part = number_format(new_price - int_part,currency_decimal_point);
        float_part = float_part.substring(2);
        float_part = float_part.length>0 ? '<sup>'+float_part+'</sup>' : '';
        new_value = currency_sign_before + int_part + currency_float_point + float_part + currency_sign_after;
        return new_value;
    }

    function price_helper(price,sale_price,is_active,currency,sale_price_tag,sale_price_class,price_tag,price_class){
        html = '';
        if(is_active == 1 && sale_price >= 0){
            html += '<' + price_tag + ' class="'+price_class+'">';
            html += currency.currency_sign_before != '' ? currency.currency_sign_before + '&nbsp;' : '';
            html += get_currency_format(price,currency);
            html += '</' + price_tag + '>';
            html += '<' + sale_price_tag + ' class="'+sale_price_class+'">';
            html += get_currency_format(sale_price,currency);
            html += currency.currency_sign_after != '' ? '&nbsp;' + currency.currency_sign_after : '';
            html += '</'+ sale_price_tag + '>';
        } else {
            html += '<' + price_tag + '>';
            html += currency.currency_sign_before != '' ? currency.currency_sign_before + '&nbsp;' : '';
            html += get_currency_format(price,currency);
            html += currency.currency_sign_after != '' ? '&nbsp;' + currency.currency_sign_after : '';
            html += '</' + price_tag + '>';
        }
        return html;
    }
     function format_price_only(price,currency){
        html = '';
        price = isNaN(price) ? 0 : price;
        currency_decimal_point = (typeof currency.currency_decimal_point != 'undefined') ? currency.currency_decimal_point : 0;
        currency_sign_before = (typeof currency.currency_sign_before != 'undefined' && currency.currency_sign_before !='') ? currency.currency_sign_before+'&nbsp;' : '';
        currency_sign_after = (typeof currency.currency_sign_after != 'undefined' && currency.currency_sign_after !='') ? '&nbsp;'+currency.currency_sign_after : '';
        //currency_float_point = typeof currency.currency_float_point != 'undefined' ? currency.currency_float_point : '';
        new_price = number_format(price, currency_decimal_point);
        int_part = Math.floor(new_price);
        float_part = number_format(new_price - int_part,currency_decimal_point);
        float_part = float_part.substring(2);
		float_part = float_part.length>0 ? '.'+float_part+'' : '';
        //float_part = float_part.length>0 ? '<sup>'+float_part+'</sup>' : '';
        return int_part + float_part;
    }

    function price_helper_only(price,sale_price,is_active,currency,sale_price_tag,sale_price_class,price_tag,price_class){
        html = '';
        if(is_active == 1 && sale_price > 0){
			html += '<' + sale_price_tag + ' class="'+sale_price_class+'">';
			html += currency.currency_sign_before != '' ? currency.currency_sign_before + '&nbsp;' : '';
            html += format_price_only(sale_price,currency);
            html += currency.currency_sign_after != '' ? '&nbsp;' + currency.currency_sign_after : '';
            html += '</'+ sale_price_tag + '>';
			html +='<br>';
            html += '<' + price_tag + ' class="'+price_class+'">';
            html += format_price_only(price,currency);
            html += '</' + price_tag + '>';
        } else {
            html += '<' + price_tag + '>';
            html += currency.currency_sign_before != '' ? currency.currency_sign_before + '&nbsp;' : '';
            html += format_price_only(price,currency);
            html += currency.currency_sign_after != '' ? '&nbsp;' + currency.currency_sign_after : '';
            html += '</' + price_tag + '>';
        }
        return html;
    }

    function get_currency_format(amount,obj_currency){
        currency_sign_before = obj_currency.currency_sign_before;
        currency_sign_after = obj_currency.currency_sign_after;
        currency_decimal_point = obj_currency.currency_decimal_point;
        formated_price = '';
        //formated_price = currency_sign_before;
        //formated_price += (currency_sign_before != '') ? " " : "";
        formated_price +=  number_format(amount,currency_decimal_point);
        //formated_price +=  (currency_sign_after != '') ? " " : "";
        //formated_price +=  currency_sign_after;
        return formated_price;

    }

function number_format (number, decimals, dec_point, thousands_sep) {
    // Formats a number with grouped thousands
    //
    // version: 906.1806
    // discuss at: http://phpjs.org/functions/number_format    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +     bugfix by: Michael White (http://getsprink.com)
    // +     bugfix by: Benjamin Lupton
    // +     bugfix by: Allan Jensen (http://www.winternet.no)    // +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +     bugfix by: Howard Yeend
    // +    revised by: Luke Smith (http://lucassmith.name)
    // +     bugfix by: Diogo Resende
    // +     bugfix by: Rival    // +     input by: Kheang Hok Chin (http://www.distantia.ca/)
    // +     improved by: davook
    // +     improved by: Brett Zamir (http://brett-zamir.me)
    // +     input by: Jay Klehr
    // +     improved by: Brett Zamir (http://brett-zamir.me)    // +     input by: Amir Habibi (http://www.residence-mixte.com/)
    // +     bugfix by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: number_format(1234.56);
    // *     returns 1: '1,235'
    // *     example 2: number_format(1234.56, 2, ',', ' ');    // *     returns 2: '1 234,56'
    // *     example 3: number_format(1234.5678, 2, '.', '');
    // *     returns 3: '1234.57'
    // *     example 4: number_format(67, 2, ',', '.');
    // *     returns 4: '67,00'    // *     example 5: number_format(1000);
    // *     returns 5: '1,000'
    // *     example 6: number_format(67.311, 2);
    // *     returns 6: '67.31'
    // *     example 7: number_format(1000.55, 1);    // *     returns 7: '1,000.6'
    // *     example 8: number_format(67000, 5, ',', '.');
    // *     returns 8: '67.000,00000'
    // *     example 9: number_format(0.9, 0);
    // *     returns 9: '1'    // *     example 10: number_format('1.20', 2);
    // *     returns 10: '1.20'
    // *     example 11: number_format('1.20', 4);
    // *     returns 11: '1.2000'
    // *     example 12: number_format('1.2000', 3);    // *     returns 12: '1.200'
    var n = number, prec = decimals;

    var toFixedFix = function (n,prec) {
        var k = Math.pow(10,prec);        return (Math.round(n*k)/k).toString();
    };

    n = !isFinite(+n) ? 0 : +n;
    prec = !isFinite(+prec) ? 0 : Math.abs(prec);    var sep = (typeof thousands_sep === 'undefined') ? ',' : thousands_sep;
    var dec = (typeof dec_point === 'undefined') ? '.' : dec_point;

    var s = (prec > 0) ? toFixedFix(n, prec) : toFixedFix(Math.round(n), prec); //fix for IE parseFloat(0.55).toFixed(0) = 0;
     var abs = toFixedFix(Math.abs(n), prec);
    var _, i;

    if (abs >= 1000) {
        _ = abs.split(/\D/);        i = _[0].length % 3 || 3;

        _[0] = s.slice(0,i + (n < 0)) +
              _[0].slice(i).replace(/(\d{3})/g, sep+'$1');
        s = _.join(dec);    } else {
        s = s.replace('.', dec);
    }

    var decPos = s.indexOf(dec);    if (prec >= 1 && decPos !== -1 && (s.length-decPos-1) < prec) {
        s += new Array(prec-(s.length-decPos-1)).join(0)+'0';
    }
    else if (prec >= 1 && decPos === -1) {
        s += dec+new Array(prec).join(0)+'0';    }
    return s;
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

function ucfirst(str) {
	str += '';
    var f = str.charAt(0).toUpperCase();
    return f + str.substr(1).toLowerCase();
}


     function niclub(showhide){
        if(showhide == 0){
            $("#niclub_member").hide();
            $("#newsletter-box").removeClass("signup-club");
            $("#ni_newsletter_header").html(ni_newsletter_header);
        } else {
            $("#niclub_member").show();
            $("#newsletter-box").addClass("signup-club");
            $("#ni_newsletter_header").html(ni_newsletter_header_cp);
        }
     }
     
    function show_newsletter_ni(campaign){
        if(campaign != 1)campaign = 0;
        niclub(campaign);
        
    	if($("#newsletter-box").css('display') != 'none') return false;
        var wW = $(window).width();
        var wH = $(window).height();
        var pW = $("#newsletter-box").width();
        var pY = 117;        //Y coodinate of the popup
        var pX = (wW-pW)/2;    //X coodinate of the popup


        //var pY = ((popupY!=null)&&(parseInt(popupY)+''!='NaN'))?parseInt(popupY):250;    //Y coodinate of the popup
        var wH = Math.max($(document).height(),pY+$("#newsletter-box").height());

        $('body').prepend("<div id='newsletter-bg' class='close-newsletter'></div>");
        $('#newsletter-bg').css({display:'block',opacity: 0.7, 'width':wW+'px','height':wH+'px'});
        $("#newsletter-box").css({display:'block',top:pY+'px',left:pX+'px'});
        $("#strFirstName").val('');
        $("#strLastName").val('');
        $("#strCity").val('');
        $("#strZip").val('');
        $("#bornday").val('');
        $("#bornmonth").val('');
        $("#bornyear").val('');
        $("#radio_m").removeAttr('checked');
        $("#radio_f").attr('checked','checked');
        if(!$('#newsletter-box form').hasClass('jNice')) $('#newsletter-box form').addClass('jNice');
        $('#newsletter-box form').jNice();

        $(".close-newsletter").click(function(){
            hide_newsletter();
        })
    }     

    function show_newsletter(){ 
    	if($("#newsletter-box").css('display') != 'none') return false;
        var wW = $(window).width();
        var wH = $(window).height();
        var pW = $("#newsletter-box").width();
        var pY = 117;        //Y coodinate of the popup
        var pX = (wW-pW)/2;    //X coodinate of the popup


        //var pY = ((popupY!=null)&&(parseInt(popupY)+''!='NaN'))?parseInt(popupY):250;    //Y coodinate of the popup
        var wH = Math.max($(document).height(),pY+$("#newsletter-box").height());

        $('body').prepend("<div id='newsletter-bg' class='close-newsletter'></div>");
        $('#newsletter-bg').css({display:'block',opacity: 0.7, 'width':wW+'px','height':wH+'px'});
        $("#newsletter-box").css({display:'block',top:pY+'px',left:pX+'px'});
        $("#strFirstName").val('');
        $("#strLastName").val('');
        $("#strCity").val('');
        $("#strZip").val('');
        $("#bornday").val('');
        $("#bornmonth").val('');
        $("#bornyear").val('');
        $("#radio_m").removeAttr('checked');
        $("#radio_f").attr('checked','checked');
        if(!$('#newsletter-box form').hasClass('jNice')) $('#newsletter-box form').addClass('jNice');
        $('#newsletter-box form').jNice();
        
        $("#strEmail").val(email_addr);

        $(".close-newsletter").click(function(){
            hide_newsletter();
        })
    }

    function hide_newsletter() {
        $("#newsletter-box").css('display','none');
        $("#newsletter-bg").css('display','none');
        $("#newsletter-bg").remove();
        if($('#newsletter-box form').hasClass('jNice')) $('#newsletter-box form').removeClass('jNice');
        $("#nMsg").html('');
    }
    
    function show_support_browser_popup(){
        if($("#browser-box").css('display') != 'none') return false;
        $('html, body').animate({scrollTop:0}, 'fast');//scroll to top
        var wW = $(window).width();
        var wH = $(window).height();
        var pW = $("#browser-box").width();
        var pY = -50;        //Y coodinate of the popup
        var pX = (wW-pW)/2;    //X coodinate of the popup
        
        //var pY = ((popupY!=null)&&(parseInt(popupY)+''!='NaN'))?parseInt(popupY):250;    //Y coodinate of the popup
        var wH = Math.max($(document).height(),pY+$("#browser-box").height());
        
        $('body').prepend("<div id='browser-bg' class='close-browser'></div>");
        $('#browser-bg').css({display:'block',opacity: 0.7, 'width':wW+'px','height':wH+'px'});
        $("#browser-box").css({display:'block',top:pY+'px',left:pX+'px'});
        $(".close-browser").click(function(){
            hide_support_browser_popup();
        })
    }
    
    function hide_support_browser_popup() {
        $("#browser-box").css('display','none');
        $("#browser-bg").css('display','none');
        $("#browser-bg").remove();
    } 
    
    function allow_only_integer_numbers(event) {
        var keyEntry = ( event.which ) ? event.which : event.keyCode;
        return (keyEntry <= 31 || (keyEntry >= 48 && keyEntry <= 57));
    }
    
    function allow_only_alphabets(event){
        var keyEntry = ( event.which ) ? event.which : event.keyCode;
        
        // allow control keys
        if ((keyEntry==null) || (keyEntry==0) || (keyEntry==8) || (keyEntry==9) || (keyEntry==13) || (keyEntry==27) ){
            return true;
        }

        return (((keyEntry >= 65) && (keyEntry <= 90)) || ((keyEntry >= 97) && (keyEntry <= 122)) || (keyEntry==46) || (keyEntry==32) || (keyEntry==45) );
    }
    
    function allow_alphabets_and_number(event){
        var keyEntry = ( event.which ) ? event.which : event.keyCode;
        return ( (((keyEntry >= 65) && (keyEntry <= 90)) || ((keyEntry >= 97) && (keyEntry <= 122)) || (keyEntry==46) || (keyEntry==32) || (keyEntry==45)) || (keyEntry <= 31 || (keyEntry >= 48 && keyEntry <= 57)) );
    }    
    
    function ban_numbers(event) {
        var keyEntry = ( event.which ) ? event.which : event.keyCode;
           
        // ban numbers
        if(keyEntry >= 48 && keyEntry <= 57){
            return false;
        }
        
        return true;
    }
    
    function ajx_popup(ajx_url, div_id, call_back){ 
        var url = site_url + ajx_url;
        
        j_div_id = "#" + div_id;
        
        current_html = $(j_div_id).html().toString();
        if(trim(current_html) == ""){
           $.ajax({
            type:"POST",
            url:url,
            dataType:"text",
            success: function(html){ 
                $(j_div_id).html(html)
                    call_back();
                }
            })
        }else{
            call_back();
        }

    }
	
	function ajx_popup_ni(ajx_url, div_id, call_back){ 
        var url = site_url + ajx_url;
        
        j_div_id = "#" + div_id;
        
        current_html = $(j_div_id).html().toString();

           $.ajax({
            type:"POST",
            url:url,
            dataType:"text",
            success: function(html){ 
                $(j_div_id).html(html)
                    call_back();
                }
            })
    

    }

    
function load_header(){
    
	// all ordered images
	$(".load-images").each(function(index,el){
        real_img_src = $(this).attr("src_to_load");
        $(this).attr('src', real_img_src);
	});

}

function clickShowNewsletter(){
    email = $.trim($("#newsletter-email").val());
    if(!validEmail_home(email)){
        show_popup(msg_error,gettext.email_invalid);
    } else {
        email_addr = email;
        $("#strEmail").val(email);
        scroll(0,0);
        ajx_popup_ni("popup/newsletter", "newsletter-box", show_newsletter);
    }
    return false;    
}
function clickShowNewsletterNi(){
    email = $.trim($("#newsletter-email").val());
	if(validEmail_home(email)){
		email_addr = email;
        $("#strEmail").val(email);
	}
    scroll(0,0);
    ajx_popup_ni("popup/newsletter/1", "newsletter-box", show_newsletter);

    return false;    
}
function clickShowNewsletterCompetition(){
    email = $.trim($("#newsletter-email").val());
	if(validEmail_home(email)){
		email_addr = email;
        $("#strEmail").val(email);
	}
    scroll(0,0);
    ajx_popup_ni("popup/newsletter/2", "newsletter-box", show_newsletter);

    return false;    
}
function clickNewsletterEmailFooter(){ 
    email = $.trim($("#newsletter-email-footer").val());
    if(!validEmail_home(email)){
        show_popup(msg_error,gettext.email_invalid);
    } else {
        $("#strEmail").val(email);
        scroll(0,0);
        ajx_popup("popup/newsletter", "newsletter-box", show_newsletter);
    }
    return false;    
}

//move from checkout.js
function submitContactForm(){
    var your_name         = $.trim($("#your-name").val());
    var your_email         = $.trim($("#your-email").val());
    var subject         = $.trim($("#select1").val());
    var order_number     = $.trim($("#order-number").val());
    var your_question     = $.trim($("#your-question").val());

    var email_pattern = /^[a-zA-Z]+([+_.-]?[a-zA-Z0-9]+)*@[a-zA-Z0-9]+([.-]?[a-zA-Z0-9]+)*\.[a-zA-Z]{2,4}$/;
    var error_message = [];

    if(your_name=='') {
        error_message.push(gettext.yourName);
    }

    if(subject=='') {
        error_message.push(gettext.questionRegarding);
    }

    if(!email_pattern.test(your_email)) {
        error_message.push(gettext.yourEmail);
    }

    if(order_number=='') {
        error_message.push(gettext.headLine);
    }

    if(your_question=='') {
        error_message.push(gettext.yourQuestion);
    }

    if(error_message.length > 0) {
        msg = gettext.followingFieldValid + ': ' + error_message.join(', ') + '\n' + gettext.checkAgain;
        show_popup(msg_error,msg);
        return false;
    } else {
        $("#contact-us-response").html(gettext.sendingEmail);
        $("#do-contact-us").attr('disabled','true');
    }

    $.ajax({
        type: "POST",
        url: site_url + "home/contact_us/",
        dataType: "text",
        data: {
            your_name        :your_name,
            your_email        :your_email,
            subject            :subject,
            order_number    :order_number,
            your_question    :your_question
        },
        success: function(html){
            $("#contact-us-response").html(html);
        }
});
}


$(window).load(function() {

    load_header();
});

$(document).ready(function(){
    try{
        Cufon.replace('.brand-menu');
    }catch(e){}
    
    try{
        $("#accordion").accordion({
            autoHeight: false
        });
    }catch(e){}
        
    try{
        //menu
        $("a.drop-mn, div.drop-menu").mouseover(function(){
            $(this).parent().children('a').addClass('currt');
            $(this).parent().children('div').show();
        });
        $("a.drop-mn, div.drop-menu").mouseout(function(){
            $(this).parent().children('a').removeClass('currt');
            $(this).parent().children('div').hide();
        });

        $(".drop-menu").mouseover(function(){
            $(this).show();
        });
        $(".drop-menu").mouseout(function(){
            $(this).hide();
        });

        $('.hover-tips-link').hover(function(e) {
            //set mouse position
            Mouse_X = e.pageX;
            Mouse_Y = e.pageY;
                    
            $('.tool-tip').css({display:'block',position:'absolute',top:Mouse_Y - 60,left:Mouse_X - 20,'z-index':9999});
        });    
        
        $('.hover-tips-link').mousemove(function(e){
            Mouse_X = e.pageX;
            Mouse_Y = e.pageY;
            $('.tool-tip').css({top:Mouse_Y - 125,left:Mouse_X - 20});
        });
        
        $('.hover-tips-link').mouseout(function(e) {                
            $('.tool-tip').css({display:'none'});
        }); 
        
        $('.show-newsletter-popup').click(function(){
            ajx_popup('popup/newsletter', 'newsletter-box', show_newsletter);
        });

        //copy from footer
        //Load data before show
        $("#show-newsletter").click(clickShowNewsletter);
        $(".campaign-popup").click(clickShowNewsletterNi);
        $(".compe-link1").click(clickShowNewsletterCompetition);
        $("#show-newsletter-footer").click(clickNewsletterEmailFooter);
        //$("#newsletter-submit").click(subscribe);
        
    	$('#newsletter-email, #newsletter-email2, #si_email_address, #newsletter-email-footer').each(function(){
            $(this).keypress(function(e) {
                if(!e) e = window.event;
                key_code = (e.keyCode ? e.keyCode : e.which);
                if(key_code == 13) { 
                    email_addr = $.trim($(this).val());
    				//if (email_addr != ''){
    					if(!validEmail_home(email_addr)){
    						show_popup(msg_error,msg_email_invalid);
    					} else {
    						scroll(0,0);
                            ajx_popup("popup/newsletter", "newsletter-box", show_newsletter);
                            $("#strEmail").val(email_addr);
    					}
    				//}
                    return false;            
                }                
            })
        })        
        
    }catch(e){}
    
    
    if(disable_basket != 1){
        $(".remove-basket-mini").live("click", function(){
            $("#"+this.id).html(gettext.processing);                    
            removeItemMini(this.id);
        })
    } else {
            $(".remove-basket-mini").each(function(){
                    $("#"+this.id).html("");
            })            
    }

    //copy from mini-list
    $("#close-mini").click(function(){
        hideMiniBasket();
    })
    $("#close-mini2").click(function(){
        hideMiniBasket();
    });


    //menu
    $("#header_banner .ad_block").mouseover(function(){
        $(this).stop().animate({height:'119px'},{queue:false, duration:700, easing: 'jswing'})
    });
    
     $("#header_banner .ad_block").mouseout(function(){
        $(this).stop().animate({height:'0px'},{queue:false, duration:700, easing: 'jswing'})
    });
    
    $(".brand_logo").click(function(){
        $(this).blur();
    });
    
    function brand_logo_mouse_on(){
        $(this).toggleClass('current');   
        block = '#'+$(this).attr('block');    
        $(block).stop().animate({height:'119px'},{queue:false, duration:700, easing: 'jswing'})
    }
    function brand_logo_mouse_out(){
        $(this).toggleClass('current');
        block = '#'+$(this).attr('block');
        $(block).stop().animate({height:'0px'},{queue:false, duration:700, easing: 'jswing'});
        
    }
    
    var config = {
        sensitivity : 1,        // number = sensitivity threshold (must be 1 or higher)    
        interval    : 150,      // number = milliseconds for onMouseOver polling interval    
        over        : brand_logo_mouse_on, // function = onMouseOver callback (REQUIRED)    
        timeout     : 0,      // number = milliseconds delay before onMouseOut    
        out         : brand_logo_mouse_out // function = onMouseOut callback (REQUIRED)    
     };
    $(".brand_logo").hoverDelay(config); 
    
    //moved from checkout.js
    $("#do-contact-us").click(submitContactForm);
    try{
        $("#do-contact-us, #your-name, #your-email, #my-dropdown, #order-number, #your-question").focus(function(){
            $("#contact-us-response").html('');
        });    
    }catch(e){};   
});