function no_navbar(){
	document.getElementById('greystuff').style.position = "relative";
	document.getElementById('greystuff').style.bottom = "9px";
}
function page_turn(e){
	tast='';
   if (!e) var e = window.event
	if(e){ tast = e.keyCode; }
	if(tast==37 && document.getElementById('pil_tilbage').href){
		document.location = document.getElementById('pil_tilbage').href;
	}
	if(tast==39 && document.getElementById('pil_frem').href){
		document.location = document.getElementById('pil_frem').href;
	}
}

function page_find(ele){
   document.location = document.getElementById(ele).href;
}

function hover_mail(me,e){
	img = document.getElementById(me).src;
	if(e=='over'){
		newimg = img.replace("mail","mail_hover");
	}
	if(e=='out'){
		newimg = img.replace("mail_hover","mail");
	}
	document.getElementById(me).src = newimg;
}

function hover_me(me,e,color){
	if(e=='over'){
		document.getElementById(me).style.color = '#FBCF9B';
	}
	if(e=='out'){
		document.getElementById(me).style.color = color;
	}
}

function resetMe(me){
	me.value = '';
}

function checkValue(me,val){
	if (me.value == ''){
		me.value = val;
	}
}

function scroll(to){
   document.location = to;
}

function resizeToBrodbox(me){
	x = Math.min(Math.max(document.body.clientWidth,782),1349)*0.264+179.952;
	document.getElementById(me).width = Math.round(x);
}

function youtubeHeight(me){
	x = Math.min(Math.max(document.body.clientWidth,782),1349)*0.264+179.952;
	y = Math.round(x*0.75+25);
	document.getElementById(me).style.height = y + 'px';
}

function writeCookie(me, value){
	expire = new Date();
	expire.setTime(expire.getTime()+(60*60*24*365*5));
	cookiestring = me + '=' + escape(value) + ';expires=' + expire.toGMTString() + ';path=/;domain=ove.org';
	document.cookie = cookiestring;
}

function readCookie(me){
	if (document.cookie != '') {
		var meEQ = me + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' '){
				c = c.substr(1,c.length);
			}
			if (c.indexOf(meEQ) == 0){
				return c.substr(meEQ.length,c.length);
			}
		}
	}
}

function alterCookie(me,change,shoptype){
   value = 0 + change;
	if(readCookie(me)>0){
		value = value + (readCookie(me)*1);
 	}
	if(value<1){
		clearCookie(me);
	}
	else{
		writeCookie(me,value);
	}
	updateVarekurv(shoptype);
}

function formatPrice(pris){
	pris = pris.toString();
	strdot = pris.length-3;
	if(pris.charAt(strdot)=='.'){
		pris = pris.substring(0,strdot) + ',' + pris.substr(strdot+1);
	}
	else{
		pris = pris + ',-';
	}
	return pris;
}

function updateVarekurv(shoptype){
	if(document.getElementById('varekurv')){
		if(shoptype=='gaver'){
			var starttext = '<table width="180" cellspacing="2"><tr class="brod_col"><td>Gave</td><td align="right">Antal&nbsp;&nbsp;</td><td align="center">Pris</td>' + "</tr>\n";
		}
		else{
			var starttext = '<table width="180" cellspacing="2"><tr class="brod_col"><td>Vare</td><td align="right">Antal&nbsp;&nbsp;</td><td align="center">Pris</td>' + "</tr>\n";
		}
		var text = starttext;
		var normalpris = 0;
		var medlemspris = 0;
		if (document.cookie != '') {
  			var ca = document.cookie.split(';');
			var color = 0;
			for(var i=0;i < ca.length;i++) {
         	var c = ca[i];
				while (c.charAt(0)==' '){
			   	c = c.substring(1);
				}
				if(c.substr(0,6)=='ordre_'){
					var cv = c.split('=');
					var ordre = ordreInfo(cv[0],'navn');
					var pris1 = (ordreInfo(cv[0],'pris1') * cv[1]);
					var pris2 = (ordreInfo(cv[0],'pris2') * cv[1]);
					if(pris1 + pris2 > 0){
						normalpris = normalpris + pris1;
						pris1 = formatPrice(pris1);
						medlemspris = medlemspris + pris2;
						pris2 = formatPrice(pris2);
						text = text + '<tr class="brod_row"';
						if(color==1){
							text = text + ' bgcolor="#FAFAFA"';
						}
						text = text + '><td style="vertical-align: middle">' + ordre + '</td>';
						text = text + '<td align="right" style="vertical-align: middle; line-height: 9px"><span style="position: relative; top: 4px">' + cv[1] + '</span>';
						text = text + ' <img src="illustrationer/plus.gif" onClick="alterCookie(' + "'" + cv[0] + "'" + ',+1,' + "'" + shoptype + "'" + ');" title="en mere" style="cursor: hand">';
						text = text + '<br><img src="illustrationer/minus.gif" onClick="alterCookie(' + "'" + cv[0] + "'" + ',-1,' + "'" + shoptype + "'" + ');" title="en mindre" style="cursor: hand">';
						text = text + '</td>';
						if(shoptype=='gaver'){
							text = text + '<td align="center" style="white-space: nowrap; vertical-align: middle; font-size: 10px; line-height: 11px">' +  pris1 + '</td>';
						}
						else{
							text = text + '<td align="center" style="white-space: nowrap; vertical-align: middle; font-size: 10px; line-height: 11px">' +  pris1 + '<br>(' + pris2 + ')</td>';
						}
						text = text + "</tr>\n";
						var regExp = /\s+/g;
						text = text + '<input type="hidden" name="ordre_' + ordre.replace(regExp,'_') + '" value ="' + cv[1] + ' stk.">';
					}
				}
			}
		}
		if(text == starttext){
         if(shoptype=='gaver'){
				text = '<br><br><br><br><br><i>Der er ikke valgt<br>nogle gaver</i>';
			}
			else{
				text = '<br><br><br><br><br><i>Der er ikke valgt<br>nogle varer</i>';
			}
		}
		else{
		   normalpris = formatPrice(normalpris);
			medlemspris = formatPrice(medlemspris);
			text = text + '<tr><td colspan="3"><hr class="hr_light"></td></tr>';
			text = text + '<tr class="brod_row"><td colspan="2" style="vertical-align: middle">I alt ex. porto</td>';
 			if(shoptype=='gaver'){
				text = text + '<td align="center" style="white-space: nowrap; vertical-align: middle; font-size: 10px; line-height: 11px">' + normalpris + '</td>' + "</tr>\n";
        		text = text + '<input type="hidden" name="ordre_hjemmesidepris" value ="' + normalpris + '">';
			}
			else{
				text = text + '<td align="center" style="white-space: nowrap; vertical-align: middle; font-size: 10px; line-height: 11px">' + normalpris + '<br>(' + medlemspris + ')</td>' + "</tr>\n";
        		text = text + '<input type="hidden" name="ordre_hjemmesidepris" value ="' + normalpris + ' (' +  medlemspris + ')">';
			}
			text = text + '</table>';
		}
		document.getElementById('varekurv').innerHTML = text;
	}
}

function clearCookie(me){
	expire = new Date();
	expire.setTime(expire.getTime()-1000);
	if (document.cookie != ''){
		var meEQ = me + "=";
		document.cookie = meEQ + ';expires=' + expire + ';path=/;domain=ove.org';
	}
}

function clearVarekurv(){
	if (document.cookie != '') {
  		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
         var c = ca[i];
			while (c.charAt(0)==' '){
			   c = c.substring(1);
			}
			if(c.substr(0,6)=='ordre_'){
				var cv = c.split('=');
				me = cv[0];
				clearCookie(me);
			}
		}
  		updateVarekurv();
	}
}

function chooseImg(img,who){
	window.opener.document.getElementById(who).value = img;
   window.opener.document.getElementById('form_edit').submit();
	window.close();
}

function closeNlogin(){
	loc = window.opener.document.URL;
	window.opener.document.location = loc.substring(0,loc.indexOf('?'));
	window.close();
}

function asignMyValue(where,me){
	what = document.getElementById(me).value;
	document.getElementById(where).value = what;
}
