/////////////////////////////////////////////////////
// Form validation vs1
// dependencies: basic.vs1
/////////////////////////////////////////////////////

function isNull(str) {
	return Strings.isEmpty(Strings.trim(str));
}

function isNumber(str) {
	return (!isNaN(str));
}

function isInteger(str) {
	return isNumber(str) && str.indexOf(".")==-1;
}

function isEmail(str) {
	if(str.length < 6) {
		return false;
	}
	var array = str.split("@");
	if(array.length != 2) {
		return false;
	}
	if(array[0].length == 0) {
		return false;
	}
	if(array[1].indexOf(".") == -1) {
		return false;
	}
	if(array[1].substring(array[1].lastIndexOf(".")+1).length < 2) {
		return false;
	}
	return true;
}

function isTime(str) {
	var array = str.split(":");
	if(array.length != 2 && array.length != 3) {
		return false;
	}
	var hours = Strings.toInteger(array[0]);
	if(!isNumber(hours) || hours<0 || hours>23)
		return false;
	var mins = Strings.toInteger(array[1]);
	if(!isNumber(mins) || mins<0 || mins>59)
		return false;
	if(array.length == 3) {
		var secs = Strings.toInteger(array[2]);
		if(!isNumber(secs) || secs<0 || secs>59)
			return false;
	}
	return true;
}

function isDate(str) {
	return Dates.valueOf(str) != false;
}

//////////////////////////////////////////////////////////////////////
// Radio class:
//////////////////////////////////////////////////////////////////////
function Radio_isSelected(radio) {
	return Radio_selectedIndex(radio) != -1;
}

function Radio_selectedIndex(radio) {
	for(i=0; i<radio.length; i++) {
		if(radio[i].checked)
			return i;
	}
	return -1;
}

function Radio_selectedValue(radio) {
	var index = Radio_selectedIndex(radio);
	if(index != -1) {
		return radio[index].value;
	}
	else {
		return false;
	}
}

function Radio_class() {
	this.isSelected = Radio_isSelected;
	this.selectedIndex = Radio_selectedIndex;
	this.selectedValue = Radio_selectedValue;
}

var Radio = new Radio_class();

//////////////////////////////////////////////////////////////////////
// Option class:
//////////////////////////////////////////////////////////////////////
function Option_isSelected(oList) {
	return Option_selectedIndex(oList) != 0;
}

function Option_selectedIndex(oList) {
	return oList.selectedIndex;
}

function Option_selectedValue(oList) {
	var index = Option_selectedIndex(oList);
	if(index != 0) {
		return oList.options[index].value;
	}
	else {
		return false;
	}
}

function Option_class() {
	this.isSelected = Option_isSelected;
	this.selectedIndex = Option_selectedIndex;
	this.selectedValue = Option_selectedValue;
}

var Option = new Option_class();
