var hasRightVersion = false;
var flash4Installed = false;
var flash5Installed = false;
var flash6Installed = false;
var flash7Installed = false;
var flash8Installed = false;
var flash9Installed = false;

var requiredFlashVersion = 5;

var maxVersion 			= 9;
var installedVersion	= 0;


var isIE 	= (navigator.appVersion.indexOf("MSIE") != -1) ? true : false;
var isWin 	= (navigator.appVersion.indexOf("Windows") != -1) ? true : false;

if((isIE) && (isWin)){
	document.write('<scr' + 'ipt language="VBScript"\>\n');
	document.write('on error resume next \n');
	document.write('flash4Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.4"))) \n');
	document.write('flash5Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.5"))) \n');  
	document.write('flash6Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.6"))) \n');
	document.write('flash7Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.7"))) \n');
	document.write('flash8Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.8"))) \n');
	document.write('flash9Installed = (IsObject(CreateObject("ShockwaveFlash.ShockwaveFlash.9"))) \n');  
	document.write('</scr' + 'ipt\> \n');
}

function checkForFlash(intFlashVersion){
	requiredFlashVersion = (intFlashVersion) ? intFlashVersion:requiredFlashVersion;
	hasRightVersion 	 = false;
	if(navigator.plugins){
		if(navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]){      			
			var isVersion2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			var flashDescription = navigator.plugins["Shockwave Flash" + isVersion2].description;			
			var flashVersion = parseInt(flashDescription.charAt(flashDescription.indexOf(".") - 1));			
			flash4Installed = flashVersion == 4;
			flash5Installed = flashVersion == 5;
			flash6Installed = flashVersion == 6;
			flash7Installed = flashVersion == 7;
			flash8Installed = flashVersion == 8;
			flash9Installed = flashVersion >= 9;
		}	
	}
	
	for(var i = 4; i <= maxVersion; i++){  
		if (eval("flash" + i + "Installed") == true){
			installedVersion = i;
		}
	}
						
	if (installedVersion >= requiredFlashVersion){
		hasRightVersion = true;
	}
		
	return hasRightVersion;
}


function printPageHeader(intFlashVersion,strFlashSwfUrl,intWidth,intHeight,strBgColor,strFallbackImageUrl,strSitemapUrl){	
	var str = '';
	var bgcolor = (strBgColor) 	  ? strBgColor : 'ffffff';
	var sitemap = (strSitemapUrl) ? ' usemap="#'+strSitemapUrl+'" ':''; 
	if(checkForFlash(intFlashVersion)){
		str += '<object type="application/x-shockwave-flash" data="' + strFlashSwfUrl + '" width="' + intWidth + '" height="' + intHeight + '">';
		str += '<param name="movie" value="' + strFlashSwfUrl + '" />';
		str += '<param name="menu" value="false" />';
		str += '<param name="quality" value="high" />';
		str += '<param name="bgcolor" value="#'+bgcolor+'" />';
		str += '</object>';
	}else{
		if(strFallbackImageUrl){
			str = '<div><img src="' + strFallbackImageUrl + '" width="' + intWidth + '" height="' + intHeight + '" alt="" '+sitemap+'/></div>';
		}
	}
	document.write(str);	
}

/*************************/

function winpop(myUrl,myWidth,myHeight){	
	
	var macAdd 			= (navigator.platform.indexOf("Mac")!= -1 || navigator.userAgent.indexOf('Opera')!= -1)?0:0;
	var macNetscapeAdd 	= ((navigator.platform.indexOf("Mac")!= -1) && (document.layers))?50:0;
	var winWidth 		= myWidth +macAdd;
	var winHeight 		= myHeight +macNetscapeAdd;
	
	var myX 	= (screen.availWidth/2) - (winWidth/2);
	var myY 	= (screen.availHeight/2) - (winHeight/2);	
	var myWin 	= window.open(myUrl,'winpop','width='+winWidth+',height='+winHeight+',toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0');
	myWin.moveTo(myX,myY);	
	myWin.resizeTo(myWidth,myHeight);
	myWin.focus();
}

function displayAd(winUrl,winName,winWidth,winHeight){			
	var myX 	= (screen.availWidth/2) - (winWidth/2);
	var myY 	= (screen.availHeight/2) - (winHeight/2);	
	var myWin 	= window.open('pop.html?width='+winWidth+'&height='+winHeight+'&image='+winUrl,winName,'width='+winWidth+',height='+winHeight+',toolbar=0,location=0,directories=0,status=0,scrollbars=0,resizable=0');
	myWin.moveTo(myX,myY);
	myWin.focus();
}

function findOutlet(f,strNavn,strID){
	var strUrl = 'outlet.php?magasin='+escape(strNavn)+'&magasinid='+strID+'&pnr='+removeSpaces(f.elements['pnr'].value);
	winpop(strUrl,300,250);	
}


function checkForm(myForm){
	var ret		 = true;
	var strError = 'Du må rette følgende:\n\n';
	
	if(isNotValidEmailFormat(myForm.elements['avsender'].value)){
		strError += '- Du må oppgi en gyldig epostadresse.';
		ret = false;
	}
	
	if(!ret){
		alert(strError);
	}
		
	return ret;
}

function isNotValidEmailFormat(email){
	// function: validates an email to format: x@x.xx
	// returns : boolean,
	
	var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
	var check=/@[\w\-]+\./;
	var checkend=/\.[a-zA-Z]{2,3}$/;

	if(((email.search(exclude) != -1)||(email.search(check)) == -1)||(email.search(checkend) == -1)){
		return true;
	} else {
		return false;
	}
}

function submitContact(myForm){
	if(myForm.elements['epost'].value != '' && !isNotValidEmailFormat(myForm.elements['epost'].value)){
		myForm.elements['work'].value = 'contact';
		myForm.submit();
	}else{
		alert('Du må fylle ut e-post i riktig format: xxx@xxx.xx');
		myForm.elements['epost'].focus();
	}
}

function removeSpaces(str){
    var re   = /[\s]/g;
    return str.replace(re,'');
}

function swap(name){
	var img = document.getElementById(name);	
	var i;
	var newSrc  = "";
	var newPath = "";
	var newName = "";
	var temp;			
	var image = img.src;
	
	var path  = image.split("/");
	var imgname = path[(path.length-1)].split("_");
	
	for(i=0;i<(path.length-1);i++){
		newPath += path[i]+"/";
	}
		
	if(imgname.length > 2){
		newName = imgname[0]+"_"+imgname[1]+".gif";
		newSrc = newPath+newName;		
		img.src = newSrc;
	}else{		
		temp = imgname[1].split(".");		
		newName = imgname[0]+"_"+temp[0]+"_over.gif";		
		newSrc = newPath+newName;		
		img.src = newSrc;			
	}	
}

// menu
function getYpos(obj) {return(obj.offsetTop + ((obj.offsetParent) ? getYpos(obj.offsetParent) : 0));}
function getXpos(obj) {return(obj.offsetLeft + ((obj.offsetParent) ? getXpos(obj.offsetParent) : 0));}

function hiLite(obj,theClass,theMenuClass){
	// function: change background-color in a layer
	// returns : nothing
	if((document.getElementById)||(document.all)){		
		obj.className = theClass;
	}
}

function loLite(obj,theClass,theMenuClass){
	// function: change background-color in a layer
	// returns : nothing
	if((document.getElementById)||(document.all)){
		obj.className = theClass;
	}
}