//------------------------------------------------------
// This file contains general JavaScript Functions
// Required to get the web and backweb to work properly
//------------------------------------------------------

//------------------------------------------------------
// functions used in newpage(), pwd & download handling...
//------------------------------------------------------

function showpwd(obj) {
	if (obj.checked == true) 
		document.frm.txtPagePwd.style.visibility = "visible";		
	else 
		document.frm.txtPagePwd.style.visibility = "hidden";		
		document.frm.txtPagePwd.value = "";
}


function showdownloadbtn(obj) {
	if (obj.checked == true) 
		document.frm.btnPageDownload.style.visibility = "visible";		
	else 
		document.frm.btnPageDownload.style.visibility = "hidden";
		lyrDownloadList.style.visibility = "hidden";
		document.frm.btnPageDownload.value = "Visa Fillista";
}


function showdownloadlist(e) {	
	if (e.style.visibility == "hidden") {
     e.style.visibility = "visible";
     document.frm.btnPageDownload.value = "Dölj Fillista ";     
  } else {
     e.style.visibility = "hidden";
     document.frm.btnPageDownload.value = "Visa Fillista";     
  }
}


function logintopage(inparam) {
	//window.showModalDialog("_bin/code_pagepwd.asp","Dialog Box Arguments # 1","dialogHeight: 100px; dialogWidth: 250px; dialogTop: px; dialogLeft: px; edge: Raised; center: Yes; help: No; resizable: No; status: No;");	
	//window.showModalDialog("_bin/code_pagepwd.asp",inparam,"dialogHeight: 100px; dialogWidth: 250px; dialogTop: px; dialogLeft: px; edge: Raised; center: Yes; help: No; resizable: No; status: No;");	
	var thisWin
	var width = "250"
	var height = "80"
	var url = "_bin/code_pagepwd.asp?inparam=" + inparam
	prefs="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no";

	prefs+=",width="+width;
	prefs+=",height="+height;
	unik="login";
	//unik=unik.getSeconds()+"_"+unik.getMinutes()+"_"+unik.getHours();
	//window.open(url,unik,prefs);
  thisWin = window.open(url,unik,prefs);  
  thisWin.moveTo((screen.width-125)/2, (screen.height-40)/2);
  thisWin.focus();
  //thisWin.frm.pagepwd.focus();
  //thisWin.frm.txtUrl.value = inparam;
}


//------------------------------------------------------
// functions used in the messagesystem...
//------------------------------------------------------

function showme(obj1,obj2) {
	obj1.style.visibility="hidden";
	obj2.style.visibility="visible";
}

function addname(username){
	var txt = document.frmSend.txtTo.value;
	if (txt == ""){
		document.frmSend.txtTo.value = username;
	}else if (txt != ""){
		document.frmSend.txtTo.value = txt + ";" + username;
	}
}


//------------------------------------------------------
// former toggle.js - visa dölj <span> i en sida
//------------------------------------------------------

function toggle(e) {
  if (e.style.visibility == "hidden") {
     e.style.visibility = "visible";
  } else {
     e.style.visibility = "hidden";
  }
}

//------------------------------------------------------
// former showHide.js - Skifta mellan två <span> i en sida
// snarlik den ovanstående...
//------------------------------------------------------

function showHide(e,sp1,sp2) {
  if (e.value == "pic") {
			sp1.style.visibility = "visible";
			sp2.style.visibility = "hidden";
  } else if (e.value == "doc") {			
			sp1.style.visibility = "visible";
			sp2.style.visibility = "hidden";			
  }	else if (e.value == "") {			
			sp1.style.visibility = "visible";
			sp2.style.visibility = "hidden";
	}
}

function showHideTriple(e,sp1,sp2,sp3) {
  if (e.value == "pic") {
			sp1.style.visibility = "visible";
			sp2.style.visibility = "hidden";
			sp3.style.visibility = "hidden";
  } else if (e.value == "doc") {			
			sp1.style.visibility = "visible";
			sp2.style.visibility = "hidden";
			sp3.style.visibility = "hidden";
  }	else if (e.value == "htm") {			
			sp1.style.visibility = "visible";
			sp2.style.visibility = "hidden";
			sp3.style.visibility = "hidden";
  }	else if (e.value == "") {			
			sp1.style.visibility = "visible";
			sp2.style.visibility = "hidden";
			sp3.style.visibility = "hidden";
	}
}

//------------------------------------------------------
// former cancelAction.js
//------------------------------------------------------

function cancelAction() {
	history.back(-1)
}

//------------------------------------------------------
// former checkReqField.js
//------------------------------------------------------

function checkreqfield(which) {
var pass=true;
if (document.images) {
for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];
if (tempobj.name.substring(0,8)=="required") {
if (((tempobj.type=="text"||tempobj.type=="textarea")&&
tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
tempobj.selectedIndex==0)) {
pass=false;
break;
         }
      }
   }
}
if (!pass) {
shortFieldName=tempobj.name.substring(8,30).toUpperCase();
//alert("Please make sure the "+shortFieldName+" field was properly completed.");
alert("OBS! Fältet: "+shortFieldName+" är inte korrekt ifyllt!");
return false;
}
else
return true;
}

//------------------------------------------------------
// former openPage.js
//------------------------------------------------------

function open_page(url,width,height)
{
prefs="toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no";

prefs+=",width="+width;
prefs+=",height="+height;
unik=new Date();
unik=unik.getSeconds()+"_"+unik.getMinutes()+"_"+unik.getHours();
window.open(url,unik,prefs);
}

//------------------------------------------------------
// former SelOrder.js
//------------------------------------------------------

//Function move(index,to)
//Function submitForm()

function move(index,to) {
var list = document.frm.list;
var total = list.options.length-1;
if (index == -1) return false;
if (to == +1 && index == total) return false;
if (to == -1 && index == 0) return false;
var items = new Array;
var values = new Array;
for (i = total; i >= 0; i--) {
items[i] = list.options[i].text;
values[i] = list.options[i].value;
}
for (i = total; i >= 0; i--) {
if (index == i) {
list.options[i + to] = new Option(items[i],values[i + to], 0, 1);
list.options[i] = new Option(items[i + to], values[i]);
i--;
}
else {
list.options[i] = new Option(items[i], values[i]);
   }
}
list.focus();
}


function submitForm() {
var list = document.frm.list;
var theList = "";
// start with a "?" to make it look like a real query-string

for (i = 0; i <= list.options.length-1; i++) { 
//theList += "list" + list.options[i].value + "=" + list.options[i].text;
theList += list.options[i].text + "|";
// a "&" only BETWEEN the items, so not at the end
//if (i != list.options.length-1) theList += "&";
}
window.document.frm.ListOrder.value = theList 
//location.href = document.frm.action + theList;
}


function highlightList() {
	/* Select All Items in list*/
	inr = document.form.list.length
	for (var i = 0; i < inr ; i++) {		
			document.form.list.options[i].selected = true
	}
}

//----------------- PETER TEST 2003-05-28--------------
function move2(inlist,index,to) {
var list = inlist;
var total = list.options.length-1;
if (index == -1) return false;
if (to == +1 && index == total) return false;
if (to == -1 && index == 0) return false;
var items = new Array;
var values = new Array;
for (i = total; i >= 0; i--) {
items[i] = list.options[i].text;
values[i] = list.options[i].value;
}
for (i = total; i >= 0; i--) {
if (index == i) {
list.options[i + to] = new Option(items[i],values[i + to], 0, 1);
list.options[i] = new Option(items[i + to], values[i]);
i--;
}
else {
list.options[i] = new Option(items[i], values[i]);
   }
}
list.focus();
}

function submitThis(inlist) {
var list = inlist;
var theList = "";
// start with a "?" to make it look like a real query-string

for (i = 0; i <= list.options.length-1; i++) { 
//theList += "list" + list.options[i].value + "=" + list.options[i].text;
theList += list.options[i].text + "|";
// a "&" only BETWEEN the items, so not at the end
//if (i != list.options.length-1) theList += "&";
}
window.document.frm.ListOrder.value = theList 
//location.href = document.frm.action + theList;
}

//------------------------------------------------------
// former AdvSearch.js
//------------------------------------------------------

function Radio_1_Reset(onoff) {
	if (onoff == false) {
		window.document.FrmSearch.one.disabled = true
		window.document.FrmSearch.two.disabled = true
	}
	if (onoff == true) {
		window.document.FrmSearch.one.disabled = false
		window.document.FrmSearch.two.disabled = false
	}
	}

function Radio_2_Reset(onoff) {
	if (onoff == false) {
		window.document.FrmSearch.three.disabled = true
		window.document.FrmSearch.four.disabled = true
		}
	if (onoff == true) {
		window.document.FrmSearch.three.disabled = false
		window.document.FrmSearch.four.disabled = false
		}
} 

function Radio_3_Reset(onoff) {

	if (onoff == false) {
		window.document.FrmSearch.five.disabled = true
		window.document.FrmSearch.six.disabled = true
			}
	if (onoff == true) {
		window.document.FrmSearch.five.disabled = false 
		window.document.FrmSearch.six.disabled = false
		}
}

function Radio_4_Reset(onoff, g) {

if (onoff == false) {
	var i
	for (i = 0; i < g; i++) {
		window.document.FrmSearch.RadioSub4[i].disabled = true
		}
	}
	
if (onoff == true) {
	var i
	for (i = 0; i < g; i++) {
	
		window.document.FrmSearch.RadioSub4[i].disabled = false
		}
	}
}

//------------------------------------------------------
// former newsScroll.js
//------------------------------------------------------

// change this to where you store the blank.gif image
var blank = "../img/blank.gif";

topedge = 70;  // location of news box from top of page
leftedge = 600;  // location of news box from left edge
boxheight = 430;  // height of news box
boxwidth = 120;  // width of news box
scrollheight = 200; // total height of all data to be scrolled

function scrollnews(cliptop) {
if (document.layers) {
newsDiv = document.news;
newsDiv.clip.top = cliptop;
newsDiv.clip.bottom = cliptop + boxheight;
newsDiv.clip.left = 0;
newsDiv.clip.right = boxwidth + leftedge;
newsDiv.left = leftedge;
newsDiv.top = topedge - cliptop;
}
else {
newsDiv = news.style;
newsDiv.clip = "rect(" + cliptop + "px " + (boxwidth + leftedge) + "px " + (cliptop + boxheight) + "px 0px)";
newsDiv.pixelLeft = leftedge;
newsDiv.pixelTop = topedge - cliptop;
}
cliptop = (cliptop + 1) % (scrollheight + boxheight);
newsDiv.visibility='visible';
setTimeout("scrollnews(" + cliptop + ")", 50); // siffran anger hur snabbt nyheterna ska scrolla
}


//------------------------------------------------------
// former selectionJump.js
//------------------------------------------------------

function selectionJump (url) {
	strlen = url.length
	targ = url.substring(0,0)
	jump = url.substring(0, strlen)
	if (url == "noWay") {
		}
	else if (targ.charAt(0) != 's') {
		window.top.location = jump
		}
	else parent.stor.location = jump
}


//------------------------------------------------------
// former submt.js (autosubmit av formulär via listbox)
//------------------------------------------------------

function submt(){	
	document.frmlst.submit();
}


//------------------------------------------------------
// former copyto.js 
// (copy values from one form to another on submit)
//------------------------------------------------------
function copyTo() {
    document.frm.txtLevel1.value = document.frmlst.selLevel1.value;
    document.frm.txtLevel2.value = document.frmlst.selLevel2.value;
    //to.myText.value = from.myText.value;
    //to.submit();
}


//------------------------------------------------------
// former checksearchstring.js
//------------------------------------------------------

function checksearchstring(which) {
var pass=true;
if (document.images) {
for (i=0;i<which.length;i++) {
var tempobj=which.elements[i];
if (tempobj.name.substring(0,12)=="searchphrase") {
if (((tempobj.type=="text"||tempobj.type=="textarea")&&
tempobj.value=='')||(tempobj.type.toString().charAt(0)=="s"&&
tempobj.selectedIndex==0)) {
pass=false;
break;
         }
      }
   }
}
if (!pass) {
shortFieldName=tempobj.name.substring(12,30).toUpperCase();
//alert("Please make sure the "+shortFieldName+" field was properly completed.");
alert("OBS! Fältet: "+shortFieldName+" måste innehålla ett sökord!");
return false;
}
else
return true;
}


//------------------------------------------------------
// TextEditor.js
//------------------------------------------------------


//____________ funktioner_____________________________________________________________________
// function TextEditor(txtArea,Type)
// function oppna(text)
// function oppnaWithRadio(text,layouttype,bild,Headline)
// function oppnaWithRadio2(text,layouttype,bild,Headline,text2)
// function TextEditorNews(text,Headline)
// function TextEditorCalendar(text,Headline)
//____________________________________________________________________________________________


function TextEditor(txtArea,Type){

txtAreaName = txtArea.name;
txtRange = document.all[txtAreaName].createTextRange();
txtContainer = txtRange.parentElement().name;

objRange = document.selection.createRange();
hiliteTxt = objRange.text;

if(hiliteTxt != ""){

		if(Type == "B")	
		{
			toFont4_Txt = "<B>" + hiliteTxt + "</B>";
		}
		
		if(Type == "Italic")
		{
			toFont4_Txt = "<I>" + hiliteTxt + "</I>";
		}
		if(Type == "Underline")
		{
			toFont4_Txt = "<U>" + hiliteTxt + "</U>";
		}
		if(Type == "Li")
		{
			toFont4_Txt = "<Li>" + hiliteTxt + "</Li>" ;
		}
		if(Type == "Liul")
		{
			toFont4_Txt = "<Ul>" + hiliteTxt + "</Ul>";
		}
		
		
		if(Type == "Href")
		{
			if (window.document.frm.TxtLink.value == "")
			{
				alert("Du måste skriva in en giltig www adress ! ")
				toFont4_Txt = hiliteTxt
			}
		
			else 
			{
				toFont4_Txt = "<A HREF=" + window.document.frm.TxtLink.value + ">" + hiliteTxt + "</A>";
			}
				
			if (window.document.frm.TxtLink.value == "http://www.")
			{
				alert("Du måste skriva in en giltig www adress ! ")
				toFont4_Txt = hiliteTxt
			}
			else 
			{
				toFont4_Txt = "<A HREF=" + window.document.frm.TxtLink.value + " target=top>" + hiliteTxt + "</A>";
			}
		}	
		
		
		if(Type == "MailTo")
		{
			if (window.document.frm.TxtMailTo.value == "")
			{
				alert("Du måste skriva in en giltig mailadress ! ")
				toFont4_Txt = hiliteTxt
			}
		
			else 
			{
				toFont4_Txt = "<A HREF=" + window.document.frm.TxtMailTo.value + ">" + hiliteTxt + "</A>";
			}
				
			//if (window.document.frm.TxtLink.value == "http://www.")
			//{
			//	alert("Du måste skriva in en giltig www adress ! ")
			//	toFont4_Txt = hiliteTxt
			//}
			//else 
			//{
				toFont4_Txt = "<A HREF=mailto:" + window.document.frm.TxtMailTo.value + ">" + hiliteTxt + "</A>";
			//}
		}	
		
		// Tillagt 020302 ---------------------
		if(Type == "Font")
		{
			if (window.document.frm.TxtFont.value == "")
			{
				alert("Du måste skriva in ett typsnitt (ex. Verdana, Arial, Tahoma, Courier etc.)")
				toFont4_Txt = hiliteTxt
			}
			else 
			{
				toFont4_Txt = "<Font face=" + window.document.frm.TxtFont.value + ">" + hiliteTxt + "</Font>";
			}
		}
		
		if(Type == "Href2")
		{
			if (window.document.frm.TxtLink2.value == "")
			{
				alert("Du måste skriva in en giltig www adress ! ")
				toFont4_Txt = hiliteTxt
			}
		
			else 
			{
				toFont4_Txt = "<A HREF=" + window.document.frm.TxtLink2.value + ">" + hiliteTxt + "</A>";
			}
				
			if (window.document.frm.TxtLink2.value == "http://www.")
			{
				alert("Du måste skriva in en giltig www adress ! ")
				toFont4_Txt = hiliteTxt
			}
			else 
			{
				toFont4_Txt = "<A HREF=" + window.document.frm.TxtLink2.value + " target=top>" + hiliteTxt + "</A>";
			}
		}	
		
		
		if(Type == "MailTo2")
		{
			if (window.document.frm.TxtMailTo2.value == "")
			{
				alert("Du måste skriva in en giltig mailadress ! ")
				toFont4_Txt = hiliteTxt
			}
		
			else 
			{
				toFont4_Txt = "<A HREF=" + window.document.frm.TxtMailTo2.value + ">" + hiliteTxt + "</A>";
			}
				
			//if (window.document.frm.TxtLink.value == "http://www.")
			//{
			//	alert("Du måste skriva in en giltig www adress ! ")
			//	toFont4_Txt = hiliteTxt
			//}
			//else 
			//{
				toFont4_Txt = "<A HREF=mailto:" + window.document.frm.TxtMailTo2.value + ">" + hiliteTxt + "</A>";
			//}
		}	

		if(Type == "Bild")
		{
			if (window.document.frm.Bild.value == "")
			{
				alert("Du måste skriva in en giltig adress till bilden ! ")
				toFont4_Txt = hiliteTxt
			}
	
			else 
			{
				toFont4_Txt = "<img src=" + window.document.frm.Bild.value + " border=0>";
			}
		}	
		if(Type == "Undo")	
		{
			var h
			var i
				
			for (i=0 ; i<200; i++){
				h = hiliteTxt.charCodeAt(i) 
			    
					if (h == 62) {
					i = i + 1
					break ;
					}
				}
							
			for (r = hiliteTxt.length ; r>0; r--){
				h = hiliteTxt.charCodeAt(r) 
			    
					if (h == 47) {
					r = r - 1
					break ;
					}
				}
			
			t = hiliteTxt.substr(i,r-i)
			 	
			toFont4_Txt =  t ;		
		}
		
		objRange.text = toFont4_Txt;
	}
}
//____________________________________________________________________________________________
//Öppnar preview på nivå ett och två och med typerna 1-4 eller 6
function oppna(text,layouttype,bild,Headline){

		
		var x = text.length;
		text = text.replace(/\n/g, "|");
		for (var i=0; i<5; i++){
			if(window.document.frm.rdoType[i].checked == true){
			layouttype = window.document.frm.rdoType[i].value
			}
		 }
			if (bild == "") {
				bild = window.document.frm.Editbild.value
				
			//if (bild == "") {
			//	alert("Välj en bild !")
			//	}
			//else
			//{
				open('../adm/preview.asp?text='+ text +'&bild=' + bild +'&layouttype='+ layouttype+'&Headline='+Headline, '', 'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,scrollbars=yes,width=760,height=585,resizable=no');
			//}
			}
}

//____________________________________________________________________________________________
//När man väljer på nivå tre, och där väljer man typ 1-4 eller 6.
function oppnaWithRadio(text,layouttype,bild,Headline){

		
		var x = text.length;
		text = text.replace(/\n/g, "|");

			if (window.document.frm.TxtRadioType.value == "01")
			{
				layouttype = window.document.frm.TxtRadioType.value
				open('../adm/preview.asp?text='+ text +'&bild=' + bild +'&layouttype='+ layouttype+'&Headline='+Headline, '', 'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,scrollbars=yes,width=760,height=585,resizable=no');
			}
			else
			{ 
				if(bild == "") 
				{
					alert("välj en bild !") 
				}
				else
				{
					bild = window.document.frm.file01.value
					layouttype = window.document.frm.TxtRadioType.value
					open('../adm/preview.asp?text='+ text +'&bild=' + bild +'&layouttype='+ layouttype+'&Headline='+Headline, '', 'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,scrollbars=yes,width=760,height=585,resizable=no');
				}					
							
			}
}

//___________________________________________________________________________________________
//När man väljer på nivå tre, och där väljer man typ 5.

function oppnaWithRadio2(text,layouttype,bild,Headline,text2){

		var x = text.length;
		text = text.replace(/\n/g, "|");
		text2 = text2.replace(/\n/g, "|");
			
			if (bild == "") 
			{
				alert("Välj en bild !")
			}
			else 
			{
				bild = window.document.frm.file01.value
				layouttype = window.document.frm.TxtRadioType.value
				open('../adm/preview.asp?text='+ text +'&bild=' + bild +'&layouttype='+ layouttype+'&Headline='+Headline+'&text2='+text2, '', 'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,scrollbars=yes,width=760,height=585,resizable=no');
			}
			
}
//___________________________________________________________________________________________
//vet ej om den används

function oppnaLevel3(text,layouttype,bild,Headline,text2){

		
		var x = text.length;
		text = text.replace(/\n/g, "|");
		text2 = text2.replace(/\n/g, "|");
			
			
			if (bild == "") {
				if (window.document.frm.Editbild3.value == "") 
				{
					alert("Välj en bild först")
				}
				else 
				{
					bild = window.document.frm.Editbild3.value
				}		
			
				}
			for (var i=0; i<5; i++){
			if(window.document.frm.rdoType[i].checked == true){
			layouttype = window.document.frm.rdoType[i].value
			}
		 }
			//layouttype = window.document.frm.rdoType[i].value
			open('../adm/preview.asp?text='+ text +'&bild='+ bild +'&layouttype='+ layouttype+'&Headline='+Headline+'&text2='+text2+'&edit=1', '', 'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,scrollbars=yes,width=760,height=585,resizable=no');
}
//____________________________________________________________________________________________
function TextEditorNews(text,Headline){

		var x = text.length;
		text = text.replace(/\n/g, "|");
		open('../adm/preview.asp?text='+ text +'&Headline='+Headline, '', 'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,scrollbars=yes,width=760,height=585,resizable=no');
}
//___________________________________________________________________________________________
function TextEditorCalendar(text,Headline){

		var x = text.length;
		text = text.replace(/\n/g, "|");
		open('../adm/preview.asp?text='+ text +'&Headline='+Headline, '', 'directories=no,location=no,menubar=no,status=no,titlebar=no,toolbar=no,scrollbars=yes,width=760,height=585,resizable=no');
}
//___________________________________________________________________________________________
