function gotopage(f) 
{
	var tmp = f.options[f.selectedIndex].value;
	if (tmp != "") 
        	document.location=tmp;                
}

function OpenWindow(URL, name, features) 
{
	if (navigator.appName != "Netscape")
	{
	        window.open(escape(URL).replace(/%3F/g,"?").replace(/%3D/g,"="), name, features);
	}
	else
	{
	        window.open(URL, name, features);
	}
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; 
if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) 
x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) 
x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_showHideLayers() { //v3.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { 
v=args[i+2];
    if (obj.style) { obj=obj.style; 
v=(v=='show')?'visible':(v='hide')?'hidden':v; }
    obj.visibility=v; }
}


// Sets cookie values. Expiration date is optional

function setCookie(name, value, expire) {
   document.cookie = name + "=" + escape(value)
   + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()))
}

// Notice the use of escape to encode special characters (semicolons, commas, spaces) in the value string. This
// function assumes that cookie names do not have any special characters.

// The following function returns a cookie value, given the name of the cookie:

function getCookie(name) {
   var search = name + "="
   if (document.cookie.length > 0) { // if there are any cookies
      offset = document.cookie.indexOf(search) 
      if (offset != -1) { // if cookie exists 
         offset += search.length 
         // set index of beginning of value
         end = document.cookie.indexOf(";", offset) 
         // set index of end of cookie value
         if (end == -1) 
            end = document.cookie.length
         return unescape(document.cookie.substring(offset, end))
      } 
   }
}


function getCookieValue(cookiename,fieldname) {
	cookie_array = cookiename.split(";")

	var res = -1

   for (var i=0; i < cookie_array.length; i++) {
      temp_array = cookie_array[i].split(",")
		if (temp_array[0] == fieldname)
		   res = temp_array[1]
   }

	return res
}


function update_cookie(old_cookie,id,new_value) {
	var pos = old_cookie.indexOf(id);

	if (pos != -1)
	{
			old_value = getCookieValue(old_cookie,id);

			var old_string = id + "," + old_value;
			var new_string = id + "," + new_value;

			var new_cookie = old_cookie.replace(old_string,new_string);
			return new_cookie;
	}
	else
   {
		if (new_value > 0)
		{
			return old_cookie + id + "," + new_value + ";";
		}
		else
		{
			return old_cookie;
		}
	}
}


function setShopCookie(id,q) {
   var today = new Date()
   var expires = new Date()

	var cookie_value = getCookie("EngelbrechtShop")

	if (cookie_value != null)
   {
		//		alert("cookie = " + cookie_value)
		var value = update_cookie(cookie_value,"id"+id,q)
	}
	else
		var value = "id" + id + "," + q + ";"
			
	expires.setTime(today.getTime() + 3600)
   setCookie("EngelbrechtShop", value)
}

function validate() 
{
	if (document.customerform.email.value == '' || document.customerform.navn.value == '' || document.customerform.adresse1.value == '' || document.customerform.adresse3.value == '' || document.customerform.tlf.value == '')
		alert("Udfyld venligst de obligatoriske felter");
	else
		document.customerform.submit();
}


function setValue(cookiename,formname,fieldname,index)
{
	var cookievalue = getCookieValue(getCookie(cookiename),fieldname);

	while (cookievalue.indexOf('+') != -1)
		cookievalue = cookievalue.replace("+"," ");

	document.forms[formname].elements[index].value = cookievalue;
}


function getValues(cookiename,formname)
{
	setValue(cookiename,formname,"navn",0);
	setValue(cookiename,formname,"firma",1);
	setValue(cookiename,formname,"adresse1",2);
	setValue(cookiename,formname,"adresse2",3);
	setValue(cookiename,formname,"adresse3",4);
	setValue(cookiename,formname,"land",5);
	setValue(cookiename,formname,"tlf",6);
	setValue(cookiename,formname,"fax",7);
	setValue(cookiename,formname,"email",8);
}


