isIE=navigator.userAgent.indexOf("MSIE")>=0?true:true;
function $(i){return document.getElementById(i);}
function trim(s){while(s.substring(0,1)==' '){s=s.substring(1,s.length);}while(s.substring(s.length-1,s.length)==' '){s=s.substring(0,s.length-1);}return s;}
function checkForm(form){
	if(trim(form.companyName.value)==''){
		errorMsg();
		form.companyName.style.backgroundColor='#ffcfcf';
		return false;
	}
	if(trim(form.contactName.value)==''){
		errorMsg();
		form.contactName.style.backgroundColor='#ffcfcf';
		return false;
	}
	if(trim(form.adress.value)==''){
		errorMsg();
		form.adress.style.backgroundColor='#ffcfcf';
		return false;
	}
	if(trim(form.phone.value)==''){
		errorMsg();
		form.phone.style.backgroundColor='#ffcfcf';
		return false;
	}
	if(trim(form.email.value)==''){
		errorMsg();
		form.email.style.backgroundColor='#ffcfcf';
		return false;
	}else{
		if(!isValidEmail(trim(form.email.value))){
			alert("Indtast venligst en gyldig e-mail adresse!");
			form.email.value='';
			form.email.style.backgroundColor='#ffcfcf';
			return false;
		}
	}
	if(trim(form.web.value)==''){
		errorMsg();
		form.web.style.backgroundColor='#ffcfcf';
		return false;
	}
	if(trim(form.empCount.value)==''){
		errorMsg();
		form.empCount.style.backgroundColor='#ffcfcf';
		return false;
	}
	return true;
}
function errorMsg(){
	alert('Udfyld venligst alle felter!');
}
function checkKlubkort(form){
	if(trim(form.firstName.value)==''){
		errorMsg();
		form.firstName.style.backgroundColor='#ffcfcf';
		return false;
	}
	if(trim(form.lastName.value)==''){
		errorMsg();
		form.lastName.style.backgroundColor='#ffcfcf';
		return false;
	}
	if(trim(form.adress.value)==''){
		errorMsg();
		form.adress.style.backgroundColor='#ffcfcf';
		return false;
	}
	if(trim(form.phone.value)==''){
		errorMsg();
		form.phone.style.backgroundColor='#ffcfcf';
		return false;
	}
	if(trim(form.email.value)==''){
		errorMsg();
		form.email.style.backgroundColor='#ffcfcf';
		return false;
	}else{
		if(!isValidEmail(trim(form.email.value))){
			alert("Indtast venligst en gyldig e-mail adresse!");
			form.email.value='';
			form.email.style.backgroundColor='#ffcfcf';
			return false;
		}
	}
	return true;
}
function checkJob(form){
	if(!form.pizzabud.checked && !form.servitrice.checked && !form.telefonpige.checked){
		alert("V\u00E6lg venligst en stilling!");
		$('stillingField').scrollIntoView(false);
		return false;
	}
	if(trim(form.firstName.value)==''){
		errorMsg();
		form.firstName.style.backgroundColor='#ffcfcf';
		return false;
	}
	if(trim(form.lastName.value)==''){
		errorMsg();
		form.lastName.style.backgroundColor='#ffcfcf';
		return false;
	}
	if(trim(form.birthday.value)==''){
		errorMsg();
		form.birthday.style.backgroundColor='#ffcfcf';
		return false;
	}
	if(trim(form.adress.value)==''){
		errorMsg();
		form.adress.style.backgroundColor='#ffcfcf';
		return false;
	}
	if(trim(form.mobil.value)==''){
		errorMsg();
		form.mobil.style.backgroundColor='#ffcfcf';
		return false;
	}
	if(trim(form.email.value)==''){
		errorMsg();
		form.email.style.backgroundColor='#ffcfcf';
		return false;
	}else{
		if(!isValidEmail(trim(form.email.value))){
			alert("Indtast venligst en gyldig e-mail adresse!");
			form.email.value='';
			form.email.style.backgroundColor='#ffcfcf';
			return false;
		}
	}
	if(trim(form.description.value)==''){
		errorMsg();
		form.description.style.backgroundColor='#ffcfcf';
		return false;
	}
	return true;
}
function checkRisros(form){
	if(trim(form.username.value)==''){
		alert("Indtast venligst navn!");
		form.username.value='';
		form.username.focus();
		form.username.style.backgroundColor='#ffcfcf';
		return false;
	}
	if(trim(form.message.value)==''){
		alert("Indtast venligst din besked!");
		form.message.value='';
		form.message.focus();
		form.message.style.backgroundColor='#ffcfcf';
		return false;
	}
	if(trim(form.recaptcha_response_field.value)==''){
		alert("Indtast venligst sikkerheds koden!\nHusk mellemrum.");
		form.recaptcha_response_field.value='';
		form.recaptcha_response_field.focus();
		return false;
	}
}
function resetInputBg(i){
	i.style.backgroundColor='#fff';
}
function isValidEmail(email){
	var regex = /^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!\.)){0,61}[a-zA-Z0-9]?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9\-](?!$)){0,61}[a-zA-Z0-9]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/;
	return regex.test(email);
}
function isNumeric(str){
	var code;
	for(i=0;i<str.length;i++){
		code = str.charCodeAt(i);
		if(code < 48 || code > 57){
			return false;
		}
	}
	return true;
}

function getRadioValue(radioObj){
	if(!radioObj)
	return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}
function getPos(o){
	var jv_left=jv_top=0;
	if(o.offsetParent){
		jv_left = o.offsetLeft;
		jv_top = o.offsetTop;
		while(o=o.offsetParent){
			jv_left += o.offsetLeft;
			jv_top += o.offsetTop;
		}
	}
	return [jv_left,jv_top];
}
function getFoodHtml(){
	h = "<div class='item' id='menu-item-"+menuID+"' onmouseover='itemOver("+menuID+")' onmouseout='itemOut("+menuID+")'><div style='margin-left:1px;'>";
	h+= "<input type='hidden' name='size-"+menuID+"' value='alm' />";

	hasSizeMenu=false;
	selMenu = "<div class='select-type'><div id='selected-type-"+menuID+"' class='selected-type' onclick='openSelect("+menuID+")'><img style='float:right' align='absmiddle' src='images/arrow-down.gif' /><span id='s-"+menuID+"'>Alm.</span></div><div class='drop-down' id='drop-down-"+menuID+"'><div onmouseover='hoverSelect(this)' onmouseout='unHoverSelect(this)' onclick=\"selectType("+menuID+",'alm')\">Alm.</div>";
	if(mI[menuID]['borne']>0){
		hasSizeMenu=true;
		selMenu += "<div onmouseover='hoverSelect(this)' onmouseout='unHoverSelect(this)' onclick=\"selectType("+menuID+",'borne')\">Børne</div>";
	}
	if(mI[menuID]['fam']>0){
		hasSizeMenu=true;
		selMenu += "<div onmouseover='hoverSelect(this)' onmouseout='unHoverSelect(this)' onclick=\"selectType("+menuID+",'fam')\">Fam (3-4 personers)</div>";
	}
	if(mI[menuID]['mega']>0){
		hasSizeMenu=true;
		selMenu += "<div onmouseover='hoverSelect(this)' onmouseout='unHoverSelect(this)' onclick=\"selectType("+menuID+",'mega')\">Mega (6-8 personers)</div>";
	}
	if(mI[menuID]['ufo']>0){
		hasSizeMenu=true;
		selMenu += "<div onmouseover='hoverSelect(this)' onmouseout='unHoverSelect(this)' onclick=\"selectType("+menuID+",'ufo')\">UFO</div>";
	}
	if(hasSizeMenu){
		selMenu=selMenu+"</div>";
	}else{
		selMenu="";
	}

	price = "<span class='price' id='base-price-"+menuID+"'>"+nicePrice(mI[menuID]['price'])+"</span>";
	deliverable=(mI[menuID]['deliv']=='no')?"<span style='color:red;'> (Bringes ikke ud)</span>":"";
	h+= "<input type='hidden' name='price-"+menuID+"' value='"+mI[menuID]['price']+"' />";
	h+= "<table width='100%' cellspacing='1' cellpadding='1'><tr>";
	h+= "	<td><span class='title'>"+menuID+". "+mI[menuID]['name']+" </span><a id='special-"+menuID+"' class='special-order' style='"+(mI[menuID]['extratype']=='none'?"display:none;":"")+"' onclick='openSpecial("+menuID+");' href='javascript:;'> \u00B1 Tilbeh\u00F8r</a><div class=\"ingr\">"+mI[menuID]['ingr']+deliverable+"</div></td>";
	h+= "	<td valign='top' width='44'>"+selMenu+"</td><td valign='top' align='right' width='84'><input class='count' type='text' name='itemCount_"+menuID+"' value='1' maxlength='1' />"+price+"<img onclick='addToBasket("+menuID+")' class='add' align='absmiddle' src='images/addbasket.gif' alt='' /></td>";
	h+= "</tr></table>";
	if(typeof(mI[menuID]['single_variant'])!='undefined'){
		h+= "<div style='width:100%'><div class='variants'><table cellpadding='0' cellspacing='0'><tr><td valign='middle'><span class='variant-title'><b>&nbsp;Kan&nbsp;fås&nbsp;med:</b></span></td>";
		for(var variantID in mI[menuID]['single_variant']){
			if(mI[menuID]['single_variant'][variantID]['default']==1){
				opSel = "checked='checked'";
			}else{
				opSel = "";
			}
			h+= "<td style='padding-right:10px;' valign='middle'><input type='radio' "+opSel+" name='variant_"+menuID+"' id='v_"+variantID+"' value='"+variantID+"' /><label for='v_"+variantID+"'>"+mI[menuID]['single_variant'][variantID]['name']+"</label></td>";
		}
		h+= "</tr></table></div></div>";
	}else if(typeof(mI[menuID]['multiple_variant'])!='undefined'){
		h+= "<div style='width:100%'><div class='variants'><table cellpadding='0' cellspacing='0'><tr><td valign='middle'><span class='variant-title'><b>&nbsp;Kan&nbsp;fås&nbsp;med:</b></span></td>";
		for(var variantID in mI[menuID]['multiple_variant']){
			if(mI[menuID]['multiple_variant'][variantID]['default']==1){
				opSel = "checked='checked'";
			}else{
				opSel = "";
			}
			h+= "<td style='padding-right:10px;' valign='middle'><input onclick='varientAlterBasePrice(this,"+menuID+","+variantID+")' type='checkbox' "+opSel+" name='variant_"+menuID+"' id='v_"+variantID+"' value='"+variantID+"' /><label for='v_"+variantID+"'>"+mI[menuID]['multiple_variant'][variantID]['name']+"</label></td>";
		}
		h+= "</tr></table></div></div>";
	}else if(typeof(mI[menuID]['optional_variant'])!='undefined'){
		h+= "<div style='width:100%'><div class='variants'><table cellpadding='0' cellspacing='0'><tr><td valign='middle'><span class='variant-title'><b>&nbsp;Kan&nbsp;fås&nbsp;med:</b></span></td>";
		for(var variantID in mI[menuID]['optional_variant']){
			h+= "<td style='padding-right:10px;' valign='middle'><input onclick='optionalVariantsAlterBasePrice(this,"+menuID+","+variantID+")' type='checkbox' name='variant_"+menuID+"' id='v_"+variantID+"' value='"+variantID+"' /><label for='v_"+variantID+"'>"+mI[menuID]['optional_variant'][variantID]['name']+"</label></td>";
		}
		h+= "</tr></table></div></div>";
	}
	h+= "<div id='extra-menu-"+menuID+"' class='extra-menu'></div>";
	h+= "</div><div align='center' style='padding:6px'><img src='images/centerSep.gif' height='5' alt='' /></div>";
	h+= "</div>";
	return h;
}
function getDrinkHtml(){
	h = "<table width='100%'>";
	cell=1;
	for(var menuID in mI){
		if(cell%2==1){
			h+="<tr>";
		}
		price = "<span class='price' id='base-price-"+menuID+"'>"+nicePrice(mI[menuID]['price'])+"</span>";
		h+="<td width='50%'><div class='item' id='menu-item-"+menuID+"' onmouseover='itemOver("+menuID+")' onmouseout='itemOut("+menuID+")'><div style='margin-left:1px;'>";
		h+="<div><span class='title'>"+mI[menuID]['name']+" </span><span id='special-"+menuID+"'></span></div>";
		h+="<div><img style='margin:2px;border:1px solid #000;' src='"+mI[menuID]['img']+"' /></div>";
			h+= "<div><table width='100%' cellspacing='1' cellpadding='1'><tr>";
			h+= "	<td><input class='count' type='text' name='itemCount_"+menuID+"' value='1' maxlength='1' />"+price+"<img onclick='addToBasket("+menuID+")' class='add' align='absmiddle' src='images/addbasket.gif' /></td>";
			h+= "</tr></table></div>";
		h+="</div></div></td>";
		if(cell%2==0){
			h+="</tr>";
			h+= "<tr><td colspan='2'><div align='center' style='padding:5px'><img src='images/centerSep.gif' height='5' /></div></td></tr>";
		}
		cell++;
	}
	h += "<tr><td colspan='2'></td></tr></table>";
	return h;
}
