function sendForm()	// check specified elements (arguments[1], with realname arguments[2] and so on) in the forms[argument[0]]-form
{
		antal = 0;
		match = false;
		theForm = arguments[0];
		if (arguments.length>1) // No use checking the form if no arguments are passed to the function
		{
			while (antal < arguments.length && !match) // until we've checked all the passed arguments OR we've found a match
			{	
				for( i = 0; i < document.forms[theForm].elements.length && !match; i++) // loop thru all the elements of theForm
				{
					for ( j = 1; j < arguments.length && !match; j=j+2) // loop thru all the passed arguments for each element
					{
						if (arguments[j] == document.forms[theForm].elements[i].name) // check if the argument and the element.name matches
						{
							if ((document.forms[theForm].elements[i].type == "select-multiple") || (document.forms[theForm].elements[i].type == "select-one")) // check if the element is a select-box
							{
								valOpt = document.forms[theForm].elements[i].selectedIndex; // the index of the first selected option in theForm
								if ((document.forms[theForm].elements[i].options[valOpt].value == "") || (document.forms[theForm].elements[i].options[valOpt].value == "undefined") || (document.forms[theForm].elements[i].options[valOpt].value == null) || (document.forms[theForm].elements[i].options[valOpt].value == '0')) // check if selected option contains a value
								{
									alert("Du har inte fyllt i " + arguments[j+1]);  //document.forms[theForm].elements[i].name);
									document.forms[theForm].elements[i].focus();
									match = true;
								}
								else
								{
								antal++;
								}
							}
							else
							{
								if ((document.forms[theForm].elements[i].value == "") || (document.forms[theForm].elements[i].value == "undefined") || (document.forms[theForm].elements[i].value == null) || (document.forms[theForm].elements[i].value == '0')) // check if element contains a value
								{
									alert("Du har inte fyllt i " + arguments[j+1]);  //document.forms[theForm].elements[i].name);
									document.forms[theForm].elements[i].focus();
									match = true;
								}
								else 
								{
								antal++;
								}

							}
						}
					}
				}
			}
		}
		if (!match)
		{
			document.forms[theForm].submit();
		}
	}


	
	
function sendFormLight(form) 
{
	document.forms[form].submit();
}



function checkForm() {

	antal = 0;
	
	while (antal < arguments.length ) {	 // loop thru the arguments sent to the function
		for( i = 0; i < document.forms[0].elements.length; i++) { // loop thru the elements
			for ( j = 0; j < arguments.length; j=j+2) {
				if (arguments[j] == document.forms[0].elements[i].name) {
					if ((document.forms[0].elements[i].value == "") || (document.forms[0].elements[i].value == "undefined") || (document.forms[0].elements[i].value == null) || (document.forms[0].elements[i].value == '0')) {
						alert("Du har inte fyllt i " + arguments[j+1]);  //document.forms[0].elements[i].name);
						document.forms[0].elements[i].focus();
						return false;
					}
					else {
					 antal++;
					}
				}
			}
		}
	}
	return true;
}


function reallySure() {
	if (confirm ("Vill du ta bort allt nytt innehåll i formuläret?"))
			return true;
		else
			return false;
}

function tabort(text) 
{
	if (confirm (text))
			return true;
	else
			return false;
}

	function go(URL) // Omdirigerar webbläsaren till ny URL
	{ 
		document.location = URL;
	}

	
var aktivList = "none"; // global variabel som sätter den aktiva boxen som listan ska flyttas från/till

function aktivLista(tempList) { // första argumentet blir 'aktiv lista', resten avaktiveras
	
	aktivList = tempList;
	for (i=1; i < arguments.length; i++) {
		arguments[i].selectedIndex = -1;
	}
}

function mover(fromList, toList) { // flyttar options mellan två selects

	var i, nyOpt, befOpt, strOpt;
	var tempList = new Array();
	
	for (i = 0; i < fromList.length; i++) {
		befOpt = fromList.options[i];
		if (befOpt.selected && befOpt.value != "empty") {
			tempList[tempList.length] = i;
			befOpt.selected = false;
			strOpt = befOpt.text;
			nyOpt = new Option(strOpt, befOpt.value);
			if (document.all) //finns bara i IE
				toList.add(nyOpt, toList.length);
			else
				toList.options[toList.length] = nyOpt;
			
			nyOpt = null;
			befOpt = null;
			
		}
	}
	for (i = tempList.length-1; i >= 0; i--) {
		if (document.all) 
			fromList.options.remove(tempList[i]);
		else
			fromList.options[tempList[i]] = null; 
	}
	x = fromList.length 
}

function moverMembers(fromList, toList) { //special för att flytta och lägga till en siffra (adm_update_members_2.asp)

if (aktivList != "none") {
	var i, nyOpt, befOpt, strOpt;
	strTemp = "";
	skip = false;
	var tempList = new Array();
	if (fromList.name == 'nt' || fromList.name == 'nt_users') 
		strTempPrefix = "1";
	if (fromList.name == 'extern' || fromList.name == 'ext_users')
		strTempPrefix = "4";
	
	for (i = 0; i < fromList.length; i++) {
		befOpt = fromList.options[i];
		if (befOpt.selected && befOpt.value != "empty") {
		
		strTemp = strTempPrefix + befOpt.value;
		for (j = 0; j < toList.length; j++) {
				if (toList.options[j].value == strTemp) skip = true;
			}
			if (!skip) {
				tempList[tempList.length] = i;
				strOpt = befOpt.text;
				befOpt.selected = false;
				nyOpt = new Option(strOpt, strTemp);
				
				if (document.all) 
					toList.add(nyOpt, toList.length);
				else
					toList.options[toList.length] = nyOpt;
			}
			skip = false;
			nyOpt = null;
			befOpt = null;
			strTemp = "";
			
		}
	}
	x = fromList.length 
}
}

function moverMembers2(fromList, toList) { //special för att flytta och lägga till en siffra (adm_update_groups.asp)

if (aktivList != "none") {
	var i, nyOpt, befOpt, strOpt;
	strTemp = "";
	skip = false;
	var tempList = new Array();
	if (fromList.name == 'local') 
		strTempPrefix = "2";
	if (fromList.name == 'global')
		strTempPrefix = "3";
	
	for (i = 0; i < fromList.length; i++) {
		befOpt = fromList.options[i];
		if (befOpt.selected && befOpt.value != "empty" && befOpt.value != "None") {
		
		strTemp = strTempPrefix + befOpt.value;
		for (j = 0; j < toList.length; j++) {
				if (toList.options[j].value == strTemp) skip = true;
			}
			if (!skip) {
				tempList[tempList.length] = i;
				strOpt = befOpt.text;
				befOpt.selected = false;
				nyOpt = new Option(strOpt, strTemp);
				
				if (document.all) 
					toList.add(nyOpt, toList.length);
				else
					toList.options[toList.length] = nyOpt;
			}
			skip = false;
			nyOpt = null;
			befOpt = null;
			strTemp = "";
			
		}
	}
	x = fromList.length 
}
}

function moverMembersBack(fromList) { //special för att skicka tillbaka användare med två mottagarboxar. (adm_update_members_2.asp)

	var i, nyOpt, befOpt, strOpt;
	strTemp = "";
	var tempList = new Array();
	
	for (i = 0; i < fromList.length; i++) {
		befOpt = fromList.options[i];
		if (befOpt.selected && befOpt.value != "empty") {
			temp = befOpt.value
			strTemp = temp.substr(1);
			tempList[tempList.length] = i;
			befOpt.selected = false;
		}
	}
	for (i = tempList.length-1; i >= 0; i--) {
		if (document.all) 
			fromList.options.remove(tempList[i]);
		else
			fromList.options[tempList[i]] = null; 
	}
	x = fromList.length 
}

function moverMembersBack2(fromList) { //special för att skicka tillbaka användare med två mottagarboxar. (adm_update_groups.asp)

	var i, nyOpt, befOpt, strOpt;
	strTemp = "";
	var tempList = new Array();
	
	for (i = 0; i < fromList.length; i++) {
		befOpt = fromList.options[i];
		if (befOpt.selected && befOpt.value != "empty") {
			temp = befOpt.value
			strTemp = temp.substr(1);
			tempList[tempList.length] = i;
			befOpt.selected = false;
		}
	}
	for (i = tempList.length-1; i >= 0; i--) {
		if (document.all) 
			fromList.options.remove(tempList[i]);
		else
			fromList.options[tempList[i]] = null; 
	}
	x = fromList.length 
}


function moverMembersBack3(fromList, fromList2) { //special för att skicka tillbaka användare med två mottagarboxar och två avsändarboxar.

	var i, nyOpt, befOpt, strOpt;
	strTemp = "";
	var tempList = new Array();
	
	for (i = 0; i < fromList.length; i++) {
		befOpt = fromList.options[i];
		if (befOpt.selected && befOpt.value != "empty") {
			temp = befOpt.value
			strTemp = temp.substr(1);
			tempList[tempList.length] = i;
			befOpt.selected = false;
		}
	}
	for (i = tempList.length-1; i >= 0; i--) {
		if (document.all) 
			fromList.options.remove(tempList[i]);
		else
			fromList.options[tempList[i]] = null; 
	}
	x = fromList.length 
	
	for (i = 0; i < fromList2.length; i++) {
		befOpt = fromList2.options[i];
		if (befOpt.selected && befOpt.value != "empty") {
			temp = befOpt.value
			strTemp = temp.substr(1);
			tempList[tempList.length] = i;
			befOpt.selected = false;
		}
	}
	for (i = tempList.length-1; i >= 0; i--) {
		if (document.all) 
			fromList2.options.remove(tempList[i]);
		else
			fromList2.options[tempList[i]] = null; 
	}
	x = fromList2.length 
}

function alla(lista) {
	for (i = 0; i < lista.length; i++) {
		if (lista.options[i].value != "empty")
			lista.options[i].selected = true;
		}
	return true;
}


function preserveSelectBox(SelectBoxToPreserve,InputToStoreValueIn,InputToStoreTextIn)
{
InputToStoreValueIn.value = ""
InputToStoreTextIn.value = ""

if(SelectBoxToPreserve.length > 0)
{
	for(i = 0; i < SelectBoxToPreserve.length ;i++)
	{
		if (i < SelectBoxToPreserve.length - 1 )
		{
			InputToStoreValueIn.value = InputToStoreValueIn.value + SelectBoxToPreserve.options[i].value + ":"	
			InputToStoreTextIn.value = InputToStoreTextIn.value + SelectBoxToPreserve.options[i].text + ":"	
		}
		else
		{
			InputToStoreValueIn.value = InputToStoreValueIn.value + SelectBoxToPreserve.options[i].value 
			InputToStoreTextIn.value = InputToStoreTextIn.value + SelectBoxToPreserve.options[i].text 
		}
	}
}
else
{
InputToStoreValueIn.value = "empty"
InputToStoreTextIn.value = "empty"
}
}

function restoreSelectBox(SelectToRestore,SelectToRemoveFrom,GetValuesFromInput,GetTextFromInput)
{
	if(GetValuesFromInput.value != "")
	{
		resetSelectBox(SelectToRestore)
	
		if (GetValuesFromInput.value != "empty")
		{
			var values = GetValuesFromInput.value.split(":")
			var texts = GetTextFromInput.value.split(":")
			for(i = 0; i < values.length; ++i)
			{
				addOption(SelectToRestore,texts[i],values[i],i,0)
			
			for (j = 0; j < SelectToRemoveFrom.length; j++)
			{
				if (SelectToRemoveFrom.options[j].value == values[i])
				{
					if (document.all) 
						SelectToRemoveFrom.options.remove(j);
					else
						SelectToRemoveFrom.options[j] = null; 
					break;
				}
			}
			
			}	
		}
	}
}

function resetSelectBox(targetSelect) // full path of the Select
{
	var i;
	for (i = targetSelect.length-1; i >= 0; i--) 
	{
		if (document.all) 
			targetSelect.options.remove(i);
		else
			targetSelect.options[i] = null; 
	}
}

function addOption(toSelect,txtOpt,valOpt,indexOpt,boolSelected)  // full path of the Select, text in Option, value of Option, index for Option
{
	var newOpt;
	
	newOpt = new Option(txtOpt, valOpt, 0, boolSelected);
	if (document.all)
			toSelect.add(newOpt, indexOpt);
		else
			toSelect.options[indexOpt] = newOpt;
	newOpt = null;
}


function isDigit (c)
{   
	return ((c >= "0") && (c <= "9"))
}

function isEmpty(s)
{   
	return ((s == null) || (s.length == 0))
}

function isInteger (s)

{   
    var i;
    for (i = 0; i < s.length; i++) 
    {   
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }
    return true;
}


function validDate(day, month, year)
{
	var ok=0;
	if(month >= "01" && month <= "12")
	{
		if(day >= "01" && day <= "31")
		{
			ok=1;
		}		
		if(ok && month == "02")
		{
			var test;
			if(leapYear(year))
				test = "29";
			else
				test = "28";
			if(day > test)
				return 0;
		}
		if(ok && (month == "04" || month == "06" || month == "09" || month == "11"))
		{
			if(day > "30")
				return 0;
		}
	}	
	return ok;
}

function leapYear(year)
{
	var yearnr = parseInt(year);
	var leap=0;
	if(yearnr == 2000)
		return 1;
		
	if(yearnr % 4 == 0)
	{
		leap=1;
		if(yearnr % 100 == 0)
			leap=1;
		if(yearnr % 400 == 0)
			leap=0;
	}
	return leap;
}

