



/*	Generic AJAX reader implementation
	2005-09-12, Johan Weitner at Mogul 
	Usage: Call ajaxRead(file,callback,dialog), where: 
	"file" is the file that should provide the needed data, 
	"callback" is the name of the method that should handle the retrieved data, 
	"target" is the target element for the data, and 
	"dialog" (optional) is the id of the dialog element
*/
  
function ajaxRead(file,callback,target,dialog) {
// XMLHttpRequest constructor
var xmlObj;
if(window.XMLHttpRequest) { 
	xmlObj = new XMLHttpRequest();
} else if(window.ActiveXObject) {
	xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
} else {
	return;
}

if(dialog) document.getElementById(dialog).style.visibility = "visible";

// Callback handler
xmlObj.onreadystatechange = function() {
	if(xmlObj.readyState == 4) {
		if (xmlObj.status == 200) eval(callback+"(xmlObj,target,dialog)");
		else {
			if(document.getElementById(dialog)) document.getElementById("loading").style.visibility = "hidden";
			alert("Data could not be retrieved. Error code: " + xmlObj.status);
		}
	}
}

// Request
try {
	xmlObj.open ('GET', file, true);
	xmlObj.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");
	xmlObj.send (null); // Method call needed to trig the onreadystatechange handler above
	} 
catch(e) { 
	if(dialog) document.getElementById(dialog).style.visibility = "hidden"; 
	alert("Request could not be made... \nMalformed URL?"); 
	}
}



/*	DEPRECATED!!
	Slides.js used instead
	
	AJAX implementation for SN: "Kommentaren"
	2006-06-01, Johan Weitner at Mogul 
	Import into pages that use the "Kommentaren" widget
	Dependencies: 
		-- /js/ajax.js
		-- /includes/kommentar.jsp - (or simply a target element with the id "tgt")
*/

function getCommentary(ix,siteUrl) {
url = (siteUrl + "index.jsp?ix=" + ix + "&service=Kommentar");
ajaxRead(url,"setAsText","tgt",null);
}

function setAsText(tree,target,dialog) {
		if(document.getElementById(target)) document.getElementById(target).innerHTML = tree.responseText;
		else alert("Target element ('" + target + "') could not be found");
		if(dialog) document.getElementById(dialog).style.visibility = "hidden";
}

window.onload = function() {
	//getCommentary(0);
}

/*	Vertical newssticker widget
	2006-06-01, Johan Weitner at Mogul 
*/

// Edit these...				
var time = 25;			// Number of milliseconds between animation frames
var delay = 5000;		// Number of milliseconds items should pause before scrolling out
var startcoord = 15;	// Vertical start position for ticker items
var pauscoord = 0;		// Vertical position for ticker items to make a pause
var endcoord = -16;		// Vertical end position for ticker items

var num; 				// Number of ticker items, is set dynamically in page
var tc = 0;
var ticker;

function initTicker(number) {
	num = number;
	if(document.getElementById) {
		for(i=0; i<num; i++) {
			document.getElementById("tickeritem" + i).style.top = startcoord + "px";
		}
		document.getElementById("ticker").style.visibility = "visible";
		ticker = setInterval("tick()",25); 
	}
}

function tick() {
obj = document.getElementById("tickeritem" + tc);
coord = parseInt(obj.style.top);
if(coord == endcoord) switchItem();
else if(coord == pauscoord) paus();
else obj.style.top = (coord - 1) + "px";
}

function continueTick() {
obj = document.getElementById("tickeritem" + tc);
coord = parseInt(obj.style.top);
obj.style.top = (coord - 1) + "px";
ticker = setInterval("tick()",time);
}

function paus() {
clearInterval(ticker);
setTimeout('continueTick()',delay);
}

function switchItem() {
document.getElementById("tickeritem" + tc).style.top = startcoord + "px";
if(tc == (num-1)) tc = 0;
else tc++;
}



function setUrl() {
	document.region_form.action = document.region_form.typ.value;
}
// JavaScript Document

function trimAll(sString) {
	while (sString.substring(0,1) == ' ') {
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ') {
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function checkPostingForm(form) {
	
	var alias = trimAll(form.alias_field.value);
	var email = trimAll(form.email_field.value);
	var rubrik = trimAll(form.title_field.value);
	var kommentar = trimAll(form.body_field.value);
	var rules = form.rules_field.checked
	
	if (form.action_url.value == "") {
		form.action_url.value = form.action;
	}
	
	if (alias.length < 1)	{
		alert("Du måste ange ett alias!");
		form.action = form.url.value;
		form.alias_field.focus();
		form.alias_field.select();
		return false;			
	}
	
	if (email.length < 1)	{
		alert("Du måste ange en e-postadress!");
		form.action = form.url.value;
		form.email_field.focus();
		form.email_field.select();
		return false;			
	}
	
	if (!isValidEmail(email))	{
		alert("E-postadressen innehåller ett felaktigt format!");
		form.action = form.url.value;
		form.email_field.focus();
		form.email_field.select();
		return false;			
	}

	if (rubrik.length < 1)	{
		alert("Du måste ange en rubrik!");
		form.action = form.url.value;
		form.title_field.focus();
		form.title_field.select();
		return false;			
	}
	
	if (kommentar.length < 1)	{
		alert("Du måste ange en kommentar!");
		form.action = form.url.value;
		form.body_field.focus();
		form.body_field.select();
		return false;			
	}
	
	if (rules != true)	{
		alert("Du måste godkänna reglerna!");
		form.action = form.url.value;
		form.rules_field.focus();
		form.rules_field.select();
		return false;			
	}
	
	form.action = form.action_url.value;
	form.secure.value = "true"; //Used to avoid spam.
	
	return true;
}

function checkSignatureForm(form) {
	
	var alias = trimAll(form.alias_field.value);
	var rubrik = trimAll(form.title_field.value);
	var kommentar = trimAll(form.body_field.value);
	var rules = form.rules_field.checked
	
	if (form.action_url.value == "") {
		form.action_url.value = form.action;
	}
	
	if (alias.length < 1)	{
		alert("Du måste ange ett namn!");
		form.action = form.url.value;
		form.alias_field.focus();
		form.alias_field.select();
		return false;			
	}
	
	if (rubrik.length < 1)	{
		alert("Du måste ange ett företag!");
		form.action = form.url.value;
		form.title_field.focus();
		form.title_field.select();
		return false;			
	}
	
	if (kommentar.length < 1)	{
		alert("Du måste ange en ort!");
		form.action = form.url.value;
		form.body_field.focus();
		form.body_field.select();
		return false;			
	}

	if (kommentar.length > 500)	{
		alert("Max 500 tecken!");
		form.action = form.url.value;
		form.body_field.focus();
		form.body_field.select();
		return false;			
	}
	
	if (rules != true)	{
		alert("Du måste godkänna reglerna!");
		form.action = form.url.value;
		form.rules_field.focus();
		form.rules_field.select();
		return false;			
	}
	form.secure.value = "true"; //Used to avoid spam.	
	form.action = form.action_url.value;
	
	
	return true;
	
}

function checkComplaintForm(form) {
	
	
	
	
	
	if(form.body.value == "" ){
		alert("Du måste ange ett klagomål!");	
		form.body_field.focus();
		form.body_field.select();
		return false;
	}
		
	
	
	
	if (form.action_url.value == "") {
		form.action_url.value = form.action;
	}
		
	
	form.secure.value="true";
	
	return true;
	
	/*
		var kommentar = trimAll(form.body_field.value);

	if (form.action_url.value == "") {
		form.action_url.value = form.action;
	}
	
	if (kommentar.length < 1)	{
		alert("Du måste ange ett klagomål!");
		form.action = form.url.value;
		form.body_field.focus();
		form.body_field.select();
		return false;			
	}

	
	
	form.action = form.action_url.value;	
	*/
	
	
	
	
}

function checkForumUnsubscribeForm(form) {
	
	var email = trimAll(form.email.value);
	
	if (email.length < 1)	{
		alert("Du måste ange en e-postadress!");
		form.email.focus();
		form.email.select();
		return false;			
	}
	
	if (!isValidEmail(email))	{
		alert("E-postadressen innehåller ett felaktigt format!");
		form.email.focus();
		form.email.select();
		return false;			
	}
	
	form.secure.value = "true"; //Is used to avoid spam.
	
	return true;
}
/**
	Embedded RSS client for HTML
	2006-09-07, Johan Weitner at Mogul
	Extended/modified by Jimi Hullegård at Mogul

	Usage:
	rssclient = new RSSClient(feed_uri, process_method, target_element, item_page, optional_dialog, optional_interval, optional_item);

	Examples:
	1. Init on page load
		window.onload = function() {
			rssclient = new RSSClient("rss.xml","this.procXML","target","someUrl","dialog",5);
		}

	2. Manual refresh
		<a href="#" onclick="rssclient.getXML()">Refresh RSS feed</a>

*/

function RSSClient(feed,process,target,itempage, dialog,interval,rssitem) {
	this.FEED = feed;
	this.PROCESS = process;
	this.TARGET = target;
	this.ITEMPAGE = itempage;
	this.DIALOG = dialog;
	this.INTERVAL = interval;
	this.ITEM = rssitem;
	var r = this;

	this.getXML();
	if(interval && interval > 0) 
		setInterval("repeatXML()",(this.INTERVAL * 60 * 1000));
		
	repeatXML = function() { 
		r.ajaxRead(r.FEED,r.PROCESS,r.TARGET,r.DIALOG,r.ITEM); 
	}
	
}


	RSSClient.prototype.getXML = function() { 
		this.ajaxRead(this.FEED,this.PROCESS,this.TARGET,this.DIALOG,this.ITEM); 
	}







/*
<item rdf:about="urn:observer.se:mwsdemo:intranet:1481945">
        <title>Top Liberal official resigns as scandal grows</title>
        <link></link>
        <description>The Liberal party's youth leader Per Jodenius, who has had unauthorized access to rival Social Democrat 
		party's internal computer network, was fired on Monday after the Social Democrats filed a police complaint about the 
		incident. The incident has do...</description>
        <dc:source>www.sr.se</dc:source>
        <dc:subject>Language|English</dc:subject>
        <dc:subject>Region|Nordic and Baltic</dc:subject>
        <dc:date>2006-09-06</dc:date>
        <content:encoded><![CDATA[The Liberal party's youth leader Per Jodenius, who has had unauthorized access to rival 
		Social Democrat party's internal computer network, was fired on Monday after the Social Democrats filed a police 
		complaint about the incident. The incident has dominated media coverage of the Swedish election. Johan Jakobsson, 
		Party Secretary of the Liberal Party, announced that he was resigning from his post immediately because he had not 
		done enough to stop Mr Jodenius from entering the Social Democratic Party's internal computer network. Also, Mr 
		Jakobsson admitted that he had known about the computer intrusions since March of this year. Furthermore, Niki 
		Westerberg, press secretary for the Liberal Party, has taken a leave of absence due to a police investigation of 
		her participation in the incident. According to Swedish Radio News, five Liberal party members have been questioned 
		so far by the police, and more are expected to be questioned about the incident.]]></content:encoded>
</item>
*/


	RSSClient.prototype.procXML = function(tree,target,dialog,rssitem) {
		rot = tree.responseXML.documentElement;
		news = rot.getElementsByTagName("item");
		var html = "<ul class=\"basiclist\">";
		if (news.length < rssitem)
        {
            rssitem = news.length;
        }
		for(i = 0; i < rssitem; i++) {
			var timestamp = "";
			if(document.all) 
			{
				if (news[i].getElementsByTagName("dc:date") && news[i].getElementsByTagName("dc:date")[0])
				{
					timestamp = news[i].getElementsByTagName("dc:date")[0].firstChild.nodeValue;
				}
			}
			else if (news[i].getElementsByTagName("date") && news[i].getElementsByTagName("date")[0])
			{
				timestamp = news[i].getElementsByTagName("date")[0].firstChild.nodeValue;
			}
				
			title = news[i].getElementsByTagName("title")[0].firstChild.nodeValue;
			guid = news[i].getAttribute('rdf:about');
			source = "";
			if (document.all)
			{
				if (news[i].getElementsByTagName("dc:source") && news[i].getElementsByTagName("dc:source")[0])
				source = news[i].getElementsByTagName("dc:source")[0].firstChild.nodeValue;
			}
			else if (news[i].getElementsByTagName("source") && news[i].getElementsByTagName("source")[0])
			{
				source = news[i].getElementsByTagName("source")[0].firstChild.nodeValue;
			}
			// SN specific: If LINK element is populated, open external link, otherwise open item locally
			//href = "ajax/rss_item.jsp?item=" + guid;
			href = this.ITEMPAGE + "?item=" + guid + "&proxyUrl=" + URLEncode(this.FEED);
			var extlink;
			if(news[i].getElementsByTagName("link")[0].firstChild)
				extlink = news[i].getElementsByTagName("link")[0].firstChild.nodeValue;
			//extlink = null;
			href = (extlink == null || extlink == "") ? href : extlink;
			onclick = (extlink == null || extlink == "") ? " onclick=\"openRSSItem('" + href + "'); return false;\"" : "";
			html += "<li>";
			html += "<div class=\"smalltext\">" + timestamp +  " <span class=\"subject\">" + source + "</span></div>";
			html += "<a href=\"" + href + "\" target=\"_blank\"" + onclick + ">"
			html += title + "</a></li>";
		}

		html += "</ul>"
		document.getElementById(target).innerHTML = html;
		if(dialog) document.getElementById(dialog).style.visibility = "hidden";
	}
	
	
	RSSClient.prototype.procItem = function(tree,target,dialog,rssitem) {
		rot = tree.responseXML.documentElement;
		news = rot.getElementsByTagName("item");
		var foundIt = false;
		html = "";
		for(i = 0; i < news.length; i++) {
			guid = news[i].getAttribute("rdf:about");
			if(guid == rssitem) {
				
				timestamp = (document.all) ? news[i].getElementsByTagName("dc:date")[0].firstChild.nodeValue : news[i].getElementsByTagName("date")[0].firstChild.nodeValue;
				title = news[i].getElementsByTagName("title")[0].firstChild.nodeValue;
				description = news[i].getElementsByTagName("description")[0].firstChild.nodeValue;
				content = document.all ? news[i].getElementsByTagName("content:encoded")[0].firstChild.nodeValue : news[i].getElementsByTagName("encoded")[0].firstChild.nodeValue;
				source = document.all ? news[i].getElementsByTagName("dc:source")[0].firstChild.nodeValue : news[i].getElementsByTagName("source")[0].firstChild.nodeValue;
				
				html += "<p class=\"smalltext\">Publicerad: " + timestamp + "</p>";
				html += "<h1>" + title + "</h1>";
				html += "<p>" + content + "</p>";
				html += "<p><strong>Källa:</strong> " + source + "</p>";
				
				foundIt = true;
				break;				
			}
		}
		if(!foundIt) alert("Couldn't find: " + rssitem);
		document.getElementById(target).innerHTML = html;
		if(dialog) document.getElementById(dialog).style.visibility = "hidden";
	}


	RSSClient.prototype.ajaxRead = function(file,callback,target,dialog,rssitem) {
	// XMLHttpRequest constructor
	var xmlObj;
	if(window.XMLHttpRequest) xmlObj = new XMLHttpRequest();
	else if(window.ActiveXObject) xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
	else return;

	if(dialog) document.getElementById(dialog).style.visibility = "visible";

	// Callback handler
	c = this; //assigning instance to local var
	xmlObj.onreadystatechange = function() {
		if(xmlObj.readyState == 4) {
			if (xmlObj.status == 200) eval("c." + c.PROCESS + "(xmlObj,target,dialog,rssitem)");
			else {
				if(document.getElementById(dialog)) document.getElementById(dialog).style.visibility = "hidden";
				alert("Data could not be retrieved. Error code: " + xmlObj.status);
				//alert("feed: " + this.FEED);
			}
		}
	}

	// Request
	try {
		xmlObj.open ('GET', file, true);
		xmlObj.send (null); // Method call needed to trig the onreadystatechange handler above
		} 
	catch(e) { 
		if(dialog) document.getElementById(dialog).style.visibility = "hidden"; 
		alert("Request could not be made... \nMalformed URL?"); 
		}
	}
	
	
function openRSSItem(url) {
window.open(url,'rssitemwin','width=800,height=600,scrollbars=yes');
}

// ====================================================================
//  	Function URLEncode
//		Based on code from:
// http://www.albionresearch.com/
// ====================================================================
function URLEncode(string)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = string;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for

	return encoded;
};
/*	Generic AJAX reader implementation
	2005-09-12, Johan Weitner at Mogul 
	Usage: Call ajaxRead(file,callback,dialog), where: 
	"file" is the file that should provide the needed data, 
	"callback" is the name of the method that should handle the retrieved data, 
	"target" is the target element for the data, and 
	"dialog" (optional) is the id of the dialog element
*/
  
function ajaxRead(file,callback,target,dialog) {
// XMLHttpRequest constructor
var xmlObj;
if(window.XMLHttpRequest) { 
	xmlObj = new XMLHttpRequest();
} else if(window.ActiveXObject) {
	xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
} else {
	return;
}

if(dialog) document.getElementById(dialog).style.visibility = "visible";

// Callback handler
xmlObj.onreadystatechange = function() {
	if(xmlObj.readyState == 4) {
		if (xmlObj.status == 200) eval(callback+"(xmlObj,target,dialog)");
		else {
			if(document.getElementById(dialog)) document.getElementById("loading").style.visibility = "hidden";
			alert("Data could not be retrieved. Error code: " + xmlObj.status);
		}
	}
}

// Request
try {
	xmlObj.open ('GET', file, true);
	xmlObj.setRequestHeader("Content-Type", "text/html; charset=iso-8859-1");
	xmlObj.send (null); // Method call needed to trig the onreadystatechange handler above
	} 
catch(e) { 
	if(dialog) document.getElementById(dialog).style.visibility = "hidden"; 
	alert("Request could not be made... \nMalformed URL?"); 
	}
}



/**
	SlideShow animation widget
	Slides horisontally aligned items in and out of a viewport
	2006-09-05, Johan Weitner at Mogul
	
	Setup:
	----------------
	<a href="#" id="rewbtn" onclick="slideshow.startAnim(false)">Back</a>
	<a href="#" id="fwdbtn" onclick="slideshow.startAnim(true)">Forward</a>
	<div id="viewport">
		<div id="slideitemholder">
			<div class="item">Item 1</div>
			<div class="item">Item 2</div>
			<div class="item">Item 3</div>
		</div>
	</div>
	<script type="text/javascript">
		slideshow = new SlideShow(200,3,25,"slideitemholder","viewport","rewbtn","fwdbtn",false);
	</script>
	
	Dependancies:
	----------------
	- A css class named "hidden" with the visibility property set "hidden", (and obviously proper styles for slideshow elements)
	- If fixHeight is used, each slideshow item is expected to contain one IMG and one P (for img caption). 
*/

function SlideShow(width,num,speed,trayID,viewportID,rewID,fwdID,fixHeight) {
	this.NUM_SLIDES = num;
	this.ANIM_DELAY = speed;
	this.SLIDE_WIDTH = width;
	this.SLIDETRAY_ID = trayID;
	this.VIEWPORT_ID = viewportID;
	this.REW_BUTTON_ID = rewID;
	this.FWD_BUTTON_ID = fwdID;
	this.FIXHEIGHT = fixHeight;
	this.ACTIVE_ITEM = 0;	
	this.END_COORD = width;
	this.ANIMATION;
	this.OBJ = document.getElementById(this.SLIDETRAY_ID);
	
	if(this.FIXHEIGHT) this.fixSlideHeight();
} 




SlideShow.prototype.startAnim = function(fwd) {
clearInterval(this.ANIMATION);

if(fwd) {
	this.ACTIVE_ITEM++;
	if(this.ACTIVE_ITEM == (this.NUM_SLIDES - 1)) document.getElementById(this.FWD_BUTTON_ID).className = "hidden";
	document.getElementById(this.REW_BUTTON_ID).className = "";
	}
else {
	this.ACTIVE_ITEM--;
	if(this.ACTIVE_ITEM == 0) document.getElementById(this.REW_BUTTON_ID).className = "hidden";
	document.getElementById(this.FWD_BUTTON_ID).className = "";
	}	
if(this.FIXHEIGHT) this.fixSlideHeight();
this.END_COORD = this.ACTIVE_ITEM * this.SLIDE_WIDTH;
ss = this; //assigning instance to local var because of crappy instance handling in setInterval
this.ANIMATION = setInterval("anim(" + fwd + ")",this.ANIM_DELAY);

		anim = function(fwd) {			
		lowPoint = fwd ? 1 : -1;
		if(ss.END_COORD + ss.OBJ.offsetLeft == 0) {
			clearInterval(ss.ANIMATION);
			return;
			}
		DIFF = Math.round(((ss.END_COORD + ss.OBJ.offsetLeft) / 2));
		DIFF = DIFF == 0 ? lowPoint : DIFF;
		ss.OBJ.style.left = ss.OBJ.offsetLeft - DIFF + "px";
		}

}







SlideShow.prototype.anim = function(fwd) {
lowPoint = fwd ? 1 : -1;
if(this.END_COORD + this.OBJ.offsetLeft == 0) {
	clearInterval(this.ANIMATION);
	return;
	}
DIFF = Math.round(((this.END_COORD + this.OBJ.offsetLeft) / 2));
DIFF = DIFF == 0 ? lowPoint : DIFF;
this.OBJ.style.left = this.OBJ.offsetLeft - DIFF + "px";
}




SlideShow.prototype.fixSlideHeight = function() {
	viewport = document.getElementById(this.VIEWPORT_ID);
	tray = this.OBJ;
	slide = tray.getElementsByTagName("DIV")[this.ACTIVE_ITEM];
	img = slide.getElementsByTagName("IMG")[0];
	txt = slide.getElementsByTagName("P")[0];
	newHeight = (img.height + txt.offsetHeight);

	slide.style.height = newHeight + "px";
	tray.style.height = newHeight + "px";
	viewport.style.height = newHeight + "px";
}



SlideShow.prototype.returnToOne = function() { 
document.getElementById(this.SLIDETRAY_ID).style.left = "0px";
document.getElementById(this.REW_BUTTON_ID).className = "hidden";
document.getElementById(this.FWD_BUTTON_ID).className = "0px";
this.ACTIVE_ITEM = 0; 
this.END_COORD = this.SLIDE_WIDTH; 
}

/*	
	Google search functions are gathered here.
	2006-09-13, Martin Kjellqvist
	Extended/modified by Jimi Hullegård at Mogul
*/

/* Set the selected type as a required field */ 
function setTopTypeSearch(f)
{
	f.requiredfields.value = f.google_type.value;
}

/* 
	Add all values from select boxes to a required field value 
	This function is used from all multiple values search.
*/
function setRequiredFields(f)
{
	// required fields
	if (f.google_type != null)
	{
		var temp = "";
		if (f.google_type.type == "select-one")
		{
			if (f.google_type.selectedIndex > 0 || f.google_type.options[0].value.length > 0) {
				temp = f.google_type.options[f.google_type.selectedIndex].value;
			}
		}
		else
		{
			temp = f.google_type.value;
		}
		
		f.requiredfields.value = addToString(f.requiredfields.value, temp, ".");
	}

	// Add value from google_checkbox_ws to requiredfields, used by filtrera special
	
	if(f.google_ws_checkbox != null && f.google_ws_checkbox.checked)
	{
		f.requiredfields.value = addToString(f.requiredfields.value, f.google_ws_checkbox.value, ".");
	}
	
	// Add value from google_checkbox_ws to requiredfields, used by filtrera gennerall

	if(f.google_ws_hidden != null)
	{
		f.requiredfields.value = addToString(f.requiredfields.value, f.google_ws_hidden.value, ".");
	}

	if (f.google_type_hidden != null)
	{
		f.requiredfields.value = addToString(f.requiredfields.value, f.google_type_hidden.value, ".");
	}

	if (f.google_subject != null   )
	{
		if (f.google_subject.selectedIndex > 0) 
		{
			f.requiredfields.value = addToString(f.requiredfields.value, f.google_subject.options[f.google_subject.selectedIndex].value, ".");
			/*
			if (f.requiredfields.value.length > 0)
			{
				f.requiredfields.value = f.requiredfields.value + ".";
			}
			f.requiredfields.value = f.requiredfields.value + f.google_subject.options[f.google_subject.selectedIndex].value;
			*/
		}
	}

	if (f.google_updated != null)
	{
		if (f.google_updated.selectedIndex > 0)
		{
			f.requiredfields.value = addToString(f.requiredfields.value, f.google_updated.options[f.google_updated.selectedIndex].value, ".");
			/*
			if (f.requiredfields.value.length > 0)
			{
				f.requiredfields.value = f.requiredfields.value + ".";
			}
			f.requiredfields.value = f.requiredfields.value + f.google_updated.options[f.google_updated.selectedIndex].value;
			*/
		}
	}

	if (f.google_event != null)
	{
		if (f.google_event.selectedIndex > 0)
		{
			f.requiredfields.value = addToString(f.requiredfields.value, f.google_event.options[f.google_event.selectedIndex].value, ".");
			/*
			if (f.requiredfields.value.length > 0)
			{
				f.requiredfields.value = f.requiredfields.value + ".";
			}
			f.requiredfields.value = f.requiredfields.value + f.google_event.options[f.google_event.selectedIndex].value;
			*/
		}
	}

	if (f.google_county != null)
	{
		if (f.google_county.selectedIndex > 0)
		{
            
			f.requiredfields.value = addToString(f.requiredfields.value, f.google_county.options[f.google_county.selectedIndex].value, ".");
			/*
			if (f.requiredfields.value.length > 0)
			{
				f.requiredfields.value = f.requiredfields.value + ".";
			}
			f.requiredfields.value = f.requiredfields.value + f.google_county.options[f.google_county.selectedIndex].value;
			*/
		}
	}

	// Partial fields
	if (f.google_section != null)
	{
		var temp = "";
		if (f.google_section.type == "select-one")
		{
			if (f.google_section.selectedIndex > 0 || f.google_section.options[0].value.length > 0) {
				temp = f.google_section.options[f.google_section.selectedIndex].value;
			}
		}
		else
		{
			temp = f.google_section.value;
		}
		
		f.partialfields.value = addToString(f.partialfields.value, temp, ".");
	}
	if (f.google_year != null)
	{
		if (f.google_year.selectedIndex > 0)
		{
			f.partialfields.value = addToString(f.partialfields.value, f.google_year.options[f.google_year.selectedIndex].value, ".");
			/*
			if (f.requiredfields.value.length > 0)
			{
				f.requiredfields.value = f.requiredfields.value + ".";
			}
			f.requiredfields.value = f.requiredfields.value + f.google_county.options[f.google_county.selectedIndex].value;
			*/
		}
	}
	if (f.google_person != null)
	{
		if (f.google_person.selectedIndex > 0)
		{
			f.partialfields.value = addToString(f.partialfields.value, f.google_person.options[f.google_person.selectedIndex].value, ".");
			/*
			if (f.partialfields.value.length > 0)
			{
				f.partialfields.value = f.partialfields.value + ".";
			}
			f.partialfields.value = f.google_person.options[f.google_person.selectedIndex].value;
			*/
		}
	}
	if (f.google_subsection != null && f.google_subsection.value != '')
	{
		f.partialfields.value = addToString(f.partialfields.value, f.google_subsection.value, ".");
	}
	if (f.google_region != null)
	{
		if (f.google_region.selectedIndex >= 0)
		{
			f.partialfields.value = addToString(f.partialfields.value, f.google_region.options[f.google_region.selectedIndex].value, ".");
			/*
			if (f.partialfields.value.length > 0)
			{
				f.partialfields.value = f.partialfields.value + ".";
			}
			f.partialfields.value = f.partialfields.value + f.google_region.options[f.google_region.selectedIndex].value;
			*/
		}
	}
	if (f.google_eventholder != null)
	{
		if (f.google_eventholder.selectedIndex > 0)
		{
			f.partialfields.value = addToString(f.partialfields.value, f.google_eventholder.options[f.google_eventholder.selectedIndex].value, ".");
			/*
			if (f.partialfields.value.length > 0)
			{
				f.partialfields.value = f.partialfields.value + ".";
			}
			f.partialfields.value = f.partialfields.value + f.google_eventholder.options[f.google_eventholder.selectedIndex].value;
			*/
		}
	}
    
    if (f.google_map_county != null)
	{
		if (f.google_map_county.selectedIndex > 0)
		{
            
			f.partialfields.value = addToString(f.partialfields.value, f.google_map_county.options[f.google_map_county.selectedIndex].value, ".");
			/*
			if (f.partialfields.value.length > 0)
			{
				f.partialfields.value = f.partialfields.value + ".";
			}
			f.partialfields.value = f.partialfields.value + f.google_eventholder.options[f.google_eventholder.selectedIndex].value;
			*/
		}
	}
    
    
	if (f.google_url != null)
	{
		f.partialfields.value = addToString(f.partialfields.value, f.google_url.value, ".");
		/*
		if (f.partialfields.value.length > 0)
		{
			f.partialfields.value = f.partialfields.value + "." + f.google_url.value;
		}
		else
		{
			f.partialfields.value = f.google_url.value;
		}
		*/
	}

	
}

function setWorkerNameField(f)
{
	if (f.nameQuery != null && f.nameQuery.value.length > 0)
	{
		var array = f.nameQuery.value.split(' ');
		if (f.partialfields.value.length > 0)
		{
			f.partialfields.value = f.partialfields.value + ".";
		}
		for (var i = 0; i < array.length; i++)
		{
			f.partialfields.value = f.partialfields.value + "profileName:" + URLEncode(array[i]);
			if (i < (array.length - 1))
			{
				f.partialfields.value = f.partialfields.value + ".";
			}
		}
	}
}

function setExtraRequiredFields(f)
{
	if (f.extraRequiredFields != null && f.extraRequiredFields.value.length > 0)
	{
		f.requiredfields.value = addToString(f.requiredfields.value, f.extraRequiredFields.value, ".");
	}
}

/* This method will hide/show the event year option box */
function changeEventTime(divID, yearObj) {
	var divObj = document.getElementById(divID);
	if (divObj.style.display == 'block' && yearObj.selectedIndex == 0) {
		divObj.style.display = 'none';
	} else if (divObj.style.display == 'none' && yearObj.selectedIndex > 0) {
		divObj.style.display = 'block';
	}
}

function setHiddenEvents(f)
{
	if (f.currentEvent != null)
	{
		f.requiredfields.value = addToString(f.requiredfields.value, f.currentEvent.value, ".");
	}
	
	// Set correct date search
	if (f.google_eventmonth != null && f.google_eventmonth.selectedIndex == 0)
	{
		f.requiredfields.value = addToString(f.requiredfields.value, f.google_eventmonth.options[f.google_eventmonth.selectedIndex].value, ".");
	}
	else if (f.google_eventmonth != null && f.google_eventyear != null)
	{
		if (f.google_eventyear.selectedIndex == 0)
		{
			// Only use the month in the search;
			//f.partialfields.value = f.partialfields.value + "startDate:" + f.google_eventmonth.options[f.google_eventmonth.selectedIndex].value;
			f.partialfields.value = addToString(f.partialfields.value, f.google_eventmonth.options[f.google_eventmonth.selectedIndex].value, ".");
		}
		else
		{
			// Use year as well in the search
			//f.partialfields.value = f.partialfields.value + "startDate:" + f.google_eventyear.options[f.google_eventyear.selectedIndex].value + f.google_eventmonth.options[f.google_eventmonth.selectedIndex].value;
			f.partialfields.value = addToString(f.partialfields.value, f.google_eventyear.options[f.google_eventyear.selectedIndex].value + "." + f.google_eventmonth.options[f.google_eventmonth.selectedIndex].value, ".");
		}
	}
}

function addToString(originalString, stringToAdd, stringInBetween)
{
	if (originalString == null || originalString.length == 0)
	{
		return stringToAdd;
	}
	if (stringToAdd == null || stringToAdd.length == 0 || originalString.indexOf(stringToAdd) != -1)
	{
		return originalString;
	}
	if (stringInBetween == null)
	{
		return originalString + stringToAdd;
	}
	return originalString + stringInBetween + stringToAdd;
}

// ====================================================================
//  	Function URLEncode
//		Based on code from:
// http://www.albionresearch.com/
// ====================================================================
function URLEncode(string)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = string;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	}

	return encoded;
};
// JavaScript Document

function fixFrameHeight(obj,slack) {
	eval("doc = " + obj.id + ".document");
	docheight = doc.body.scrollHeight;
	docheight = (slack) ? docheight + slack : docheight;
	obj.style.height = docheight + "px";
} 

function openPopup(url, h, w) {
    newwindow=window.open(url,'name','height='+h+',width='+w+',scrollbars=yes,menubar=yes,toolbar=no');
	    if (window.focus) {newwindow.focus()}
	return false;
}

function isValidEmail(str) 
{
	var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    return pattern.test(str);  
}

function stripQuote(str){
	return str.replace(/\'|\"/g,''); 
}
function checkEmailSurveillanceForm(form) {
	
	var subscriptionType = "";
	for (var i=0; i < form.subscriptionType.length; i++)
	{
		if (form.subscriptionType[i].checked)
			subscriptionType = form.subscriptionType[i].value;
	}

	if (subscriptionType == '0')
		form.action = "/forum/insertSubscription.do";
	else
		form.action = "/email/unSubscribe.do";

	var email = trimAll(form.email.value);
	
	if (email.length < 1)	{
		alert("Du måste ange en e-postadress!");
		form.email.focus();
		form.email.select();
		return false;			
	}
	
	if (!isValidEmail(email))	{
		alert("E-postadressen innehåller ett felaktigt format!");
		form.email.focus();
		form.email.select();
		return false;			
	}
	
	form.secure.value = "true"; //Is used to avoid spam.
	
	return true;
}
var tw_latestbloggedSection = "Reformbanken";
var tw_latestbloggedUrl = "http://www.svensktnaringsliv.se/";
var tw_language = 'swedish';

/* Twingly settings */