// ONERROR_START
function onError(input_object, error_message){
	alert(error_message);
  input_object.select();
	input_object.focus();
	return false;	
}
// ONERROR_END

// REQUIRED_START
function hasValue(obj, obj_type)
    {
    if (obj_type == "TEXT" || obj_type == "PASSWORD")
	{
    	if (obj.value.length == 0) 
      		return false;
    	else 
      		return true;
    	}
    else if (obj_type == "SELECT")
	{
        for (i=0; i < obj.length; i++)
	    	{
		if (obj.options[i].selected)
			return true;
		}

       	return false;	
	}
    else if (obj_type == "SINGLE_VALUE_RADIO" || obj_type == "SINGLE_VALUE_// CHECKBOX")
	{

		if (obj.checked)
			return true;
		else
       		return false;	
	}
    else if (obj_type == "RADIO" || obj_type == "CHECKBOX")
	{

        for (i=0; i < obj.length; i++)
	    	{
		if (obj[i].checked)
			return true;
		}

       	return false;	
	}
	}
// REQUIRED_END

// CHECKDATE_START
function checkdate(object_value)
    {
    //Returns true if value is a date format or is NULL
    //otherwise returns false	

    if (object_value.length == 0)
        return true;

    //Returns true if value is a date in the mm/dd/yyyy format
	isplit = object_value.indexOf('/');

	if (isplit == -1 || isplit == object_value.length)
		return false;

    sMonth = object_value.substring(0, isplit);

	if (sMonth.length == 0)
        return false;

	isplit = object_value.indexOf('/', isplit + 1);

	if (isplit == -1 || (isplit + 1 ) == object_value.length)
		return false;

    sDay = object_value.substring((sMonth.length + 1), isplit);

	if (sDay.length == 0)
        return false;

	sYear = object_value.substring(isplit + 1);

	if (!checkinteger(sMonth)) //check month
		return false;
	else
	if (!checkrange(sMonth, 1, 12)) //check month
		return false;
	else
	if (!checkinteger(sYear)) //check year
		return false;
	else
	if (!checkrange(sYear, 0, 9999)) //check year
		return false;
	else
	if (!checkinteger(sDay)) //check day
		return false;
	else
	if (!checkday(sYear, sMonth, sDay)) // check day
		return false;
	else
		return true;
    }
// CHECKDATE_END

// CHECKEURODATE_START
function checkeurodate(object_value)
    {
    //Returns true if value is a eurodate format or is NULL
    //otherwise returns false	

    if (object_value.length == 0)
        return true;

    //Returns true if value is a date in the dd/mm/yyyy format
	isplit = object_value.indexOf('/');

	if (isplit == -1)
	{
		isplit = object_value.indexOf('.');
	}

	if (isplit == -1 || isplit == object_value.length)
		return false;

    sDay = object_value.substring(0, isplit);

	monthSplit = isplit + 1;

	isplit = object_value.indexOf('/', monthSplit);

	if (isplit == -1)
	{
		isplit = object_value.indexOf('.', monthSplit);
	}

	if (isplit == -1 ||  (isplit + 1 )  == object_value.length)
		return false;

    sMonth = object_value.substring((sDay.length + 1), isplit);

	sYear = object_value.substring(isplit + 1);

	if (!checkinteger(sMonth)) //check month
		return false;
	else
	if (!checkrange(sMonth, 1, 12)) // check month
		return false;
	else
	if (!checkinteger(sYear)) //check year
		return false;
	else
	if (!checkrange(sYear, 0, null)) //check year
		return false;
	else
	if (!checkinteger(sDay)) //check day
		return false;
	else
	if (!checkday(sYear, sMonth, sDay)) //check day
		return false;
	else
		return true;
    }
// CHECKEURODATE_END

// CHECKDAY_START
function checkday(checkYear, checkMonth, checkDay)
    {

	maxDay = 31;

	if (checkMonth == 4 || checkMonth == 6 ||
			checkMonth == 9 || checkMonth == 11)
		maxDay = 30;
	else
	if (checkMonth == 2)
	{
		if (checkYear % 4 > 0)
			maxDay =28;
		else
		if (checkYear % 100 == 0 && checkYear % 400 > 0)
			maxDay = 28;
		else
			maxDay = 29;
	}

	return checkrange(checkDay, 1, maxDay); //check day
    }
// CHECKDAY_END


// CHECKINTEGER_START
function checkinteger(object_value)
    {
    //Returns true if value is a number or is NULL
    //otherwise returns false	

    if (object_value.length == 0)
        return true;

    //Returns true if value is an integer defined as
    //   having an optional leading + or -.
    //   otherwise containing only the characters 0-9.
	var decimal_format = ".";
	var check_char;

    //The first character can be + -  blank or a digit.
	check_char = object_value.indexOf(decimal_format)
    //Was it a decimal?
    if (check_char < 1)
	return checknumber(object_value);
    else
	return false;
    }
// CHECKINTEGER_END

// CHECKNUMBERRANGE_START
function numberrange(object_value, min_value, max_value)
    {
    // check minimum
    if (min_value != null)
	{
        if (object_value < min_value)
		return false;
	}

    // check maximum
    if (max_value != null)
	{
	if (object_value > max_value)
		return false;
	}
	
    //All tests passed, so...
    return true;
    }
// CHECKNUMBERRANGE_END

// CHECKNUMBER_START
function checknumber(object_value)
    {
    //Returns true if value is a number or is NULL
    //otherwise returns false	

    if (object_value.length == 0)
        return true;

    //Returns true if value is a number defined as
    //   having an optional leading + or -.
    //   having at most 1 decimal point.
    //   otherwise containing only the characters 0-9.
	var start_format = " .+-0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;

    //The first character can be + - .  blank or a digit.
	check_char = start_format.indexOf(object_value.charAt(0))
    //Was it a decimal?
	if (check_char == 1)
	    decimal = true;
	else if (check_char < 1)
		return false;
        
	//Remaining characters can be only . or a digit, but only one decimal.
	for (var i = 1; i < object_value.length; i++)
	{
		check_char = number_format.indexOf(object_value.charAt(i))
		if (check_char < 0)
			return false;
		else if (check_char == 1)
		{
			if (decimal)		// Second decimal.
				return false;
			else
				decimal = true;
		}
		else if (check_char == 0)
		{
			if (decimal || digits)	
				trailing_blank = true;
        // ignore leading blanks

		}
	        else if (trailing_blank)
			return false;
		else
			digits = true;
	}	
    //All tests passed, so...
    return true
    }
// CHECKNUMBER_END

// CHECKRANGE_START
function checkrange(object_value, min_value, max_value)
    {
    //if value is in range then return true else return false

    if (object_value.length == 0)
        return true;


    if (!checknumber(object_value))
	{
	return false;
	}
    else
	{
	return (numberrange((eval(object_value)), min_value, max_value));
	}
	
    //All tests passed, so...
    return true;
    }
// CHECKRANGE_END 

// CHECKTIME_START
function checktime(object_value)
    {
    //Returns true if value is in time format or is NULL
    //otherwise returns false	

    if (object_value.length == 0)
        return true;

    //Returns true if value is a date in the mm/dd/yyyy format
	isplit = object_value.indexOf(':');

	if (isplit == -1 || isplit == object_value.length)
		return false;

    sHour = object_value.substring(0, isplit);
	iminute = object_value.indexOf(':', isplit + 1);

	if (iminute == -1 || iminute == object_value.length)
		sMin = object_value.substring((sHour.length + 1));
	else
		sMin = object_value.substring((sHour.length + 1), iminute);

    if (!checkinteger(sHour)) //check hour
		return false;
    else
    if (!checkrange(sHour, 0, 23)) //check hour
		return false;

	if (!checkinteger(sMin)) //check minutes
		return false;
	else
	if (!checkrange(sMin, 0, 59)) // check minutes
		return false;

	// did they specify seconds
    if (iminute != -1)
	{
		sSec = object_value.substring(iminute + 1);

		if (!checkinteger(sSec)) //check seconds
			return false;
		else
		if (!checkrange(sSec, 0, 59)) //check seconds
			return false;	
	}
    
    return true;
    }
// CHECKTIME_END

// CHECKPHONENUMBER_START
function checkphone(object_value)
    {
    if (object_value.length == 0)
        return true;
		
    if (object_value.length != 12)
        return false;

	// check if first 3 characters represent a valid area code
    if (!checknumber(object_value.substring(0,3)))
		return false;
    else
	if (!numberrange((eval(object_value.substring(0,3))), 100, 1000))
		return false;

	// check if area code/exchange separator is either a'-' or ' '
	if (object_value.charAt(3) != "-" && object_value.charAt(3) != " ")
        return false

	// check if  characters 5 - 7 represent a valid exchange
    if (!checknumber(object_value.substring(4,7)))
		return false;
    else
	if (!numberrange((eval(object_value.substring(4,7))), 100, 1000))
		return false;
	
	// check if exchange/number separator is either a'-' or ' '
	if (object_value.charAt(7) != "-" && object_value.charAt(7) != " ")
        return false;

	// make sure last for digits are a valid integer
	if (object_value.charAt(8) == "-" || object_value.charAt(8) == "+")
        return false;
	else
	{
		return (checkinteger(object_value.substring(8,12)));
	}
    }
// CHECKPHONENUMBER_END 

// CHECKEMAIL_START
function checkEmail(object_value)
    {
    var error_id = "NULL";
    	
    	var emailOk  = true;
    	var notAllowed = ",*<>():#;%&?";			
    	var alfaSym  = object_value.indexOf('@');
    	var punktum  = object_value.lastIndexOf('.');
    	var space    = object_value.indexOf(' ');
    	var lengde   = object_value.length - 1;   // Array is from 0 to length-1
    	
    	if (lengde == -1) // The field doesn't contain anything
    		{ emailOk = false; error_id = 0; }
    	else if (alfaSym == -1) // '@' nust appear in address
    		{ emailOk = false; error_id = 1; }
    	else if (alfaSym == 0) // '@' cannot be in first position
    		{ emailOk = false; error_id = 2; }
    	else if (punktum <= alfaSym+1) // Must be at least one valid char btwn '@' and '.'
    		{ emailOk = false; error_id = 3; }
    	else if (punktum == lengde ) // Must be at least one valid char after '.'
    		{ emailOk = false; error_id = 4; }
    	else if (space  != -1) // No empty spaces permitted
    		{ emailOk = false; error_id = 5; }
    	else {	// checks for characters not allowed in address
    		for(i=0; i<=lengde; i++) {
    			if (notAllowed.indexOf(object_value.charAt(i)) != -1){
    				emailOk = false; error_id = 6; break;
    			}
    		}
    	}
    	
	return emailOk;
    }
// CHECKEMAIL_END 

// CHECKCREDITCARD_START
function checkcreditcard(object_value)
    {
	var white_space = " -";
	var creditcard_string="";
	var check_char;


    if (object_value.length == 0)
        return true;

	// squish out the white space
	for (var i = 0; i < object_value.length; i++)
	{
		check_char = white_space.indexOf(object_value.charAt(i))
		if (check_char < 0)
			creditcard_string += object_value.substring(i, (i + 1));
	}	

	// if all white space return error
    if (creditcard_string.length == 0)
        return false;
	 
	 	
	// make sure number is a valid integer
	if (creditcard_string.charAt(0) == "+")
        return false;

	if (!checkinteger(creditcard_string))
		return false;

    // now check mod10

	var doubledigit = creditcard_string.length % 2 == 1 ? false : true;
	var checkdigit = 0;
	var tempdigit;

	for (var i = 0; i < creditcard_string.length; i++)
	{
		tempdigit = eval(creditcard_string.charAt(i))

		if (doubledigit)
		{
			tempdigit *= 2;
			checkdigit += (tempdigit % 10);

			if ((tempdigit / 10) >= 1.0)
			{
				checkdigit++;
			}

			doubledigit = false;
		}
		else
		{
			checkdigit += tempdigit;
			doubledigit = true;
		}
	}	
	return (checkdigit % 10) == 0 ? true : false;

    }
// CHECKCREDITCARD_END 

// CHECKORGNR_START
function checkorgnr(object_value)
    {
	var white_space = " -+.";
	var orgnr_string="";
	var check_char;

  if (object_value.length == 0)
    return true;
			  
	// squish out the white space
	for (var i = 0; i < object_value.length; i++)
	{
		check_char = white_space.indexOf(object_value.charAt(i))
		if (check_char < 0)
			orgnr_string += object_value.substring(i, (i + 1));
	}	
	
	// if all white space return error
  if (orgnr_string.length != 9)
  	return false;
		
	// make sure number is a valid integer
	if (!checkinteger(orgnr_string))
		return false;

	return true;
}
// CHECKORGNR_END 

// SETFORMVAR_START
// Function, called by Java applets, to set a specified form param's value.
function setFormParam( strFormName, strParamName, strParamValue )
	{
		var strObjName = "document." + strFormName + "." + strParamName;
		var obj = eval( strObjName );
		obj.value = strParamValue;
		return true;
	}
// SETFORMVAR_END

// CHECKREGEX_START
function checkregex(object_value, regex)
	{
	//Returns true if the value matches the Regular Expression passed in.
	
	return regex.test(object_value);

	}
// CHECKREGEX_END