

function inet_pop_win(pageToLoad, winName, width, height, center, ramme) {
	xposition=0; yposition=0;
	if ((parseInt(navigator.appVersion) >= 4 ) && (center)){
		xposition = (screen.width - width) / 2;
		yposition = (screen.height - height) / 2;
		}
	width = width + ramme * 2
	args = "width=" + width + "," 
	+ "height=" + height + "," 
	+ "location=0," 
	+ "menubar=0,"
	+ "resizable=0,"
	+ "scrollbars=0,"
	+ "status=0," 
	+ "titlebar=0,"
	+ "toolbar=0,"
	+ "hotkeys=0,"
	+ "left=" + xposition + ","
	+ "top=" + yposition;

	window.open(pageToLoad+"&ramme="+ramme,winName,args );
}

function inet_open_win() {
	if (ua["dom"]) {
		var url = "";
		var target = "";

		var attributes = "";


		if (arguments.length > 0) {
			url = arguments[0];
		}

		//Target attribute:
		if (arguments.length > 1) {
			target = arguments[1];
		}
			
		//Optional attributes:
		if (arguments.length > 2) {
			attributes = arguments[2];
		}
	
		win = window.open(url, target, attributes);
		win.focus();
		return false;
	}
}

function toggleMenuLink(obj) {
	parobj = obj.parentNode;

	parclasses = parobj.className.split(" ");

	for (i=0; i<parclasses.length; i++) {
		if (parclasses[i] == "closed") {
			parclasses[i] = "open";
			parobj.className = parclasses.join(" ");
			i = parclasses.length;
		}
		else if (parclasses[i] == "open") {
			parclasses[i] = "closed";
			parobj.className = parclasses.join(" ");


			i = parclasses.length;


		}
	}

	return false;
}



/**** INIT ****/

function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != "function") {
		window.onload = func;
	}
	else {
		window.onload = function() {
			oldonload();
			func();
		}
	}
}


function hasClassName(elm, cname) {
	if (ua["dom"]) {
		aCname = elm.className.split(" ");
		for (j=0; j<aCname.length; j++) {
			if (aCname[j] == cname) return true;
		}
	}
	return false;
}



function inet_print() {
	if (!ua["iemac"]){// && !ua["safari"]) {
		window.print();
	}
	return false;
}

function mo_lang(elm) {
	if (document.getElementById) {
		elm.className = 'on';
		elm.onmouseout = function() {
			elm.className = 'off';
		}
	}
}





function showSubMap(id) {
	var oSub = document.getElementById("submap");
	if (oSub) {
		oSub.style.backgroundImage = 'url(/site/images/submap'+id+'.gif)';

		var aDiv = oSub.getElementsByTagName('DIV');
		for (var i = 0; i < aDiv.length; i++) {
			if (aDiv[i].className == 'submap') {
				aDiv[i].style.display = (aDiv[i].id == 'submap'+id ? 'block' : 'none' );
			}
			else if (aDiv[i].id == 'submaptxt') {
				aDiv[i].style.display = 'none';
			}
		}
	}
	return false;
}

function overSubMapArea(submapid, areaid) {
	var oImg = document.getElementById('submap'+submapid+'img');
	if (oImg) {
		oImg.src = '/site/images/submap'+submapid+'_'+areaid+'.gif';
	}
}

function outSubMapArea(submapid) {
	var oImg = document.getElementById('submap'+submapid+'img');
	if (oImg) {
		oImg.src = '/site/images/blank.gif';
	}
}

function overMapArea(areaid) {
	var oImg = document.getElementById('rootmapimg');
	if (oImg) {
		oImg.src = '/site/images/map_'+areaid+'.gif';
	}
}

function outMapArea() {
	var oImg = document.getElementById('rootmapimg');
	if (oImg) {
		oImg.src = '/site/images/blank.gif';
	}
}



function trim(str) {
	return str.replace(/(^(\s+))|((\s+)$)/g, '');
}

function checkCompletion(id, complete) {
	if (ua["dom"]) {	
		var aLABEL = document.getElementsByTagName('LABEL');
		for (var i = 0; i < aLABEL.length; i++) {
			if (aLABEL[i].htmlFor == id) {
				aLABEL[i].className = (complete ? '' : 'incomplete');
			}
		}
	}
}

function validateField(elm) {
	if (ua["dom"]) {
		elm.value = trim(elm.value);
		if (elm.value == '') {
			checkCompletion(elm.id, false);	
		}
		else {
			checkCompletion(elm.id, true);
		}
	}
}

function validateCatalogueForm() {
	var cf = document.forms['catalogue_form'];
	if (cf) {
		var proceed = true;
		var cf_lang = cf.lang;
		
		var cf_fname = cf.firstname;
		validateField(cf_fname);
		if (cf_fname.value == '') {
			proceed = false;
		}

		var cf_lname = cf.lastname;
		validateField(cf_lname);
		if (cf_lname.value == '') {
			proceed = false;
		}

		var cf_address = cf.address;
		validateField(cf_address);
		if (cf_address.value == '') {
			proceed = false;
		}
		
		var cf_postalcode = cf.postalcode;
		validateField(cf_postalcode);
		if (cf_postalcode.value == '') {
			proceed = false;
		}

		var cf_city = cf.city;
		validateField(cf_city);
		if (cf_city.value == '') {
			proceed = false;
		}

		var cf_country = cf.country;
		validateField(cf_country);
		if (cf_city.value == '' ) {
			proceed = false;
		}

		var cf_email = cf.email;
		cf_email.value = trim(cf_email.value);

		var c_count = 0;
		for (var i = 0; i < cf.catalogue.length; i++) {
			c_count += (cf.catalogue[i].checked ? 1 : 0);
		}
		if (c_count == 0) {
			proceed = false;
		}



		if (cf_fname.value != '' &&
			cf_lname.value != '' &&
			cf_address.value != '' &&
			cf_postalcode.value != '' &&
			cf_city.value != '' &&
			cf_country.value != '' &&
			c_count > 0) {
			return true;
		}
		else {
			var error_str = "";

			if (c_count == 0) {
				switch(cf_lang.value) {
					case '1' :
						error_str += "- Vaelg mindst ét katalog.\n";
						break;
					case '2' :
						error_str += "- Please select at least one brochure.\n";
						break;
					case '3' :
						error_str += "- Please select at least one brochure.\n";
						break;
				}
			}

			if (cf_fname.value == '' || 
				cf_lname == '' || 
				cf_address == '' || 
				cf_postalcode == '' ||
				cf_city == '' ||
				cf_country == '') {
				switch(cf_lang.value) {
					case '1' :
						error_str += "- Ret venligst adresseoplysninger.\n";
						break;
					case '2' :
						error_str += "- Please complete address information.\n";
						break;
					case '3' :
						error_str += "- Please complete address information.\n";
						break;
				}
			}
			if (error_str.length > 0) {
				alert(error_str);
			}
			return false;
		}


	}
	return true;
}