// -- 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 showLargeImage(url){
    NewWin(url,'image','width=100,height=100')
}

function doOtherImage(img,obj){
    document[obj].src = img;
}
function goToUrl(vUrl){
    document.location.href=vUrl
}
// -- SEARCHFORM -- //
function submitForm(obj){
    document.searchForm.submit();
}


// -- FORUM -- //
function newSubject(aID,pageID,fID){
    url="http://actions.inzites.dk/iz5Forum/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){
    urlPage="/printPage.asp?id="+iID
    winName="printWin"
    feature="width=600,height=500,scrollbars=yes,resizable=yes"
    NewWin(urlPage,winName,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(imgSrc,'largeImage')
    doOtherImage('/templ/'+stock+'.gif','stockImage'+iId)
    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 tjekForm(formName){
    if(formName=="formBet"){
    email=document.formBet.customEmail.value
        if(!IsEmail(email)){
            alert('Email skal udfyldes!');
            formBet.customEmail.select();
            return false;
        }
    payType=document.formBet.betForm[document.formBet.betForm.selectedIndex].value
        if(payType==0){
            alert('Betalingsform skal vælges!');
            return false;
        }
    }
}

function doDelBasket(){
    document.location.href='/delBasket.asp';
    return false;
}

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() { //v4.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!='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');
}

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();
}


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!")
    }
}

function NewFragt(iVal,iLand){
    if(iVal){
    document.kundeForm.plusFragt.value=iVal;
    document.kundeForm.country.value=iLand;
        for(i=0;i<document.kundeForm.elements.length;i++){
            if(document.kundeForm.elements[i].name=="secCountry"){
                document.kundeForm.secCountry.value=iLand;
    break;
            }
        }
    }
}