

function PMHi(id) {
	document.getElementById('pmi' + id).className = 'picture-aktivni';
}

function PMLo(id) {
	document.getElementById('pmi' + id).className = 'picture';
}
var aktivniObrazek = 1;
function ZmenitObrazek(poradi) {
    obrazek = imagesArray[poradi -1 ][1];
    id_obrazku = imagesArray[poradi - 1][2];
    if (document.getElementById('full_obrazek')) document.getElementById('full_obrazek').href = "./img-upload/" + imagesArray[poradi - 1][0];
    aktivniObrazek = poradi;
    var cilovyImg = document.getElementById('obrazek_hlavni');
	//cilovyImg.style.visibility = 'hidden';
	cilovyImg.src = './img-upload/' + obrazek;
	//cilovyImg.onload = ZobrazitObrazek;
	var boxiky = document.getElementById('detail-img-td2').getElementsByTagName('div')
	var last_position;
	var first_position;
	for (i = 0; i < boxiky.length; i++) {
	    cisla = boxiky[i].getElementsByTagName('div');
	    for (j = 0; j < boxiky.length; j++) {
	        if (cisla[j]) {
	            cisla[j].className = 'detail-img-number';
	            last_position = cisla[j];
	            if (first_position == null) {
	                first_position = cisla[j];
	            }
	        }
	    }
	}
	if (document.getElementById('detail-img-td3')){
	    var popisy = document.getElementById('detail-img-td3').getElementsByTagName('div')
	    for (i = 0; i < popisy.length; i++) {
	        if (popisy[i]) {
	            popisy[i].className = 'invisible';
	        }
	    }
	}
	if (document.getElementById('thundernail_' + id_obrazku)) {
	    document.getElementById('thundernail_' + id_obrazku).className = 'detail-img-number-selected';
	}
	if (document.getElementById('popis_' + id_obrazku)) {
	    document.getElementById('popis_' + id_obrazku).className = 'visible';
	}
	return false;
}
function obrazek_next() {
    if (imagesArray.length >= aktivniObrazek + 1) {
        ZmenitObrazek(aktivniObrazek + 1)
    } else {
        ZmenitObrazek(1)
    }
    return false;
}
function obrazek_previous() {
    if (aktivniObrazek > 1) {
        ZmenitObrazek(aktivniObrazek - 1)
    } else {
    ZmenitObrazek(imagesArray.length + 1)
    }
}
function ZobrazitObrazek() {
    var cilovyImg = document.getElementById('obrazek_hlavni');
	cilovyImg.style.visibility = 'visible';
}

function IdenticalClick() {
	if(document.getElementById('shipping_identical').checked) {
		document.getElementById('form_shipping').style.display = 'none';
	} else {
		document.getElementById('form_shipping').style.display = 'block';
	}
}

function SearchFocus(vychozi_text) {
	var l = document.getElementById('search_input');
	if(l.value == vychozi_text) l.value = '';
}

function SearchBlur(vychozi_text) {
	var l = document.getElementById('search_input');
	if(l.value == '') l.value = vychozi_text;
}

function ChangePage(strana) {
    if (document.getElementById("search-paging").strana) {
        document.getElementById("search-paging").strana.value = strana;
    } else {
        document.getElementById("search-paging").p.value = strana;
    }
    document.getElementById("search-paging").submit();
    
    if (document.getElementById("search-paging2").strana) {
        document.getElementById("search-paging2").strana.value = strana;
    } else {
        document.getElementById("search-paging2").p.value = strana;
    }
    document.getElementById("search-paging2").submit();
    
}
function setOne() {
    if (document.getElementById("search-paging").strana) {
        document.getElementById("search-paging").strana.value = 1;
    } else {
        document.getElementById("search-paging").p.value = 1;
    }
    if (document.getElementById("search-paging2").strana) {
        document.getElementById("search-paging2").strana.value = 1;
    } else {
        document.getElementById("search-paging2").p.value = 1;
    }
    
}

function JenCisla() {
	with (event) if (keyCode < 48 || keyCode > 57) returnValue = false;
}

function zmenitPozadi(id, pozadi) {
    document.getElementById(id).style.backgroundImage = "url('./img-upload/" + pozadi + "')";
   }


   function sendOrder(formId, type) {
       if (document.getElementById(formId)) {
   		document.getElementById(formId + '-input').value = type;
   		document.getElementById(formId).submit();
   	}
}
var isOrderSended = false;
function submitOrderTlc(obj){
    //obj.disabled = 'disabled';
    if (isOrderSended) {
        return false;
    } else {
        isOrderSended = true;
        return true;
    }
    
}


jQuery.noConflict();
jQuery(document).ready(function () {
    jQuery("#coupon-anchor").click(function () {
        jQuery(".coupon-box").toggle("slow");
        jQuery(".stav_msg_ok").remove();
        jQuery(".stav_msg_ok").remove();
    });

    jQuery(".send_form").click(function () {
        jQuery(".odkaz-big").attr('disabled', 'disabled');
        return true;
    });

    jQuery("#coupon-validate").click(function () {
        jQuery.ajax({
            type: "GET",
            url: "./actions/validate-coupon.asp",
            contentType: "application/x-www-form-urlencoded; charset=Windows-1250",
            data: "akce=validate&code=" + jQuery("#coupon").val(),
            error: function (msg) {
                alert(msg.responseText)
            },
            success: function (data, textStatus, XMLHttpRequest) {
                jQuery(".chybova-msg2").remove();
                if (data == "exist") {
                    jQuery("#coupon-block").css("display", "none");
                    location = "cart.asp"
                } else {
                    jQuery('<div class="chybova-msg2"><span>' + data + '</span><br /><br /></div>').insertBefore(jQuery("#coupon-anchor"));
                }
            }
        });
    });

    jQuery(".opened_coupon").ready(function () {
        if (jQuery(".opened_coupon").length > 0) { jQuery("#coupon-anchor").trigger("click"); }
    });

    jQuery("#selectStates").change(function () {
        if (jQuery(this).val() == "other") {
            jQuery("#otherCountries").show();
            jQuery("#otherStates").hide();
        } else {
            jQuery("#otherCountries").hide();
            jQuery("#otherStates").show();
        }
    });

    jQuery("#selectStates2").change(function () {
        if (jQuery(this).val() == "other") {
            jQuery("#otherCountries2").show();
            jQuery("#otherStates2").hide();
        } else {
            jQuery("#otherCountries2").hide();
            jQuery("#otherStates2").show();
        }
    });




});



function OdstranitKupon(id) {
    jQuery.ajax({
        type: "GET",
        url: "./actions/validate-coupon.asp",
        contentType: "application/x-www-form-urlencoded; charset=Windows-1250",
        data: "akce=remove&id_kosiku=" + id,
        error: function (msg) {
            alert(msg.responseText)
        },
        success: function (data, textStatus, XMLHttpRequest) {
            jQuery("#coupon-block").css("display", "block");
            jQuery("#coupon-active").remove();
            jQuery(".stav_msg_ok").remove();
            jQuery(".stav_msg_ok").remove();
            location = "cart.asp"
        }
    });
}

function validateCoupon() {
    jQuery("#coupon-validate").trigger("click");
    return false;
}



