
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(obj){
	obj.value = "";
}

function confirmAction(confirmText, location){
	if(confirm(confirmText)) 
	{
		document.location.href = location;
	}
}

/* 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')
}

var AvatarList = {
	item : null,
	avatarItems : [],
	Init : function(){
		var ulElmColl = document.getElementsByTagName("*"), liItems;
		for(var i=0,ulElm;ulElm=ulElmColl[i];i++){
			if(/avatar-item/i.test(ulElm.className)){
				AvatarList.avatarItems.push(ulElm);
				ulElm.onmouseover = AvatarList.ShowLiItem;
			}
		}
	},
	ShowLiItem : function(){
		//remove all visible classes and set lower zindex on all non visible
		AvatarList.item = this;
		AvatarList.HideItem();
				
		var ulChild = this.getElementsByTagName("ul")[0];
		ulChild.className = "visible";
		ulChild.onmouseout = function(){
			AvatarList.HideItem();
		}
		this.style.zIndex = "10";
	},
	HideItem : function(){
		if(AvatarList.item != null){
			var parentUl = AvatarList.item.parentNode;
			for(var i=0,liElm;liElm=AvatarList.avatarItems[i];i++){
				if(/avatar-item/i.test(liElm.className)){
					liElm.style.zIndex = 1;
				
					var ulColl = liElm.getElementsByTagName("ul");
					for(var x=0,ulElm;ulElm=ulColl[x];x++){
						ulElm.className = "hidden";
					}
				}
			}
		}
	}
}
var ToggleWysiwyg = {
	formObj : null,
	buttonObj : null,
	Init : function(){
		var buttons = document.getElementsByTagName("*");
		for(var i=0,button;button=buttons[i];i++){
			if(/wysiwyg/i.test(buttons[i].className)){
				ToggleWysiwyg.formObj = buttons[i].parentNode;
				//attach events
				ToggleWysiwyg.buttonObj = buttons[i];
				buttons[i].onclick = ToggleWysiwyg.AddRemoveWysiwyg;
			}
		}	
	},
	AddRemoveWysiwyg : function(){
		//remove save class
		var editorId;
		if(this.className.indexOf("save") != -1){
			var normalClass = this.className.substring(0, this.className.indexOf("save")-1);
			editorId = normalClass.substring(8,normalClass.length); 
		}
		else{
			editorId = this.className.substring(8,this.className.length);
		}
		if (tinyMCE.getInstanceById(editorId) == null){
			this.parentNode.className = "wys-form presentation-filled";
			tinyMCE.execCommand('mceAddControl', false, editorId);
			var buttons = document.getElementsByTagName("*");
			for(var i=0,button;button=buttons[i];i++){
				if(/wysiwyg/i.test(button.className))
					buttons[i].className += " save";
			}
		}
		else{
			tinyMCE.execCommand('mceRemoveControl', false, editorId);		
			ToggleWysiwyg.Save();
			this.className = normalClass;
		}
		return false;
	},
	Save : function(){
		var presentation = document.getElementById("presentation").innerHTML;
		presentation = escape(presentation); //.replace("&","%26");
		var ajaxSave = new AjaxObj();
		ajaxSave.method = "POST";
		ajaxSave.url = "/min-sida/installningar/set-presentation-data.xml";
		
		//build parameter, obs hardcoded, change!
		var formItems = document.getElementById("presentation-form").getElementsByTagName("input");
		ajaxSave.parameters = "&"
		for(var i=0, formItem;formItem=formItems[i];i++){
			ajaxSave.parameters += formItems[i].getAttribute("name") + "=" + formItems[i].value + "&";
		}

		ajaxSave.parameters += "presentation-data=" + presentation;
		ajaxSave.parameters += "&hijax=1";
		ajaxSave.Fetch();
		
		if(presentation != ""){
			this.formObj.className = "wys-form presentation-filled";
		}
		else{
			this.formObj.className = "wys-form presentation-empty";
		}
		
		//ajaxSave.ClearXmlHttp();
	}
}
