function getOASScript(serverurl, sitepage, listpos, query, target) {

	document.writeln("<script type='text/javascript'>");
	//configuration 
	document.writeln("OAS_url = '" + serverurl + "';"); //ex. http://oasc-training7.247realmedia.com/RealMedia/ads/
	document.writeln("OAS_sitepage = '" + sitepage + "';");
	document.writeln("OAS_listpos = '" + listpos + "';");
	document.writeln("OAS_query = '" + query + "';");
	document.writeln("OAS_target = '" + target + "';");
	//end of configuration
	document.writeln("OAS_version = 10;");
	document.writeln("OAS_rn = '001234567890'; OAS_rns = '1234567890';");
	document.writeln("OAS_rn = new String (Math.random()); OAS_rns = OAS_rn.substring (2, 11);");
	
	document.writeln("function OAS_NORMAL(pos) {");
	
	document.writeln("document.write('<A HREF=\"' + OAS_url + 'click_nx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '!' + pos + '?' + OAS_query + '\" TARGET=' + OAS_target + '>');"); 
	document.writeln("document.write('<IMG SRC=\"' + OAS_url + 'adstream_nx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '!' + pos + '?' + OAS_query + '\" BORDER=0/></A>'); "); 
	document.writeln("}");

	document.writeln("OAS_version = 11;");
	document.writeln("if ((navigator.userAgent.indexOf('Mozilla/3') != -1) || (navigator.userAgent.indexOf('Mozilla/4.0 WebTV') != -1))");
	document.writeln(" OAS_version = 10;");
	document.writeln("if (OAS_version >= 11)");
	document.writeln(" document.write('<SCR' + 'IPT type=\"text/javascript\" LANGUAGE=\"JavaScript1.1\" SRC=\"' + OAS_url + 'adstream_mjx.ads/' + OAS_sitepage + '/1' + OAS_rns + '@' + OAS_listpos + '?' + OAS_query + '\"><\/SCR' + 'IPT>');"); 
	
	document.writeln("function OAS_AD(pos) {");
	document.writeln("if (OAS_version >= 11)");
	document.writeln(" OAS_RICH(pos);");
	document.writeln("else");
	document.writeln(" OAS_NORMAL(pos);");
	document.writeln("}");
	
	document.writeln("</script>");
	
}

function getAd(site, position) {
	// make it possible to use different ad scripts on different sites
	getAdOAS(position);
}

function getAdOAS(position) {
	document.writeln('<script type="text/javascript"> OAS_AD("' + position + '"); </script>');
}

function getSifoScript(server, sitepage, position, taxonomy) {
	//Open Insight OAS 6.0 TAGGING
	document.writeln("<script type='text/javascript'>");
	document.writeln("_version=11;");
	document.writeln("if (navigator.userAgent.indexOf('mozilla/3') != -1){");
	document.writeln("	_version=10;");
	document.writeln("} ");

	document.writeln("var server = '" + server + "';"); //ex. http://sifomedia.resume.se
	document.writeln("var sitepage = '" + sitepage + "';"); //bonniertids
	document.writeln("var position ='" + position + "';"); //TopRight

	document.writeln("if (! (RN)) {");
	document.writeln("	var RN = new String (Math.random());");
	document.writeln("	var RNS = RN.substring (2, 11);");
	document.writeln("}");

	document.writeln("var oas=server;");
	document.writeln("var oaspage= sitepage + '/1' + RNS + '@' + position;");

	document.writeln("oaspage+='?XE';"); //Don't touch.
	document.writeln("oaspage+='" + taxonomy + "';"); //Add Taxonomy here. ex. &Sajt=resumese&Sektion=&var.sifosect;&Sida=&var.sifopage;
	document.writeln("oaspage+=OAS_rdl + '&if_nt_CookieAccept=' + OAS_CA + '&XE';"); //Don't touch.

	document.writeln("if (_version < 11) {");
	document.writeln("	document.write ('<a href=\"' + oas + '/1c/'+ oaspage + '\" TARGET=\"_top\" ><img src=\"' + oas + '/1/' + oaspage + '\" border=0 width=1 height=1 alt=\" \"/></a>');");
	document.writeln("} else {");
	document.writeln("	document.write ('<scr'+'ipt type=\"text/javascript\" src=\"' + oas + '/3/' + oaspage + '\">//<\/scr'+'ipt\>');");
	document.writeln("}");
	document.writeln("</script>");
}

/* Global Javascripts */

/* Error trap */
window.onerror=errorTrap;
function errorTrap(sMsg,sUrl,sLine){
	return true;
}

function clearSearchField(){
document.getElementById('search-field').value = "";
}

/* Generic popup function */
function PopWin(url,name,width,height,menubar,location,toolbar,scrollbars,resizable,directories) {
	window.open(url, name, 'resizable='+resizable+',menubar='+menubar+',scrollbars='+scrollbars+',location='+location+',toolbar='+toolbar+',width='+width+',height='+height +',directories='+directories+'');
}

function metaOver(navItem) { 
	document.getElementById(navItem).className = 'metanavOn'; 
}
function metaOut(navItem) { 
	document.getElementById(navItem).className = 'metanav'; 
}

function tipFriend() {
	window.open('/tip-friend.xml?__xsl=/templates/tip-friend-layout.xsl&amp;page=&page.path;','tipsa','toolbar=no,menubar=no,width=260,height=270')
}

document.onclick = function(e){
	anchorHref = EventDelegation.GetTarget(e).parentNode.getAttribute("href");
	anchorClass = EventDelegation.GetTarget(e).parentNode.className;
	if(anchorHref != null){
		if(anchorHref.indexOf("zoom") != -1){
			anchorId = anchorHref.substring(anchorHref.indexOf("#") + 1,anchorHref.length)
			
			ShowImage(anchorId);
		}
	}
	//find comment links
	var commentLink = EventDelegation.GetTarget(e).className;
	if(commentLink.indexOf("form-comment") != -1){
		ShowCommentForm(EventDelegation.GetTarget(e));
	
	}
	
	//find comment post links
	if(commentLink.indexOf("read-comment") != -1){
		ShowCommentPosts(EventDelegation.GetTarget(e));
	}
	
	
}


var EventDelegation = {
	GetTarget : function(e){
		e = e || window.event;
    	return e.target || e.srcElement;
	}
}




//find all zoom links and comment links
function ZoomImage(){
	var anchorObj = document.getElementsByTagName("a");
	var anchorName, anchorHref, anchorId, anchorClass;

	for(var i=0;i<anchorObj.length;i++){
		anchorHref = anchorObj[i].getAttribute("href");
		anchorClass = anchorObj[i].className;
		if(anchorHref != null){
			if(anchorHref.indexOf("zoom") != -1){
				anchorObj[i].onclick = function(){
					anchorId = this.getAttribute("href");
					anchorId = anchorId.substring(anchorId.indexOf("#") + 1,anchorId.length);
					ShowImage(anchorId);
				}
			}
			
			//find comment links
			if(anchorClass.indexOf("form-comment") != -1){
				anchorObj[i].onclick = ShowCommentForm;
			}
			
			//find comment post links
			if(anchorClass.indexOf("read-comment") != -1){
				anchorObj[i].onclick = ShowCommentPosts;
			}
		}	
	}
}

function ShowCommentForm(obj){
	var objLink = obj.href;
	objLink = objLink.substring(objLink.indexOf("#comment-form-")+14,objLink.length);
	if(document.getElementById("showcase_write_comment_" + objLink).className == "hidden")
		document.getElementById("showcase_write_comment_" + objLink).className = "visble";
	else
		document.getElementById("showcase_write_comment_" + objLink).className = "hidden";
	return false;
}

function ShowCommentPosts(obj){
	var objLink = obj.href;
	objLink = objLink.substring(objLink.indexOf("#comment-posts-")+15,objLink.length);
	if(document.getElementById("showcase_show_comment_" + objLink).className == "hidden")
		document.getElementById("showcase_show_comment_" + objLink).className = "visble";
	else
		document.getElementById("showcase_show_comment_" + objLink).className = "hidden";
	return false;
}

function GetCloseButton(){
	var spanObj = document.getElementsByTagName("span");
	for(var i = 0;i<spanObj.length;i++){
		if(spanObj[i].className == "close-popup"){
			spanObj[i].onclick = function(){
				this.parentNode.parentNode.style.display = "none";
			}
		}
	}
}
/*	function ShowHideImage(obj){
	if(obj.parentNode.style.display == "none")
		obj.parentNode.style.display = "block";
	else
		obj.parentNode.style.display = "none";
}*/
function ShowImage(objId){
	var obj = document.getElementById(objId).parentNode;
	
	if(obj.style.display == "block")
		obj.style.display = "none";
	else
		obj.style.display = "block";

	obj.onmouseover = function(){
		
		var closeObj  = this.getElementsByTagName("span");
		closeObj[0].style.display = "block";
	}
	obj.onmouseout = function(){
		var closeObj  = this.getElementsByTagName("span");
		closeObj[0].style.display = "none";
	}
}

function ClientValidationForm(){
	var FormObj = document.getElementById("create-home");
	if(FormObj != null){
		FormObj.onsubmit = function(){
			//perform client validation
			var inputObj = this.getElementsByTagName("input");
			var attrib, inputValue;
			var failed = false;
			var failedElm;
			
			for(var i=0;i<inputObj.length;i++){
				attrib = inputObj[i].getAttribute("type");
				if(attrib != "file"){
					inputValue = inputObj[i].value;
					if(inputValue.length < 1){
						failed  = true
						inputObj[i].parentNode.className = "error";
						failedElm = inputObj[i].parentNode.getElementsByTagName("p");
						failedElm[0].style.display = "block";
						
					}
					else{
						inputObj[i].parentNode.className = "noerror";
						failedElm = inputObj[i].parentNode.getElementsByTagName("p");
						failedElm[0].style.display = "none";
					}
				}
			}
			var texareaObj = this.getElementsByTagName("textarea");
			var texareaValue;

			for(var i=0;i<texareaObj.length;i++){
				texareaValue = texareaObj[i].value;
				if(texareaValue.length < 1){
					failed  = true;
					texareaObj[i].parentNode.className = "error";
					failedElm = texareaObj[i].parentNode.getElementsByTagName("p");
					failedElm[0].style.display = "block";
				}
				else{
					texareaObj[i].parentNode.className = "noerror";
					failedElm = texareaObj[i].parentNode.getElementsByTagName("p");
					failedElm[0].style.display = "none";
				}
			}
			
			var comboboxObj = document.getElementById("select-categoryid");
			if(comboboxObj != null){
				if(comboboxObj.options[comboboxObj.selectedIndex].value == ""){
					failed = true;
					comboboxObj.parentNode.className = "error";
					failedElm = comboboxObj.parentNode.getElementsByTagName("p");
					failedElm[0].style.display = "block";
				}
				else{
					comboboxObj.parentNode.className = "noerror";
					failedElm = comboboxObj.parentNode.getElementsByTagName("p");
					failedElm[0].style.display = "none";
				}
			}
						
			if(failed)
				return false;
			else
				return true;
		}
	}
}
/*SafeOnload.AddFunction(ZoomImage);*/
SafeOnload.AddFunction(GetCloseButton);
SafeOnload.AddFunction(ClientValidationForm);