function TrimString(sInString) {
	sInString = sInString.replace( /^\s+/g, "" );// strip leading
	return sInString.replace( /\s+$/g, "" );// strip trailing
}

function checkAlphaOnly(s) {
	var i;
	for (i = 0; i < s.length; i++) {
		var code = s.charCodeAt(i);
		if((code>=65 && code<=90 )||(code>=97 && code<=122)|| code==32 || code == 39 || code == 45 || code == 46){
		} else {
			return false;
		}
	}
	return true;
}

	function checkNumberOnly(s){
		var i;
		for (i = 0; i < s.length; i++) {
			var c = s.charCodeAt(i);
			if( c < 48 || c > 57) return false;
		}
		return true;
	}

	function disableRightClick(e, Id){
		if(e.button == 2 || e.button == 3){
			alert("Right Click Not Allowed.");
			document.getElementById(Id).value="";
			window.event.returnValue = false;		
		}
	}

	function openWindow(url){
		window.open(url,'location=0,status=1,scrollbars=0,width=800,height=400');
	}

	
	function disableCtrlKey(e){
		var code = (document.all) ? e.keyCode: e.which;
		if(parseInt(code) == 17){
			alert("Ctrl Key functionality is disabled.");
			window.event.returnValue = false;
		}
	}

	function checkNumberWithDecimalOnly(s){
		var i;
		for (i = 0; i < s.length; i++) {
			var c = s.charCodeAt(i);
			if( c < 46 || c > 57) return false;
		}
		return true;
	}

	function checkCharacter() {
		var code=windowEvent.which;
		if((code>=65 && code<=90 )||(code>=97 && code<=122)|| code==32) {
			return true;
		} else {
			alert("Only alphabets are allowed for this field.");
			windowEvent.which=0;
			return false;
		}
	}


	function chkNumberOnly(){
		var code = windowEvent.which;
		if((code>=48 && code <= 57)) {
		} else {
			alert("Only Numbers are allowed for this field.");
			windowEvent.which=0;
			return false;
		}
    }

	function checkAlphaNumeric(s){
		var i;
		for (i = 0; i < s.length; i++ ){
			var code = s.charCodeAt(i);
			if((code>=65 && code<=90 )||(code>=97 && code<=122)|| code==32 || code == 35 || code == 39 || (code>44 && code<=57) ){
			} else {
				return false;
			}
		}
		return true;
	}

	function checkemail(objEmail) {
		var str = objEmail;
		var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (filter.test(str))
			testresults=true
		else {
			testresults=false
		}
		return (testresults)
	}

	function checkPhone(objPhone) {
		var str = objPhone;
		var filter=/^\d{3}\-\d{3}-\d{4}$/;
		if (filter.test(str))
			testresults=true
		else {
			testresults=false
		}
		return (testresults)
	}

	function isEmpty(s){
		return ((s == null) || (s.length == 0))
	}

	function isWhiteSpace(s){
		var whitespace = " \t\n\r";
		var i;
		if (isEmpty(s)) return true;
		for (i = 0; i < s.length; i++){
			var c = s.charAt(i);
			if (whitespace.indexOf(c) == -1) return false;
		}
		return true;
	}

	function checkForZerosOnly(p_Number) {
		var number = new Number(p_Number);
		if (number <= 0) {
			return false;
		}
		return true;
	}

	function trimAll(strValue){
		var objRegExp = /^(\s*)$/;
		//check for all spaces
	    if(objRegExp.test(strValue)) {
			strValue = strValue.replace(objRegExp, '');
			if( strValue.length == 0) return strValue;
		}

		//check for leading & trailing spaces
	    objRegExp = /^(\s*)([\W\w]*)(\b\s*$)/;
		if(objRegExp.test(strValue)){
	       //remove leading and trailing whitespace characters
		   strValue = strValue.replace(objRegExp, '$2');
		}
	    return strValue;
	}

	//.generaltext { font-family: verdana, tahoma, arial; font-size: 8pt; color: #5F5F5F; line-height: 1.25; }
	//validations for comparing the dates.
	var calFormat = "mm/dd/yyyy";
	function compareDates(date1, date2) {
		var calRE = getFormat();
		var d1, d2;
		if (calRE.test(date1)) {
		    d1 = getNumbers(date1);
		} else {
		    d1 = getNumbers(getCurrentDate());
		}

		if (calRE.test(date2)) {
		    d2 = getNumbers(date2);
		} else {
		    d2 = getNumbers(getCurrentDate());
		}

		var dStr1 = d1[0] + "" + d1[1] + "" + d1[2];
		var dStr2 = d2[0] + "" + d2[1] + "" + d2[2];
		if (dStr1 == dStr2) {
			return 0;
		} else if (dStr1 > dStr2) {
		    return 1;
		} else {
		    return -1;
		}
	}

	function getFormat() {
		var calF = calFormat;
		calF = calF.replace(/\\/g, '\\\\');
		calF = calF.replace(/\//g, '\\\/');
		calF = calF.replace(/\[/g, '\\\[');
		calF = calF.replace(/\]/g, '\\\]');
		calF = calF.replace(/\(/g, '\\\(');
		calF = calF.replace(/\)/g, '\\\)');
		calF = calF.replace(/\{/g, '\\\{');
		calF = calF.replace(/\}/g, '\\\}');
		calF = calF.replace(/\</g, '\\\<');
		calF = calF.replace(/\>/g, '\\\>');
		calF = calF.replace(/\|/g, '\\\|');
		calF = calF.replace(/\*/g, '\\\*');
		calF = calF.replace(/\?/g, '\\\?');
		calF = calF.replace(/\+/g, '\\\+');
		calF = calF.replace(/\^/g, '\\\^');
		calF = calF.replace(/\$/g, '\\\$');

		calF = calF.replace(/dd/i, '\\d\\d');
		calF = calF.replace(/mm/i, '\\d\\d');
		calF = calF.replace(/yyyy/i, '\\d\\d\\d\\d');
		calF = calF.replace(/day/i, '\\w\\w\\w');
		calF = calF.replace(/mon/i, '\\w\\w\\w');
		return new RegExp(calF);
	}

	function getNumbers(date) {
		var calRE = getFormat();
		var y, m, d;
		if (calRE.test(date)) {
		    var yIdx = calFormat.search(/yyyy/i);
			var mIdx = calFormat.search(/mm/i);
			var m3Idx = calFormat.search(/mon/i);
			var dIdx = calFormat.search(/dd/i);

			y = date.substring(yIdx,yIdx+4);
		    if (mIdx != -1) {
				m=date.substring(mIdx,mIdx+2);
			} else {
				var mm=getMonthFromName(date.substring(m3Idx,m3Idx+3))+1;
				m=(mm<10)?("0"+mm):(""+mm);
			}
		    d=date.substring(dIdx,dIdx+2);
			return new Array(y,m,d);
		} else {
		    return new Array("", "", "");
		}
	}

	function getCurrentDate() {
		var date=calFormat, d = new Date();
		date = date.replace(/yyyy/i, d.getFullYear());
		date = date.replace(/mm/i, get2Digits(d.getMonth()+1));
		date = date.replace(/dd/i, get2Digits(d.getDate()));
		return date;
	}

	function get2Digits(n) {
		return ((n<10)?"0":"")+n;
	}

	function compareDateObjects(d1,d2){
		var date1  = new Date(d1);
		var date2  = new Date(d2);
		if (date1 < date2) {
			return 1;
		} else if (date1 > date2) {
			return 2;
		} else {
			return 0;
		}
	}
	//end of validation for comparing the dates.