if (window != top) top.location.href = location.href;

function newWin(p, w, h) {
	win = window.open(p, 'ny', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=' + w + ',height=' + h);
	win.focus();
}

function closeWin() {
	if (window.win) {
		win.close();
	}
}

function preloadImages() {
	var d = document;
	if (d.images) {
		if (!d.imgArray) {
			d.imgArray = new Array();
		}
		var i;
		var j = d.imgArray.length;
		var a = preloadImages.arguments;
		for (i = 0; i < a.length; i++) {
			if (a[i].indexOf("#") != 0){ 
				d.imgArray[j] = new Image; 
				d.imgArray[j++].src = a[i];
			}
		}
	}
}

function swapImage(name, src) {
	document.images[name].src = src;
}

function changeLoc(address) {
	window.location.href = address;
}
function over(element) {
	if (document.getElementById || (document.all && !(document.getElementById))) {
		if (document.all) {
			element.style.cursor = "hand";
		}
		for (i = 0; i < element.childNodes.length; i++) {
			if (element.childNodes[i].tagName == 'A') { 
				el = element.childNodes[i];
				//el.style.textDecoration = "underline";
				el.className = "over";
			}
		}
	}
}
function out(element) {
	if (document.getElementById || (document.all && !(document.getElementById))) {
		for (i = 0; i < element.childNodes.length; i++) {
			if (element.childNodes[i].tagName == 'A') { 
				el = element.childNodes[i];
				//el.style.textDecoration = "none";
				el.className = "out";
			}
		}
	}
}

function setCookie (cookieNamn, cookieVarde, antalGiltigaMinuter) {
	var cookieStr = cookieNamn + '=' + escape(cookieVarde);
	if (antalGiltigaMinuter > 0) {
		var exp = new Date();
		var giltigTill = exp.getTime() + (antalGiltigaMinuter * 60 * 1000);
		exp.setTime(giltigTill);
		cookieStr += '; expires=' + exp.toGMTString();
	} else if (antalGiltigaMinuter < 0) {
		var exp = new Date();
		var giltigTill = exp.getTime() - (1 * 60 * 60 * 1000);
		exp.setTime(giltigTill);
		cookieStr += '; expires=' + exp.toGMTString();
	}
	document.cookie = cookieStr;
} 
function getCookie(cookieNamn) {
	var crumbs = document.cookie.split('; ');
	for (var i in crumbs) {
		crumbName = crumbs[i].split('=')[0];
		crumbValue = unescape(crumbs[i].split('=')[1]);
		if (crumbName == cookieNamn) {
			return crumbValue;
		}
	}
	return '';
}

function showMessage(msg) {
	//if (getCookie('msg_was_showed') != 'yes') {
	//	setCookie('msg_was_showed', 'yes', 10);
		alert(msg);
	//}	
}

function is_date(str) {
	var re = /^[1-2][0-9]{3}-[0-1][0-9]-[0-3][0-9]$/;
	if (!re.test(str)) {
		return false;
	}
	return true;
}

function is_time(str) {
	var re = /^[0-2][0-9]:[0-5][0-9](:[0-5][0-9])?$/;
	if (!re.test(str)) {
		return false;
	}
	return true;
}

function is_email(str) {
	var re = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/;
	if (!re.test(str)) {
		return false;
	}
	return true;
}

function is_url(str) {
	var re = /^(ht||f)tp(s)?:[\/]{2}[a-z0-9_-]+(\.[a-z0-9_-]+)*(:[0-9]+)?(\/||\?)?.*$/i	
	if (!re.test(str)) {
		return false;
	}
	return true;
}

function displayFlash (swf, w, h, img, lnk, trg, col, rtl, rtr, rbr, rbl) { // corner radiuses and color
	if (img) {
		var qstr = '?w=' + w + '&h=' + h + '&img=' + img + '&lnk=' + lnk + '&trg=' + trg + '&col=' + col;
		if (rtl && rtr && rbr && rbl) {
			qstr += '&rtl=' + rtl + '&rtr=' + rtr + '&rbr=' + rbr + '&rbl=' + rbl;
		} else if (rtl) {
			qstr += '&rtl=' + rtl + '&rtr=' + rtl + '&rbr=' + rtl + '&rbl=' + rtl;
		}
	} else {
		var qstr = '';
	}
	document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"' +
	'codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0"' +
	'width="' + w + '" height="' + h + '" align="middle">');
	document.write('<param name="movie" value="' + swf + qstr + '" />');
	document.write('<param name="quality" value="high" />');
	document.write('<param name="bgcolor" value="#fff" />');
	document.write('<param name="scale" value="noscale" />');
	document.write('<embed src="' + swf + qstr + '" quality="high" scale="noscale"' +
	'bgcolor="#fff" width="' + w + '" height="' + h + '" align="middle" type="application/x-shockwave-flash"' +
	'pluginspage="http://www.macromedia.com/go/getflashplayer" />');
	document.write('</object>');
}

function markupWord(node, word) {
	// depth-first, so first recurse down into children
	if (node.hasChildNodes) {
		for (var i = 0; i < node.childNodes.length; i++) {
			markupWord(node.childNodes[i], word);
		}
	}
	// massage this node (if needed)
	if (node.nodeType == 3) { // text node
		// lowercase both content and word to get a caseinsensitive match
		var lowercasedContent = node.nodeValue.toLowerCase();
		var lowercasedWord = word.toLowerCase();
	
		// can we find our word in this text blob ?
		if (lowercasedContent.indexOf(lowercasedWord) != -1) {
			// yep, it's there - check that we haven't massaged this one before, 
			// (due to insertions in the DOM we might see the same node twice)
			if (node.parentNode.className.indexOf("searchword") == -1) {
				// no, we need to fix it - need to insert <span> around the word
				var startIndex = lowercasedContent.indexOf(lowercasedWord);
	
				// create a text node for the content before the word
				var preContent = document.createTextNode(node.nodeValue.substr(0, startIndex));
				// create a node for the word
				var searchWord = document.createTextNode(node.nodeValue.substr(startIndex, word.length));
				// create a node for the content after the word
				var postContent = document.createTextNode(node.nodeValue.substr(startIndex + word.length));
		
				// create the span around the word
				var highlight = document.createElement("span");
				highlight.className = "searchword";
				highlight.appendChild(searchWord);
	
				// insert the new nodes before the old one
				node.parentNode.insertBefore(preContent, node);
				node.parentNode.insertBefore(highlight, node);
				node.parentNode.insertBefore(postContent, node);
	
				// remove the old content
				node.parentNode.removeChild(node);
			}
		}
	}
}

function chooseText(s) {
	/*
	if (document.all) { // ie
		var r, i;
		if (s) {
			r = document.body.createTextRange();	
			for( i = 0; r.findText(s); i++) {
				r.execCommand('BackColor', '', '#c0eb35');
				r.collapse(false);
			}
		}
	} else 
	*/
	if (document.getElementById) { // ff
		markupWord(document.getElementsByTagName("body")[0], s);
	}
}

function display_email(email, mailto, icon) {
	aParts = email.split("@");
	var user = aParts[0];
	var domain = aParts[1];
	if (mailto) {
		document.write('<a href="mailto:' + user);
		document.write('@' + domain + '">');
	}
	if (icon) {
		document.write('<img src="/img/mail.gif" width="16" height="16"');
		document.write(' alt="Send mail" title="Send mail" />');
	} else {
		document.write(user);
		document.write('@' + domain);
	}
	if (mailto) {
		document.write('</a>');
	}	
}

