﻿
function gotoURL(pUrl) {
        var aUrl = pUrl.split("_atarget_");
        var tUrl = '';
        if(aUrl.length>1) {
                pUrl = aUrl[0];
                tUrl = aUrl[1];
        }
        if (tUrl == '') { 
                location.href = pUrl;
        } else {
                nWindow = window.open(pUrl,tUrl);
        }
}

/*
--------------------------------------------------------
Search
--------------------------------------------------------
*/

function postSearch(searchStr,filterCategoryObj){
        // clean up spaces around string 
        var searchStr = trimString(searchStr);
        //alert(searchStr.length);      
        var filterCategory = "";
        
       /* if(document.mainform.searchBtn != undefined){
                document.mainform.searchBtn.disabled = true;
                document.mainform.search.disabled = true;
                
        }*/
        
        if(filterCategoryObj){
                var filterCategory = filterCategoryObj.options[filterCategoryObj.options.selectedIndex].value;
        }
        if(searchStr != ''){
              document.mainform.method="post";
              document.mainform.action= "http://"+location.hostname+ "/sog.aspx?search=" + encodeURI(searchStr) + "&filter="+filterCategory;
			  document.mainform.submit();
              //alert("/sog.aspx?search="+searchStr+"&filter="+filterCategory);
              //document.getElementById("__VIEWSTATE").value='';
              //  var urllink ="http://"+location.hostname+ "/sog.aspx?search=" + encodeURI(searchStr) + "&filter="+filterCategory;
              // window.location.hash=urllink;
         }
        return false;  
}


function postSearchExtended(searchStr,filterCategoryObj, page){
        // clean up spaces around string 
        var searchStr = trimString(searchStr);
        //alert(searchStr.length);      
        var filterCategory = "";
	   
        if(filterCategoryObj){
                var filterCategory = filterCategoryObj.options[filterCategoryObj.options.selectedIndex].value;
        }
	     if(searchStr != ''){
              document.mainform.method="post";
              document.mainform.action= "http://"+location.hostname+ "/sog.aspx?search=" + encodeURI(searchStr) + "&filter="+filterCategory + "&page=" + page; 
			  document.mainform.submit();
         }
        return false;  
}


function postSearchKomplement(searchStr,filterCategoryObj){
        // clean up spaces around string 
        var searchStr = trimString(searchStr);
        //alert("http://"+location.hostname+ "/sog.aspx?search=" + encodeURI(searchStr) + "&filter="+filterCategory);      
        var filterCategory = "";
                      
        if(filterCategoryObj){
                var filterCategory = filterCategoryObj.options[filterCategoryObj.options.selectedIndex].value;
        }
        if(searchStr != ''){
              document.forms[0].method="post";
              document.forms[0].action= "http://"+location.hostname+ "/soeg.aspx?search=" + encodeURI(searchStr) + "&filter="+filterCategory;
			  document.forms[0].submit();
            }
        return false;  
}



function checkEnter(e,caller) //e is event object passed from function invocation
{

        var characterCode //literal character code will be stored in this variable

        if(e && e.which ||e.which == 0)
        { //if which property of event object is supported (NN4)
        
                e = e
                characterCode = e.which //character code is contained in NN4's which property
        }
        else
        {
                e = event
                characterCode = e.keyCode //character code is contained in IE's keyCode property
        }

        if(characterCode == 13)//if generated character code is equal to ascii 13 (if enter key)
        { 
                document.getElementById(caller).click();
                return false
        }
        else
        {
                return true
        }
                
}



function popUp(url){
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(url, '" + id + "', 'toolbars=0, scrollbars=1, location=0, statusbars=0, menubars=0, resizable=1, width=500, height=550');");

}



/*calculator */
var iakPrice = 900;
var taxTotal = 3144; 
function calculate(obj){
var price = parseInt(document.forms['mainform'].selOrganisation.value);
        
if(price == 0){
        //
alert("Vælg venligst din organisation");
        return false
}
total =  price - iakPrice;
//document.forms['mainform'].txtBesparelse.value = total;
if(total < 0){
        document.getElementById('calculatorResult').innerHTML = '<b style="color:red;">'+total+'</b> kr.';
}       
else{
        document.getElementById('calculatorResult').innerHTML = '<b style="color:green;">'+total+'</b> kr.';
}


}



function swapSearchCategory(){
title = document.getElementById("searchCategory");
table = document.getElementById("searchCategoryTable");

if(title.className == "searchCategory"){
title.className = "searchCategoryOpen";
table.className = "searchCategoryTableOpen";
}
else{
title.className = "searchCategory";
table.className = "searchCategoryTable";
}
}


// clear form fields
function clearDefault(el) {
var defaultValue = "skriv søgeord...";
if (defaultValue==el.value){el.value = "";}
}


function trimString (str) {
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}


// for parsing mail addresses
function rev(s) {
        var ns = "";
        for(var i = s.length;i > -1;i--)
          ns += s.charAt(i);
        return ns;
      }
      function em(n) {
        s = rev(":otliam\"=ferh a<");
        s += n;
        s += rev(">\"kd.kai;46#&");
        s += n;
        s += rev(">/a<kd.kai;46#&");
        document.write(s);
      }
	  
	  
	 
function getQueryStringKeyValue( name ){ 
	name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); 
	var regexS = "[\\?&]"+name+"=([^&#]*)"; 
	var regex = new RegExp( regexS ); 
	var results = regex.exec(window.location.href); 
	if( results == null ) return ""; 
	else return results[1];
}
