function check_file(v, extList){
	var allowedFileExt = extList;
	var sUpload = v;
	if(sUpload != ""){
		var iExt = sUpload.indexOf("\\");
		var iDot = sUpload.indexOf(".");
		if(iDot > 0){
			var aUpload=sUpload.split(".");
			try{
				if(allowedFileExt.indexOf(aUpload[aUpload.length-1].toUpperCase()) < 0){
					return false;
				}else{
					if(!aUpload[aUpload.length-1]){
						return false;
					}
				}
			}catch(e){
				return false;
			}
		}
		return true;
	}
	return true;
}


function isEmpty( strValue ) {
	return  ((strValue == null) || (strValue.length == 0));
}


function validateRequired( strValue ) {

	return  !isEmpty(strValue) && !/^\s+$/.test(strValue);
}

function validateEmail( strValue ) {

	var objRegExp  = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;

	//check for integer characters
	return objRegExp.test(strValue);
}

function  validateNumeric( strValue ) {
	var objRegExp  =  /(^-?\d\d*\.\d*$)|(^-?\d\d*$)|(^-?\.\d\d*$)/;

	//check for numeric characters
	return objRegExp.test(strValue);
}

function validateInteger( strValue ) {
	var objRegExp  = /(^-?\d\d*$)/;

	//check for integer characters
	return objRegExp.test(strValue);
}

function validateAlphaNum( strValue ) {

	var objRegExp  = /([a-z][A-Z][0-9])+/;

	//check for integer characters
	return objRegExp.test(strValue);
}

function validateAlphabet( strValue ) {

	var objRegExp  = /^[a-zA-Z]{1,}$/;

	//check for integer characters
	return objRegExp.test(strValue);
}


function validatePassword(strValue, badWordVal) {
    	var options = {
    		lower:    0,
    		upper:    0,
    		alpha:    2, /* lower + upper */
    		numeric:  2,
    		special:  0,
    		length:   [8, Infinity],
    		custom:   [ /* regexes and/or functions */ ],
    		badWords: [badWordVal],
    		badSequenceLength: 0,
    		noQwertySequences: false,
    		noSequential:      false
    	};

    	// default options (allows any password)
    	var o = {
    		lower:    0,
    		upper:    0,
    		alpha:    0, /* lower + upper */
    		numeric:  0,
    		special:  0,
    		length:   [0, Infinity],
    		custom:   [ /* regexes and/or functions */ ],
    		badWords: [badWordVal],
    		badSequenceLength: 0,
    		noQwertySequences: false,
    		noSequential:      false
    	};


    	for (var property in options)
    		o[property] = options[property];

    	var	re = {
    			lower:   /[a-z]/g,
    			upper:   /[A-Z]/g,
    			alpha:   /[A-Z]/gi,
    			numeric: /[0-9]/g,
    			special: /[\W_]/g
    		},
    		rule, i;

    	// enforce min/max length
    	if (strValue.length < o.length[0] || strValue.length > o.length[1])
    		return false;

    	// enforce lower/upper/alpha/numeric/special rules
    	for (rule in re) {
    		if ((strValue.match(re[rule]) || []).length < o[rule])
    			return false;
    	}

    	// enforce word ban (case insensitive)
    	for (i = 0; i < o.badWords.length; i++) {
    		if (strValue.toLowerCase().indexOf(o.badWords[i].toLowerCase()) > -1)
    			return false;
    	}

    	// enforce the no sequential, identical characters rule
    	if (o.noSequential && /([\S\s])\1/.test(strValue))
    		return false;

    	// enforce alphanumeric/qwerty sequence ban rules
    	if (o.badSequenceLength) {
    		var	lower   = "abcdefghijklmnopqrstuvwxyz",
    			upper   = lower.toUpperCase(),
    			numbers = "0123456789",
    			qwerty  = "qwertyuiopasdfghjklzxcvbnm",
    			start   = o.badSequenceLength - 1,
    			seq     = "_" + strValue.slice(0, start);
    		for (i = start; i < strValue.length; i++) {
    			seq = seq.slice(1) + strValue.charAt(i);
    			if (
    				lower.indexOf(seq)   > -1 ||
    				upper.indexOf(seq)   > -1 ||
    				numbers.indexOf(seq) > -1 ||
    				(o.noQwertySequences && qwerty.indexOf(seq) > -1)
    			) {
    				return false;
    			}
    		}
    	}

    	// enforce custom regex/function rules
    	for (i = 0; i < o.custom.length; i++) {
    		rule = o.custom[i];
    		if (rule instanceof RegExp) {
    			if (!rule.test(strValue))
    				return false;
    		} else if (rule instanceof Function) {
    			if (!rule(strValue))
    				return false;
    		}
    	}

    	// great success!
    	return true;
}


function validateDate( strValue ) {

	//var objRegExp = /^\d{1,2}(\-|\/|\.)\d{1,2}\1\d{4}$/

	var objRegExp = /^\d{4}(\-|\/|\.)\d{1,2}\1\d{1,2}$/

	//check to see if in correct format
	if(!objRegExp.test(strValue))
		return false; //doesn't match pattern, bad date
	else{
		var arrayDate = strValue.split(RegExp.$1); //split date into month, day, year

		var intDay = parseInt(arrayDate[2],10);
		var intYear = parseInt(arrayDate[0],10);
		var intMonth = parseInt(arrayDate[1],10);

		//check for valid month
		if(intMonth > 12 || intMonth < 1) {
			return false;
		}

		//create a lookup for months not equal to Feb.
		var arrayLookup = { '01' : 31,'03' : 31, '04' : 30,'05' : 31,'06' : 30,'07' : 31,
		'08' : 31,'09' : 30,'10' : 31,'11' : 30,'12' : 31}

		//check if month value and day value agree

		if(arrayLookup[arrayDate[1]] != null) {
			if(intDay <= arrayLookup[arrayDate[2]] && intDay != 0)
				return true; //found in lookup table, good date
		}

		//check for February
		var booLeapYear = (intYear % 4 == 0 && (intYear % 100 != 0 || intYear % 400 == 0));
		if( ((booLeapYear && intDay <= 29) || (!booLeapYear && intDay <=28)) && intDay !=0)
		return true; //Feb. had valid number of days
	}
	return false; //any other values, bad date
}


function checkAll(chk, frm) {
 with(frm)
 {
  totalElements = elements.length;
  for(i = 0; i < totalElements; i++)
  { if (elements[i].type == 'checkbox')
   { elements[i].checked = chk;
   }
  }
 }
}

function changeCheckAll(chk, frm) {
  var flg;
  with(frm) {
	if(chk){
	  flg=true;
	  totalElements = elements.length;
	for(i = 0; i < totalElements; i++) {
	   if (elements[i].type == 'checkbox' && elements[i].name != 'chkAll' && !(elements[i].checked)) {
		 flg=false;
		 break;
	 }
	}
	  chkAll.checked=flg;
	} else {
	  chkAll.checked=false;
	}
 }
}

function unCheckAll(frmobj){
	with(frmobj){
		var totalElements = elements.length;

		for(i = 0; i < totalElements; i++){
			if (elements[i].type == "checkbox"){
				elements[i].checked = false;
			}
		}
	}
}

function CheckAll(frmobj){
	with(frmobj){
		var totalElements = elements.length;

		for(i = 0; i < totalElements; i++){
			if (elements[i].type == "checkbox"){
				elements[i].checked = true;
			}
		}
	}
}

function checkSelected(frmobj)
{	with(frmobj)
	{	totalChecked = 0;
		totalElements = elements.length;
		for(i = 0; i < totalElements; i++)
		{
			if (elements[i].type == 'checkbox')
			{	if (elements[i].checked)
				{	totalChecked++;
					break;
				}
			}
		}
		if (totalChecked == 0)
		{	alert("Select atleast one record");
			return false;
		}
		return true;
	}
}

function confirmStatusChange(frmobj)
{	with(frmobj)
	{	if (checkSelected(frmobj))
		{	return confirm("Changing Status for the selected Records(s).\n\nSure?");
		}
		else
		{	return false;
		}
	}
}

function confirmDelete(frmobj)
{	with(frmobj)
	{	if (checkSelected(frmobj))
		{	return confirm("Delete selected Records(s).\n\nSure?");
		}
		else
		{	return false;
		}
	}
}
