//***************************************************************************
//*                            formCheck.js
//*                           ---------------------
//*   datum			         : februari 2005
//*   author		         : PS/TBWA
//*
//***************************************************************************

var formatNumber = /^\d+$/;							// A number contains only digits
var formatHouseNumber = /^\d+$/;					// HouseNumber format starts with a digit
var formatPostalCode = /^(\d{4})\s*([a-z]{2})$/i;	// PostalCode format is 4 digits, possibly some blanks, and 2 letters
var formatEmail = /^[^@\s]+\@[^@\s]+\.[^@\s]+/;		// E-mail is x@x.x
var formatPhone = /^\d{2,4}[ -]{0,1}\d{6,8}$/;		// A phonenumber is formated nn-nnnnnnnn or nnn-nnnnnnn or nnnn-nnnnnn
var formatDate = /^([0-3]{1}[0-9]{1})(\/|-)([0-1]{1}\d{1})(\/|-)([1]{1}[9]{1}\d{2})$/;	// A date is formated dd/mm/jjjj (or dd-mm-jjjj) with only digits

function textboxFilled(Field) {
	var value = Field.value;
	if (value == "") {
		return false;
	}
	return true;
}

function radioChecked(radioGroup) {
	var i;
	for (i = 0; i < radioGroup.length; i++) {
		if (radioGroup[i].checked) {
			radioGroup[i].focus;
			return true;
		}
	}
	return false;
}

function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

function checkboxChecked(checkboxGroup) {
	if(checkboxGroup.checked) {
		return true;
	}
	return radioChecked(checkboxGroup);
}

function isNumber(numberField) {
	var value = numberField.value;
	if (! formatNumber.test(value)) {
		return false;
	}
	return true;
}

function isLength(numberField, length) {
	var value = numberField.value;
	if (value.length < length) {
		return false;
	}	
	return true;
}

function selectboxFilled(Field) {
	var value = Field.selectedIndex;
	if (value =="") {
		return false;
	}
	return true;
}

function isValid(Field, format) {
	var value = Field.value;
	if (! format.test(value)) {
		return false;
	}
	return true;
}

function isValidOrEmpty(Field, format) {
	var value = Field.value;
	if (value == "") {
		return false;
	}
	if (!format.test(value)) {
		Field.focus();
		return false;
	}
	return true;
}

function oneOfTwoFilled(Field1, Field2) {
	var value1 = Field1.value;
	var value2 = Field2.value;
	if (value1 == "" && value2 == "") {
		Field1.focus();
		return false;
	}
	return true;
}

function getVar(name)  {

	get_string = document.location.search;         
    return_value = '';
         
	do {		//This loop is made to catch all instances of any get variable.
		name_index = get_string.indexOf(name + '=');

	if(name_index != -1) {
		get_string = get_string.substr(name_index + name.length + 1, get_string.length - name_index);
		end_of_value = get_string.indexOf('&');
		if (end_of_value != -1)                
			value = get_string.substr(0, end_of_value);                
		else                
			value = get_string;                

		if (return_value == '' || value == '')
			return_value += value;
		else
			return_value += ', ' + value;
		}
	} 
	while(name_index != -1)

	//Restores all the blank spaces.
	space = return_value.indexOf('+');
	while(space != -1) { 
		return_value = return_value.substr(0, space) + ' ' + 
		return_value.substr(space + 1, return_value.length);
		space = return_value.indexOf('+');
	}

	return(return_value);        

}
