/** 
 * Validator 
 * Basically used for html form validations.
 */

_this=Validator.prototype;

function Validator(){}

_this.isDefined=function(x){
	return typeof(x)!="undefined";
};	

_this.isRadioChecked=function(x){
	if(!this.isDefined(x))
		return false;
	for (i=0; i<x.length; i++) {
    	if (x[i].checked) 
    		return true;
	} 
 return false;
};

_this.isEmpty=function(x){
	if(!this.isDefined(x))
		return false;
	if(this.isNumeric(x))
		return false;
	if(x=="")
		return true;
	return false;
};

_this.isEmail=function(x){
	if(!this.isDefined(x))
		return false;
	return x.search(/^[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*@[A-Za-z0-9]+([_\.-][A-Za-z0-9]+)*\.([A-Za-z]){2,4}$/ig) != -1;
};

_this.isWhiteSpace=function(x){
	if(!this.isDefined(x)) 
		return false;
	return /^\s*$/.test(x);
};

_this.isInteger=function(x){
	if(!this.isDefined(x))
		return false;
	x=(""+x).replace(/\.0*$/g,"");
	var intNumber=parseInt(x);
	if(!isNaN(intNumber)){
		x=x.replace(/^0*/, '');
		if(x=="")x=0;
	}
	intNumber=parseInt(x);
	if((!isNaN(intNumber))&&((""+intNumber)==x))
		return true;
	return false;
};

_this.isFloat=function(x){
	if(!this.isDefined(x))
		return false;
//	x=(""+x).replace(/,/g,".");
	return x!=""&&!isNaN(x);
};

_this.isNumeric=function(x){
	return this.isFloat(x);
};

_this.isString=function(x){
	if(!this.isDefined(x))
		return false;
	return typeof(x)=="string";
};

_this.isDate=function(intYear,intMonth,intDay){
	if(!this.isDefined(intYear)||!this.isDefined(intMonth)||!this.isDefined(intDay)||
			this.isEmpty(intYear)||this.isEmpty(intMonth)||this.isEmpty(intDay))
		return false;
	var arMonth=new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	if((parseInt(intYear)%4==0&&parseInt(intYear)%100!=0)||parseInt(intYear%400)==0)
		arMonth[1]=29;
	else 
		arMonth[1]=28;
	var intMaxDay=arMonth[parseInt(intMonth)-1];
	if(parseInt(intDay)>intMaxDay)
		return false;return true;
};

_this.isPositive=function(x){
	if(!this.isNumeric(x))
		return false;
	return parseFloat(x)>=0;
};

_this.isPositiveStrict=function(x){
	if(!this.isNumeric(x))
		return false;
	return parseFloat(x)>0;
};

_this.isNegative=function(x){
	if(!this.isNumeric(x))
		return false;
	return parseFloat(x)<=0;
};

_this.isNegativeStrict=function(x){
	if(!this.isNumeric(x))
		return false;
	return parseFloat(x)<0;
};

_this.isPositiveInt = function(x) {
	if (this.isInteger(x) && x > 0)
		return true;
	else return false;
};