function getWindowWithFrame (name)
{
	var result = "";

	function getWindowObject (name, w)
	{
		for (var i = 0; i < w.frames.length; i++) {
			if (w.frames[i].name == name) {
				result = w.frames[i];
				return;
			} else {
				getWindowObject (name, w.frames[i]);
			}
		}
	}
	getWindowObject (name, top);
	return result
}

// collect all checbox values in srcFrame, tag them to an url and execute that url in dstFrame
function doAction (srcFrame, dstFrame, url)
{
	vars = "";
	
	var srcWin = getWindowWithFrame (srcFrame);
	var dstWin = getWindowWithFrame (dstFrame);
	var forms = srcWin.document.forms;

	for (i = 0; i < forms.length; i++) {
		for (j = 0; j < forms[i].elements.length; j++) {
			theElement = theType = forms[i].elements[j];
			theType = theElement.type;
			theName = theElement.name;
			theValue = theElement.value;
			if (theElement.type == "checkbox" && theElement.checked == false) {
				continue;
			}
			vars += theName + "=" + theValue + "&";
		}
	}
	
	vars = vars.replace (/ /g, "%20");
	dstWin.location = url + "?" + vars;
}

function setAllCheckboxes (theFrame, theForm)
{
	var theWin = getWindowWithFrame (theFrame);
	var elements = theWin.document.forms[theForm].elements;
	

	for (i = 0; i < elements.length; i++) {
		if (elements[i].type == "checkbox") {
			elements[i].checked = true;
		}
	}
}

function clearAllChecboxes (theFrame, theForm)
{
	var theWin = getWindowWithFrame (theFrame);
	var elements = theWin.document.forms[theForm].elements;
	
	for (i = 0; i < elements.length; i++) {
		if (elements[i].type == "checkbox") {
			elements[i].checked = false;
		}
	}
}

function setCheckboxNamed (theFrame, theForm, theName)
{
	var theWin = getWindowWithFrame (theFrame);
	var elements = theWin.document.forms[theForm].elements;
	
	if (elements[theName].type == "checkbox") {
			elements[theName].checked = true;
	}
}

function clearCheckboxNamed (theFrame, theForm, theName)
{
	var theWin = getWindowWithFrame (theFrame);
	var elements = theWin.document.forms[theForm].elements;
	
	if (elements[theName].type == "checkbox") {
			elements[theName].checked = false;
	}
}

function isCheckboxSet (theFrame, theForm, theName)
{
	var theWin = getWindowWithFrame (theFrame);
	var elements = theWin.document.forms[theForm].elements;
	
	return (elements[theName].type == "checkbox" && elements[theName].checked == true);
}

function getAll (theWin)
{
	//var theWin = getWindowWithFrame ("liste");
	var elements = theWin.document.forms["skjema"].elements;
	
	res = "";
	for (i = 0; i < elements.length; i++) {
		if (elements[i].type == "checkbox" && elements[i].checked == true) {
			res += elements[i].value + ",";
		}
	}
	return res;
}

var allIsSet = true;

function toggleAllChecboxesOn (theFrame, theForm, theName)
{
	if (allIsSet)
	{
		setAllCheckboxes (theFrame, theForm);
		setCheckboxNamed (theFrame, theForm, theName);
		allIsSet = false;
	}
	else
	{
		clearAllChecboxes (theFrame, theForm);
		allIsSet = true;
	}
}
function openArticle (article_id, language)
{
	var the_url = '/' + language.toUpperCase () + '/Pages/News/article.phtml?article_id=' +  article_id + '&language=' + language;
	var the_target = "Article";
	var wf = "";	
	wf = wf + "width=" + 200;
	wf = wf + ",height=" + 200;
	wf = wf + ",resizable=" + "yes";
	wf = wf + ",scrollbars=" + "yes";
	wf = wf + ",menubar=" + "no";
	wf = wf + ",toolbar=" + "no";
	wf = wf + ",directories=" + "no";
	wf = wf + ",location=" + "no";
	wf = wf + ",status=" + "no";	

	window.open (the_url, the_target, wf);
}