function check_radio_set (elem){
	if (elem.length){
		for (var i = 0; i<elem.length; i++){
			if(elem[i].checked)  
    		   return elem[i].value;
		}
	} else {
		if (elem.checked){
			return elem.value;	
		}
	}
}
// webshop variant, viewport fullprod
function create_price_fullprod(pid, adj,nr,namenr){
	// calculates std price from percent adjustment
	var tmp_price = parseInt(std_price_fullprod[pid]);
	tmp_price = parseInt(tmp_price)+parseInt(priceadj_fullprod[pid][nr][adj]);
	priceadj_fullprod[pid][nr][999] = priceadj_fullprod[pid][nr][adj];

	// run through all variants
	for (var i=0; i<priceadj_fullprod[pid].length; i++){
 		if (i != nr){
			tmp_price = tmp_price + parseInt(priceadj_fullprod[pid][i][999]);
		}
	}
	document.getElementById("span_prod_price_"+pid).innerHTML = tmp_price;
	document.getElementById("prod_price_"+pid).value = tmp_price;
}
// use these to fix select boxes in IE. Used in webshop -> products that got variants. onblur onfocus
function expandSELECT(sel) {
  sel.style.width = '';
}
function contractSELECT(sel) {
  sel.style.width = '180px';
}
function toggle_comments(c) {
	obj=document.getElementById(c);
	visible=(obj.style.display!="none")
	if (visible) {
		obj.style.display="none";
	} else {
		obj.style.display="block";
		window.location.hash=c;
	}
}
function switchMenu(obj) {
	var el = document.getElementById(obj);
	if ( el.style.display != "none" ) {
		el.style.display = 'none';
	} else {
		el.style.display = '';
	}
}
function show_large(n) {
	var pos = "center";
	var w = 620;
	var h = 600;
	if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
	else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
	window.open("/picture.php?p=" + n,"sample","height=" + h + ",width=" + w + ",top=" +TopPosition+",left="+LeftPosition+",status=no,location=no,toolbar=no,directories=no,scrollbars=1,menubar=no,resizable");
}
function page_search() {
	var form = document.form_page_search;
	if(form.str.value == "") {
		alert("Du må skrive inn et søkeord");
	} else {
		form.submit();
	}
}
function popup_pic (src){
	document.getElementById('overlay_img').src = src;
	// Get page sizes
	var arrPageSizes = ___getPageSize();
	// Get page scroll
	var arrPageScroll = ___getPageScroll();
	// Calculate top and left offset for the jquery-lightbox div object and show it
	document.getElementById('waxpadhangerwaxpadautoid1').style.width = arrPageSizes[0]+'px';
	document.getElementById('waxpadhangerwaxpadautoid1').style.height = arrPageSizes[1]+'px';
	document.getElementById('waxpadvertseedwaxpadautoid1').style.top =  arrPageScroll[1] + (arrPageSizes[3] / 10)+'px';
	document.getElementById('waxpadvertseedwaxpadautoid1').style.left =	arrPageScroll[0]+'px';
	document.getElementById('waxpadvertseedwaxpadautoid1').style.width = arrPageSizes[0]+'px';
	document.getElementById('waxpadhangerwaxpadautoid1').style.display = 'block';
	document.getElementById('waxpadvertseedwaxpadautoid1').style.display = 'block';
}
function popup_closepic (){
	document.getElementById('overlay_img').src = '/tp2_templates/tp002/common/blank.gif';
	document.getElementById('waxpadvertseedwaxpadautoid1').style.display = 'none'; 
	document.getElementById('waxpadhangerwaxpadautoid1').style.display = 'none';	
}
/**
/ THIRD FUNCTION
* getPageSize() by quirksmode.com
*
* @return Array Return an array with page width, height and window width, height
*/
function ___getPageSize() {
	var xScroll, yScroll;
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
};
/**
/ THIRD FUNCTION
* getPageScroll() by quirksmode.com
*
* @return Array Return an array with x,y page scroll values.
*/
function ___getPageScroll() {
	var xScroll, yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop) {	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}
	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
};
function filterFileType(field, ext) {
if (field.value.indexOf('.' + ext) == -1) {
	return false;
}
	return true;
}
function validate_guestbook() {
	var form;
	form = document.form_guestbook;
	if(form.author.value == "") {
		alert("Du må skrive inn ditt navn");
		form.author.focus();
		return false;
	} else if (form.title.value == "") {
		alert("Du må skrive inn en tittel");
		form.title.focus();
		return false;
	} else if (tinyMCE.getContent() == "") {
		alert("Du må skrive inn en melding");
		form.comment.focus();
		return false;
	} else if (form.userdigit.value == "") {
		alert("Du må skrive inn en kode");
		form.userdigit.focus();
		return false;
	} else {
		form.submit();	
	}
}
function validate_comments() {
	var form;
	form = document.form_comments;
	if(form.author.value == "") {
		alert("Du må skrive inn ditt navn");
		form.author.focus();
		return false;
	} else if (form.comment.value == "") {
		alert("Du må skrive inn en kommentar");
		form.comment.focus();
		return false;
	} else if (form.userdigit.value == "") {
		alert("Du må skrive inn en kode");
		form.userdigit.focus();
		return false;
	} else {
		form.submit();	
	}
}
function validate_comments_blogg(n) {
	var form;
	form = document.getElementById("form_comments" + n);
	if(form.author.value == "") {
		alert("Du må skrive inn ditt navn");
		form.author.focus();
		return false;
	} else if (form.comment.value == "") {
		alert("Du må skrive inn en kommentar");
		form.comment.focus();
		return false;
	} else if (form.userdigit.value == "") {
		alert("Du må skrive inn en kode");
		form.userdigit.focus();
		return false;
	} else {
		form.submit();	
	}
}
function jump_blog(targ,selObj,restore,cid,loc){ //v3.0
	if(selObj.options[selObj.selectedIndex].value != 0) {
	  eval(targ+".location='"+loc+"/index.php?cid=" +cid +"&entry="+selObj.options[selObj.selectedIndex].value+"'");
	}
}
function shareFacebook(strArtUrl,strArtTitle){
	var tmpUrl = encodeURIComponent(strArtUrl);
	var tmpTitle = encodeURIComponent(strArtTitle);
	window.open("http://www.facebook.com/sharer.php?t=" + tmpTitle + "&u=" + tmpUrl, "Facebook", "width=645,height=436,location=0,menubar=0,resizabl=1,scrollbars=0,status=0,toolbar=0");
}
function shareNettby(strArtUrl,strArtTitle){
	var tmpUrl = encodeURIComponent(strArtUrl);
	var tmpTitle = encodeURIComponent(strArtTitle);
	window.open("http://www.nettby.no/user/edit_link.php?name=" + tmpTitle + "&url=" + tmpUrl + "&description=", "Nettby", "width=450,height=430,location=0,menubar=0,resizabl=1,scrollbars=0,status=0,toolbar=0");
}
function search_blog() {
	if((document.form_page_searchblog.search.value != "") && (document.form_page_searchblog.search.value != "Søk")) {
		document.form_page_searchblog.submit();	
	}
}
/* 
 * Cross-browser event handling, by Scott Andrew
 */
function addEventInput(element, eventType, lamdaFunction, useCapture) {
    if (element.addEventListener) {
        element.addEventListener(eventType, lamdaFunction, useCapture);
        return true;
    } else if (element.attachEvent) {
        var r = element.attachEvent('on' + eventType, lamdaFunction);
        return r;
    } else {
        return false;
    }
}