// globals passed from PHP in html-header:
// var lang
// var europe_without_de

function over(nam){
	document.images[nam].src = 'img/menu/'+lang+'/'+nam+'_on.gif';
}
function out(nam){
	document.images[nam].src = 'img/menu/'+lang+'/'+nam+'.gif';
}
function MM_preloadImages() { //v3.0
	var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
	var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
	if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function checkForm(){
	var l=checkForm.arguments;
	var o=l[0];
	var bool=1;
	
	for (var i=1;i<l.length;i++) {
	
		var e=o[l[i]];
		//var val=(e.options && !e.value)?e.options[e.selectedIndex].value:e.value;//NS4, select
		var val = e.value;
		if (val==''){
			e.focus();
			alert(lang=="de"?"Bitte alle erforderlichen Felder ausfüllen!":"Please fill in all required fields!");
			return false;
		} else if ((l[i]=='email') && (!isEmail(e.value))){
			e.focus();
			e.select();
			alert(lang=="de"?"Bitte eine korrekte Email-Adresse eingeben!":"Please enter a correct email address!");
			return false;
		} else if ((l[i]=='datum') && (!isDate(e.value))){
			e.focus();
			e.select();
			alert(lang=="de"?"Bitte eine korrektes Datum eingeben!":"Please enter a correct date!");
			return false;
		}        
	}
	return true;
}
function isJpg(fileName){
	if(fileName!='' && fileName.substr(s.length-4,4).toLowerCase()!='.jpg'){
		alert('F&uuml;r Bilddatei nur Endung *.jpg erlaubt!');
		return false;
	}
	return true;
}
function isImg(fileName){
	if (fileName=='') return true;
	var typ=fileName.substr(s.length-4,4).toLowerCase();
	if(typ!='.jpg' && typ!='.gif' && typ!='.png'){
		alert('F&uuml;r Bilddatei nur Endungen *.jpg, *gif, *.png erlaubt!');
		return false;
	}
	return true;
}
function isEmail(email) {
	reg = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@([a-zA-Z0-9-]+\.)+([a-zA-Z]{2,3})$/;
	return reg.exec(email);
}

function isDate(d){
	var reg = /^[0-3][0-9].[0-1][0-9].20[0-9]{2}$/;
	return (reg.exec(d)!=null);
}

function showHide(check,l){
	if(document.getElementById){
		//for(var i=0;i<l.length;i++) document.getElementById(l[i]).style.visibility=(check.checked)?'hidden':'visible';
		for(var i=0;i<l.length;i++) document.getElementById(l[i]).style.display=(check.checked)?'none':'inline';
	}
}

function hideShow(check,l){
	if(document.getElementById){
		//for(var i=0;i<l.length;i++) document.getElementById(l[i]).style.visibility=(check.checked)?'visible':'hidden';
		for(var i=0;i<l.length;i++) document.getElementById(l[i]).style.display=(check.checked)?'inline':'none';
	}
}

// entfernt Rahmen um Links in IE5+
function cl(o){
	if(o.blur)o.blur();
}

function m(d,n){
	location.href='mai'+'lto'+':'+n+unescape('%40')+d; 
	return false;
}

function checkOrderForm(f) {
	var ok = checkForm(f, 'Icompany1', 'IfirstName', 'IlastName', 'Iaddress1', 'Icity', 'Izip', 'country', 'email');
	if (!ok) return false;
	if(!f.shippingSame.checked){
		var ok = checkForm(f, 'Scompany1', 'SfirstName', 'SlastName', 'Saddress1', 'Scity', 'Szip');
		if (!ok) return false;
	}

	//var EU = ["BE", "DK", "FI", "FR", "GR", "IE", "IT", "LU", "NL", "AT", "PT", "SE", "ES", "GB"]; //ohne DE !
	//var EU = ['BE','DK','EE','FI','FR','GR','IE','IT','LV','LT','LU','MT','NL','PL','AT','PT','SE','SK','SI','ES','CZ','HU','GB','CY']; //ohne DE !
	if (in_array(f.country.value, EU)){
		if(f.vat.value != ""){
			if(f.vat.value.substring(0,2)!=f.country.value || f.vat.value.length<10 || f.vat.value.length>14){
				alert(lang=="de"?"Bitte korrigieren oder entfernen Sie Ihre Umsatzsteuer-Identifikationsnummer.":"Please correct or remove (VAT will be applied) your VAT ID-No.");
				f.vat.focus();
				return false;
			}
		}
	}
	else
		f.vat.value = "";

//	if(f.payment.value == "") {
//		alert(lang=="de"?"Bitte wählen Sie eine Zahlungsart aus.":"Please select a payment method.");
//		f.payment.focus();
//		return false;
//	}
//	if(f.delivery.value == "") {
//		alert(lang=="de"?"Bitte wählen Sie eine Lieferart.":"Please select a delivery method.");
//		f.delivery.focus();
//		return false;
//	}
//	if(f.delivery.value == "mail" && f.payment.value == "cod" ) {
//		alert(lang=="de"?"Für die Lieferung via E-Mail ist nur Zahlungsart 'Vorausbezahlung' möglich.":"Delivery via email and 'cash on delivery' can not be combined.");
//		f.payment.focus();
//		return false;
//	}
	if(f.agb.checked == false) {
		alert(lang=="de"?"Bitte bestätigen Sie, das Sie die AGB gelesen und akzeptiert haben.":"Please confirm that you have read and agree with the standard business conditions.");
		f.agb.focus();
		return false;
	}
	if(f.eula.checked == false) {
		alert(lang=="de"?"Bitte bestätigen Sie, das Sie die Endnutzerbedingungen (EULA) gelesen und akzeptiert haben.":"Please confirm that you have read and agree with the EndUser License Agreement (EULA).");
		f.eula.focus();
		return false;
	}
}

function in_array(val, arr){
	for (el in arr) if (arr[el]==val) return true;
	return false;
}

function showShippingAddress(bool){
	var ids=['Scompany1','SfirstName','SlastName','Saddress1','Scity','Szip','Sstate'];
	for(var i in ids)document.getElementsByName(ids[i])[0].style.display=bool?'none':'inline';
}

function toggleDiv(id){
	if(document.getElementById)
		document.getElementById(id).style.display=(document.getElementById(id).style.display=='none')?'block':'none';
}