// JavaScript Document

// Indsat af Hanert og Anthony - Bruges af File Upload with Javascript
function windowOpenCms(strCms){
      var popUrl=new String(strCms.pophref)
      var popParam=new String(strCms.popparam)
      window.open(popUrl,'PostDanmark',popParam)
    }

// Fjernet af Hanert - per 7/7 erstattes denne af ovenstaende
//function windowOpenCms(strCms){
//        var popTempLocale=""
//	var popString=new String(strCms.hreflang)
//	var popLocale=new String(document.location)
//	if(popLocale.indexOf("da-dk")>-1){
//	    popTempLocale="/cms/da-dk/files/"
//	}else if(popLocale.indexOf("en-us")>-1){
//	    popTempLocale="/cms/en-us/files/"	
//	}else{
//	    popTempLocale=""	
//	}	
//	var popSplit=popString.split("?")
//	var popUrl=popSplit[0]
//	var popTmpSplit=popSplit[1].replace(/\&/g,",")
//	popTmpSplit=popTmpSplit.replace(/\=\,/g,"=1,")
//	popTmpSplit=popTmpSplit.replace(/width\=1\,/g,"width=800,")
//	popTmpSplit=popTmpSplit.replace(/height\=1\,/g,"height=600,")
//	var theWidth=popTmpSplit.match(/width\=(\d+)/)
//	theWidth=theWidth[1]
//	var theHeight=popTmpSplit.match(/height\=(\d+)/)
//    theHeight=theHeight[1]
//	var leftpos = (screen.width - theWidth) / 2;
//    var toppos = (screen.height - theHeight) / 2;
//	var param = popTmpSplit+",left="+leftpos+",top="+toppos
//	window.open(popTempLocale+popUrl,'PostDanmark',param)
//     
//}

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 MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}


function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function MM_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage; }}
  else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) location.reload();
}
MM_reloadPage(true);

function MM_findObj(n, d) { //v4.01
  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);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.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; }
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}



function printPage(){
	window.print();
}


function sendUrl(theUrl,theMenu){
  if (theMenu.length != 1) {
    sendUrlFull('/content.dk?content=' + theUrl + '&menufile=' + theMenu);
  }else{
    if (theUrl && (theUrl.length>0)){ 
      top.contentframe.content.location = theUrl;
     }
  }
} 

function sendUrlFull(theUrl){
   if (theUrl && (theUrl.length>0)){
      top.contentframe.location = theUrl;
   }
} 

// ''''''''''''''''''''''''''''''''''''''''''''
//
// ?ldre version af Trach & Trace Javascript, skiftet ud ned nyt script den 21. juli 2004.
// 
// ''''''''''''''''''''''''''''''''''''''''''''
//
// function dd(){
//  var tretten = 13;
//  var lengde = document.podAdvanced.i_stregkode.value.length;
//  var x = document.podAdvanced.i_stregkode.value;
//  var x1 = x.substring(lengde-2,lengde);

//  if(document.podAdvanced.i_stregkode.value == null || lengde == 0){
//      alert("Feltet skal udfyldes inden sgning startes");
//      document.podAdvanced.i_stregkode.focus();
//      return;
//  }

//  if(parseInt(lengde) < parseInt(tretten)){
//     alert("Stregkoden m ikke vre mindre end 13 tegn");
//     document.podAdvanced.i_stregkode.focus();
//     return;
//  }

//  if(parseInt(lengde) == parseInt(tretten)){
//      var sKode = document.podAdvanced.i_stregkode.value;
//      var sKode1 = sKode.substr(2,9);

//      if (sKode1.match(/^\d{9}$/) == null) {
//          alert("En 13 tegns stregkode skal indeholde cifre i postion 3 - 11");
//          document.podAdvanced.i_stregkode.focus();
//          return;
//      }

//      var sKode2 = sKode.substr(11,12);

//      if(sKode2.match(/[a-zA-Z]{2}/) == null){
//        alert("En 13 tegns stregkode skal indeholde bogstaver i position 12 og 13");
//          document.podAdvanced.i_stregkode.focus();
//          return;
//      }
//  }

//  document.podAdvanced.i_lang.value = "IND";
//  document.podAdvanced.sourceurl.value = "http://www.post.dk/posthuset/track_and_trace/index.asp";
//  document.podAdvanced.action = "http://193.3.125.100/jsp/podIndex.jsp";
//  document.podAdvanced.submit();
// }

function dd() { 
  if(document.podAdvanced.i_stregkode.value == null || document.podAdvanced.i_stregkode.value == "Indtast T&T nr." || lengde == 0){
      alert("Feltet skal udfyldes inden sogning startes");
      document.podAdvanced.i_stregkode.focus();
			return;
  }
  
  document.podAdvanced.i_stregkode.value = stripNoneLetterNumeral(document.podAdvanced.i_stregkode.value);
  var tretten = 13;
  var lengde = document.podAdvanced.i_stregkode.value.length;

  var x = document.podAdvanced.i_stregkode.value;
  var x1 = x.substring(lengde-2,lengde);
  
 
  if ( parseInt(lengde) < parseInt(tretten) ) {
     alert("Stregkoden må ikke være mindre end 13 tegn");
     document.podAdvanced.i_stregkode.focus();
     return;
  }

  if (parseInt(lengde) == parseInt(tretten)) {  
      var sKode = document.podAdvanced.i_stregkode.value;
      var sKode1 = sKode.substr(2,9);
      
      if  (sKode1.match(/^\d{9}$/) == null) {
		      alert("En 13 tegns stregkode skal indeholde cifre i postion 3 - 11");
          document.podAdvanced.i_stregkode.focus();
          return;
      }

      var sKode2 = sKode.substr(11,12);

      if  (sKode2.match(/[a-zA-Z]{2}/) == null) {
    		  alert("En 13 tegns stregkode skal indeholde bogstaver i position 12 og 13");
          document.podAdvanced.i_stregkode.focus();
          return;
      }
  }

  if (document.podAdvanced.i_lang.value == "") 
  	document.podAdvanced.i_lang.value = "IND";
  //document.podAdvanced.sourceurl.value = "index.html";
  document.podAdvanced.action = "/tracktrace/TrackTrace.do";
  document.podAdvanced.submit();
}

function validateTrackAndTrace() { 

	var f=document.TrackTraceForm;
	if(f.i_stregkode.value!="" && f.customerId.value=="" && f.referenceId.value==""){
		if(f.i_stregkode.value==""){
			if(f.i_lang.value=="INE"){
				  alert("Please fill in the field prior to starting a search");
			}else{
				alert("Feltet skal udfyldes inden s\370gning startes");
			};
			f.i_stregkode.focus();
			return false;
		  }else if(f.i_stregkode.value.length<13 || f.i_stregkode.value.length>35){
			if(f.i_lang.value=="INE"){
				 alert("The Barcode is between 13 and 35 characters long");
			}else{
				alert("Stregkoden skal v\346re mellem 13 og 35 tegn");
			};
			
			f.i_stregkode.focus();
			return false;
		  }else if(f.i_stregkode.value.length==13 && isNaN(f.i_stregkode.value.substring(2,11))){
		  	
			if(f.i_lang.value=="INE"){
				alert("A 13 character barcode must contain numbers only in postions 3 to 11");
			}else{
				alert("En 13 tegns stregkode skal indeholde cifre i postion 3 - 11");
			};
			f.i_stregkode.focus();
			return false; 
		  };
	}else if(f.i_stregkode.value=="" && f.customerId.value!="" && f.referenceId.value!=""){
		  if (f.customerId.value.length!=9) {
		      alert("Kundenummer skal v\346re på 9 cifre.");
		      f.customerId.focus();
			  return false;
		  };
	 	  
	 	  if(f.referenceId.value == null || f.referenceId.value.length == 0){
		      alert("Reference skal udfyldes inden s\370gning startes");
		      f.referenceId.focus();
			  return false;
		  };
	}else if(f.i_stregkode.value=="" && f.customerId.value=="" && f.referenceId.value!=""){
		  
		     alert("Kundenummer skal udfyldes inden s\370gning startes");
		      f.customerId.focus();
			  return false;
		 
	}else if(f.i_stregkode.value=="" && f.customerId.value!="" && f.referenceId.value==""){
		  
		      alert("Reference skal udfyldes inden s\370gning startes");
		      f.referenceId.focus();
			  return false;
		    
	}else if(f.i_stregkode.value=="" && f.customerId.value=="" && f.referenceId.value==""){
		if(f.i_lang.value=="INE"){
				  alert("Please fill in the field prior to starting a search");
			}else{
				alert("Feltet skal udfyldes inden s\370gning startes");
			};
			 return false;
	}else if(f.i_stregkode.value!="" && f.customerId.value=="" && f.referenceId.value!=""){
		if(f.i_lang.value=="INE"){
				  alert("Please fill in the field prior to starting a search");
			}else{
				alert("Feltet skal udfyldes inden s\370gning startes");
			};
			 return false;		 
	};
	
	
};



function dduk()
{ 
  var tretten = 13;
  var lengde = document.podAdvanced.i_stregkode.value.length;

  var x = document.podAdvanced.i_stregkode.value;
  var x1 = x.substring(lengde-2,lengde);

  if (document.podAdvanced.i_stregkode.value == null || lengde == 0)
  {
      alert("Please fill in the field prior to starting a search");
      document.podAdvanced.i_stregkode.focus();
      return;
  }
 
  if ( parseInt(lengde) < parseInt(tretten) )
  {
     alert("Barcodes can't be less than 13 characters in length");
     document.podAdvanced.i_stregkode.focus();
     return;
  }

  if (parseInt(lengde) == parseInt(tretten))
  {  
      var sKode = document.podAdvanced.i_stregkode.value;
      var sKode1 = sKode.substr(2,9);
      
      if  (sKode1.match(/^\d{9}$/) == null)
      {
					alert("A 13 character barcode must contain numbers only in postions 3 to 11");
					document.podAdvanced.i_stregkode.focus();
          return;
      }

      var sKode2 = sKode.substr(11,12);

      if  (sKode2.match(/[a-zA-Z]{2}/) == null)
      {
		      alert("A 13 character barcode must contain letters only in positions 12 and 13");
          document.podAdvanced.i_stregkode.focus();
          return;
      }
  }

  document.podAdvanced.i_lang.value = "INE";
  document.podAdvanced.sourceurl.value = "/tracktrace/indexUK.htm";
  document.podAdvanced.action = "/tracktrace/TrackTrace.do";
  

  document.podAdvanced.submit();
}

function stripNoneLetterNumeral(value) {
	var result = "";
	var tegn = "";
	
	for (var i=0; i<value.length; i++) {
		tegn = value.substring(i, i+1);
		if  (tegn.match(/[a-zA-Z0-9]/)) {
			result += tegn;
		}
	}
	
	return result;
}


<!--nedstende funktion er kun til formular submit-->

n = (document.layers) ? 1:0;


   
   function switchLayout(menu,contents)
   {
      if (menu=="open")
         parent.menu.location.href = "/ekom/menu.html";
      else
         parent.menu.location.href = "/ekom/menu.html?logon";
      
      location.href = contents;
   }
   
   function forceLogin(who)
   {
      who.location.href = "/ekom/login.ni";
   }

   function selfRegistration(who)
   {
      who.location.href = "/ekom/html/selvreg.htm";   
   }
   
   function serverURI(do_ssl)
   {
      return ("http://localhost");
   }
   
   function loginURI(addon)
   {
      return (addon);
   }

   function gotoLoginURI(win,addon)
   {
      win.location.href = addon;
   }

   function showGuide()
   {
//      var swf = window.open('/ekom/swfdemo/page1.jsp','winGuide','width=600,height=385,status=yes,scrolling=no');
//      swf.focus();
      openCenteredWindow("/ekom/swfdemo/page1.jsp","winGuide",600,385,"status=yes,scrollbars=no");
   }
   
   function showEBoksDemo()
   {
      var eBoksDemoWindow = window.open('/ekom/eboks/demo/default.htm', 'Demo', 'height=430,width=610,left=200,top=100,scrollbars=no,resizable=no');
      eBoksDemoWindow.focus();
   }
   
function submitFindPostnummer(){
   	if(document.AddressQuery.searchString.value==""){
   		alert("Find postnummeret - feltet ma ikke v?re tomt.")
   		return false;
   	}else{	  
   	   document.AddressQuery.submit();
    }
}

function getEcomSpecialPage(){ //til at vise en speciel eKom index side, af JTJ
	var theDomain=document.domain
	try {
		if(parent.location=="https://"+theDomain+"/ekom/mitEPosthus.ni"){
	
			var objTable=document.getElementsByTagName("Table")
			var objTd=document.getElementsByTagName("TD")
			var strTempTable=objTable[1].innerHTML
			strTempTable=strTempTable.replace(objTd[5].innerHTML,"<img height=187 src=/cms/web_resources/images/spacer.gif width=1>")
			parent.container=strTempTable
			parent.viewEcomSpecialPage()
		}
	}
	catch(strErrorMsg) {} 
}
setTimeout("getEcomSpecialPage()",1000) 

//----frameset killer & builder by jtj
	//try {top.document.domain}
	//catch(errorObject){top.location=document.location}
	
if(parent.frames.length==0){
	var doc=document.location.href.toLowerCase()
	if(doc.indexOf("/cms/")>-1 && doc.indexOf("-pf")==-1 && doc.indexOf("/dmmicrosite/")==-1 && doc.indexOf("/intraposten/")==-1 && doc.indexOf("/kampagneeffekt/")==-1){
		var postUrl=""
		var theProtocol
		var validateUrl
		if(doc.indexOf("http://")>-1){
			theProtocol="http://"
		}else if(doc.indexOf("https://")>-1){
			theProtocol="https://"
		}
		doc=doc.replace(theProtocol+document.domain,"")
		validateUrl=doc.replace("/cms/","")
		if(validateUrl.length>6){
			if(doc.indexOf("pdkframeset=no")==-1){
				if(doc.indexOf("/cms/da-dk/eposthuset/")>-1){
					postUrl=theProtocol+document.domain+"/contentfull.dk?content="+doc+"&menufile=/cms/da-dk/menufiles/ekom_open_menu.xml&lang=dk"
				}else if(doc.indexOf("/cms/da-dk/erhverv/")>-1){
					postUrl=theProtocol+document.domain+"/contentfull.dk?content="+doc+"&menufile=/cms/da-dk/menufiles/erhverv.xml&lang=dk"
				}else if(doc.indexOf("/cms/da-dk/kontaktos/")>-1){
					postUrl=theProtocol+document.domain+"/contentfull.dk?content="+doc+"&menufile=/cms/da-dk/menufiles/kontaktos.xml&lang=dk"
				}else if(doc.indexOf("/cms/da-dk/presse/")>-1){
					postUrl=theProtocol+document.domain+"/contentfull.dk?content="+doc+"&menufile=/cms/da-dk/menufiles/presse.xml&lang=dk"
				}else if(doc.indexOf("/iis/postjobs/")>-1){
					postUrl=theProtocol+document.domain+"/postjobs.dk?content="+doc
				}else if(doc.indexOf("/cms/da-dk/ompostdanmark/")>-1){
					postUrl=theProtocol+document.domain+"/contentfull.dk?content="+doc+"&menufile=/cms/da-dk/menufiles/ompostdanmark.xml&lang=dk"
				}else if(doc.indexOf("/cms/en-us/private/")>-1){
					postUrl=theProtocol+document.domain+"/contentfull.dk?content="+doc+"&menufile=/cms/en-us/menufiles/private.xml&lang=en"
				}else if(doc.indexOf("/cms/en-us/business/")>-1){
					postUrl=theProtocol+document.domain+"/contentfull.dk?content="+doc+"&menufile=/cms/en-us/menufiles/business.xml&lang=en"
				}else if(doc.indexOf("/cms/en-us/contact/")>-1){
					postUrl=theProtocol+document.domain+"/contentfull.dk?content="+doc+"&menufile=/cms/en-us/menufiles/contact.xml&lang=en"
				}else if(doc.indexOf("/cms/en-us/press/")>-1){
					postUrl=theProtocol+document.domain+"/contentfull.dk?content="+doc+"&menufile=/cms/en-us/menufiles/press.xml&lang=en"
				}else if(doc.indexOf("/cms/en-us/aboutus/")>-1){
					postUrl=theProtocol+document.domain+"/contentfull.dk?content="+doc+"&menufile=/cms/en-us/menufiles/aboutus.xml&lang=en"
				}else{
					postUrl=theProtocol+document.domain+"/contentfull.dk?content="+doc+"&menufile="
				}
				top.location=postUrl
			}
		}
	}
}


//----frameset killer & builder end
function openerWindow(theUrl,theName,theProp){
    var SCRW = screen.width;
    var SCRH = screen.height;
    var centerSCRW=SCRW/2
    var centerSCRH=SCRH/2
    
    arraytheProp = new Array("width=","height=","left=","top=")
        if(theProp=="ebox"){
            var W = parseInt(SCRW/10);
            var H = parseInt(SCRH/10);
            var screenW = SCRW-W;
            var screenH = SCRH-H-150;
            var Wpos = parseInt(W/2);
            var Hpos = parseInt(H/2);
            
            theProp="toolbar=yes,location=yes,directories=yes,status=yes,menubar=yes,scrollbars=yes,resizable=yes,width="+ screenW + ",height=" + screenH + ",left=" + Wpos + ",top="+Hpos
        }else{
            if(theProp.indexOf("width=")==-1){
                theProp=theProp+",width=800"
            }
            if(theProp.indexOf("height=")==-1){
                theProp=theProp+",height=600"
            }
            if(theProp.indexOf("left=")==-1){
                theProp=theProp+",left=0"
            } 
            if(theProp.indexOf("top=")==-1){
                theProp=theProp+",top=0,"
            }
            for(x=0;x<arraytheProp.length;x++){
                if(theProp.indexOf(arraytheProp[x])>-1){
                    startIndex=theProp.indexOf(arraytheProp[x],0)
                    endIndex=theProp.indexOf(",",startIndex)
                        if(x==0){
                            theWidth=theProp.substring(startIndex+arraytheProp[x].length,endIndex);
                            var centertheWidth=theWidth/2;
                            var Wpos = centerSCRW-centertheWidth;
                        }
                        if(x==1){
                            theHeight=theProp.substring(startIndex+arraytheProp[x].length,endIndex);
                            var centertheHeight=theHeight/2;
                            var Hpos = centerSCRH-centertheHeight;
                        }
                        if(x==2){
                            theProp=theProp.replace(theProp.substring(startIndex,endIndex),"left="+Wpos)
                        }
                        if(x==3){
                            theProp=theProp.replace(theProp.substring(startIndex,endIndex),"top="+Hpos)
                        }   
                }
            }
        }
        
    pdkopener=window.open(theUrl,theName,theProp);
    if(!pdkopener){
        alert("Slå din pop-up til");
    };
}