function putFlash(sPath, iWidth, iHeight, sID) {
    with (document) {
        write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="'+iWidth+'" height="'+iHeight+'" id="'+sID+'">');
        write('  <param name="movie" value="'+sPath+'" />');
        write('  <param name="quality" value="high" />');
        write('  <param name="wmode" value="transparent" />');
        write('  <param name="menu" value="false" />');
        write('  <embed src="'+sPath+'" quality="high" wmode="transparent" menu="false" width="'+iWidth+'" height="'+iHeight+'" swLiveConnect=true name="'+sID+'" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
        write('</object>');
    }
}


function checkCreditCard(obForm) {
    cardNumber = new String(obForm.elements['CreditCardNumber'].value)
    if (obForm.elements['payment_f'][0].checked == true) {
        switch (obForm.elements['CreditCardType'].value) {
            case "Visa" :
            if (cardNumber.substring(0, 1) != "4") {
                alert("The card number you entered is not a Visa.");
                return false;
            }
            break;
            case "MasterCard" :
            if (cardNumber.substring(0, 1) != "5") {
                alert("The card number you entered is not a Mastercard.");
                return false;
            }
            break;
            case "Amex" :
            if ((cardNumber.substring(0, 2) != "34") && (cardNumber.substring(0, 2) != "37")) {
                alert("The card number you entered is not an American Express.");
                return false;
            }
            break;
            case "Discover" :
            if ((cardNumber.substring(0, 2) != "30")&&(cardNumber.substring(0, 1) != "6")&&(cardNumber.substring(0, 2) != "36")&&(cardNumber.substring(0, 2) != "38")) {
                alert("The card number you entered is not a Discover.");
                return false;
            }
            break;
            default : break;
        }
    }
    return true;

}

function makeVisible(Eid) {
    if (Eid == "") Eid = 1;
    var zak = "z"+Eid;
    var li = "li"+Eid;
    var ilosc_elementow = 6; //ilosc elementow do fora..
    var i;

    // oznaczenie wszystkich zakladek jako nieaktywne
    for (i=1; i <= ilosc_elementow; i++) {
        document.getElementById('z'+i).className="box-h";
        document.getElementById('li'+i).className="";
    }

    // uaktywnienie wybranej zakladki
    document.getElementById(zak).className="box-v";
    document.getElementById(li).className="on";
}

// licznik do pol
function licznik(f, text_count, counter, ilosc) {
    var text_area = document.forms[f].elements[text_count];
    var count_inp = document.forms[f].elements[counter];
    var ta_val = text_area.value;
    var ta_len = ta_val.length;
    count_inp.value = (ilosc-ta_len);
    if (count_inp.value == -1) count_inp.value = 2;
    if(ta_len >= ilosc) {
        // alert("Przekroczono dozwoloną ilość: "+ilosc);
        text_area.value = ta_val.substring(0, ilosc);
    }
}

//ustawianie ceny w zaleznosci od cechy
//uwaga funkcja jeszcze nie liczy  cen z podwojnymi cechami
// UWAGA!!!  ceny netto nie licze, bo w cechach jest podawana cena brutto
//cene netto mozna podac przy fakturze
function setPrice(price) {
    //return "$"+makeGrosze(price);
    return formatCurrency(price);
}

function usuwanie_conf() {
    if (confirm("Are you sure, you want to delete this item?")) {
        return true;
    } else {
        return false;
    }
}
//dodawanie 00 do danej kwoty
function makeGrosze(price) {
    strNumber = "" + price;
    kwota = strNumber.split("\.");
    zlote = kwota[0];
    if (kwota[1] != undefined) {
        grosze = kwota[1];
        last = grosze.length;
        if (last == 1) grosze = grosze+"0";
    } else {
        grosze = "00";
        //grosze = "";
    }
    price = kwota[0] + "." + grosze;
    //price = kwota[0];

    return price;
}

//obliczanie ceny koszyka na stronie z koszykkiem
/**
wykorzystane id:
cechy_selects_{$towid} - lista cech
cbrutto_{$towid}
suma_{$towid}
koszyk id form koszyka
hiddeny:
cart_form[27][c_brutto_f]
cart_form[27][c_netto_f]
cart_form[27][vat_f]
cart_form[27][tid_f]
shipment_price[1]
shipment_price[2]
*/
function setPriceKoszyk(pid, prod_c_brutto, prod_c_netto, vat, rabat, ilosc) {
    var c_brutto = 0;
    var suma = 0;
    var selects = document.getElementById('cechy_selects_'+pid).getElementsByTagName('SELECT');
    //obsluga cen gift wrap
    var gift = de('gift_'+pid);
    var gift_price = 0;

    //alert(gift);
    if (gift != null) {
        if (gift.checked == true) gift_price = gift.value*1;
        else gift_price = 0;
    }


    cechy_ids = '';
    for (i=0; i < selects.length; i++) {
        cechy_ids += selects[i].value+'_';
    }
    //alert(cechy_ids);
    if (variation_cart[pid][cechy_ids] != undefined) {
        fname = document.forms["koszyk"];
        c_brutto_hid = fname.elements["cart_form["+pid+"][c_brutto_f]"];
        c_netto_hid = fname.elements["cart_form["+pid+"][c_netto_f]"]

        //vinf = variation_info_cart[pid][variation_cart[pid][cechy_ids]];
        vinf = variation_cart[pid][cechy_ids];


        if (vinf[2] == 'f') {
            alert("sorry this configuration is unavailable");
            prod_available = false;
        } else {
            /*
            if (vinf[1] != '') {
            de('bigfoto').src = dir_img+'/'+dir_prefix+vinf[1];
            } else {
            de('bigfoto').src = dir_img+'/'+dir_prefix+picture;
            }
            */
            if (vinf[0] != 0.00) {
                c_brutto = vinf[0];
                suma = Math.round(c_brutto*ilosc*100)/100;
            } else {
                suma = Math.round(prod_c_brutto*ilosc*100)/100;
                c_brutto = prod_c_brutto;
            }
            rabat = rabat.replace(",",".");
            if (rabat < 1) {
                rabat = 1-rabat;
                //prompt("sdsd", c_brutto*ilosc*rabat);
                suma = Math.round(c_brutto*ilosc*rabat*100)/100;
            }
            de('cbrutto_'+pid).innerHTML = setPrice(c_brutto);
            de('suma_'+pid).innerHTML = setPrice(suma+gift_price*ilosc);
            c_brutto_hid.value = c_brutto;
            c_netto_hid.value = Math.round(c_brutto/vat*100)/100;

            //alert(vinf[0]);
            prod_available = true;
        }
    }
}

function setGiftPrice(pid, gift_price, ilosc, sender) {
    var prod_suma_price = de('suma_'+pid).innerHTML;
    prod_suma_price = prod_suma_price.toString().replace(/\$|\,/g,'');
    if (sender.checked == true) {
        suma = prod_suma_price*1+(gift_price*ilosc);
    } else {
        suma = prod_suma_price*1-(gift_price*ilosc);
    }
    de('suma_'+pid).innerHTML = setPrice(suma);

}

//dostawa - do sumy dodawanie ceny dostawy
function setDostawaPrice(suma, cena) {
    cena_brutto = Math.round((suma+cena)*100)/100;
    if (isNaN(cena_brutto)) {
        cena_brutto = suma;
    }
    //document.dostawa.suma_all.value = cena_brutto;
    //formatCurrency(cena_brutto);
    document.getElementById('allsuma').innerHTML = setPrice(cena_brutto);
}

function formatCurrency(num) {
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num))
    num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10)
    cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
    num = num.substring(0,num.length-(4*i+3))+','+
    num.substring(num.length-(4*i+3));
    //return (((sign)?'':'-') + '$' + num + '.' + cents);
    //return '$'+ (((sign)?'':'-') + num + '.' + cents);
    //return '$'+ (((sign)?'':'-') + num + '.' + cents);
    return (((sign)?'':'-') + '$' + num + '.' + cents);
}

function lupka_foto(strona) {
    lupka(strona, 330, 330, 'no');
}

function lupka(plik_strony, w, h, przew) {
    if (!w) {w=500;}
    if (!h) {w=400;}
    if (!przew) {przew='yes';}

    if (window.screen){
        aw=screen.availWidth;
        ah=screen.availHeight;
    } else{
        aw=640;
        ah=450;
    }

    ustawienia=
    "left=" + (aw-w)/2 + ","
    +"top=" + (ah-h)/2 + ","
    +"screenX=" + (aw-w)/2 + ","
    +"screenY=" + (ah-h)/2 + ","
    +"width=" + w + ","
    +"height=" + h + ","
    +"innerWidth=" + w + ","
    +"innerHeight=" + h + ","
    +"toolbar=no,"
    +"location=no,"
    +"directories=no,"
    +"status=no,"
    +"menubar=no,"
    +"scrollbars=" +przew+ ","
    +"resizable=yes"
    self.window.name='glowne';
    noweOkienko = window.open(plik_strony,'noweOkienko',ustawienia);

    noweOkienko.document.close();
    noweOkienko.focus();
}

function winres() {
    var el=document.getElementById('obrazek');
    var ow=el.offsetWidth;
    var oh=el.offsetHeight;
    if (ow<100) ow=100;
    if (oh<100) oh=100;
    var mp=false;
    var mp1,mp2;
    var w,h,i;



    mp1=1;mp2=1;
    if (ow>screen.availWidth-30) {
        mp1=(screen.availWidth-30)/ow;
        mp=true;
    }
    if (oh>screen.availHeight-50) {
        mp2=(screen.availHeight-50)/oh;
        mp=true;
    }

    if (mp) {
        if (mp1>mp2) mp1=mp2;
        ow=Math.floor(mp1*ow);
        oh=Math.floor(mp1*oh);
        el.width=ow;
        el.height=oh;
    }
    for (i=0;i<3;i++) {
        if (window.innerWidth) {
            w=window.innerWidth;
            h=window.innerHeight;
        }
        else {
            w=document.body.clientWidth;
            h=document.body.clientHeight;
        }
        if (i <2) h-=20;
        window.resizeBy(ow-w,oh-h);
    }
    window.resizeTo(w+15, h+30);
    w=(screen.availWidth-ow)/2;
    h=(screen.availHeight-oh)/2;
    if (w<0) w=0;
    if (h<0) h=0;
    window.moveTo(w,h);
}

function hide_obj(name) {
    var agt=navigator.userAgent.toLowerCase();
    var is_ie5 = ((parseInt(navigator.appVersion) == 4) && (agt.indexOf("msie 5.0")!=-1) && (agt.indexOf("opera") == -1));

    if (document.getElementById && !is_ie5) {
        obj=document.getElementById(name).style.visibility = "hidden";
        document.getElementById(name).style.display = "none";
    } else if (document.layers) {
        obj=document.layers[name].visibility = "hide";
        document.layers[name].display = "none";
    } else if (document.all) {
        obj=document.all[name].style.visibility = "hidden";
        document.all[name].display = "none";
    } else {
        obj=false;
    }
    showSelects();
    Blink();
}

function show_obj(name) {
    var agt=navigator.userAgent.toLowerCase();
    var is_ie5 = ((parseInt(navigator.appVersion) == 4) && (agt.indexOf("msie 5.0")!=-1) && (agt.indexOf("opera") == -1));
    if (document.getElementById && !is_ie5) {
        obj=document.getElementById(name).style.visibility = "visible";
        document.getElementById(name).style.display = "inline";
    } else if (document.layers) {
        obj=document.layers[name].visibility = "show";
        document.layers[name].display = "inline";
    } else if (document.all) {
        obj=document.all[name].style.visibility = "visible";
        document.all[name].display = "inline";
    } else {
        obj=false;
    }
    hideSelects();
    Blink();
}
function hide_obj_clear(name) {
    var agt=navigator.userAgent.toLowerCase();
    var is_ie5 = ((parseInt(navigator.appVersion) == 4) && (agt.indexOf("msie 5.0")!=-1) && (agt.indexOf("opera") == -1));

    if (document.getElementById && !is_ie5) {
        obj=document.getElementById(name).style.visibility = "hidden";
        document.getElementById(name).style.display = "none";
    } else if (document.layers) {
        obj=document.layers[name].visibility = "hide";
        document.layers[name].display = "none";
    } else if (document.all) {
        obj=document.all[name].style.visibility = "hidden";
        document.all[name].display = "none";
    } else {
        obj=false;
    }
}

function show_obj_clear(name) {
    var agt=navigator.userAgent.toLowerCase();
    var is_ie5 = ((parseInt(navigator.appVersion) == 4) && (agt.indexOf("msie 5.0")!=-1) && (agt.indexOf("opera") == -1));
    if (document.getElementById && !is_ie5) {
        obj=document.getElementById(name).style.visibility = "visible";
        document.getElementById(name).style.display = "inline";
    } else if (document.layers) {
        obj=document.layers[name].visibility = "show";
        document.layers[name].display = "inline";
    } else if (document.all) {
        obj=document.all[name].style.visibility = "visible";
        document.all[name].display = "inline";
    } else {
        obj=false;
    }
}


function setPaymentMethod(sender_form, sender) {
    //credit card
    if (sender.value == 1) {
        show_obj_clear('cc_info');
        sender_form.action = '/paypal_dcc.php';
    } else {
        hide_obj_clear('cc_info');
        sender_form.action = '/paypal_ecc.php';
    }
}

function submitForm() {
    document.myForm.submit();
    //setTimeout('self.close();',100000);
}

// nowa opcja obrazkow
function reSizeToImage( ){
    var isNN, isIE;

    if ( parseInt( navigator.appVersion.charAt( 0 ) ) >= 4 ){
        isNN = ( navigator.appName == "Netscape" ) ? 1 : 0;
        isIE = ( navigator.appName.indexOf( "Microsoft" ) != -1 ) ? 1 : 0;
    }

    if ( isNN ){
        width = document.images["obrazek"].width;
        height = document.images["obrazek"].height;

        if( width > screen.availWidth ){
            width = screen.availWidth - screen.availWidth/5;
            document.body.scroll = "yes";
        }
        if( height > screen.availHeight ){
            height = screen.availHeight - screen.availHeight/5;
            document.body.scroll = "yes";
        }
        window.innerWidth =		width;
        window.innerHeight =	height;
    }
    else {
        window.resizeTo( 100, 100 );
        width =		100 - ( document.body.clientWidth - document.images[0].width );
        height =	100 - ( document.body.clientHeight - document.images[0].height );

        if( width > screen.availWidth ){
            width = screen.availWidth - screen.availWidth / 5;
            document.body.scroll = "yes";
        }
        if( height > screen.availHeight ){
            height = screen.availHeight - screen.availHeight / 5;
            document.body.scroll = "yes";
        }
        window.resizeTo( width+12, height );
    }

    moveWindowToImage( width, height );

}
function moveWindowToImage( iWindowWidth, iWindowHeight ){

    var iPosX = ( screen.availWidth - iWindowWidth ) / 2;
    var iPosY = ( screen.availHeight - iWindowHeight ) / 2;

    window.moveTo( iPosX, iPosY );

} // end function moveWindowImage
function doTitle( ){
    document.title = "Argent 3:";
}

// funkcja do ustawiania pozycji
function centerLayer() {
    var objDiv = document.getElementById("divPics"); //div - parent tabelki
    var objTable = document.getElementById("tablePics"); //table ze zdjeciami

    var widthTable = objTable.offsetWidth;
    var widthObjDiv = objDiv.offsetWidth;

    //ustawienie zdjec centralnie na stronie
    if (widthTable < widthObjDiv) {
        midVal = (Math.round(widthObjDiv/2))-(Math.round(widthTable/2));
        objDiv.style.left = midVal +"px";
        //alert ((Math.round(widthObjDiv/2)) +":"+ (Math.round(widthTable/2)) +":"+ midVal);
    }

}

var timer;
function moveLayer(direction) {

    var obj = document.getElementById("pics"); //ogolny div
    var objDiv = document.getElementById("divPics"); //div - parent tabelki
    var objTable = document.getElementById("tablePics"); //table ze zdjeciami

    // dlugosci danych elementow
    var widthTable = objTable.offsetWidth;
    var widthObj = obj.offsetWidth;
    var widthObjDiv = objDiv.offsetWidth;

    var iloscPx = 10; //iloe px przesuwac w lewo/prawo

    //cntPics ilosc zdjec w tabeli * margin

    //alert(widthTable +" df "+ objDiv.style.left + " : " + objDiv.offsetWidth + " : " + obj.offsetWidth);

    //dalej nie przewijam...
    var maxLeft = (widthTable-widthObjDiv)*-1;
    var maxRight = -1;

    //alert(maxLeft);

    if (direction == 'leftside') {
        if (parseInt(objDiv.style.left) <= maxLeft) {
            stopScroller();
        } else {
            objDiv.style.left = parseInt(objDiv.style.left)-iloscPx +"px";
        }
        if (objDiv.style.left > maxLeft) {
            stopScroller();
        }
    } else {
        if (parseInt(objDiv.style.left) < maxRight) {
            objDiv.style.left=parseInt(objDiv.style.left)+iloscPx +"px";
        } else {
            stopScroller();
        }
    }

    //ustawienie zdjec centralnie na stronie
    //if (widthTable < widthObjDiv) objDiv.style.left = (Math.round(widthObj/2))-(Math.round(widthTable/2)) ;

    //timer = setTimeout("moveLayer('"+direct+"', '"+cntPics+"');", 20);
    timer = setTimeout("moveLayer('"+direction+"');", 30);

}
function stopScroller() {
    clearTimeout(timer)
}
function showHeight(obj) {
    alert("w: "+ obj.offsetWidth +" h: "+ obj.offsetHeight);
}


//funkcja do disebledowania selectu state'ow w momencie wyboru innego kraju niz usa
function disableState(t) {
    var disbl = true;
    if (t.value == 221) {
        disbl = false;
    } else {
        disbl = true;
    }
    document.forms['rejestracja'].elements["woj_id"].disabled = disbl;
}

function hideSelects() {
    var selecty = document.getElementsByTagName("select");
    var ilosc_selectow = selecty.length;

    for (var i=0; i < ilosc_selectow; i++) {
        selecty[i].style.visibility = "hidden";
    }
}

function showSelects() {
    var selecty = document.getElementsByTagName("select");
    var ilosc_selectow = selecty.length;

    for (var i=0; i < ilosc_selectow; i++) {
        selecty[i].style.visibility = "visible";
    }
}

// ----------- kategorie header ----------------- //


//Set tab to intially be selected when page loads:
//[which tab (1=first tab), ID of tab content to display]:
var initialtab=[1, "sc1"]

//Turn menu into single level image tabs (completely hides 2nd level)?
var turntosingle=0 //0 for no (default), 1 for yes

//Disable hyperlinks in 1st level tab images?
var disabletablinks=0 //0 for no (default), 1 for yes

////////Stop editting////////////////

var previoustab ="";

if (turntosingle==1)
document.write('<style type="text/css">\n#tabcontentcontainer{display: none;}\n</style>')

function expandcontent(cid, aobject) {
    if (de(cid) != null) {
        if (disabletablinks==1)
        aobject.onclick=new Function("return false")
        if (document.getElementById){
            if (aobject != "undefined") highlighttab(aobject)
            if (turntosingle==0) {
                if (previoustab != "") {
                    de(previoustab).style.display="none";
                }
                de(cid).style.display="block";
                //ukrywanie obecnej (tylko dla onclick!)
                if (previoustab == cid) {
                    de(previoustab).style.display="none";
                    previoustab="";
                } else {
                    previoustab=cid;
                }
            }
        }
    }
}

function highlighttab(aobject){
    if (typeof tabobjlinks=="undefined")
    collecttablinks()
    for (i=0; i<tabobjlinks.length; i++)
    tabobjlinks[i].className=""
    aobject.className="current"
}

function collecttablinks(){
    var tabobj=document.getElementById("tablist")
    tabobjlinks=tabobj.getElementsByTagName("A")
}

function do_onload(){
    var currenttab = '';
    collecttablinks()
    //expandcontent(initialtab[1], tabobjlinks[initialtab[0]-1])
    //rk:
    for (i=0; i<tabobjlinks.length; i++) {
        if (tabobjlinks[i].className == "current") {
            currenttab = tabobjlinks[i].id.replace('-', '');
            break;
        }
    }
    if (currenttab != '') expandcontent(currenttab, "undefined");
}

function clrPrice(t) {
    var REG_EXP = /[^0-9+.]/gi;
    t.value = t.value.replace(',', '.');
    t.value = t.value.replace(REG_EXP, '');

    //return new_price;
}


//funkcja do pobierania wartosci cech
/*
dostepne id:
bigfoto - zdjecie
cenaKoncowa - cena brutto
cenaKoncowaStrike - cena rabatowa
*/
var bruttoPrice=0; //main price if price == 0.00
var bruttoPriceNoRabat=0; //main price if price == 0.00
var c_netto=0;
var vat=1.00;
var picture='';
var rabat=0;
var dir_img = '';
var dir_prefix = '';
var prod_available = false;
var variation = new Array();
var variation_info = new Array();


/**
formid - id formularza z koszykiem
info {0,1} 1-pokazuje alert(w przypadku, gdy fn jest wywolana przez select)
0 - gdy ma nie byc alertow
*/
function getCechyValues(formid, info) {
    var c_brutto = 0;
    var selects = document.getElementById(formid).getElementsByTagName('SELECT');

    cechy_ids = '';
    for (i=0; i < selects.length; i++) {
        cechy_ids += selects[i].value+'_';
    }

    if (variation[cechy_ids] != undefined) {
        c_brutto_hid = document.forms["add2koszyk"].elements["cena_brutto"];
        vinf = variation_info[variation[cechy_ids]];
        if (vinf[2] == 'f') {
            if (info == 1) alert("sorry this configuration is unavailable");
            prod_available = false;
        } else {
            if (vinf[1] != '') {
                //de('bigfoto').src = dir_img+'/'+dir_prefix+vinf[1];
                de('bigfoto').src = images[variation[cechy_ids]];
            } else {
                de('bigfoto').src = dir_img+'/'+dir_prefix+picture;
            }
            rabat = rabat.replace(",",".");
            if (vinf[0] != 0.00) {
                c_brutto = vinf[0];
                c_brutto_hid.value = c_brutto;
                if (rabat < 1) {
                    c_no_rabat = c_brutto;
                    c_brutto = Math.round(c_no_rabat*rabat*100)/100;
                    de('cenaKoncowaStrike').innerHTML = setPrice(c_no_rabat);
                    c_brutto_hid.value = c_no_rabat;
                }
            } else {
                c_brutto = bruttoPrice;
                c_no_rabat = bruttoPriceNoRabat;
                if (rabat < 1) {
                    de('cenaKoncowaStrike').innerHTML = setPrice(c_no_rabat);
                }
                c_brutto_hid.value = c_no_rabat;
            }
            de('cenaKoncowa').innerHTML = setPrice(c_brutto);

            //alert(vinf[0]);
            prod_available = true;
        }
    } else {
        prod_available = true;
    }
}

// ____________________ funkcje do koszyka _____________________
//w zaleznosci od buttony (update, google) ustawiam action danego forma
//703503722364427 | 832113847156808
function changeFormAction(o_Form, opt, merchant_id) {
    //alert(o_Form.action);
    if (opt == 1) {
        o_Form.action = '/cart.php';
    } else {
        o_Form.action = 'https://checkout.google.com/cws/v2/Merchant/'+merchant_id+'/checkoutForm';
    }
}

function saveCechyKoszyk(id) {
    //alert()

}
