/* Script to check if dev cookie exists */
function chkDev() {
  if (document.cookie.length>0) {
    if (document.cookie.indexOf("dev=")!=-1) {
      return true;
    }
    else {
      return false;
    }
  }
}

/* Script to swap language */
function setLang(value) {
  var exdate=new Date();
  var exdays=400;
  exdate.setDate(exdate.getDate() + exdays);
  var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString())+ "; path=/";
  document.cookie='lang' + "=" + c_value; 
  
  switch(value) {
    case 'sv':
      value = 'SE';
      break;
    case 'en':
      value = 'GB';
      break;
    case 'de':
      value = 'D';
      break;
    case 'nl':
      value = 'NL';
      break;
    default:
      value = value.toUpperCase();
  }

  var loc = window.location;
  var prefix = loc.pathname.substr(0,4)

  /* Clean up old cookie in sub-path after programming mistake */
  document.cookie='lang' + "=" + c_value; 
  switch(prefix) {
    case '/D/D':
    case '/NL/':
    case '/SE/':
    case '/GB/':
      document.cookie='lang' + "=" + escape(value) + "; expires=Thu, 01-Jan-1970 00:00:01 GMT"; 
  }

  /* Switch language page */
  switch(prefix) {
    case '/':
    case '/ind':
      var newURL = loc.href;
      break;    
    case '/D/D':
      var newPathname = value +"/" + value + loc.pathname.substr(4);
      var newURL = loc.protocol + "//" + loc.host + "/" + newPathname + loc.search + loc.hash;
      break;
    default:
      var newPathname = value +"/" + value + loc.pathname.substr(6);
      var newURL = loc.protocol + "//" + loc.host + "/" + newPathname + loc.search + loc.hash;
  }
  if (newURL==loc.href) {
    loc.reload(true);
  } else {
    loc.replace( newURL );
  }    
} 



/* Script by unknown
 * Preload images on page
 */
 
function FP_preloadImgs() {//v1.0
 var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
 for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
}

function FP_swapImgRestore() {//v1.0
 var doc=document,i; if(doc.$imgSwaps) { for(i=0;i<doc.$imgSwaps.length;i++) {
  var elm=doc.$imgSwaps[i]; if(elm) { elm.src=elm.$src; elm.$src=null; } } 
  doc.$imgSwaps=null; }
}

function FP_swapImg() {//v1.0
 var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
 n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
 elm.$src=elm.src; elm.src=args[n+1]; } }
}

function FP_getObjectByID(id,o) {//v1.0
 var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
 else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
 if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
 for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
 f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
 for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
 return null;
}

function popup(folder,bestand,b,h) {
  var loc=""+folder+"/"+bestand;
  var parameters="toolbar=no,scrollbars=no,location=no,status=no,menubar=no,resizable=yes,top=0,left=0,width="+b+",height="+h;
  foto = window.open("","pic",parameters);
  foto.moveTo((screen.availWidth-b)/2, (screen.availHeight-h)/2);
  foto.document.write("<html><head><title>:: Pic - "+bestand+" ::</title></head>");
  foto.document.write("<style>body { margin: 0px;overflow: hidden; }</style>");
  foto.document.write("<body><a href='javascript:window.close();' title='[Click to close]'><img src='"+loc+"' border='0' height="+h+"></a></body></html>");
  foto.document.close();
}
