// -- MENU FUNKTION TIL IE //
sfHover = function() {
    if(document.getElementById("nav")){
        var sfEls = document.getElementById("nav").getElementsByTagName("LI");
        for (var i=0; i<sfEls.length; i++) {
            sfEls[i].onmouseover=function() {
                this.className+=" sfhover";
            }
            sfEls[i].onmouseout=function() {
                this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
            }
        }
    }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);
function chgImg(obj,img){
    document.getElementById(obj).src = img;
}
// -- MENU END --//

function NewWin(url,name,feature){
    window.open(url,name,feature);
}

function doOtherImage(img,obj){
    document[obj].src = img;
    LBimg=img.replace('_b','_m')
    try{
    document.getElementById('lbHref').href = LBimg;}
    catch(e){}
}
function doOtherLBImage(img){
    document.getElementById('lightboxImage').src = img;
}
function showLargeImage(imgUrl){
    NewWin(imgUrl,'largeImage','width=500,height=500');
}

function goToUrl(vUrl){
    document.location.href=vUrl
}
// -- DOKUMENT HØJDE -- //
function getDocHeight(doc) {
  var docHt = 0, sh, oh;
  if (doc.height) docHt = doc.height;
  else if (doc.body) {
    if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
    if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
    if (sh && oh) docHt = Math.max(sh, oh);
  }
  return docHt;
}
// -- SET HØJDE PÅ IFRAME (f.eks profil-sider) -- //
function setIframeHeight(iframeName,minHeight) {
  var iframeWin = window.frames[iframeName];
  var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
  if ( iframeEl && iframeWin ) {
    iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous  

    var docHt = getDocHeight(iframeWin.document);
	var minHeight=minHeight
	if(docHt<minHeight)docHt=minHeight;
    // need to add to height to be sure it will all show
    if (docHt) iframeEl.style.height = docHt + 30 + "px";
  }
}
//


// -- SEARCHFORM -- //
function submitForm(obj){
    document.searchForm.submit();
}

// -- FORUM -- //
function newSubject(aID,pageID,fID){
    url="/forum/new.asp?id="+pageID+"&fID="+fID+"&aID="+aID
    feature="width=500,height=500"
    window.open(url,"newForum",feature);
}

// -- LOGIN FORM -- //
function tjekLoginForm(){
    if(document.loginForm.userName.value=="" || document.loginForm.pwd.value==""){
        alert("Brugernavn og Password skal udfyldes!")
        return false;
    }
}

function printPage(iID){
    url="/printPage.asp?id="+iID
    name="win"
    feature="width=600,height=500,scrollbars=yes,resizable=yes"
    window.open(url,name,feature);
}

// -- PRODUKTER SYSTEMER -- //
function checkStockPrice(iVal){
    // ID€antal|pris|systemPris|mainProductsID|vareNummer|lagerStatus //
    spIval=iVal.split("|");
    iId=spIval[3]
    imgSrc="/image/products/"+spIval[4]+"_1_b.jpg"
    stock=spIval[5]
    iPrice=spIval[1]
    doOtherImage('/templ/'+stock+'.gif','stockImage'+iId)
    doOtherImage(imgSrc,'largeImage')
    setSystemIDs();
}

function setSystemIDs(){
    var newPrice=0
    var allSystemIDs=""
    var delimiter=""
    prisFelter=document.getElementsByName("sysaID")
    for(i=0;i<prisFelter.length;i++){
        if(prisFelter[i].tagName=="select"){
            spValue=prisFelter[i].options(prisFelter[i].selectedIndex).value.split("|")
        }else{
            spValue=prisFelter[i].value.split("|")
        }
        allSystemIDs=allSystemIDs+delimiter+spValue[0]
        splitSystem=spValue[0].split("€"); antal=splitSystem[1]
        newPrice=newPrice+eval(spValue[1]*antal)
        delimiter=";"
        systemPris=spValue[2]
    }
    document.basketForm.systemIDs.value=allSystemIDs
    systemRabat=document.basketForm.vareSystemRabat.value
    newPrice=newPrice-eval(systemRabat)
    newSystemPrice.innerHTML=newPrice;
    if(newPrice!=systemPris){newPriceTable.style.display=""}else{newPriceTable.style.display="none"}
}


function IsEmail(emailStr){
  var regex =/^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]{1,}[.][a-z]{2,4}$/
  return (regex.exec(emailStr)!=null)
}

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_validateForm() { //v5.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; ed=args[i+1];val1=val ;nm1 = nm.split("_"); if ((val=val.value)!=""){
      if (test.indexOf('isEmail')!=-1) {
        if (!IsEmail(val)) errors+='- '+ed+'\n';
      }else if (test.indexOf('isChecked')!=-1){// val1=boxens navn - ed=alert , ex. "'mybox','Kryds af!','RisChecked'
           if(!val1.checked) errors+='- '+ed+'\n';
      }else if (test.indexOf('isSelect')!=-1){// val1=boxens navn - ed=alert , ex. "'myList','Vælg!','RisSelect'
           if(!val1.selectedIndex) errors+='- '+ed+'\n';
      }else if (test!='R'){ 
         num = parseFloat(val);
          if (isNaN(val)) errors+='- '+ed+'\n';
          if (test.indexOf('inRange') != -1) { 
            p=test.indexOf(':');
            min=test.substring(8,p); max=test.substring(p+1);
            if (num<min || max<num) errors+='- '+ed+'\n';
          } 
      }
    }else if(test.charAt(0) == 'R') errors += '- '+ed+'\n'; }
  } 
  if (errors) alert('!!!\n'+errors);
  document.MM_returnValue = (errors == '');
}

function doVaelgDato(tf){
    window.open('files/vaelgDato.asp?tf='+tf,'','width=250,height=250');
}

function expandThread(threadID){
    if(document.all["I"+threadID+"Z"].style.display=="none"){
    document.all["I"+threadID+"Z"].style.display="block";
    }else{
    document.all["I"+threadID+"Z"].style.display="none";
    }
}

function addRemoveCompare(iVal,iStatus){
    myForm=document.compare
    allProd=myForm.products.value
    if(myForm.products.value==""){
    allProd="," //+myForm.products.value
    }    
    thisVal=iVal+","
    if(iStatus){
    myForm.products.value=allProd+thisVal
    }else{
    myForm.products.value=allProd.replace(thisVal,"")
    }
}

function compareProducts(){
    var leftPos=(screen.availWidth-500) / 2
    var topPos=(screen.availHeight-500) / 2 
    products=document.compare.products.value;
    tID=document.compare.templateID.value;
    pID=document.compare.pageID.value;
    if((products!="")&&(products!=",")){
    window.open('/config/compare.asp?pID='+pID+'&tID='+tID+'&prod='+products,'Compare','width=500,height=500,scrollbars=yes,resizable=yes,left='+leftPos+',top='+topPos)
    }else{
    alert("Du skal vælge mindst 2 produkter!")
    }
}

// BASKET //
function doDelBasket(){
    document.location.href='/delBasket.asp';
    return false;
}
function updateBetText(iVal){
    document.kundeForm.betFormText.value=iVal
}
function NewFragt(iVal,iLand){
    if(iVal){
    document.kundeForm.plusFragt.value=iVal;
    document.kundeForm.country.value=iLand;
    }
}
var paywin = null;
function payPopup(f) {
  paywin = window.open('', 'Betaling', 'scrollbars,status,width=800,height=600,resizable=yes');
  paywin .focus();
  if (!self.name) self.name = 'shopwin';
  if (!paywin .opener) paywin.opener = self;
  f.opener.value = self.name;
  return true;
}
function eDankortRouter(form) {
    var oHeight = 0;
    var oWidth = 0;
    var iHeight = 300;
    var iWidth = 350;
    var iLeft = 0;
    var iTop = 0;

    oHeight = top.window.screen.availHeight;
    oWidth = top.window.screen.availWidth;
    if(oHeight > 3*iHeight)
        iHeight = oHeight/3;
    if(oWidth > 3*iWidth)
        iWidth = oWidth/3;
    if(oWidth > iWidth)
        iLeft = (oWidth - iWidth)/2;
    if(oHeight > iHeight)
        iTop = (oHeight - iHeight)/2;

    window.open('','router','scrollbars=yes,toolbar=no,directories=no,menubar=no,resizable=no,status=yes,width='
        + iWidth + ',height=' + iHeight + ',left='
        + iLeft + ',top=' +iTop +'dependent=yes');
    form.target = 'router';
    form.submit();
}
