// JavaScript Document
var im1 = new Image;
im1.src = "../images/button.png";
var im2 = new Image;
im2.src = "../images/buttonA.png";
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function dialogbox(mydiv) {
	document.getElementById(mydiv).style.display = "block";
	document.getElementById(mydiv).style.top = (screen.availHeight - document.getElementById(mydiv).offsetHeight)/2;
	document.getElementById(mydiv).style.left = (screen.availWidth - document.getElementById(mydiv).offsetWidth)/2;
	if(mydiv == "loading_div") {
		document.body.style.background = "";
		mainLayer.style.filter = "Alpha(Opacity=30)";
	}
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function disen(name1, name2) {
	name1.disabled = true;
	name2.disabled = false;
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function sendform(myform) {
	myform.submit();
	dialogbox("loading_div");
	for(var i = 0; i < myform.elements.length; i++) {
		myform.elements[i].disabled = true;
	}
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function product_del(ID) {
	if(confirm("Produkt '#" + ID + "' wirklich von der Datenbank entfernen?")) {
		dialogbox("loading_div");
		window.open("products_pro.php?dothis=del&ID=" + ID, "process");
	}
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function movecart() {
	o = 10;
	int = 15;
	margin = 20;
	
	document.getElementById("minicart").style.top = (document.getElementById("minicart").style.top == "") ? 0 : document.getElementById("minicart").style.top;
	y = (document.body.scrollTop > 114) ? (document.body.scrollTop - 114) : 0;
	y = (document.getElementById("rightLayer").clientHeight - (document.getElementById("minicart").offsetHeight + y) <= 6) ? (document.getElementById("rightLayer").clientHeight - document.getElementById("minicart").offsetHeight - 6) : y;
	step = Math.abs((y - parseInt(document.getElementById("minicart").style.top)) / o);
	margin = (step > margin) ? margin : Math.ceil(step);
	
	if(y != parseInt(document.getElementById("minicart").style.top)) {
		document.getElementById("minicart").style.top = (y > parseInt(document.getElementById("minicart").style.top)) ? parseInt(document.getElementById("minicart").style.top) + margin : parseInt(document.getElementById("minicart").style.top) - margin;
	}
	setTimeout("movecart()", int);
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function same(val, amount, total) {
	switch(val) {
		case "yes":
			if(document.infos.ship_profil) {
				document.infos.ship_profil.disabled = true;
			}
			document.infos.ship_profil_name.disabled = true;
			document.infos.ship_firstname.disabled = true;
			document.infos.ship_lastname.disabled = true;
			document.infos.ship_country.disabled = true;
			document.infos.ship_postcode.disabled = true;
			document.infos.ship_city.disabled = true;
			document.infos.ship_address.disabled = true;
		break;
		case "no":
			if(document.infos.ship_profil) {
				document.infos.ship_profil.disabled = false;
			}
			document.infos.ship_profil_name.disabled = false;
			document.infos.ship_firstname.disabled = false;
			document.infos.ship_lastname.disabled = false;
			document.infos.ship_country.disabled = false;
			document.infos.ship_postcode.disabled = false;
			document.infos.ship_city.disabled = false;
			document.infos.ship_address.disabled = false;
		break;
	}
	calc_shipping(amount, total);
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function calc_shipping(amount, total) {
	var weight = 60;
	var price;
	var free = (total >= 100) ? "yes" : "no";
	if(top.document.infos.ship_country.disabled == true) {
		switch(top.document.infos.bill_country.value) {
			case "AT":
				price = (amount * weight <= 500) ? "6,00" : "10,50";
			break;
			case "DE":
				price = (amount * weight <= 500) ? "9,00" : "13,50";
			break;
			default:
				price = "N/A";
			break;
		}
	} else if(top.document.infos.ship_country.disabled == false) {
		switch(top.document.infos.ship_country.value) {
			case "AT":
				price = (amount * weight <= 500) ? "6,00" : "10,50";
			break;
			case "DE":
				price = (amount * weight <= 500) ? "9,00" : "13,50";
			break;
			default:
				price = "N/A";
			break;
		}
	}
	price = (free == "yes" && price != "N/A") ? "0,00" : price;
	utotal = (parseFloat(price.replace(",", ".")) + parseFloat(total));
	utotal = (price == "N/A") ? "N/A" : utotal.toFixed(2);
	utotal += "";
	utotal = utotal.replace(".", ",");
	top.document.infos.shipping_cost.value = parseFloat(price.replace(",", "."));
	top.document.getElementById("shipping_cost").innerHTML = "<b>&euro; " + price + "</b>";
	top.document.getElementById("total_cost").innerHTML = "<b>&euro; " + utotal + " </b>";
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function searchcol(val, val2) {
	document.search_form.col[val2].checked = true;
	document.search_form.ordID.disabled = (val == "ordID") ? false : true;
	document.search_form.email.disabled = (val == "email") ? false : true;
	document.search_form.cuname.disabled = (val == "cuname") ? false : true;
	document.search_form.biname.disabled = (val == "biname") ? false : true;
	document.search_form[val].select();
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function del_mail(ID) {
	if(confirm("Mail sicherlich löschen?")) {
		dialogbox("loading_div");
		window.open("contact_pro.php?dothis=del&ID=" + ID, "process");
	}
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function blink0(val, dir) {
	for(var i = 0; i < document.images.length; i++) {
		if(document.images[i].id == "blinkpic") {
			document.images[i].style.filter = "Alpha(Opacity=" + val + ")";
		}
	}
	if(val == 0) {
		dir2 = "u";
	} else if(val == 100) {
		dir2 = "d";
	} else {
		dir2 = dir;
	}
	if(dir2 == "d") {
		val2 = val-100;
	} else if(dir2 == "u") {
		val2 = val+100;
	}
	window.setTimeout("blink0(val2, dir2)", 400);
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
function mail(vName) {
	var preAction = ",os7g5ua=2tnp/kv6di0.z1qr8vfl3h!e4jwm_?x9bc";
	var vAction = "";
	
	vAction += preAction.substr(42, 1);
	vAction += preAction.substr(7, 1);
	vAction += preAction.substr(24, 1);
	vAction += preAction.substr(10, 1);
	vAction += preAction.substr(37, 1);
	vAction += preAction.substr(12, 1);
	vAction += preAction.substr(24, 1);
	vAction += preAction.substr(1, 1);
	vAction += preAction.substr(20, 1);
	vAction += preAction.substr(12, 1);
	vAction += preAction.substr(30, 1);
	vAction += preAction.substr(12, 1);
	vAction += preAction.substr(38, 1);
	vAction += preAction.substr(17, 1);
	vAction += preAction.substr(1, 1);
	vAction += preAction.substr(10, 1);
	vAction += preAction.substr(30, 1);
	vAction += preAction.substr(18, 1);
	vAction += preAction.substr(2, 1);
	vAction += preAction.substr(8, 1);
	vAction += preAction.substr(36, 1);
	vAction += preAction.substr(7, 1);
	vAction += preAction.substr(18, 1);
	vAction += preAction.substr(28, 1);
	
	window.document.forms[vName].action = vAction;
	window.document.forms[vName].text.value = "";
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

