var save_or_add_button;

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

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

}

function imagePrepare( image )
{
}

function imageHighlight( image )
{
	if ( image == null ) { return; }
	if ( image.src.lastIndexOf( "_over." ) != -1 ) { return 0; }
	image.src = image.src.substring( 0, image.src.lastIndexOf( "." ) ) +"_over" +image.src.substring( image.src.lastIndexOf( "." ), image.src.length );
}

function imageHighlight( image, text )
{
	if ( image == null ) { return; }
	if ( image.src.lastIndexOf( "_over." ) != -1 ) { return 0; }
	image.src = image.src.substring( 0, image.src.lastIndexOf( "." ) ) +"_over" +image.src.substring( image.src.lastIndexOf( "." ), image.src.length );
	window.status = text;
}

function imageRestore( image )
{
	if ( image.src.lastIndexOf( "_over." ) == -1 ) { return 0; }
	image.src = image.src.substring( 0, image.src.lastIndexOf( "_over." ) ) +image.src.substring( image.src.lastIndexOf( "." ), image.src.length );

	if ( typeof(post_position_js) == "undefined" ) { window.status = ""; } 
	else { window.status = record_text1 + " " + post_position_js[1] + " " + record_text2 + " " + post_position_js[0]; }
}

function logout()
{
	document.main.action.value = "logout";
	document.main.submit();
}

function setAction( action )
{
	pleaseWait();
	document.main.action.value = action;
}

function setAction( action, param )
{
	pleaseWait();
	document.main.action.value = action;
	document.main.param.value = param;
}

function submitAndGoto( url )
{
	setAction( 'goto', url );
	document.main.submit();
}

function submitAndSearch( url )
{
	if ( document.main.search_name.value == '' && document.main.search_name_first.value == '' && document.main.search_name_middle.value == '' && document.main.search_name_last.value == '' ) { return; }
	setAction( 'goto', url );
	document.main.submit();
}


function submitAction ( action, param, focus )
{
	if (focus) { document.main.field_focused.value = focus; }
	setAction( action, param);
	document.main.submit();
}

function pleaseWait ()
{
	if ( document.getElementById('please_wait') == null ) { return; }
	for (i=0;i < document.main.elements.length;i++) {
		if (document.main.elements[i].name.indexOf("goto_") != 0) { document.main.elements[i].style.display='none'; }
	}
  document.getElementById('please_wait').style.display='block';
}

function navigate( offset, length )
{
	if ( document.main.offset  != null ) document.main.offset.value  = offset;
	if ( document.main.length  != null ) document.main.length.value  = length;

	submitAndSearch('index.cgi?section=search&page=search_result');
}

function changeOrderColumn( index )
{
	if ( document.main.order_col != null && document.main.order_dir != null )
	{
		if ( document.main.order_col.value == index )
		{
			document.main.order_dir.value = ((document.main.order_dir.value == "ASC")?"DESC":"ASC");
		}
		else
		{
			document.main.order_col.value = index;
			document.main.order_dir.value = "ASC";
		}

		repeatSearch();
	}
}

function repeatSearch()
{
	document.main.section.value = "private/search";
	document.main.page.value = "search";
	document.main.action.value = document.main.search_action.value;
	document.main.submit();
}

function browseMenu( action, param )
{
	setAction( action, param);
	document.main.submit();
}

function setArea( target, source )
{
	document.main[target].value = zip[source.value];
}

function saveHighlight()
{
	if ( document.main.altered.value == ( "" || 0 ) ) return 0;

	var buttonObject = document.getElementById('save_or_add_button');
	if ( buttonObject != null && buttonObject.src == null )
	{
		buttonObject.style.backgroundColor='#ee9c00';
		buttonObject.style.color='white';
	}
	else imageHighlight( save_or_add_button, "" );
}

function setElementFocus(field)
{
	if ( field ) (document.main[ field ]).focus();
}

function setPrevPageVars(confirm, alter)
{
	document.main.confirmed.value = confirm;
	document.main.altered.value = alter;

	document.main.section.value = document.main.section_previous.value;
	document.main.page.value = document.main.page_previous.value;
	document.main.id.value = document.main.id_previous.value;

 	document.main.section_previous.value = document.main.section_next.value;
 	document.main.page_previous.value = document.main.page_next.value;
 	document.main.id_previous.value = document.main.id_next.value;
}

function setUsertype()
{
	//alert(document.main["user_information_type"].value);
	if ( document.main["user_information_type"].value == "L" ) document.main["user_information_type"].value = "S";
}

function showOrHide(id) {
	if (document.getElementById(id).style.display == 'none')
	{
	  document.getElementById(id).style.display='block';
	  document.getElementById(id).style.width='100%';
	}
	else
	{
	  document.getElementById(id).style.display='none';
	  document.getElementById(id).style.width='0px';
	}
}

function setFieldValue(from, to)
{
	document.main[to].value = from.value;
	//document.main[to].focus();
}


function setPostStatus()
{
	if ( typeof(post_position_js) != "undefined" ) {
		window.status = record_text1 + " " + post_position_js[1] + " " + record_text2 + " " + post_position_js[0];
	}
}

// at login page - set focus on password field
function setPasswordFocused()
{
	if( document.main.password ) { document.main.password.focus(); }
}

// find person info from 'folkeregisteret' if ssn is given
function getPersonInfoFolkeregisteret( comp )
{
//alert(document.main[ comp + "_ssn" ].value);
	if ( document.main[ comp + "_ssn" ].value ) { submitAction( "folkeregisteret", comp); }
}


