function getMeta(metatag)
{
    try {
        var nodeList;
        if ((navigator.appName=='Netscape') && (navigator.appVersion.charAt(0)<'5'))
            nodeList = parent.prosa.document.tags["META"];
        else
            nodeList = parent.prosa.document.getElementsByTagName("META");
        for (var i = 0; i < nodeList.length; i++)
            if (nodeList[i].name == metatag)
                return (nodeList[i].content);
    } catch (e) {
    }
    return "";
}

function changeProsaHref(newhref)
{
	prosalocation.href=newhref;
}

function replaceProsaHref(newhref)
{
	    prosalocation.replace(newhref);
}

function changeArticle(ident)
{
    changeProsaHref(schShowArticle+"?ident="+ident+"&wfw="+(new Date()).getTime());
}

function replaceArticle(ident)
{
    replaceProsaHref(schShowArticle+"?ident="+ident+"&wfw="+(new Date()).getTime());
}

function showBasket()
{
	var inbasket = "";
	pos = prosalocation.href.indexOf("ident=");
	if (pos > -1) {
		if (prosalocation.href.substring(pos+6, pos+20) == "oaseShowBasket")
			inbasket="_not";
	}
	replaceProsaHref(schRedir + "?wfw="+(new Date()).getTime()+"&kurv_urlbefore"+inbasket+"="+escape(prosalocation.href)+"&url="+escape(schShowArticle+"?ident="+schillingbasketident+"&wfw="+(new Date()).getTime()));
}

function SchGoBeforeBasket()
{
	if (schillingurlbeforebasket != null && schillingurlbeforebasket != "")
		changeProsaHref(schillingurlbeforebasket);
	else
		window.history.go(-1);
}

function showLogin(event)
{
	if (event==null)
		changeProsaHref(schShowArticle+"?ident=loginCombo&wfw="+(new Date()).getTime());
	else
		changeProsaHref(schShowArticle+"?ident=loginCombo&kurv_event="+event+"&wfw="+(new Date()).getTime());
}

function showHome()
{
	_top.location.href="/";
}

function SAL(catid, ident)
{
	if (frames['prosa'] != null)
		frames['prosa'].location.href = schShowArticle + "?art_event=GET_CATEGORY&art_categoryId="+catid+"&ident="+schillinglistprefix+ident+"&art_sorttype=VTXT_ASC";
}

function SA(catid, ident)
{
	changeProsaHref(schShowArticle + "?art_event=GET_CATEGORY&art_categoryId="+catid+"&ident="+schillinglisteprefix+ident+"&art_sorttype=VTXT_ASC");
}

function OAA(warn, artnr, antal)
{
	if (warn == true) {
		doContinue = confirm("The article is not in stock.\n\nDo you wish to order anyway?");
		if (doContinue != true)
			return;
	}
	document.basketForm.kurv_vnr.value = artnr;
	if (antal > 0)
		document.basketForm.kurv_antal.value = antal;
	else
		document.basketForm.kurv_antal.value = 1;
	document.basketForm.submit();
}

function OAAM(warn, artnr, antal, minantal)
{
	if (warn == true) {
		doContinue = confirm("The article is not in stock.\n\nDo you wish to order anyway?");
		if (doContinue != true)
			return;
	}
	document.basketForm.kurv_vnr.value = artnr;
	if (minantal == 0 ) {
		if (antal > 0)
			document.basketForm.kurv_antal.value = antal;
		else
			document.basketForm.kurv_antal.value = 1;
	} else {
		if ( ( antal < minantal)) {
			doContinue = confirm("Varen s‘lges i minimum "+minantal+" stk.\n\nVil du bestille alligevel?");
			if (doContinue != true)
				return;
			document.basketForm.kurv_antal.value = minantal;
		} else
			document.basketForm.kurv_antal.value = antal;
	}
	// Only update menu-frame
	document.basketForm.target = "info";
	document.basketForm.action = parent.frames['info'].window.location.href
//	dummy = alert("URL: "+parent.frames['info'].document.URL+"\nreferrer: "+parent.frames['info'].document.referrer);
//	dummy = alert("Refresh: "+document.basketForm.action+"\nident="+document.basketForm.ident.value);
	document.basketForm.submit();
}

function OAAMSIF(warn, artnr, antal, minantal, basketident, forpak, kurvantal)
{
	return  OAAMF(warn, artnr, antal, minantal, forpak, kurvantal);
}

function OAAMSIP(warn, artnr, antal, minantal, abtype, ident, pgp)
{
	if (warn == true && abtype == "") {
		doContinue = confirm("The article is not in stock.\n\nDo you wish to order anyway?");
		if (doContinue != true)
			return;
	}
	if (minantal == 0 ) {
		if (antal <= 0)
			antal = 1;
	} else {
		if ( ( antal < minantal)) {
			doContinue = confirm("Varen s.lges i minimum "+minantal+" stk.\n\nVil du bestille alligevel?");
			if (doContinue != true)
				return;
			antal = minantal;
		}
	}
	orderlocation.replace(schRedir + "?wfw="+(new Date()).getTime()+"&kurv_event=KURV_ADD&kurv_vnr="+artnr+"&kurv_antal="+antal+"&kurv_abtype="+abtype+"&url="+escape(orderlocation.href));
}

function OAAMSI(warn, artnr, antal, minantal, abtype, ident)
{
	return OAAMSIP(warn, artnr, antal, minantal, abtype, ident, '');
}

function OAWAAMFKAA(warn, artnr, antal, minantal, forpak, kurvantal, abtype, abogrp)
{
	// Not aboready
    return OAAMF(warn, artnr, antal, minantal, forpak, kurvantal);
}

function OAWAAMFKAAE(warn, artnr, antal, minantal, forpak, kurvantal, abtype, abogrp, e)
{
	var characterCode;
	if (e && e.which) { //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)
		OAAMF(warn, artnr, antal, minantal, forpak, kurvantal);
		return false
	} else {
		return true
	}
}

function OAAMS(warn, artnr, antal, minantal, abtype)
{
	//document.basketForm.kurv_abtype.value = abtype;
	OAAMSI(warn, artnr, antal, minantal, abtype, '');
}

function OAAMF(warn, artnr, antal, minantal, forpak, kurvantal)
{
	var totalantal = Math.round(antal) + Math.round(kurvantal);
	if (warn == true) {
		doContinue = confirm("The article is not in stock.\n\nDo you wish to order anyway?");
		if (doContinue != true)
			return;
	}
	if (minantal < 1 ) {
		if (antal < 1)
			antal = 1;
	} else {
		if (totalantal < minantal) {
			doContinue = confirm("The article is sold in a minimum quantity of "+minantal+" items.\n\nDo you wish to order anyway?");
			if (doContinue != true)
				return;
			antal = minantal;
		}
	}
	if (schilling_check_packing_quantity) {
		if (forpak > 0) {
			if ((antal % forpak) > 0) {
				doContinue = confirm("The article is sold in packages of "+forpak+" items.\n\nDo you wish to order anyway?");
				if (doContinue != true)
					return;
				antalgange = Math.round(antal / forpak);
				antalgange2 = antal / forpak;
				if (antalgange2 > antalgange)
					antalgange = antalgange + 1;
				antal = forpak * antalgange;
			}
		}
	}
	replaceProsaHref(schRedir + "?wfw="+(new Date()).getTime()+"&kurv_event=KURV_ADD&kurv_vnr="+artnr+"&kurv_antal="+antal+"&url="+escape(location.href));
	return false;
}

function OA(warn, artnr)
{
	if (warn == true) {
		doContinue = confirm("The article is not in stock.\n\nDo you wish to order anyway?");
		if (doContinue != true)
			return;
	}
	//document.basketForm.kurv_vnr.value = artnr;
	//document.basketForm.submit();
	abtype=""
	orderlocation.replace(schRedir + "?wfw="+(new Date()).getTime()+"&kurv_event=KURV_ADD&kurv_vnr="+artnr+"&kurv_antal="+antal+"&abtype="+abtype+"&url="+escape(orderlocation.href));
}

function EAN13check(field)
{
	var csumTotal = 0;
	if (field.value.length == 0) return true;
	if (field.value.length != 13)
	{
		alert('Der skal indtastes 13 cifre i EAN-feltet.');
		field.focus();
		return false;
	}
	for (charPos = 11; charPos >= 0; charPos--)
	{
		if (charPos / 2 == parseInt(charPos/2))
			csumTotal = csumTotal + (parseInt(field.value.substring(charPos,charPos+1)));
		else
			csumTotal = csumTotal + (3 * parseInt(field.value.substring(charPos,charPos+1)));
	}
	var remainder = csumTotal - parseInt(csumTotal/10) * 10;
	if (remainder == 0)
		checksumDigit = '0';
	else
		checksumDigit = String.fromCharCode(48+10-remainder);
	if (field.value.substring(12,13)!=checksumDigit) {
		alert('EAN-nummeret er ikke korrekt.');
		field.focus();
		return false;
	}
	return true;
}

function submitUserForm(form)
{
	var nodeList = document.getElementsByTagName("INPUT");
	for (var i = 0; i < nodeList.length; i++) {
		if (nodeList[i].className == "UserRequiredField") {
			nodeList[i].focus();
			alert("The field must be filled out!");
			return false;
		}
		if (nodeList[i].name == "ean")
			if (!EAN13check(nodeList[i])) return false;
	}
	validateEmail(form.email, '', true);
	form.submit();
	return true;
}


function panelIsLoading()
{
	try {
	var nodeList;
	if ((navigator.appName=='Netscape') && (navigator.appVersion.charAt(0)<'5'))
		nodeList = parent.prosa.document.tags["META"];
	else
		nodeList = parent.prosa.document.getElementsByTagName("META");
	for (var i = 0; i < nodeList.length; i++) {
		if (nodeList[i].name == "ArticleIdent") {
			if (nodeList[i].content == "oaseShowBasketFrozen" ||
				nodeList[i].content == "oaseShowBasket") {
				parent.prosa.location.href= schShowArticle + "?ident=oaseShowBasket&wfw="+(new Date()).getTime();
				return true;
			} else {
				ahref = parent.prosa.location.href;
				parent.prosa.location.href = ahref;
				return true;
			}
		}
	}
	} catch (e) {
	}
	return false;
}

function resetFavoritList()
{
	var nodeList = parent.prosa.document.getElementsByTagName("INPUT");
	for (var i = 0; i < nodeList.length; i++)
		if (nodeList[i].className == "number")
			nodeList[i].value = "0";
}

function refreshPanel()
{
//	ahref = parent.menuframe.window.location.href;
//	parent.menuframe.window.location.href = ahref+"&wfw="+(new Date()).getTime();
//	parent.frames['info'].window.location.href = schShowArticle + "?ident=oaseLeftIn&nident=oaseLeft&wfw="+(new Date()).getTime();
}

function pilover(pilid)
{
	pilid.src="/images/arrow_off.gif";
}

function pilout(pilid)
{
	pilid.src="/images/arrow_on.gif";
	//eval(Pic+".src="+Pic+"off.src") ;
}

function printProsa()
{
	var windowtoprint;
	if (top.frames['prosa'] != null)
		windowtoprint = top.frames['prosa'];
	else
		windowtoprint = window;
	if (windowtoprint.print) {
		windowtoprint.focus();
		windowtoprint.print()
	}
}

function deleteBasket(olid)
{
	var f = document.getElementById(olid);
	var snabpos = f.name.indexOf("@");
	var vnr = f.name;
	if (snabpos > -1)
		vnr = f.name.substring(0,snabpos);
	window.location.replace(schShowArticle + "?ident=oaseShowBasket&kurv_event=KURV_DEL&kurv_vnr="+vnr+"&wfw="+(new Date()).getTime());
}

function deleteCourseBasket(olid, courseno, coursegrp)
{
	var f = document.getElementById(olid);
   	window.location.replace(schShowArticle + "?ident=oaseShowBasket&kurv_event=KURV_DEL&kurv_vnr="+f.name+"&kurv_courseno="+courseno+"&kurv_coursegrp="+coursegrp+"&arttype=COURSE&wfw="+(new Date()).getTime());

}

function emptyBasket()
{
    changeProsaHref(schShowArticle+"?ident="+schillingbasketident+"&kurv_event=KURV_EMPTY&wfw="+(new Date()).getTime());
}

function handleUserLogin()
{
//	dummy = alert("Handle user login");
//  refreshProsaCond();
//  changeProsaHref(schShowArticle + "?ident=LoginInfo&wfw="+(new Date()).getTime());
//  refreshPanel(); /* Rest POST STATUS */
}

function handleUserLogout()
{
//  dummy = alert("Handle user logout");
//  refreshProsaCond()
//  refreshPanel(); /* Rest POST STATUS */
//  refreshTotalFrame();
}

function mkcss(style_name)
{
	// Create dynamic stylesheet link
	if (document.createStyleSheet) {
		// The IE way...
		document.createStyleSheet(style_name, 0);
		var last=0;
		if (document.styleSheets.length>1) {
			for (var i=1; i<document.styleSheets.length; i++)
				if (document.styleSheets[i].href) {
					document.styleSheets[last].href = document.styleSheets[i].href;
					last = i;
				}
			document.styleSheets[last].href = style_name;
		}
	} else {
		// The Mozilla way
		_TEMP_OUTP = document.createElement("LINK");
		_TEMP_OUTP.setAttribute("REL","stylesheet");
		_TEMP_OUTP.setAttribute("TYPE","text/css");
		_TEMP_OUTP.setAttribute("HREF",style_name);
		document.getElementsByTagName("HEAD").item(0).appendChild(_TEMP_OUTP);
	}
}

function toggleEnlarge()
{
	var aCookie = document.cookie.split("; ");
	var curEnlarge = 0;
	chunkarr=new Array();
	for (i=0; i < aCookie.length && !curEnlarge; i++)
	{
		// a name/value pair (a crumb) is separated by an equal sign
		var aCrumb = aCookie[i].split("=");
		if (aCrumb[0] == "ShopEnlarge") {
			curEnlarge = aCrumb[1].substr(0,3)=="yes";
			break;
		}
	}	
	if (document.styleSheets.length>0) {
		var sheet;
		for (i=document.styleSheets.length-1; i>=0; i--) {
			sheet=document.styleSheets[i];
			if (sheet.href) {
				// Got the last stylesheet.
				hasLarge = (sheet.href.length>10 &&
							sheet.href.substr(sheet.href.length-10)=="-large.css");
				break;
			}
		}
		if (i<0) return;	// No CSS-files at all - not supported.
		if (hasLarge) {
			if (curEnlarge)
				document.styleSheets[i].disabled=true;
			else
				document.styleSheets[i].disabled=false;
		} else
			if (!curEnlarge)
				mkcss(sheet.href.substr(0,sheet.href.length-4)+"-large.css");
		if (curEnlarge)
			document.cookie="ShopEnlarge=no; expires=Sat, 31 Dec 2050 23:59:59 GMT";
		else
			document.cookie="ShopEnlarge=yes; expires=Sat, 31 Dec 2050 23:59:59 GMT";
	}
}

function OCSISBN(isbn)
{
	if(isbn == "")
		return;
	document.searchIsbnForm.isbn.value = isbn;
	document.searchIsbnForm.submit();
}

function OCSISBNK(isbn)
{
	if(event.keyCode==13)
	{
		OCSISBN(isbn);
		event.returnValue=false;
	}
}

function SV(artnr)
{
    changeProsaHref("/vare/"+artnr);
}

function OCSISBN(isbn)
{
	document.searchIsbnForm.isbn.value = isbn;
	if(document.searchIsbnForm.isbn.value != "")
		document.searchIsbnForm.submit();
}

function OCSISBNK(isbn)
{
	if(event.keyCode==13)
	{
		event.returnValue=false;
		OCSISBN(isbn);
	}
}

function showLogin(event)
{
	if(event=="")
		changeProsaHref(schShowArticle + "?ident=loginCombo&wfw="+(new Date()).getTime());
	else
		changeProsaHref(schShowArticle + "?ident=loginCombo&kurv_event="+event+"&wfw="+(new Date()).getTime());
}

function doLogout()
{
	changeProsaHref(logouturl);
//	dummy = alert("after logout - going to front.");
//	changeProsaHref("/");
}

function doLogin()
{
	changeProsaHref(loginurl+"&wfw="+(new Date()).getTime());
}

function doChangeUser()
{
	changeProsaHref(changeuserurl+"&wfw="+(new Date()).getTime());
}


function frontPage()
{
	/* Er ikke nogen endelig funkton - er blot her for at arkivere URL'en */
	changeProsaHref(schShowArticle + "?ident=Forside&art_event=GET_CATEGORY&art_categoryId="+forsidecat+"&wfw="+(new Date()).getTime());
}

function showMailPwdPage()
{
	changeProsaHref(schShowArticle + "?ident=GlemtKode&wfw="+(new Date()).getTime());
}

function showErrorMessage(message)
{
	dummy = alert(message);
	return false;
}

function basketEanNotValidError()
{
	dummy = alert("Angivet EAN er ikke validt.");
}

// -----------------------------------------
//               validateEmail
// Validate if e-mail address
// Returns true if so (and also if could not be executed because of old browser)
// -----------------------------------------

function validateEmail  (vfld,   // element to be validated
                         ifld,   // id of element to receive info/error msg
                         reqd)   // true if required
{
//dummy = alert("validateEmail");
  var stat = commonCheck (vfld, ifld, reqd);
  if (stat != proceed) return stat;

  var tfld = trim(vfld.value);  // value of field with whitespace trimmed off
  var email = /^[^@]+@[^@.]+\.[^@]*\w\w$/
  if (!email.test(tfld)) {
    showErrorMessage ("ERROR: not a valid e-mail address");
    vfld.focus();
    return false;
  }
  var email2 = /^[A-Za-z][\w.-]+@\w[\w.-]+\.[\w.-]*[A-Za-z][A-Za-z]$/
  if (!email2.test(tfld)) 
    showErrorMessage ("Unusual e-mail address - check if correct");
  return true;
};

function flipflopblock(nodehit, idshowornot)
{
	elemtoshowornot = document.getElementById(idshowornot);
	iconwhenhidden = document.getElementById(idshowornot+"_icoshow");
	iconwhenshown = document.getElementById(idshowornot+"_icohide");
	if (elemtoshowornot != null) {
		if (elemtoshowornot.style.display == "none") {
			elemtoshowornot.style.display = "block";
			if (iconwhenshown != null)
				iconwhenshown.style.display = "block";
			if (iconwhenhidden != null)
				iconwhenhidden.style.display = "none";
		} else {
			elemtoshowornot.style.display = "none";
			if (iconwhenshown != null)
				iconwhenshown.style.display = "none";
			if (iconwhenhidden != null)
				iconwhenhidden.style.display = "block";
		}
	}
}

function BC_Cancel(questiontxt, distno, ident)
{
	doContinue = confirm(questiontxt);
	if (doContinue != true)
		return;
	replaceProsaHref(schRedir + "?wfw="+(new Date()).getTime()+"&art_event=BCCNCL&art_bcdst="+distno+"&url="+escape(location.href));
}

function BC_Enrole(questiontxt, distno, ident)
{
	doContinue = confirm(questiontxt);
	if (doContinue != true)
		return;
	replaceProsaHref(schRedir + "?wfw="+(new Date()).getTime()+"&art_event=BCNRL&art_bcdst="+distno+"&url="+escape(location.href));
}

function SCHOC(vnr, courseno, coursegrp, loggedin)
{
	if (loggedin == "true") {
		var antal = 1;
		location.replace(schRedir + "?wfw="+(new Date()).getTime()+"&kurv_event=KURV_ADD&kurv_vnr="+vnr+"&kurv_courseno="+courseno+"&kurv_coursegrp="+coursegrp+"&kurv_antal="+antal+"&arttype=COURSE"+"&url="+escape(location.href));
	} else {
		alert("Vg log ind");
	}
}

function UserLogin(ident) {
	var user = document.getElementsByName("user_id");
	var password = document.getElementsByName("user_passwd");
	location.replace(schRedir + "?wfw="+(new Date()).getTime()+"&user_event=USER_LOGIN&user_oldevent=USER_LOGIN&ident="+ident+"&user_id="+user[0].value+"&user_passwd="+password[0].value+"&url="+escape(location.href));
}

function UserLogout(ident) {
	location.replace(schRedir + "?wfw="+(new Date()).getTime()+"&user_event=USER_LOGOUT&ident="+ident);
	frontPage();
}

function SCHCC(vnr, courseno, coursegrp)
{
	var doContinue;
	doContinue = confirm("Vil du afmelde dig fra dette kursus?");
	if (doContinue != true)
		retur;
	location.replace(schRedir + "?wfw="+(new Date()).getTime()+"ident=oaseUserCourses&user_event=USER_DELCOURSE&user_vnr="+vnr+"&user_courseno="+courseno+"&user_coursegrp="+coursegrp+"&url="+escape(location.href));
}

function SchClickToDownloadEbook(url, name)
{
	open(url, null, 'toolbar=0,location=0,directories=0,menubar=0,width=640,height=200');
}

function getDescriptionHref(ElemType)
{
	thiselement = document.getElementById(ElemType);
	var anchor = 0;
	anchor = location.href.indexOf("#");
	if (anchor > 0) {
		actlink = location.href.substring(0, anchor+1);
		thiselement.href = actlink+"show"+ElemType;
	} else {
		thiselement.href = location.href+"#show"+ElemType;
	}
}

function updateDeliveryMethod()
{
	var i=document.olform.deliverymethod.selectedIndex;
	document.olform.kurv_levmaade.value = document.olform.deliverymethod.options[i].text;
	document.olform.kurv_levmaadekode.value = document.olform.deliverymethod.options[i].value;
	document.olform.kurv_event.value = "KURV_UPDATE";
	document.olform.ident.value = "oaseShowBasket";
}

function SchBasketBack(backtourl)
{
    changeProsaHref(backtourl+"&wfw="+(new Date()).getTime());
}

function SchShopInfo()
{
    changeProsaHref(schillingshopinfourl);
}

function SchShowTipFriend(vnr)
{
	window.open(schShowArticle+"?ident="+schillingtiparticle+"&noshowtype=true&notemplate=true&wfw="+(new Date()).getTime()+"&ident="+schillingtiparticle+"&art_event=GET_ART&art_vnr="+vnr, null, 'toolbar=0,location=0,directories=0,menubar=0,width=460,height=300');
	
}

function SchClearSelect(node)
{
	node.value = "";
	node.select();
}

function goToNextPage()
{
    var nextid;
    var s=location.href.split('art_pageId=');
    if (s[1] == undefined) {
	nextid = 2;
	location.replace(s[0]+'&art_pageId='+nextid);
    } else {
    	var endchar = s[1].indexOf('&');
    	if (endchar == -1)
        	endchar = s[1].length;
    	var id = s[1].substring(0, endchar);
	nextid = parseInt(id)+1;
	location.replace(s[0]+'art_pageId='+nextid+s[1].substring(endchar));
    }

}

function goToPrevPage()
{
    var nextid;
    var s=location.href.split('art_pageId=');
    if (s[1] == undefined) {
	nextid = 2;
	location.replace(s[0]+'&art_pageId='+nextid);
    } else {
	var endchar = s[1].indexOf('&');
    	if (endchar == -1)
        	endchar = s[1].length;
    	var id = s[1].substring(0, endchar);
    	var nextid = parseInt(id)-1;
    	location.replace(s[0]+'art_pageId='+nextid+s[1].substring(endchar));
    }
}

function showPageInList(showId)
{
    var s = location.href.split('art_pageId=');
    if (s[1] == undefined) {
	location.replace(s[0]+'&art_pageId='+showId);
    } else {
    	var endchar = s[1].indexOf('&');
    	if (endchar == -1)
        	endchar = s[1].length;
    	if (s[1].length > 1) {
        	location.replace(s[0]+'art_pageId='+showId+s[1].substring(endchar));
    	} else
        	location.replace(s[0]+'art_pageId='+showId);
    }
}

function PaymentCheck() {
}

function PaymentCheck2() {
}

function BasketOnSubmit() {
	if (document.olform.deliverymethod.value != "BLANK")
		document.olform.submit();
	else {
		alert("Please select delivery destination!");
		return false;
	}
}
