opacity = [];
 
    function addToBasket(url, argumenti, where) {
        var httpRequest;

        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            httpRequest = new XMLHttpRequest();
            if (httpRequest.overrideMimeType) {
                httpRequest.overrideMimeType('text/xml');
                // See note below about this line
            }
        } 
        else if (window.ActiveXObject) { // IE
            try {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } 
            catch (e) {
                try {
                    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                } 
                catch (e) {}
            }
        }

        if (!httpRequest) {
            alert('Napaka XMLHTTP!');
            return false;
        }
        httpRequest.onreadystatechange = function() { alertContents(httpRequest, where); };
        httpRequest.open('GET', url+"?"+"id_izdelka="+argumenti, true);
        httpRequest.send('');

    }

    function alertContents(httpRequest, where) {

        if (httpRequest.readyState == 4) {
            if (httpRequest.status == 200) {
                document.getElementById(where).innerHTML = httpRequest.responseText;
            } else {
                alert('Napaka! Vrnjeni napačni podatki');
            }
        }

    }

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


function showElement(element_id){

	document.getElementById(element_id).style.display = "list-item";

}

function hideElement(element_id){

	document.getElementById(element_id).style.display = "none";

}

function changeIskalnik(argumenti){

        var httpRequest;

		url = "reinitIskalnik.php";
		
        if (window.XMLHttpRequest) { // Mozilla, Safari, ...
            httpRequest = new XMLHttpRequest();
            if (httpRequest.overrideMimeType) {
                httpRequest.overrideMimeType('text/xml');
                // See note below about this line
            }
        } 
        else if (window.ActiveXObject) { // IE
            try {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } 
            catch (e) {
                try {
                    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                } 
                catch (e) {}
            }
        }

        if (!httpRequest) {
            alert('Napaka XMLHTTP!');
            return false;
        }
        httpRequest.onreadystatechange = function() { alertContents(httpRequest, 'iskalnik'); };
        httpRequest.open('GET', url+"?"+"skupina="+argumenti, true);
        httpRequest.send('');

}

function payOptions(id){

	var placilna_polja = document.getElementById('placinla_polja');
	placilna_polja.innerHTML = "";
	
	var naprej = document.getElementById("naprej");
	
	id = Number(id);
		
	switch(id){
		
		default:
		
			naprej.disabled = true;
		
		break;
		
		case 1:
		case 2:
			naprej.disabled = false;	
		break;
		
		
		case 3:
		 	naprej.disabled = false;
			
			var msg 	  = document.createElement("div");
			    msg.className = "";
			    msg.innerHTML = "<br style=\"display:block; margin-bottom:15px;\"/><p>Payment with a credit card will proceed over a secure HTTPS connection.</p>"
				          + "<p>After choosing a shipping method you will be redirected to a payment site secured with a 3-D secure system.</p>";

			var varnost = document.createElement("div");
			    varnost.className = "";
			    varnost.innerHTML = "<img src=\"template/crocsTemplate/images/visa.jpg\" alt=\"\" height=35 onclick=\"document.order.submit();\" style=\"float: right;\" > <img src=\"template/crocsTemplate/images/mastercard.gif\" alt=\"\" height=35 onclick=\"document.order.submit();\" style=\"float: right;\" ><div style=\"clear:both;\"></div>";
			
			placilna_polja.appendChild(msg);
			placilna_polja.appendChild(varnost);
			
		break;
	
		case 4:
			naprej.disabled = false;
		break;
	
		case 5:
		 	naprej.disabled = false;
			
			var msg 	  = document.createElement("div");
			    msg.className = "";
			    msg.innerHTML = "<br style=\"display:block; margin-bottom:15px;\"/><p>Payment with a PayPal will proceed over a secure HTTPS connection.</p>"
				          + "<p>After choosing shipping method you will be redirected to a PayPal payment site.</p><br style=\"display:block; margin-bottom:15px;\"/>";

			var varnost = document.createElement("div");
			    varnost.className = "";
			    varnost.innerHTML = "<img src=\"https://fpdbs.sandbox.paypal.com/dynamicimageweb?cmd=_dynamic-image\" alt=\"\" style=\"float: right;\" onclick=\"document.order.submit();\" ><div style=\"clear:both;\"></div>";
			
			placilna_polja.appendChild(msg);
			placilna_polja.appendChild(varnost);
		break;
		case 6:
			naprej.disabled = false;
		break;
	}

}

function shipOptions(id){

	var placilna_polja = document.getElementById('placinla_polja');
	placilna_polja.innerHTML = "";
	
	var naprej = document.getElementById("nextS");
	
	id = Number(id);
		
	switch(id){
		
		default:
		
			naprej.disabled = true;
		
		break;
		
		case 1:
		case 2:
			
			naprej.disabled = false;
		
			var li_povzemnik = document.createElement("li");
			li_povzemnik.className = "urejanje_li";
			li_povzemnik.innerHTML = "<strong>Recipient</strong>";
			
			var li_kupec_ime = document.createElement("li");
			li_kupec_ime.className = "urejanje_li";
			li_kupec_ime.innerHTML = "<label for=\"zip\">Name: </label><input size=\"40\" maxlength=\"64\" class=\"text_field\" name=\"ime\" value=\"" + document.getElementById("ime").value +"\"/>";
			
			var li_kupec_priimek = document.createElement("li");
			li_kupec_priimek.className = "urejanje_li";
			li_kupec_priimek.innerHTML = "<label for=\"zip\">Surname: </label><input size=\"40\" maxlength=\"64\" class=\"text_field\" name=\"priimek\" value=\"" + document.getElementById("priimek").value +"\"/>";
			
			var li_email = document.createElement("li");
			li_email.className = "urejanje_li";
			li_email.innerHTML = "<label for=\"zip\">E-mail: </label><input size=\"40\" maxlength=\"64\" class=\"text_field\" name=\"email\" value=\"" + document.getElementById("email").value + "\"/>";			

			var li_naslov = document.createElement("li");
			li_naslov.className = "urejanje_li";
			li_naslov.innerHTML = "<label for=\"zip\">Address: </label><input size=\"40\" maxlength=\"64\" class=\"text_field\" name=\"naslov\" value=\"" + document.getElementById("naslov").value +"\"/>";			

			var li_posta = document.createElement("li");
			li_posta.className = "urejanje_li";
			li_posta.innerHTML = "<label for=\"zip\">City: </label><input size=\"40\" maxlength=\"64\" class=\"text_field\" name=\"posta\" value=\"" + document.getElementById("posta").value +"\"/>";	

			var li_postna_stevilka = document.createElement("li");
			li_postna_stevilka.className = "urejanje_li";
			li_postna_stevilka.innerHTML = "<label for=\"zip\">Postcode: </label><input size=\"40\" maxlength=\"64\" class=\"text_field\" name=\"postna_stevilka\" value=\"" + document.getElementById("postna_stevilka").value +"\"/>";	

			var li_country = document.createElement("li");
			li_country.className = "urejanje_li";
			li_country.innerHTML = "<label for=\"zip\">Country: </label><input size=\"40\" maxlength=\"64\" class=\"text_field\" name=\"country\" value=\"" + document.getElementById("country").value +"\"/>";	

			var li_telefon = document.createElement("li");
			li_telefon.className = "urejanje_li";
			li_telefon.innerHTML = "<label for=\"zip\">Phone: </label><input size=\"40\" maxlength=\"64\" class=\"text_field\" name=\"telefon\" value=\"" + document.getElementById("telefon").value +"\"/>";	

			placilna_polja.appendChild(li_povzemnik);
			placilna_polja.appendChild(li_kupec_ime);
			placilna_polja.appendChild(li_kupec_priimek);
			placilna_polja.appendChild(li_email);
			placilna_polja.appendChild(li_naslov);
			placilna_polja.appendChild(li_posta);
			placilna_polja.appendChild(li_postna_stevilka);
			placilna_polja.appendChild(li_country);
			placilna_polja.appendChild(li_telefon);
			
		break;
		
		
		case 3:
		case 4:
			naprej.disabled = false;
		break;
		
	}

}

function ShowShipping(id){
		
	var naprej = document.getElementById("nextS");
	var ele = document.getElementById("dostava_nacin");
	
	id = Number(id);
		
	switch(id){
		
		default:
			naprej.disabled = true;
			break;
		case 0:
			naprej.disabled = true;
			ele.style.display = "none";
			break;
		case 1:
			naprej.disabled = false;
			ele.style.display = "block";
			break;		
		case 2:
			naprej.disabled = false;
			$(".clear_input").val('');
			ele.style.display = "block";
			break;
		case 3:
			naprej.disabled = false;
			ele.style.display = "block";
			break;
		case 4:
			naprej.disabled = false;
		break;
		
	}
}

function DostavaCountry(id){
	$naziv = $("#country_list option:selected").text();
	$(".country_name").val($naziv);
}

function validateDostava(){
	if($("#order").valid()){
		document.order.submit();
	}else{
		alert("Please fill in mandatory fields!");
	}	
}

function ShipGift(){
	
	var ele = document.getElementById("gift_polja");
	if(ele.style.display == "block") {
    		ele.style.display = "none";
  	}
	else {
		ele.style.display = "block";
	}

}

function doDaPrint(){
	window.print();	
}

function goPrint(id)
{

str=document.getElementById(id).innerHTML;
newwin=window.open('','printwin','left=100,top=100,width=600,height=500');
newwin.document.write('<HTML>\n<HEAD>\n');
newwin.document.write('<TITLE>Print Page</TITLE>\n');
newwin.document.write('<link href="template/acTemplate/css/print.css" rel="stylesheet" type="text/css" />');
newwin.document.write('<script>\n');
newwin.document.write('function chkstate(){\n');
newwin.document.write('if(document.readyState=="complete"){\n');
newwin.document.write('window.close()\n');
newwin.document.write('}\n');
newwin.document.write('else{\n');
newwin.document.write('setTimeout("chkstate()",2000)\n');
newwin.document.write('}\n');
newwin.document.write('}\n');
newwin.document.write('function print_win(){\n');
newwin.document.write('window.print();\n');
newwin.document.write('chkstate();\n');
newwin.document.write('}\n');
newwin.document.write('<\/script>\n');
newwin.document.write('</HEAD>\n');
newwin.document.write('<BODY onload="print_win();" style="background: #ffffff;">\n');
newwin.document.write(str);
newwin.document.write('</BODY>\n');
newwin.document.write('</HTML>\n');
newwin.document.close();
setTimeout("newwin.close();", 2000);



/*	var a = window.open('','','width=800,height=600');
	a.document.open("text/html");
	a.document.write(document.getElementById(toprint).innerHTML);
	a.document.write("<script>function doDaPrint(){window.print();} window.onload = function(){window.print();}</script>");
	//a.onload = a.print();
	//a.document.print();*/
/*	var tags = document.getElementsByTagName('div');
	var gogo = tags.length;

	for(var i=0; i<gogo; i++){

		tags[i].style.display = "none";
	}
	
	//alert(toprint);

	var 	natisni = document.getElementById(toprint);
	var tagsnatisni = natisni.getElementsByTagName('div');
	var    goprints = tagsnatisni.length;

	//alert(natisni.id);		

	natisni.style.display = "block";

	for (var j=0; j<goprints; j++){
		tagsnatisni[j].style.display = "block";
	}

	window.print();
	for(var i=0; i<gogo; i++){
		tags[i].style.display = "block";
	}*/
}

function toggleVisable(what){
	
	var stuff = document.getElementById(what);
	
	if(stuff.style.display == "none"){
	
		stuff.style.display = "block";

	}else{
		stuff.style.display = "none";
	}
	

}


function rotateMe(rotateImg, where, run, rotatetime, inst){

	run++;
	var goes = rotateImg.length;
	if(run >= goes) run = 0;

	var location = document.getElementById(where);		
		
	location.src = rotateImg[run];
	location.onload = function(){
		new FadeIn(location, rotateImg, where, run, rotatetime, inst);
	}	
	
}

function FadeIn(element, rotateImg, where, run, rotatetime, inst){

	if(opacity[inst] == null) opacity[inst] = 0;

	var reduce_opacity_by = 2;
	var rate = 30;	// 15 fps

	if (opacity[inst] < 100) {
		opacity[inst] += reduce_opacity_by;
		if (opacity[inst] > 100) opacity[inst] = 100;

		if (element.filters) {
			try {
				element.filters.item("DXImageTransform.Microsoft.Alpha").opacity = opacity[inst];
			} catch (e) {
				// If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.
				element.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity[inst] + ')';
			}
		} else {
			element.style.opacity = opacity[inst] / 100;
		}
	}
	
	//if(over==1){
		if (opacity[inst] < 100) {
			setTimeout(function() { new FadeIn(element, rotateImg, where, run, rotatetime, inst); }, rate);
		//}
	}else{

		setTimeout(
			function() {   
				new FadeOut(element, rotateImg, where, run, rotatetime, inst);
			}
		,rotatetime);
	
	}
}

function FadeOut(element, rotateImg, where, run, rotatetime, inst){

	if(opacity[inst] == null) opacity[inst] = 0;

	var reduce_opacity_by = 2;
	var rate = 30;	// 15 fps

	if (opacity[inst] > 10) {
		opacity[inst] -= reduce_opacity_by;
		if (opacity[inst] < 10) opacity[inst] = 10;

		if (element.filters) {
			try {
				element.filters.item("DXImageTransform.Microsoft.Alpha").opacity = opacity[inst];
			} catch (e) {
				// If it is not set initially, the browser will throw an error.  This will set it if it is not set yet.
				element.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + opacity[inst] + ')';
			}
		} else {
			element.style.opacity = opacity[inst] / 100;
		}
	}
	//if(over==0){
		if (opacity[inst] > 10) {
			setTimeout(function() { new FadeOut(element, rotateImg, where, run, rotatetime, inst); }, rate);
		}
		else{
			new rotateMe(rotateImg, where, run, rotatetime, inst);
		}
	//}
}

function imagegallery(num) {	
	var buttonCast	= document.getElementById("gallery_nav");
	
	if(document.getElementById("gallery"+num) != null){
		var changeTo = document.getElementById("gallery"+num).src;
	}
	
	var toChange 	= document.getElementById("velika");
	var button   	= document.getElementById("barva"+num).src="template/crocsTemplate/images/swatchesLi_img_active.png";

	var buttonMass	= buttonCast.getElementsByTagName("img");
	var buttonNum	= buttonMass.length;

	for(var i = 0; i < buttonNum; i++){
		
		if(buttonMass[i].id != "barva"+num){
			buttonMass[i].src = "template/crocsTemplate/images/swatchesLi_img.png";
		}
	}

	if(document.getElementById("gallery"+num) != null){
		if( toChange != null){
			toChange.src = changeTo.replace("5_", "4_");
		}
	}
	
	document.getElementById("barva").value = num;
//	var barva_vrednost = document.getElementById("barva").value;
//	alert(num+" nastavleno = "+barva_vrednost);
	
	
	var velikost = document.getElementById("velikost").value;

//	checkZaloga(num, velikost);
	checkZalogaNoParm();



}

function changeVelika(slika, id, pot, barva){

	document.getElementById("velika").src	= pot+id+"/4_"+slika;

	if(barva != null){
		document.getElementById("barva").value 	= barva;
		
		var buttonCast	= document.getElementById("gallery_nav");	
			
		var button   	= document.getElementById("barva"+barva).src="template/crocsTemplate/images/swatchesLi_img_active.png";

		var buttonMass	= buttonCast.getElementsByTagName("img");
		var buttonNum	= buttonMass.length;
		
		for(var i = 0; i < buttonNum; i++){
			
			if(buttonMass[i].id != "barva"+barva){
				buttonMass[i].src = "template/crocsTemplate/images/swatchesLi_img.png";
			}
		}
		var velikost = document.getElementById("velikost").value;
		//checkZaloga(barva, velikost);
		checkZalogaNoParm();
	}
}


function checkZaloga(barva, velikost){
	
	if(barva != null && velikost != null){
	
		if(document.getElementById("zaloga"+barva+"_"+velikost) != null){
			var zaloga  = document.getElementById("zaloga"+barva+"_"+velikost).value;
		}else{
			var zaloga 	= "ne";
		}
/*		if (zaloga=="da"){
			zaloga = "<img src=\"template/crocsTemplate/images/item_instock.png\" alt=\"In Stock\" width=\"70\" />";
		}else{
			zaloga = "<img src=\"template/crocsTemplate/images/item_nostock.png\" alt=\"In Stock\" width=\"70\" />";
		}
		*/
		document.getElementById("zaloga_display").innerHTML = "On stock: <span class=\"zaloga_"+zaloga+"\">" + zaloga +"</span>";		
		
	}
}




function checkZalogaNoParm(){
	
	var barva = document.getElementById("barva").value;
	var velikost = document.getElementById("velikost").value;
	var id_izd = document.getElementById("id_izd").value;
	
	//alert(velikost);
	
	if(barva != "" && velikost != ""){
	
		if(document.getElementById("zaloga"+barva+"_"+velikost) != null){
			var zaloga  = document.getElementById("zaloga"+barva+"_"+velikost).value;
		}else{
			var zaloga 	= "ne";
		}
		if (zaloga=="da"){
			zaloga = "<img src=\'template/crocsTemplate/images/item_instock.png\' alt=\'In Stock\' width=\'70\' />";
		}else{
			zaloga = "<img src=\'template/crocsTemplate/images/item_nostock.png\' alt=\'In Stock\' width=\'70\' /><br style=\'display: block; margin-top:15px;\' /><a href=\'main.php?com=sold_out&izdelek_sold="+id_izd+"\'>Request a sold out item!</a>";
		}		
		document.getElementById("zaloga_display").innerHTML = "On stock: <span style=\"padding-left:3px;\" class=\"zaloga_"+zaloga+"\">" + zaloga +"</span>";		
		
	} else {

		document.getElementById("zaloga_display").innerHTML = "Choose size and colour!";			
	
	}
}

function DodajVKosaro(){

	if(document.getElementById("barva") != null && document.getElementById("velikost") != null){
		var barva = document.getElementById("barva").value;
		var velikost = document.getElementById("velikost").value;
		
		if(barva != "" && velikost != ""){
		
			if(document.getElementById("zaloga"+barva+"_"+velikost) != null){
				if(document.getElementById("zaloga"+barva+"_"+velikost).value == "da"){
					document.addtob.submit();
				}else{
					alert("item is not on stock!");
				}
			}else{
				alert("item is not on stock!");
			}
			
		} else {
			alert("Choose colour and size!");
		}	
	}else{
		
		document.addtob.submit();
		
	}
}

function potrdi_nakup() {

	if(document.getElementById('strinjam_se').checked == true){ 
		//alert("submit");
		document.potrdi_narocilo.submit();
	} else {
		alert("For completing your shopping you need to accept terms of use.");
	}
	//document.potrdi_narocilo.submit();
	
}

function check_code() {

	if (document.getElementById('discount_code').value.length == 0 || document.getElementById('discount_code').value == null) {
		alert("Please enter code!");
	}
	else {
		var vpisana_koda = document.getElementById('discount_code').value;
		var koda = document.getElementById('koda_povprasevanje').value = vpisana_koda;
		document.popust.submit();
	}
	
}

