var ip;
var http_request;
var subscriptionDone;
var ajax_putinbasket_obj = false;
var ajax_keepalive_obj = false;

// Initialize HttpRequest object to be used later....
// 
function initAjaxPutInBasket()
{
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        ajax_putinbasket_obj = new XMLHttpRequest();
        if (false && ajax_putinbasket_obj.overrideMimeType) {
            ajax_putinbasket_obj.overrideMimeType('text/xml');
            // See note below about this line
        }
    } else if (window.ActiveXObject) { // IE
        try {
            ajax_putinbasket_obj = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                ajax_putinbasket_obj = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
	/*
    if (ajax_putinbasket_obj)
    	ajax_putinbasket_obj.onreadystatechange = function() { SchAjaxNotify(ajax_putinbasket_obj, 'SchMiniBasket'); };
	else
        alert('Giving up :( Cannot create an XMLHTTP instance');
	*/
	if (!ajax_putinbasket_obj) {
        //alert('Giving up :( Cannot create an XMLHTTP instance');
		ajax_putinbasket_enabled = false;	// Disable functionality and revert to old style page-reload.
	}
}


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)
{
	if (newhref == '')
		newhref = "/";
	prosalocation.replace(newhref);
}

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

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

function getBasketUrl()
{
	return "/servlet/oase.article.showArticle?ident=Basket&wfw="+(new Date()).getTime();
}

function showBasket()
{
	changeProsaHref(getBasketUrl());
}

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

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

function refreshTotalFrame()
{
//	top.frames['menutop'].window.location.replace("/servlet/oase.article.showArticle?ident=oaseShowTopMenu&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)
{
	changeProsaHref("/servlet/oase.article.showArticle?art_event=GET_CATEGORY&art_categoryId="+catid+"&ident=ArtList"+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 OAAMSI(warn, artnr, antal, minantal, abtype, ident)
{
	if (abtype == "") {
		if (warn == true) {
			doContinue = confirm("Varen er ikke på lager.\n\nVil du bestille alligevel?");
			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("/servlet/oase.div.redir2?wfw="+(new Date()).getTime()+"&kurv_event=KURV_ADD&kurv_vnr="+artnr+"&kurv_antal="+antal+"&kurv_abtype="+abtype+"&url="+escape(location.href));
}

function OAAMSIP(warn, artnr, antal, minantal, abtype, ident, pgp)
{
	if (abtype == "") {
		if (warn == true) {
			doContinue = confirm("Varen er ikke på lager.\n\nVil du bestille alligevel?");
			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("/servlet/oase.div.redir2?wfw="+(new Date()).getTime()+"&kurv_event=KURV_ADD&kurv_vnr="+artnr+"&kurv_antal="+antal+"&kurv_abtype="+abtype+"&kurv_prisgruppe="+pgp+"&url="+escape(location.href));
}

function Old_OAAMSI(warn, artnr, antal, minantal, abtype, ident)
{
	if (abtype == "") {
		if (warn == true) {
			doContinue = confirm("Varen er ikke på lager.\n\nVil du bestille alligevel?");
			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;
		}
	}
	if (ident == "")
		ident = getMeta("ArticleIdent");
	orderlocation.replace("/servlet/oase.article.showArticle?ident="+ident+"&kurv_event=KURV_ADD&kurv_vnr="+artnr+"&kurv_antal="+antal+"&kurv_abtype="+abtype+"&wfw="+(new Date()).getTime());
	/*orderlocation.replace("/servlet/oase.article.showArticle?ident="+ident+"&wfw="+(new Date()).getTime()); */
}

function Old_OAAMSIP(warn, artnr, antal, minantal, abtype, ident, pgp)
{
	if (abtype == "") {
		if (warn == true) {
			doContinue = confirm("Varen er ikke på lager.\n\nVil du bestille alligevel?");
			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;
		}
	}
	if (ident == "")
		ident = getMeta("ArticleIdent");
	orderlocation.replace("/servlet/oase.article.showArticle?ident="+ident+"&kurv_event=KURV_ADD&kurv_vnr="+artnr+"&kurv_antal="+antal+"&kurv_abtype="+abtype+"&kurv_prisgrup="+pgp+"&wfw="+(new Date()).getTime());
}

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;
	}
	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("/servlet/oase.article.showArticle?ident="+orderident+"&kurv_event=KURV_ADD&kurv_vnr="+artnr+"&kurv_antal="+antal+"&wfw="+(new Date()).getTime());
}

function OAAMS(warn, artnr, antal, minantal, abtype)
{
	OAAM(warn, artnr, antal, minantal);
	return false;
}

function OAAMF(warn, artnr, antal, minantal, forpak, kurvantal)
{
	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 alligvel?");
			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();
	}
}

function OAWAAMFKAA(warn, artnr, antal, minantal, forpak, kurvantal, abtype, abogrp)
{
	return OAAMSI(warn, artnr, antal, minantal, abtype, "")
}

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 == "UserRequiredField") {
			nodeList[i].focus();
			alert("Feltet skal udfyldes!");
			return false;
		}
	}
	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="/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);
	var snabpos = f.name.indexOf("@");
	var vnr = f.name;
	if (snabpos > -1)
		vnr = f.name.substring(0,snabpos);
	window.location.replace(schillingbase + "/servlet/oase.article.showArticle?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(schillingbase + "/servlet/oase.article.showArticle?ident=oaseShowBasket&kurv_event=KURV_DEL&kurv_vnr="+f.name+"&kurv_courseno="+courseno+"&kurv_coursegrp="+coursegrp+"&arttype=COURSE&wfw="+(new Date()).getTime());
}

//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()
{
	//changeProsaHref("http://www.djoef-forlag.dk:88/");
	replaceProsaHref("/servlet/oase.div.redir2?wfw="+(new Date()).getTime()+"&kurv_event=KURV_CHANGE&url="+escape('http://www.djoef-forlag.dk/'));
//	refreshPanel();	/* Rest POST STATUS */
}

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

function orderAll()
{
//	document.compareform.ident.value = "oaseShowTopMenu";
//	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 != "")
		prosalocation.replace("/servlet/oase.div.redir2?wfw="+(new Date()).getTime()+"&kurv_event=KURV_SEARCH_ISBN&isbn="+isbn+"&url="+escape(getBasketUrl()));
//		document.searchIsbnForm.submit();
}

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

function showLogin(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=djoefRequestPassword&wfw="+(new Date()).getTime());
}

function showErrorMessage(message)
{
	window.status = message;
    dummy = alert(message);
}

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

function Schmail_open(id)
{	
	//var imtg = document.all['im'+id];
	var imtg = document.getElementById('SchEcImg_'+id);
	imtg.src = '/layout/images/minus.gif';
	imtg.state=0;
	//var tg = document.all['gr'+id];
	var tg = document.getElementById('SchEcGr_'+id);
	if (tg) tg.style.display = 'block';
	
}

function SchToggleEC(id, plusimg, minusimg)
{	
	var imtg = document.getElementById('SchEcImg_'+id);
//alert("state of "+id+"="+imtg.state);
	if (imtg.state == undefined)
		imtg.state = 0;
	if (imtg.state==0) {
		imtg.src = plusimg;
		imtg.state = 1;
	} else {
		imtg.src = minusimg;
		imtg.state = 0;
	}
	var tg = document.getElementById('SchEcGr_'+id);	// Id on table containing children
//alert("display="+tg.style.display);
	if (tg.style.display=="")
		tg.style.display = 'block';
	if (tg.style.display == 'block')
		tg.style.display = 'none';
	else
		tg.style.display = 'block';
}

function OLD_SchToggleEC(id, plusimg, minusimg)
{	
	var imtg = document.getElementById('SchEcImg_'+id);
	if (imtg.state==0) {
		imtg.src = plusimg;
		imtg.state = 1;
	} else {
		imtg.src = minusimg;
		imtg.state = 0;
	}
	var tg = document.getElementById('SchEcGr_'+id);	// Id on table containing children
	if (tg.style.display == 'block')
		tg.style.display = 'none';
	else
		tg.style.display = 'block';
}

function SchToggleOpenEC(id, plusimg, minusimg)
{
	var tg = document.getElementById('SchEcGr_'+id);	// Id on table containing children
	if (tg && tg.style.display == 'none')
		SchToggleEC(id, "", "");
}

function OLD_SchCheckEC(formname,state,id,pid)
{	
//dummy = alert("SchCheckEC(formname="+formname+" Check state="+state+" id="+id+" pid="+pid);
	var f = document.forms[formname];
	var titletd;
	var searchClassName = "SchEcChk_"+id;
	var classlength = searchClassName.length;
	var childsfound = false;
	// Select all children
	for (i = 0; i < f.elements.length; i++) {
		var childclassName = f.elements[i].className;
//dummy = alert("childclassName="+childclassName.substring(0,classlength)+" searchClassName="+searchClassName);
		if (childclassName.substring(0,classlength) == searchClassName) {
			childsfound = true;
	//		if (state == true)		// Only select sub-codes when adding.
				f.elements[i].checked = state;
			var fid = f.elements[i].id;
			var thisid = fid.substring(11,fid.length);	// FIXME: hardcode of 11.
//dummy = alert("thisid="+thisid);
		}
	}
	var theid = "SchEcBox_" + id;
	var clickelem = document.getElementById(theid);
	if (clickelem.className == "")
		return;
	var title = "";
	if (clickelem != null)
		titletd = document.getElementById('SchEcTit_'+id);
		if (titletd != null)
			title = titletd.childNodes[0].nodeValue;
	// Children found and checked - open folder to show
	if (childsfound) {
		var imtg = document.getElementById('SchEcImg_'+id)
		var table = document.getElementById('SchEcGr_'+id)
//dummy = alert ("Childsfound imtg=SchEcImg_"+id+" imgtg.state="+imtg.state);
		if (table.style.display == "none")
			SchToggleEC(id, '/images/extcodeplus.gif','/images/extcodeminus.gif');
	}
}

function SchCheckEC(formname,state,id,pid)
{	
//dummy = alert("SchCheckEC(formname="+formname+" Check state="+state+" id="+id+" pid="+pid);
	var f = document.forms[formname];
	var titletd;
	var searchClassName = "SchEcChk_"+id;
	var classlength = searchClassName.length;
	var childsfound = false;
	// Select all children
	for (i = 0; i < f.elements.length; i++) {
		var childclassName = f.elements[i].className;
//dummy = alert("childclassName="+childclassName.substring(0,classlength)+" searchClassName="+searchClassName);
		if (childclassName.substring(0,classlength) == searchClassName) {
			childsfound = true;
	//		if (state == true)		// Only select sub-codes when adding.
				f.elements[i].checked = state;
			var fid = f.elements[i].id;
			var thisid = fid.substring(11,fid.length);	// FIXME: hardcode of 11.
//dummy = alert("thisid="+thisid);
		}
	}
	var theid = "SchEcBox_" + id;
	var clickelem = document.getElementById(theid);
	if (clickelem.className == "")
		return;
	var title = "";
	if (clickelem != null)
		titletd = document.getElementById('SchEcTit_'+id);
		if (titletd != null)
			title = titletd.childNodes[0].nodeValue;
	// Children found and checked - open folder to show
	if (childsfound) {
		var imtg = document.getElementById('SchEcImg_'+id)
		var table = document.getElementById('SchEcGr_'+id)
//dummy = alert ("Childsfound imtg=SchEcImg_"+id+" imgtg.state="+imtg.state);
		if (table.style.display == "none")
			SchToggleEC(id, '/images/extcodeplus.gif','/images/extcodeminus.gif');
	}
}

function SchCheckAll()
{
	var f = document.forms['formular'];
	for (i = 0; i < f.elements.length; i++)
	{	f.elements[i].checked = true;
	}
}

//email validator returnerer true eller false
function SchValidEmail(mail)
{
	
	var email=/^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/i;
	return(email.test(mail));
}

//function SchUserError(errlayerid, errno, errmsg)
function SchUserError(errno, errmsg)
{
	if (errno != "38")
		dummy = alert(errmsg);
}

function SchGetURLParam(strParamName){
	var strReturn = "";
	var strHref = window.location.href;
	var apos = strHref.indexOf("&");
	var qpos = strHref.indexOf("?");
	if ( qpos > -1 || apos > -1 ) {
		var strQueryString = strHref.substr(strHref.indexOf("?")).toLowerCase();
		var aQueryString = strQueryString.split("&");
		for ( var iParam = 0; iParam < aQueryString.length; iParam++ ) {
			if ( aQueryString[iParam].indexOf(strParamName + "=") > -1 ) {
				var aParam = aQueryString[iParam].split("=");
				strReturn = aParam[1];
				break;
			}
		}
	}
	return strReturn;
}

function SchSubmitEc(form)
{
    if (form.email != null) {
	if (SchValidEmail(form.email.value) == false) {
		SchUserError(99,'Den indtastede e-mail accepteres ikke.');
		form.email.focus();
		return false;
	}
	}
	form.submit();
	return false;
}
function toggleSubmits() {
    alt = document.getElementsByName("basketaltsubmit");
    real = document.getElementsByName("basketsubmit");
    if (alt[0].style.display == "none" || alt[0].style.display == "") {
        alt[0].style.display = "inline";
        real[0].style.display = "none";
    } else {
        alt[0].style.display = "none";
        real[0].style.display = "inline";
    }
}

function confirmAcceptConditions(checkbox) {
    if (checkbox.checked == true)
        return true;
    else {
		alert('Venligst l\u00e6s og accepter vilk\u00e5rene inden du bestiller');
       return false;
	}
}

function SchKeepAlive()
{
	if (!ajax_keepalive_obj) {
    	if (window.XMLHttpRequest) { // Mozilla, Safari,...
        	ajax_keepalive_obj = new XMLHttpRequest();
        	if (false && ajax_keepalive_obj.overrideMimeType) {
            	ajax_keepalive_obj.overrideMimeType('text/xml');
            	// See note below about this line
        	}
    	} else if (window.ActiveXObject) { // IE
        	try {
            	ajax_keepalive_obj = new ActiveXObject("Msxml2.XMLHTTP");
        	} catch (e) {
            	try {
                	ajax_keepalive_obj = new ActiveXObject("Microsoft.XMLHTTP");
            	} catch (e) {}
        	}
    	}
	}
	window.status="KA";
    try {
    	ajax_keepalive_obj.open('GET', keep_alive_url+"&wfw="+(new Date()).getTime(), true);
    	ajax_keepalive_obj.onreadystatechange =
			function() {
				window.status = ""+(new Date()).getTime();
				setTimeout( function() { window.status=""; }, 3000 );
			};
	} catch (open_e) {
		window.status = "Cannot keep alive "+open_e;
	}
	try {
    	ajax_keepalive_obj.send(null);
	} catch (ex) {
		window.status = "Cannot keep alive "+ex;
	}
	setTimeout("SchKeepAlive()", keep_alive_interval);
}
function submitCvrForm(cvrform) {
        if(cvrform.cvr.value != "") {
            if (cvrform.cvr.value.length == 8)
                cvrform.submit();
            else
                alert("Det indtastede CVR nummer skal v\u00e6re 8 cifre langt");
        }
}

