/*
 * Check email with regular expression.
 */
function checkEmail(email) {	

	var emailRegularExpression = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
	
	return emailRegularExpression.test(email);
}


/*
 * Returns true if passed value contains only numbers.
 */
function isNumeric(value) {

	var numberChars = "0123456789";
	
	for (i = 0; i < value.length; i++)
		if (numberChars.indexOf(value.charAt(i)) < 0) return false;
		
	return true;
}


/* 
 * Check passwords chars
 */
function checkPassword(password) {

	var passwordChars = "abcdefghijklmnopqrstuvwxyz0123456789";
	
	for (i = 0; i < password.length; i++)
		if (passwordChars.indexOf(password.charAt(i)) < 0) return false;
		
	return true;
}


/* 
 * Loads items from passed table into destination combobox.
 * If parameter selected_item is passed it will be automatically selected.
 */
function LoadComboBox(comboBoxDest, items, selected_item) {

	for (i = 0; i < items.length; i++) {				
		var new_option = document.createElement("OPTION");	
		comboBoxDest.options.add(new_option);
		new_option.text = items[i];
		if (i == 0) new_option.value = "";
		else new_option.value = items[i];
		if (items[i] == selected_item) new_option.selected = true;
	}
}


/* 
 * Loads items into specifed comboBoxDst using selected item in comboBoxSrc and passed items.
 * If parameter selected_item is passed it will be automatically selected.
 */
function ReloadComboBox(comboBoxSrc, comboBoxDst, items, selected_item) {

	if (comboBoxSrc.selectedIndex == 0) {
		comboBoxDst.disabled = true;
		comboBoxDst.style.background = "#D4D0C8";
	}
	else {		
		comboBoxDst.disabled = false;
		comboBoxDst.style.background = "#FFFFFF";
	}
			
	while (comboBoxDst.options.length > 1) comboBoxDst.options.remove(comboBoxDst.options.length - 1);
	
	for (i = 0; i < items[comboBoxSrc.selectedIndex].length; i++) {											
		var new_option = document.createElement("OPTION");
		comboBoxDst.options.add(new_option);
		new_option.innerHTML = items[comboBoxSrc.selectedIndex][i];
		if (items[comboBoxSrc.selectedIndex][i] == selected_item) new_option.selected = true;
	}	
}

