

function showByPosition(object,x,y,e,w) {
    if (document.layers && document.layers[object]) {
        if ((e.x + x + 50 + document.layers[object].clip.width) > (window.pageXOffset + window.innerWidth))
            x = x - document.layers[object].clip.width;

        if ((e.y + y + 50 + document.layers[object].clip.height) > (window.pageYOffset + window.innerHeight))
            y *= -4;

        document.layers[object].left = e.x + (x - w);
        document.layers[object].top = e.y + y;
        document.layers[object].visibility = 'visible';
    }
    else if (document.all) {
        e = window.event;

       /* if ((e.x + x + document.all[object].clientWidth) > (document.body.clientWidth + document.body.scrollLeft))
            x = (document.body.clientWidth + document.body.scrollLeft) - document.all[object].clientWidth;
        else*/
            x = e.x + x;

        /*if ((e.y + y + document.all[object].clientHeight) > (document.body.clientHeight + document.body.scrollTop))
            y = e.y - (y * 4);
        else*/
            y = e.y + y;
//		var scrollH
//		scrollH = document.body.scrollTop
        document.all[object].style.posLeft = x - w;
        document.all[object].style.posTop = (y + document.body.scrollTop);
		
		//alert("tst")
        document.all[object].style.visibility = 'visible';
		//window.scrollTo(0, scrollH);
		//alert(document.body.scrollLeft)
		//alert(document.body.scrollTop)
		//window.scroll(0, 5555)
		//window.scrollBy(0, window.innerHeight);
		//window.scrollByPages(1);
		//scroll();
    }
}

			
function hide(object) {
    if (document.layers && document.layers[object])
        document.layers[object].visibility = 'hidden';
    else if (document.all)
        document.all[object].style.visibility = 'hidden';
}	

//**************************************************************************
//der kan kun skrive fra 0 til 9 plus - saa svenske postnr kan komme med
	function tjekPostnr(){
		if ((event.keyCode < 48 || event.keyCode > 57)) {
			//alert(event.keyCode)
			if (event.keyCode != 45){
				event.returnValue = false;
			}
		}
	}

//***************************************************************************
// print
	function makePrintout() {
			if (window.print) {   // Avoids errors 
		 		window.print();
			}
	 	}
//***************************************************************************
//bruges til fangstkurven

/* 
' Browser check
'--------------------------------------------------------------------------------------
*/
	function checkBrowser(){
		this.strVersion		= navigator.appVersion
		this.strAgent			= navigator.userAgent.toLowerCase()
		this.bolIsDom			= document.getElementById ? 1:0
		this.bolIsSafari	= (this.strAgent.indexOf('safari')>-1);
		this.bolIsOp5			= (this.strAgent.indexOf('opera 5')>-1 || this.strAgent.indexOf('opera/5')>-1) && window.opera 
		this.bolIsOp6			=	(this.strAgent.indexOf('opera 6')>-1 || this.strAgent.indexOf('opera/6')>-1) && window.opera
		this.bolIsOp7			=	(this.strAgent.indexOf('opera 7')>-1 || this.strAgent.indexOf('opera/7')>-1) && window.opera   
		this.bolIsIe5			= (this.strAgent.indexOf('msie 5')>-1 && !this.bolIsOp5 && !this.bolIsOp6)
		this.bolIsIe55		= (this.bolIsIe5 && this.strAgent.indexOf('msie 5.5')>-1)
		this.bolIsIe6			= (this.strAgent.indexOf('msie 6')>-1 && !this.bolIsOp5 && !this.op6)
		this.bolisIe4			= (this.strAgent.indexOf('msie')>-1 && document.all &&!this.bolIsOp5 &&!this.bolIsOp6 &&!this.bolIsIe5&&!this.bolIsIe6)
		this.bolIsIe			= (this.bolIsIe4 || this.bolIsIe5 || this.bolIsIe6)
		this.bolIsMac			= (this.strAgent.indexOf('mac')>-1)
		this.bolIsNs6			= (this.strAgent.indexOf('gecko')>-1 || window.sidebar)
		this.bolIsNs7			= ((this.strAgent.indexOf('gecko')>-1 || window.sidebar) && this.strAgent.indexOf('7')>-1);
		this.bolIsNs4			= (!this.bolIsDom && document.layers)?1:0;
		this.strBrowser		= (this.bolIsIe6 || this.bolIsIe5 || this.bolIsIe4 || this.bolIsNs4 || this.bolIsNs6 || this.bolIsOp5 || this.bolIsO6)
		return this
	}
	var objBrowser = new checkBrowser()
	
	
	function validateBrowser(){
		var bolIsValid = false;
		if(objBrowser.bolIsSafari || objBrowser.bolIsIe5 || objBrowser.bolIsIe55 || objBrowser.bolIsIe6 || objBrowser.bolIsNs7 || objBrowser.bolIsOp7){
			bolIsValid = true;
		} else {
			var objBrowserInfo = window.open('browser_information.html','BrowserInfo','width=500,height=550,status=no,toolbar=no,menubar=no,scrollbars=no,resizable=yes');
			objBrowserInfo.focus();
			bolIsValid = false;
		}
	}
	
	
	//de bliver foerst slettet efter 2 aar
	function setCookieListe(strName, strValue, dtmExpires, path, bolIsSecure) {
		var objCurrentCookie = strName + '=' + escape(strValue) +
		((dtmExpires) ? '; expires=' + dtmExpires.toGMTString() : '') +
		((path) ? "; path=" + path : "") +
		((bolIsSecure) ? '; secure' : '');
		document.cookie = objCurrentCookie;
	}

	function getCookieListe(strName) {
		var objCookie = document.cookie;
		var strPrefix = strName + '=';
		var lngBegin = objCookie.indexOf('; ' + strPrefix);
		if (lngBegin == -1) {
			lngBegin = objCookie.indexOf(strPrefix);
			if (lngBegin != 0) return null;
		} else {
			lngBegin += 2;
		}
		var lngEnd = document.cookie.indexOf(';', lngBegin);
		if (lngEnd == -1)
			lngEnd = objCookie.length;
		return unescape(objCookie.substring(lngBegin + strPrefix.length, lngEnd));
	}

	function deleteCookie(strName,path) {
		if (getCookieListe(strName)) {
			document.cookie = strName + '=' + 
			((path) ? "; path=" + path : "") +
			'; expires=Thu, 01-Jan-70 00:00:01 GMT';
		}
	}
	
	//saetter datoen til 1 foer cookie blive expired
	function setDate(){
		var dtmCurrentDate = new Date();
		repairDate(dtmCurrentDate);				
		return new Date((dtmCurrentDate.getTime() + 1*1000*60*60*5));
	}

	function repairDate(dtmDate) {
		var objBase = new Date(0);
		var objSkew = objBase.getTime();
		if (objSkew > 0)
			dtmDate.setTime(dtmDate.getTime() - objSkew);
	}


	function skiftListeImage(strImageId, strImageName){
		objButton = new imageElement(strImageId);
		objButton.imgUrl('http://www.efish.dk/grafik/' + strImageName);
	}
	
	function addFangsTilKurv(prodID, strImageId){
		var objListe = getCookieListe('fangstCookie');
		var kundeIdentifier = prodID + '';
		if(!tjekFangstListe(prodID)){
			if (!objListe){
				setCookieListe('fangstCookie', kundeIdentifier, setDate(), '/', false);
			} else {
				var strCurrentValue = getCookieListe('fangstCookie');
				setCookieListe('fangstCookie', strCurrentValue + ';' + kundeIdentifier, setDate(), '/', false)
			}
			skiftListeImage(strImageId, 'kurv_markt.gif');
			skiftListeImage('fangstkurv', 'fangsttopindhold.gif');
			//skifter huskesedlen til at vise er nu er der noget i huskesedlen
		} else {
			alert("Produktet er tilføjet til din fangstkurv\nDu kan ændrer antal og farve i din fangstkurv\n------------------------------------------------------\nFangstkurven er placeret i øverste højre hjørne");
			/*sletVarerFraKurv(prodID);
			skiftListeImage(strImageId, 'post-it1.gif');
			if(getCookieListe('fangstCookie')){
				//der er stadig fangster kurven	 den er ikke tom
			}else{
				//skiftListeImage('seddel', 'post-it1.gif');
				//skift huskesedlen i venstre side under sogning fordi nu er huskesedlen tom
			}*/
		}
	}
	
	function sletVarerFraKurv(prodID){
		var objListe = getCookieListe('fangstCookie');
		var kundeIdentifier = prodID + '';
		var strNewList = '';
		if(objListe){
			var nowList = objListe.split(';');
			for(i=0;i<nowList.length;i++){
				if(nowList[i] != kundeIdentifier){
					(strNewList!='') ? strNewList += ';' : strNewList += '';
					strNewList += nowList[i];
				}
			}
		}
		deleteCookie('fangstCookie', '/');
		setCookieListe('fangstCookie', strNewList, setDate(), '/', false);
	}
	
	function tjekFangstListe(prodID){
		var objListe = getCookieListe('fangstCookie');
		var kundeIdentifier = prodID + '';
		var bolIsListed = false;
		if(objListe){
			var nowList = objListe.split(';');
			for(i=0;i<nowList.length;i++){
				if(nowList[i] == kundeIdentifier){
					return bolIsListed = true;
				}
			}
		}
	}



function imageElement(strId){
	this.id = strId;
	(objBrowser.bolIsDom == 1) ? this.element = document.getElementById(strId) : this.element = document.all[strId] ;
	this.style = this.element.style;
}



imageElement.prototype.imgUrl = function(strUrl){
	this.element.src = strUrl;
	if (this.element.id == "seddel"){
		if(getCookieListe('fangstCookie')){
			this.element.alt = 'Klik for at se indholdet af din huskeseddel';
			//der er stadig restauranter i huskesedlen den er ikke tom
		}else{
			this.element.alt = 'Din huskeseddel er tom';
			//skift huskesedlen i venstre side under sogning fordi nu er huskesedlen tom
		}
	}else{
		if (this.element.src.indexOf('post-it1.gif') != -1){
			this.element.alt = 'Restauranten er nu slettet fra din huskeseddel';
		}else{
			this.element.alt = 'Du har tilføjet produktet til din fangstkurv, du ændrer antal og farve i din fangstkurv\n------------------------------------------------------\nFangstkurven er placeret i øverste højre hjørne';
		}
	}
}

function ProduktErIKurv() {
	alert("Produktet findes allerede i din fangstkurv\nDu kan ændrer antal og farve i din fangstkurv\n------------------------------------------------------\nFangstkurven er placeret i øverste højre hjørne");
}
