﻿jQuery.extend({
	isEmpty: function(objElt) {
	   // alert("Empty : " + objElt);
	    //alert("Empty : " + objElt.val());
		data =	$.trim(objElt.val());
		if ( data.length > 0 ) 
		{ return false; }
		return true;
	},

	isAlpha: function(objElt) {
	    //alert("Alpha: " + objElt);
	    //alert("Alpha1: " + objElt.val());
		return	/^[a-zA-Z]+$/.test(objElt.val());
	},
	
	isAlpha1: function(objElt) {
		return	/^[a-zA-Z ]+$/.test(objElt.val());
	},
	
	isNumeric: function(objElt) {
		return	/^[0-9]+$/.test(objElt.val());
	},

	isDOB: function(objElt) {
		return	/^[0-9/+ ]+$/.test(objElt.val());
	},
	
	isAlphaNumeric: function(objElt) {
		return	/^[a-zA-Z0-9 ]+$/.test(objElt.val());
	},
	isAlphaNumericSplChar: function(objElt) {
		return	/^[a-zA-Z0-9-_. ]+$/.test(objElt.val());
	},
	isPhone: function(objElt) {
		return	/^[0-9\-()+ ]+$/.test(objElt.val());
	},

	isEmail: function(objElt) {
		return	/^[a-z0-9]([a-z0-9_\-\.]*)@([a-z0-9_\-\.]*)(\.[a-z]{2,4}(\.[a-z]{2}){0,2})$/i.test(objElt.val());
	},
	
	isAmount: function(objElt) {
		return	/^[0-9]+(.){0,1}([0-9]*)$/i.test(objElt.val());
	},

	isPositiveInt: function(objElt) {
		if(parseInt(objElt.val())>0) {	return true; }
		return false;
	},

	isPositiveFloat: function(objElt) {
		return this.isNotNegativeFloat(objElt) && (parseFloat(objElt.val())>0);	
	},

	isNotNegativeFloat: function(objElt) {
		return /^[0-9]*[.]{0,1}[0-9]*$/.test(objElt.val());
	},

	isNotNegativeInt: function(objElt) {
		return /^[0-9]*$/.test(objElt.val());
	},

	isZip: function(objElt, noOfChars) {
		patZip	=	eval("/^[0-9]{"+noOfChars+"}$/");
		return patZip.test(objElt.val());
	},
    isValidDate:function(objElt){
        var check = false;
        var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
        if( re.test(objElt.val())){
            var adata = objElt.val().split('/');
            var dd = parseInt(adata[0],10);
            var mm = parseInt(adata[1],10);
            var yyyy = parseInt(adata[2],10);
            var xdata = new Date(yyyy,mm-1,dd);
            if ((xdata.getFullYear() == yyyy ) && ((xdata.getMonth() + 1) == mm ) && (xdata.getDate() == dd))
                check = true;
            else
                check = false;
        } else
            check = false;
        return check;
    },
	isPeriod: function(objElt) {
		return /^[1-9][0-9]{2}$/.test(objElt.val());
	},

	isFloat: function(objElt) {
		return /^[\-\+]{0,1}[0-9]*[.]{0,1}[0-9]*$/.test(objElt.val());
	},

	isInt: function(objElt) {
		i = parseInt(objElt.val());
		if(i>0 ||i==0 || i<0) { return true; }
		return false;
	},
	
	isSpace: function(objElt) {
		return /^[ ]+$/.test(objElt.val());
	},

	itemsChecked: function(type, eltName, form) {
		a = 0;
		for(var i=0; i<form.elements.length; i++) {
			var e = form.elements[i];
			if(e.type == type && e.name == eltName && e.checked) { a++; }
		}
		return a;
	},

	itemSelected: function(objElt) {
		if ( objElt.options.selectedIndex == 0 || objElt.options.selectedIndex == -1 )
			return false;
		return true;
	},

	itemsSelected: function(objElt) {
		a = 0;
		for(i=0; i<objElt.options.length; i++)
		{
		  if(objElt.options[i].selected)
			a++;
		}
		return a;
	},

	itemSelectedData: function(objElt, mode) {
		return (mode == "value") ? objElt.val() : objElt.options[objElt.selectedIndex].text;
	}
});

