
function enTilbake() {
var thisfname = window.location.href;
if(thisfname.indexOf('_IE4') >= 0 || thisfname.indexOf('_40') >= 0 || thisfname.indexOf('_Nav3') >= 0 || thisfname.indexOf('_Gen') >= 0)
{
  window.history.go(-2);
}
else
{
  window.history.back();
}
 }

	// This file contains the data validation JavaScript functions
	// It is included in the HTML pages with forms that need these
	// data validation routines.


// DEFINE VARIABLES

// whitespace characters
var whitespace = " \t\n\r";


function replaceAll (s, fromStr, toStr)
{
	var new_s = s;
	for (i = 0; i < 100 && new_s.indexOf (fromStr) != -1; i++)
	{
		new_s = new_s.replace (fromStr, toStr);
	}
	return new_s;
}

/****************************************************************/

/* PURPOSE:  Since we are using the single tick mark as the
	string delimiter to construct our SQL queries, a string with
	a tick mark in it will cause a SQL error.  Therefore we replace
	all "'" with "''", which eliminates the possibility of a SQL error.
*/

function sqlSafe (s)
{
	var new_s = s;
	new_s = replaceAll (new_s, "'", "|");
	new_s = replaceAll (new_s, "|", "''");
	new_s = replaceAll (new_s, "\"", "|");
	new_s = replaceAll (new_s, "|", "''");
	return new_s;
}

/****************************************************************/

function makeSafe (i)
{
	i.value = sqlSafe (i.value);
}

/****************************************************************/

// Check whether string s is empty.

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

/****************************************************************/

// Returns true if string s is empty or 
// whitespace characters only.

function isWhitespace (s)

{   var i;

    // Is s empty?
    if (isEmpty(s)) return true;

    // Search through string's characters one by one
    // until we find a non-whitespace character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
	// Check that current character isn't whitespace.
	var c = s.charAt(i);

	if (whitespace.indexOf(c) == -1) return false;
    }

    // All characters are whitespace.
    return true;
}

/****************************************************************/

// Checks to see if a required field is blank.  If it is, a warning
// message is displayed...

function ForceEntry(objField, FieldName)
{
	var strField = new String(objField.value);
	if (isWhitespace(strField)) {
		alert("Feltet " + FieldName + " er obligatorisk.");
		objField.focus();
		objField.select();
		return false;
	}

	return true;
}

/****************************************************************/

// Sjekk om feltet er utfylt

function ErUtfylt(objField)
{
	var strField = new String(objField.value);
	if (isWhitespace(strField)) {
		return false;
	}

	return true;
}
				
/****************************************************************/

/* PURPOSE:  Returns true if the string is a valid date number.
	A method is passed in (1 = day, 2 = month).  If the string is
	nonnumeric, false is passed back.  If the day in the date string
	is greater than 31, false is returned.  If the month is greater
	than 12, an error is returned.
*/

function isDateNumber(strNum,method)
{
	var str = new String(strNum);
	var i = 0;

	if (isNaN(parseInt(str)) || parseInt(str) < 0) return false;

	if (method == 1)
		if (parseInt(str) > 31)
			return false;
	if (method == 2)
		if (parseInt(str) > 12)
			return false;

	for (i = 0; i < str.length; i++)
		if (str.charAt(i) < '0' || str.charAt(i) > '9')
			return false;


	return true;
}

/****************************************************************/

/*      Returnerer TRUE hvis riktig tidselement er angitt.
        En metode sendes inn som input (1=time, 2=sekund). 
        FALSE returneres hvis feil.  
*/

function isTimeNumber(strNum,method)
{
	var str = new String(strNum);
	var i = 0;

	if (isNaN(parseInt(str)) || parseInt(str) < 0) return false;

	if (method == 1)
		if (parseInt(str) > 23)
			return false;
	if (method == 2)
		if (parseInt(str) > 60)
			return false;

	for (i = 0; i < str.length; i++)
		if (str.charAt(i) < '0' || str.charAt(i) > '9')
			return false;


	return true;
}


/****************************************************************/

// Displays an alert box with the passed in string...

function PromptErrorMsg(Field,strError,strFormat)
{
	alert("Du har feil format i feltet " + strError + ".  Format skal være " + strFormat);
	Field.focus();
}

/****************************************************************/

/* PURPOSE: Checks to see if the string is a valid date.  A valid
	date is defined as any of the following:

		DD/MM/YY, DD/MM/YYYY, D/M/YY, D/M/YYYY,
		DD.MM.YY, DD.MM.YYYY, D.M.YY, D.M.YYYY
*/

function ForceDate(strDate,strField)
{
	var str = new String(strDate.value);
	if (isWhitespace(str)) {
		return true;
		// if the field is empty, just return true...
	}

	var i = 0, count = str.length, j = 0;
	while ((str.charAt(i) != "/" && str.charAt(i) != ".") && i < count)
		i++;

	if (i == count || i > 2) {
		PromptErrorMsg(strDate,strField,"DD.MM.ÅÅÅÅ");
		return false;
	}

	var addOne = false;
	if (i == 2) addOne = true;

	if (!isDateNumber(str.substring(0,i),1)) {
		PromptErrorMsg(strDate,strField,"DD.MM.ÅÅÅÅ");
		return false;
	}

	j = i+1;
	i = 0;

	while ((str.charAt(i+j) != "/" && str.charAt(j+i) != ".") && i+j < count)
		i++;

	if (i+j == count || i > 2) {
		PromptErrorMsg(strDate,strField,"DD.MM.ÅÅÅÅ");
		return false;
	}

	if (!isDateNumber(str.substring(j,i+j),2)) {
		PromptErrorMsg(strDate,strField,"DD.MM.ÅÅÅÅ");
		return false;
	}

	j = i+3;
	i = 0;

	if (addOne) j++;

	while (i+j < count)
		i++;


	if (i != 2 && i != 4) {
		PromptErrorMsg(strDate,strField,"DD.MM.ÅÅÅÅ");
		return false;
	}

	if (!isDateNumber(str.substring(j,i+j),3)) {
		PromptErrorMsg(strDate,strField,"DD.MM.ÅÅÅÅ");
		return false;
	}

	return true;
}

/****************************************************************/

/* Sjekker at riktig tid er angitt

   Gyldig 		TT:MM
			TT.MM
*/

function SjekkTid(strTid,strFelt)
{
	var str = new String(strTid.value);
	if (isWhitespace(str)) {
		return true;
		// tomt felt, returner TRUE
	}

	var i = 0, count = str.length, j = 0;

	while ((str.charAt(i) != ":" && str.charAt(i) != ".") && i < count)
		i++;

	if (i == count || i > 2) {
		PromptErrorMsg(strTid,strFelt,"TT:MM");
		return false;
	}

	if (!isTimeNumber(str.substring(0,i),1)) {
		PromptErrorMsg(strTid,strFelt,"TT:MM");
		return false;
	}

	j = i+1;

	if (!isTimeNumber(str.substring(j,count),2)) {
		PromptErrorMsg(strTid,strFelt,"TT:MM");
		return false;
	}

	return true;
}

/****************************************************************/

function ValiderUtleierFelter() {
        var CanSubmit = false;

// Utleier må være utfylt
        CanSubmit = ForceEntry(document.forms[0].utleiernavn,"Utleiernavn");

// Email må være utfylt
        if (CanSubmit) CanSubmit = ForceEntry(document.forms[0].email,"Email");

// Passord må være utfylt
        if (CanSubmit) CanSubmit = ForceEntry(document.forms[0].passord,"Passord");
        
        return CanSubmit;
}