var invLines=0;
var cornerImages = new Array();
var is;

//browser detection
function Is() {
    var agent = navigator.userAgent.toLowerCase();
    this.major = parseInt(navigator.appVersion);
    this.minor = parseFloat(navigator.appVersion);
    this.ns  = ((agent.indexOf('mozilla')!=-1) && ((agent.indexOf('spoofer')==-1) && (agent.indexOf('compatible') == -1)));
    this.ns2 = (this.ns && (this.major == 2));
    this.ns3 = (this.ns && (this.major == 3));
    this.ns4b = (this.ns && (this.minor < 4.04));
    this.ns4 = (this.ns && (this.major >= 4));
    this.ie   = (agent.indexOf("msie") != -1);
    this.ie3  = (this.ie && (this.major == 2));
    this.ie4  = (this.ie && (this.major >= 4));
    this.op3 = (agent.indexOf("opera") != -1);
    this.win   = (agent.indexOf("win")!=-1);
    this.mac   = (agent.indexOf("mac")!=-1);
    this.unix  = (agent.indexOf("x11")!=-1);
}

is = new Is();



	function makeTools(lang){
		var retStr="";
			if(lang=="dk"){
				retStr+="<a href='javascript:printPage()' class='tools'>print</a><br>"
				retStr+="<a href='#' class='tools'>Kontakt</a><br>"
				retStr+="<a href='javascript:openLogin()' class='tools'>login</a>"
				document.write(retStr);
				return false;
			}
			
	}


	function signupNewsletter(){
			frm = document.getElementById("signupFrm")
			
			m = document.getElementById("email")
			
			if(m.value == ""){
				m.focus();
				m.style.borderColor="red"
				return false;
			}else{
				m.style.borderColor=""
			}
			
			if(m.value == "" || m.value.indexOf("@")==-1){
				m.focus();
				m.style.borderColor="red"
				return false
			}else{
				m.style.borderColor=""
			}
			
			frm.submit();
		}
			


	
	function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
	}
	
function printPage(){
	MM_openBrWindow('/print.asp','print','scrollbars=yes,resizable=yes,width=650,height=650')	
}

function openSitemap(){
	MM_openBrWindow('/mod_inc/?p=siteMap&thisPage=','siteMap','scrollbars=yes,resizable=yes,width=440,height=550')	
}

function checkSendToFriend(){
	mailObj=getObj('reciever-mail');
	nameObj=getObj('sender-name');
	bodyObj=getObj('mailbody');
	
	if(mailObj.value=="" || mailObj.value.indexOf('@')<1 ){
		globStatus=false
		alert('Feltet: "Vens email" skal indeholde en gyldig email');
		mailObj.focus();
		return false
	}
	
	if(nameObj.value==""){
		globStatus=false
		alert('Feltet: "Dit navn" skal udfyldes!');
		nameObj.focus();
		return false
	}	
	bodyObj.value=bodyObj.value.replace(/%name%/,nameObj.value);
	
	return true;
}

function sendToFriend()
{
	MM_openBrWindow('/sendtoFriend.asp?extUrl='+document.location,'sendToFriend','scrollbars=yes,resizable=yes,width=236,height=190')
}

function getCookieByName(sName)
{
  
  // cookies are separated by semicolons
  
  var aCookie = document.cookie.split("; ");
  
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return "";
}

function setCookie(name,value){
	removeCookiebyName(name);
	document.cookie = name + "=" + value + ";"
}

function removeCookiebyName(sName)
{
	
  // cookies are separated by semicolons
  
  var aCookie = document.cookie.split("; ");
  var returnArr = new Array();
  var cookieStr = "";
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName != aCrumb[0]) 
      returnArr[returnArr.lenght]= aCookie[i]
  }
	cookieStr = aCookie.join("; ")
	document.cookie = cookieStr
}


function hndlInp(obj,state){
	if(state){
		obj.className = obj.className+"Active"	
	}else{
		obj.className = obj.className.toString().replace(/Active/gi,"")
	}
}

function zoom(){			
	var exp = new Date()
	expCalc = exp.getTime() + (7*24*60*60);
	exp.setTime(expCalc);
	if(document.cookie.indexOf("zoomed=true")>-1){
		document.body.style.zoom="100%"
		document.cookie = "zoomed=false; expires=" + exp.toGMTString();
		document.getElementById("zoomIcon").src="/gfx/icons/zoomIn.gif"
	}else{
		document.body.style.zoom="150%"
		document.cookie = "zoomed=true; expires=" + exp.toGMTString();
		document.getElementById("zoomIcon").src="/gfx/icons/zoomOut.gif"
	}
}

function openLogin(obj){
	MM_openBrWindow('/loginExtranet.asp','extranetlogin','scrollbars=no,resizable=no,width=289,height=266')
}

	function popBasket(){
			MM_openBrWindow("/mod_inc/?p=showBasket&templateFile=popbasket",'basket','scrollbars=yes,resizable=yes,width=320,height=390')
	}
	
function sendPassword(){
			MM_openBrWindow("/sendPassword.asp",'basket','scrollbars=yes,resizable=yes,width=300,height=200')
	}

function zoom(){			
	var exp = new Date()
	expCalc = exp.getTime() + (7*24*60*60);
	exp.setTime(expCalc);
	if(document.cookie.indexOf("zoomed=true")>-1){
		document.body.style.zoom="100%"
		document.cookie = "zoomed=false; expires=" + exp.toGMTString() + "; path=/";
		document.getElementById("zoomIcon").src="/gfx/icons/zoomIn.gif"
	}else{
		document.body.style.zoom="150%"
		document.cookie = "zoomed=true; expires=" + exp.toGMTString() + "; path=/";
		document.getElementById("zoomIcon").src="/gfx/icons/zoomOut.gif"
	}
}

function documentLoaded(){
	//set zoom level 
	
}


function popWin(url,width,height){
	MM_openBrWindow(url,'siteMap','scrollbars=yes,resizable=yes,width='+width+',height='+height)	
}





	function bannerObj(){
		this.imgs = new Array();
		this.imgsrc = new Array();
		this.img = 0;
		this.filterStr = "";
		this.timeBetween = 0;
		this.htmlImage=null
		this.width = 0;
		this.height = 0;
		
		this.addImage = __addBannerImage;
		this.start = __startBanner;
		
		this.changeBanner = __changeBanner;
		
		this.timer=null
		return this;
	}
	
	function __addBannerImage(src){
		this.imgsrc[this.imgsrc.length] = src;
	}
	
	function __startBanner(){
		var dStr
		if(this.htmlImage!=null){
		this.img==-1 ? this.img = parseInt(Math.random() * this.imgsrc.length):null;
		
		this.img > this.imgsrc.length ? this.img=0:null;
		//preload images
		for(i=this.img;i<this.imgsrc.length;i++){
			this.imgs[i]=new Image();
			this.imgs[i].src=this.imgsrc[i];
			dStr+="\n"+this.imgs[i].src
		}

		for(i=0;i<this.img;i++){
			this.imgs[i]=new Image();
			this.imgs[i].src=this.imgsrc[i];
			dStr+="\n"+this.imgs[i].src
		}
		//preload Images END
		this.htmlImage.src = this.imgs[this.img].src
		obj=this

		this.changeBanner(obj)
		}
	}
	
	function __changeBanner(obj){
		if(this.htmlImage){
			if(document.all){
				this.htmlImage.style.filter=this.filterStr;
				this.htmlImage.filters[0].apply();
				this.htmlImage.src=this.imgs[this.img].src;
				this.htmlImage.filters[0].play();
				this.img++
			}
			if(this.img == this.imgs.length){
				this.img=0
			}
		}
		
		//window.setTimeout("__changeBanner(obj)",obj.timeBetween)
	}
	
	
		 
function getCoords (element) {
		var coords = { x: 0, y: 0, width: element.offsetWidth, height:element.offsetHeight };
		while (element) {
			coords.x += element.offsetLeft;
			coords.y += element.offsetTop;
			element = element.offsetParent;
		}
		return coords;
}




//Form Validations
function FormValidationNode(nodeName,canContainNull,isEmail,isNummeric){
	this.obj=document.getElementById(nodeName);
	this.objName=nodeName;
	this.objOrgClassName = this.obj.className;
	this.canContainNull=false;
	this.isEmail=isEmail;
	this.isNumeric=isNummeric;
	return this
}

function validateValidationNode(validationNode){
	
	retValue = true;
	if(!validationNode.canContainNull && (validationNode.obj.value=="" || validationNode.obj.value==null)){
		retValue = false;
	}
	
	
	if(validationNode.isEmail && !isValidEmail(validationNode.obj.value)){
		retValue = false;
	}
	//other rules will go here
	return retValue;
}

function isValidEmail(mailstr){
  var re = /^ *([a-z0-9_-]+\.)*[a-z0-9_-]+@(([a-z0-9-]+\.)+(com|net|org|mil|edu|gov|arpa|info|biz|inc|name|[a-z]{2})|[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}) *$/;
  return (re.test(mailstr.toLowerCase()));
}
