// JavaScript Document
function EditItem1() {
	window.document.Form_Submenu.editSM.value = 1;
	window.document.Form_Submenu.submit();
}

function SubmitChangedItem() {
	window.document.Form_Submenu.editSM.value = 1;
	window.document.Form_Submenu.submit();
}

function KeyEnterPressed() {
	if (window.event.keyCode == 13) {
		SubmitChangedItem();
	}
}

function OpenWindow(sFile,name,par) {
	hWndHandle=window.open(sFile,name,par);
	hWndHandle.focus();	
}

var ImageWND = null;

function CloseViewer() {
	if (ImageWND) {
		//ImageWND.close();
	}
}

function ShowImage (id,img_x,img_y,istxt,mod) {
	img_x = img_x+20;
	img_y = img_y+70;
	if (self.innerHeight) img_y += 15; //Add 15 Pixels if not IE
	if (istxt) img_y = img_y+60;
	if (img_x < 200) img_x = 200;
	
	var1 = '/file.php?f=modules/gallery/showimage.php&id='+id+'&module='+mod;
	var2 = '\'ImageViewer\'';
	var3 = '\'scrollbars=no,width=1,height=1\'';
	
	ImageWND = window.open(var1,'ImageViewer',var3);
	ImageWND.resizeTo(img_x,img_y);
	ImageWND.focus();
}

function PopupImg(file,w,h) {
	ImageWND = window.open(file,'ImageViewer','scrollbars=no,width='+w+',height='+h);
	ImageWND.focus();
}


function ShowShopImage (url,img_x,img_y) {
	img_x = img_x +20;
	img_y = img_y +20;
	
	var1 = 'mydata/images/'+url;
	var3 = '\'scrollbars=no,width='+img_x+',height='+img_y+'\'';
	
	ImageWND = window.open(var1,'ItemViewer',var3);
	ImageWND.focus();
}

function CheckAll(par) {
	var count = document.getElementsByName("NumChecks")[0].value;	
	for (var i = 0; i < count; i++) {
		document.getElementsByName('files[]')[i].checked = par;
	}
}

function SetChecks() {
	if (window.document.getElementsByName("Btn_ChangeChecks")[0].checked == true) {
		CheckAll(true);
	} else {
		CheckAll(false);
	}
}

function SubmitGuestbook(v1,v2,v3) {
	string = "";
	if (window.document.Form_Guestbook.name.value == "") string += v2;

	/*if (window.document.Form_Guestbook.header.value == "") {
		if (string != "") string += ", ";
		string += "Titel";
	}*/

	if (window.document.Form_Guestbook.text.value == "") {
		if (string != "") string += ", ";
		string += v3;
	}

	if (string == "") { 
		window.document.Form_Guestbook.submit();
	} else {
		alert (v1+": "+string);
	}
}

function AddSmilie(smile) {
	window.document.Form_Guestbook.text.value += smile;
	window.document.Form_Guestbook.text.focus();
}

function SubmitContactForm(myform,values,markers,info) {
	if (values) {
		if (!info) info="Bitte alle Pflichtfelder ausfüllen!";
		val = values.split(";");
		nr = markers.split(",");
		empty_field = 0;
		
		for (i=0; i<val.length; i++) {
			if (document.forms[myform].elements[val[i]].value == "") {
				empty_field = 1;	
				document.getElementById("formitem_"+nr[i]).style.color = "red";
			}
		}
		
		if (empty_field) {
			alert(info);
		} else {
			document.forms[myform].submit();
		}
	} else {
		document.forms[myform].submit();
	}
}

function GetImage(box,img,w,h) {

	innerbox = box+'_inner';
	imgid = box+'img';
	
	$(box).update('<div id="'+innerbox+'" style="height:'+h+'px; "> </div>');
	$(box).innerHTML;
	
	$(innerbox).update('<img id="'+imgid+'" src="'+img+'" width="'+w+'" height="'+h+'" style="display:none" />');
	$(innerbox).innerHTML;
	new Effect.Appear(imgid, { duration: 1.0 });

}

function ChangePrice(id,value) {

	prop_price = 0.00;
	parseFloat(prop_price);
	
	//Get all property prices
	for (i=1;i<=5;i++) {		
		if (document.getElementById(id+'prop'+i)) {
			str = document.getElementById(id+'prop'+i).value;
			if (str.match('_#_')) {		
				arr = str.split('_#_');
				priceadd = arr[1];
				prop_price += parseFloat(priceadd);
			}
		}
		
	}
	
	//add propertiy prices to item price
	oldprice = document.forms['shopitem'+id].baseprice.value;
	newprice = parseFloat(oldprice) + parseFloat(prop_price);
	newprice = newprice.toFixed(2);
	
	//write newitemprice to document
	document.forms['shopitem'+id].price.value = newprice;
	document.getElementById('price_'+id).innerHTML = newprice.replace(/\./g,",");

}

function CheckPaymentSubmit() {
	if (document.getElementById("pay128")!=null) {
		if (document.getElementById("pay128").checked==true) {
			//document.form_payment.action='https://www.gemoney.at/genome/wkf/interface_tests';
			document.form_payment.action='https://www.gemoney.at/genome/wkf/calc';
		}
	}
	document.form_payment.submit();	
}

