function changeProsaHref(newhref)
{
	parent.prosa.location.href=newhref;
}

function showBasket()
{
    parent.frames['prosa'].location.href="/servlet/oase.article.showArticle?ident=oaseShowBasket&wfw="+(new Date()).getTime();
}

function SAL(catid, ident)
{
	if (frames['prosa'] != null)
		frames['prosa'].location.href = "/servlet/oase.article.showArticle?art_event=GET_CATEGORY&art_categoryId="+catid+"&ident=oaseShowArtList"+ident+"&art_sorttype=VNR_ASC";
}

function SA(catid, ident)
{
	if (parent.prosa != null)
//		parent.setProsaLocation("/servlet/oase.article.showArticle?art_event=GET_CATEGORY&art_categoryId="+catid+"&ident=oaseShowArtList"+ident+"&art_sorttype=VNR_ASC");
		parent.prosa.location.href = "/servlet/oase.article.showArticle?art_event=GET_CATEGORY&art_categoryId="+catid+"&ident=oaseShowArtList"+ident+"&art_sorttype=VNR_ASC";
}

function OAA(warn, artnr, antal)
{
	if (warn == true) {
		doContinue = confirm("Varen er ikke på lager.\n\nVil du bestille alligevel?");
		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("Varen er ikke på lager.\n\nVil du bestille alligevel?");
		if (doContinue != true)
			return;
	}
	document.basketForm.kurv_vnr.value = artnr;
	if (minantal < 1 ) {
		if (antal > 6)
			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;
	}
	document.basketForm.submit();
}

function OAAMF(warn, artnr, antal, minantal, forpak, kurvantal)
{
	if (antal < 1)
		antal = 1;
	var totalantal = Math.round(antal) + Math.round(kurvantal);
	if (warn == true) {
		doContinue = confirm("Varen er ikke på lager.\n\nVil du bestille alligevel?");
		if (doContinue != true)
			return;
	}
	document.basketForm.kurv_vnr.value = artnr;
	if (minantal < 1 ) {
		if (antal > 0)
			document.basketForm.kurv_antal.value = antal;
		else
			document.basketForm.kurv_antal.value = 1;
	} else {
		if ( ( totalantal < minantal)) {
			doContinue = confirm("Varen sælges i minimum "+minantal+" stk.\n\nVil du bestille alligevel?");
			if (doContinue != true)
				return;
			antal = minantal;
			document.basketForm.kurv_antal.value = minantal;
		} else
			document.basketForm.kurv_antal.value = antal;
	}
	if (forpak > 0) {
		if ((antal % forpak) > 0) {
			doContinue = confirm("Varens forpakning er "+forpak+" stk.\n\nVil du bestille alligevel?");
			if (doContinue != true)
				return;
			antalgange = Math.round(antal / forpak);
			antalgange2 = antal / forpak;
			if (antalgange2 > antalgange)
 				antalgange = antalgange + 1;
			antal = forpak * antalgange;
			document.basketForm.kurv_antal.value = antal;
		} else {
			document.basketForm.kurv_antal.value = antal;
		}
	}
//	document.basketForm.submit();
	document.compareform.action="";
	location.replace("/servlet/oase.div.redir2?wfw="+(new Date()).getTime()+"&kurv_event=KURV_ADD&kurv_vnr="+artnr+"&kurv_antal="+antal+"&url="+escape(location.href));
}

function OAAMSI(warn, artnr, antal, minantal, abtype, basketident, abogrp)
{
	OAAMF(warn, artnr, antal, minantal, 0, document.basketForm.kurv_antal.value);
	return false;
}

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

function OAWAAMFKAA(warn, artnr, antal, minantal, forpak, kurvantal, abtype, abogrp)
{
	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) {
		e = e;
		characterCode = e.which
	} else {
	e = event
		characterCode = e.keyCode
	}
	if (characterCode == 13) {
		OAAMF(warn, artnr, antal, minantal, forpak, kurvantal);
		return false
	} else {
		return true
	}
}

function OAAMSIP(warn, artnr, antal, minantal, abtype, abogrp) {
	/* Dette er ikke den generelle definition */
	return  OAAMF(warn, artnr, antal, minantal, 0, document.basketForm.kurv_antal.value);
}

function OA(warn, artnr)
{
	if (warn == true) {
		doContinue = confirm("Varen er ikke på lager.\n\nVil du bestille alligevel?");
		if (doContinue != true)
			return;
	}
	document.basketForm.kurv_vnr.value = artnr;
	document.basketForm.submit();
}

function submitUserForm(form)
{
	var nodeList = document.getElementsByTagName("INPUT");
	for (var i = 0; i < nodeList.length; i++) {
		if (nodeList[i].className == "RequiredField") {
			nodeList[i].focus();
			alert("Feltet skal udfyldes!");
			return false;
		}
	}
	form.submit();
	return true;
}

function SchArtListShown()
{
	var catid = gup(location.href, "category_id");
	var catnode = parent.menu.document.getElementById("SchART"+catid);
	if (catnode != null)
		TS(catnode);
}

function panelIsLoading()
{
return false;
	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="/servlet/oase.article.showArticle?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()
{
//	dummy = alert("refreshPanel");
//	if (panellocation != "")
//		panellocation.replace("/servlet/oase.article.showArticle?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()
{
	if (window.print) {
		window.focus();
		window.print();
	}
	return false;
}

function deleteBasket(olid)
{
	var f = document.getElementById(olid);
	replaceProsaHref("/servlet/oase.article.showArticle?ident=oaseShowBasket&kurv_event=KURV_DEL&kurv_vnr="+f.name+"&wfw="+(new Date()).getTime());
}


function emptyBasket()
{
	replaceProsaHref("/servlet/oase.article.showArticle?ident=oaseShowBasket&kurv_event=KURV_EMPTY&wfw="+(new Date()).getTime());
}

function refreshProsaCond()
{
//	dummy = alert("refreshProsaCond");
	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="/servlet/oase.article.showArticle?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 handleUserLogin()
{
//	dummy = alert("Login OK.");
//	refreshProsaCond();
//	changeProsaHref("http://www.cypax.com");
//	refreshPanel();	/* Rest POST STATUS */
}

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

function orderAll()
{
	document.compareform.ident.value = "oaseShowPutIKurv";
	document.compareform.art_event.value="";
	document.compareform.kurv_event.value= "KURV_ADD";
//	document.compareform.target = "menutop";
	document.compareform.submit();
	document.compareform.reset();
}

function doCompare()
{
	document.compareform.ident.value = "oaseShowCompare";
	document.compareform.art_event.value="GET_COMPARE";
	document.compareform.kurv_event.value= "";
	document.compareform.target = "";
	document.compareform.submit();
}

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)
{
	document.searchIsbnForm.isbn.value = isbn;
	document.searchIsbnForm.submit();
}

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 XshowLogin(kurvevent)
{
	if (kurvevent == '')
		changeProsaHref("/servlet/oase.article.showArticle?ident=loginCombo&wfw="+(new Date()).getTime());
	else
		changeProsaHref("/servlet/oase.article.showArticle?ident=loginCombo&kurv_event="+kurvevent+"&wfw="+(new Date()).getTime());
}

function doLogout()
{
	changeProsaHref(logouturl+"&wfw="+(new Date()).getTime());
//	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("/servlet/oase.article.showArticle?ident=Forside&art_event=GET_CATEGORY&art_categoryId="+forsidecat+"&wfw="+(new Date()).getTime());
}

function showMailPwdPage()
{
	changeProsaHref("/servlet/oase.article.showArticle?ident=oaseSendPassword&wfw="+(new Date()).getTime());
}

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

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

function gup(where, name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( where );
  if( results == null )
    return "";
  else
    return results[1];
}


