/******************************************************************************
*@Name		:	script.js
*@Project	:	CEN
*@Company	:	Nascent http://www.nastec.biz/
*@Version	:	1.0
*@Created	:	Rishi Dev
*@Desc		:	Common script functions for CEN web application of CSS.
*@Date		:	01-Sep-2002
*@License	:	This script is a copyright program conceived, designed and developed by CSS Pvt. Ltd.
				Use of this script without prior written permission is illegal.
******************************************************************************/

	function validateForm(frmToValidate) {
		errMsg.innerHTML = "&nbsp;";
		noOfElementsInForm = frmToValidate.elements.length;
		for(i=0;i<noOfElementsInForm;i++) {
			objToBeValidated = frmToValidate.elements[i];
			if(objToBeValidated.getAttribute("toBeValidated")) {
				if(objToBeValidated.getAttribute("validationType")=="onlyNonBlank" || objToBeValidated.getAttribute("validationType")=="nonBlankAndDataType") {
					if(objToBeValidated.value == "") {
						errMsg.innerHTML ="<font color='red' face='arial'><B>Error:</B> Please enter "+objToBeValidated.getAttribute("desc")+".</font>";
						objToBeValidated.focus();
						return false;
					}
				}

			if(objToBeValidated.getAttribute("validationType")=="emailType") {
				if(objToBeValidated.value == "") {
					errMsg.innerHTML ="<font color='red' face='arial'><B>Error:</B> Please enter "+objToBeValidated.getAttribute("desc")+".</font>";
					objToBeValidated.focus();
					return false;
				}else{
					if(!objToBeValidated.value .match(/^\w+([\.-]\w+)*@\w+([\.-]\w+)*\.[a-z]{2,3}$/i)){
						errMsg.innerHTML = "<B>Error:</B> Please enter valid "+objToBeValidated.getAttribute("desc")+".";
						objToBeValidated.focus();
						return false;
					}
				}
			}
			
			
			if(objToBeValidated.value != "" && objToBeValidated.getAttribute("validationType")=="nonBlankwebsiteType"){
				if(!objToBeValidated.value.match(/^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/)){
						errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Please enter valid "+objToBeValidated.getAttribute("desc")+".</font>";
						objToBeValidated.focus();
						return false;
					}
			}
			
			if(objToBeValidated.getAttribute("validationType")=="websiteType") {
				if(objToBeValidated.value == "") {
					errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Please enter "+objToBeValidated.getAttribute("desc")+".</font>";
					objToBeValidated.focus();
					return false;
				}else{
					if(!objToBeValidated.value .match(/^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/)){
						errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Please enter valid "+objToBeValidated.getAttribute("desc")+".</font>";
						objToBeValidated.focus();
						return false;
					}
				}
			}
			
			if(objToBeValidated.getAttribute("validationType")=="nonBlankAndDataType"){
				if(objToBeValidated.getAttribute("dataType")=="currency") if(!validateCurrencyFormat(objToBeValidated)) return false;
				if(objToBeValidated.getAttribute("dataType")=="date"){
					var ff=validate_Date(objToBeValidated.value);
					if(ff!="true") {
						alert(ff);objToBeValidated.value="";objToBeValidated.focus();
						return false;
					}
				}
				
				
				if(objToBeValidated.getAttribute("dataType")=="mobile") if(!validateMobile(objToBeValidated)) return false;
				if(objToBeValidated.getAttribute("dataType")=="number"){
					if(!validateNumericFormat(objToBeValidated)) return false;
				}
				if(objToBeValidated.getAttribute("dataType")=="float") if(!validateFloatFormat(objToBeValidated)) return false;
				if(objToBeValidated.getAttribute("dataType")=="emailid") if(!validateEmailIdFormat(objToBeValidated)) return false;
			}

			if(objToBeValidated.getAttribute("validationType")=="onlyDataType" && objToBeValidated.value!=""){
				if(objToBeValidated.getAttribute("dataType")=="currency") if(!validateCurrencyFormat(objToBeValidated)) return false;
				if(objToBeValidated.getAttribute("dataType")=="date"){
					var ff=validate_Date(objToBeValidated.value);
					if(ff!="true") {
						alert(ff);objToBeValidated.value="";objToBeValidated.focus();
						return false;
					}
				}
				if(objToBeValidated.getAttribute("dataType")=="mobile") if(!validateMobile(objToBeValidated)) return false;
				if(objToBeValidated.getAttribute("dataType")=="number"){
					if(!validateNumericFormat(objToBeValidated)) return false;
				}
				if(objToBeValidated.getAttribute("dataType")=="float") if(!validateFloatFormat(objToBeValidated)) return false;
				if(objToBeValidated.getAttribute("dataType")=="emailid") if(!validateEmailIdFormat(objToBeValidated)) return false;
			}

		}
	}
	return true;
}




function isValidFormData(dataFormToValidate){
	errMsg.innerHTML = "&nbsp;";
	noOfElementsInForm = dataFormToValidate.elements.length;
	for(i=0;i<noOfElementsInForm;i++) {
		objToBeValidated = dataFormToValidate.elements[i];
		if(objToBeValidated.getAttribute("toBeValidated")) {
			//mandatoryNumeric
			//alert(objToBeValidated.getAttribute("validationType"));

			if(objToBeValidated.getAttribute("validationType")=="mandatoryNumeric") {
				if(objToBeValidated.value == "") {
					errMsg.innerHTML ="<font color='red'><B>Error:</B> Please enter "+objToBeValidated.getAttribute("desc")+".</font>";
					objToBeValidated.focus();
					return false;
				}
				if(isNaN(objForValidation.value)){
					errMsg.innerHTML = "<font color='red'><B>Error:</B> Please enter valid "+objToBeValidated.getAttribute("desc")+".</font>";
					objToBeValidated.focus();
					return false;
				}
			}

			//nonMandatoryNumeric
			if(objToBeValidated.getAttribute("validationType")=="nonMandatoryNumeric") {
				if(objToBeValidated.value != "" && !validateNumericFormat(objToBeValidated)) {
					errMsg.innerHTML = "<font color='red'><B>Error:</B> Please enter valid "+objToBeValidated.getAttribute("desc")+".</font>";
					objToBeValidated.focus();
					return false;
				}
			}

			//mandatoryEmail
			if(objToBeValidated.getAttribute("validationType")=="mandatoryEmail") {
				if(objToBeValidated.value == "") {
					errMsg.innerHTML ="<font color='red'><B>Error:</B> Please enter "+objToBeValidated.getAttribute("desc")+".</font>";
					objToBeValidated.focus();
					return false;
				}
				if(!objToBeValidated.value .match(/^\w+([\.-]\w+)*@\w+([\.-]\w+)*\.[a-z]{2,3}$/i)){
					errMsg.innerHTML = "<font color='red'><B>Error:</B> Please enter valid "+objToBeValidated.getAttribute("desc")+".</font>";
					objToBeValidated.focus();
					return false;
				}
			}
			//nonMandatoryEmail
			if(objToBeValidated.getAttribute("validationType")=="nonMandatoryEmail") {
				if(objToBeValidated.value != "" && !objToBeValidated.value .match(/^\w+([\.-]\w+)*@\w+([\.-]\w+)*\.[a-z]{2,3}$/i)) {
					errMsg.innerHTML = "<font color='red'><B>Error:</B> Please enter valid "+objToBeValidated.getAttribute("desc")+".</font>";
					objToBeValidated.focus();
					return false;
				}
			}

			//mandatoryWebSite
			if(objToBeValidated.getAttribute("validationType")=="mandatoryWebSite") {
				if(objToBeValidated.value == "") {
					errMsg.innerHTML = "<font color='red'><B>Error:</B> Please enter "+objToBeValidated.getAttribute("desc")+".</font>";
					objToBeValidated.focus();
					return false;
				}
				if(!objToBeValidated.value .match(/^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/)){
					errMsg.innerHTML = "<font color='red'><B>Error:</B> Please enter valid "+objToBeValidated.getAttribute("desc")+".</font>";
					objToBeValidated.focus();
					return false;
				}
			}
		
			//nonMandatoryWebSite
			if(objToBeValidated.getAttribute("validationType")=="nonMandatoryWebSite") {
				if(objToBeValidated.value != "" && !objToBeValidated.value .match(/^(([\w]+:)?\/\/)?(([\d\w]|%[a-fA-f\d]{2,2})+(:([\d\w]|%[a-fA-f\d]{2,2})+)?@)?([\d\w][-\d\w]{0,253}[\d\w]\.)+[\w]{2,4}(:[\d]+)?(\/([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)*(\?(&?([-+_~.\d\w]|%[a-fA-f\d]{2,2})=?)*)?(#([-+_~.\d\w]|%[a-fA-f\d]{2,2})*)?$/)) {
					errMsg.innerHTML = "<font color='red'><B>Error:</B> Please enter valid "+objToBeValidated.getAttribute("desc")+".</font>";
					objToBeValidated.focus();
					return false;
				}
			}

			//mandatoryCharecter
			if(objToBeValidated.getAttribute("validationType")=="mandatoryCharecter") {
				if(objToBeValidated.value == "") {
					errMsg.innerHTML = "<font color='red'><B>Error:</B> Please enter "+objToBeValidated.getAttribute("desc")+".</font>";
					objToBeValidated.focus();
					return false;
				}
				inputStr=objToBeValidated.value;
				for(var i=0;i<inputStr.length;i++){
					var oneInt=inputStr.charCodeAt(i);
					if(oneInt>=33 && oneInt<=45 || oneInt>=58 && oneInt<=64 || oneInt>=91 && oneInt<=96 || oneInt>=123 && oneInt<=255 || oneInt==47){
						errMsg.innerHTML = "<font color='red'><B>Error:</B> Only character Value is Allowed in "+objToBeValidated.getAttribute("desc")+".</font>";
						objToBeValidated.focus();
						return false;
					}
				}						
			}
		
			//nonMandatoryCharecter
			if(objToBeValidated.getAttribute("validationType")=="nonMandatoryCharecter") {
				inputStr=objToBeValidated.value;
				for(var i=0;i<inputStr.length;i++){
					var oneInt=inputStr.charCodeAt(i);
					if(oneInt>=33 && oneInt<=45 || oneInt>=58 && oneInt<=64 || oneInt>=91 && oneInt<=96 || oneInt>=123 && oneInt<=255 || oneInt==47){
						errMsg.innerHTML = "<font color='red'><B>Error:</B> Only character Value is Allowed in "+objToBeValidated.getAttribute("desc")+".</font>";
						objToBeValidated.focus();
						return false;
					}
				}						
			}

			//onlyMandatory
			if(objToBeValidated.getAttribute("validationType")=="onlyMandatory"){
				if(objToBeValidated.value == "") {
					errMsg.innerHTML ="<font color='red'><B>Error:</B> Please enter "+objToBeValidated.getAttribute("desc")+".</font>";
					objToBeValidated.focus();
					return false;
				}
			}
		}
	}
	return true;	
}

function validateMobile(objForValidation)
{
	if(isNaN(objForValidation.value)) {
		errMsg.innerHTML = "<font color='red'><B>Error:</B> Please enter valid "+objForValidation.getAttribute("desc")+" .</font>";
		objForValidation.value="";
		objForValidation.focus();
		return false;
	} else if(objForValidation.value.length<7){
		errMsg.innerHTML = "<font color='red'><B>Error:</B> "+objForValidation.getAttribute("desc")+" can not be less than 7.";
		objForValidation.value="";
		objForValidation.focus();
		return false;
	} return true;
}


function validateNumericFormat(objForValidation)
{
	if(isNaN(objForValidation.value)) {
		errMsg.innerHTML = "<font color='red'>Please enter valid "+objForValidation.getAttribute("desc")+" .</font>";
		objForValidation.value="";
		objForValidation.focus();
		return false;
	} else if(parseInt(objForValidation.value)<0){
		errMsg.innerHTML = objForValidation.getAttribute("desc")+" can not be less than zero.";
		objForValidation.value="";
		objForValidation.focus();
		return false;
	} return true;
}
function validateCurrencyFormat(objForValidation) {
	if(objForValidation.value=="") return true;
	currencyDetails = (objForValidation.value).split(".");
	currencyFirstHalf = currencyDetails[0];
	if(currencyDetails.length>1) currencySecondHalf = currencyDetails[1]; else currencySecondHalf=0;
	if(!isNaN(currencySecondHalf)) decimalAmtOfField = parseInt(currencySecondHalf); else decimalAmtOfField=9;
	if(currencyDetails.length>2 || isNaN(currencyFirstHalf) || isNaN(currencySecondHalf) || decimalAmtOfField>99) {
		errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Please enter "+ objForValidation.getAttribute("desc") +" in correct currency format.</font>";
		objForValidation.value = "0.00";
		objForValidation.focus();
		return false;
	}
	return true;
}
function validateFloatFormat(objForValidation) {
	if(objForValidation.value=="") return true;
	floatDetails = (objForValidation.value).split(".");
	floatFirstHalf = floatDetails[0];
	if(floatDetails.length>1) floatSecondHalf = floatDetails[1]; else floatSecondHalf=0;
	if(!isNaN(floatSecondHalf)) decimalAmtOfField = parseInt(floatSecondHalf); else decimalAmtOfField=9;
	if(isNaN(floatFirstHalf) || isNaN(floatSecondHalf))
	{
		alert("<font color='red' face='arial'>Please enter "+ objForValidation.getAttribute("desc") +" in correct decimal format.</font>");
		objForValidation.value = "";
		objForValidation.focus();
		return false;
	}
	return true;
}

	function validateEmailIdFormat(objForValidation) {
		/*
			Possible input email id formats
			
			1. "rishi@global.nastec.biz" <rishi@global.nastec.biz>
			2. rishi@global.nastec.biz
			3. "rishi.dev@global.nastec.biz" <rishi.dev@global.nastec.biz>
			4. rishi.dev@global.nastec.biz
		*/
		
		str = objForValidation.value;
		var at="@"
		var dot="."
		var angleLeft="<";
		var angleRight=">";
		var emailids = str.split(",");
		for(emailno=0;emailno<emailids.length;emailno++){
			str=emailids[emailno];
			if(str.indexOf(angleLeft)!=-1){
				//It is either format 1 or 3.
				var nameandEmail = str.split(angleLeft);
				if(nameandEmail.length>1){
					str = nameandEmail[1].substring(0,nameandEmail[1].length-2);
				}else {
					errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Please enter valid "+ objForValidation.getAttribute("desc") +" .</B> <B>Example:</B> yourname@yourdomain.com </font>";
					return false;
				}
			}
			
			var lat=str.indexOf(at)
			var lstr=str.length
			var ldot=str.indexOf(dot)
			if (str.indexOf(at)==-1){
			   errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Please enter <B>valid</B> "+ objForValidation.getAttribute("desc") +" .</B> <B>Example:</B> yourname@yourdomain.com </font>";
			   return false;
			}
			if (str.indexOf(at)==0){
			   errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Please enter <B>valid</B> "+ objForValidation.getAttribute("desc") +" .</B> <B>Example:</B> yourname@yourdomain.com </font>";
			   return false;
			}
			
			if (str.indexOf(at)==lstr-1){
			   errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Please enter <B>valid</B> "+ objForValidation.getAttribute("desc") +" .</B> <B>Example:</B> yourname@yourdomain.com </font>";
			   return false;
			}
			if (str.indexOf(dot)==-1){
			   errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Please enter <B>valid</B> "+ objForValidation.getAttribute("desc") +" .</B> <B>Example:</B> yourname@yourdomain.com </font>";
			   return false;
			}
			if (str.indexOf(dot)==0){
			    errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Please enter <B>valid</B> "+ objForValidation.getAttribute("desc") +" .</B> <B>Example:</B> yourname@yourdomain.com </font>";
			    return false;
			}
	
			if (str.indexOf(dot)==lstr-1){
					errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Please enter <B>valid</B> "+ objForValidation.getAttribute("desc") +" . <B>Example:</B> yourname@yourdomain.com </B></font>";
			    return false;
			}
	
			 if (str.indexOf(at,(lat+1))!=-1){
			    errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Please enter <B>valid</B> "+ objForValidation.getAttribute("desc") +" . <B>Example:</B> yourname@yourdomain.com </font>";
			    return false;
			 }
	
			 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			    errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Please enter <B>valid</B> "+ objForValidation.getAttribute("desc") +" . <B>Example:</B> yourname@yourdomain.com </font>";
			    return false;
			 }
	
			 if (str.indexOf(dot,(lat+2))==-1){
			    errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Please enter <B>valid</B> "+ objForValidation.getAttribute("desc") +" . <B>Example:</B> yourname@yourdomain.com </font>";
			    return false;
			 }
			 if (str.indexOf(" ")!=-1){
			    errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Please enter <B>valid</B> "+ objForValidation.getAttribute("desc") +" . <B>Example:</B> yourname@yourdomain.com </font>";
			    return false;
			 }
		}
 		return true;
}

function dateFormat(x,e)
{
	if(e.keyCode==36 || e.keyCode==37 || e.keyCode==39 ) return;
	var dateOut = x.value;
	if(dateOut.charAt(1)=="/") {dateOut = "0"+dateOut;x.value=dateOut;}
	if(dateOut.charAt(4)=="/") {dateOut = dateOut.substring(0,2)+"/0"+dateOut.charAt(3)+"/";x.value=dateOut;}
	if((dateOut.length==2)&&(dateOut.charAt(2)!="/"))
	{
		if(isNaN(dateOut)){
			dateOut="";alert("No of days has to be numeric.(DD/MM/YYYY)");
		}else if(parseInt(dateOut)>31){
			dateOut="";alert("No of days can not be more than 31.(DD/MM/YYYY)");
		}else
			dateOut = dateOut+"/";
	}
	if((dateOut.length==5)&&(dateOut.charAt(5)!="/"))
	{
		mm = dateOut.substring(3,5);
		if(isNaN(mm)){
			dateOut=dateOut.substring(0,3);errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Month has to be numeric.(DD/MM/YYYY)</font>";
		}else if(parseInt(mm)>12){
			dateOut=dateOut.substring(0,3);errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Month can not be larger than 12.(DD/MM/YYYY)</font>";
		}else
			dateOut = dateOut+"/";
	}
	if(dateOut.length>6)
	{
		yy = dateOut.substring(6,dateOut.length);
		if(isNaN(yy)){
			dateOut=dateOut.substring(0,6);errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Year has to be numeric.(DD/MM/YYYY)</font>";
		}
	}
	if((dateOut.length>10)){
		dateOut=dateOut.substring(0,10);errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Date can not have more than 10 characters.</font>";}
	x.value = dateOut;
	return;
}
function myTrim(sinput) {
//	'*********************************************
//	'* general routine for trimming input data.
//	'*********************************************
	var stemp='';
	var counter = 0;
	for( var i=0; i<sinput.length; i++ ){
		  if( sinput.substring( i,i+1 ) !=" ") {
				stemp=stemp + sinput.substring( i,i+1 );
		  }
	}
	return(stemp);
}
function isNumeric( data )
{
//	'*********************************************
//	'* general routine for validating numeric data.
//	'*********************************************
    var numString = "0123456789";
    var thisChar;
    var counter = 0;
    for( var i=0; i<data.length; i++ ){
		  thisChar = data.substring( i,i+1 );
		  if(numString.indexOf(thisChar,0)!=-1)
		  counter++;						
    }
	if(counter == data.length)
	{
		   return(true);  // 'validateNumber(data); %>
	}
	else
		return(false);	
}
function getDaysPerMonth(month, year) 
{
//	'*********************************************
//	'* Purpose:  general routine for getting Days Per Month.
//	'*
//	'*
//	'* Desc:	 creates an array to hold number of days in each month,
//	'*			 then returns value based on month, year passed in
//	'*
//	'* Inputs:	 month, year
//	'*********************************************


            var daysPerMonth = new Array(12);
            daysPerMonth[0] = 31;           // January
            daysPerMonth[1] = (isLeapYear(year)) ? 29 : 28;    // ' February
            daysPerMonth[2] = 31;           // March
            daysPerMonth[3] = 30;           // April
            daysPerMonth[4] = 31;           // May
            daysPerMonth[5] = 30;           // June
            daysPerMonth[6] = 31;           // July
            daysPerMonth[7] = 31;           // August
            daysPerMonth[8] = 30;           // September
            daysPerMonth[9] = 31;           // October
            daysPerMonth[10] = 30;          // November
            daysPerMonth[11] = 31;          // December

            return daysPerMonth[ month-1 ]
}

function isLeapYear(year) 
{
//	'*********************************************
//	'* Purpose:  To find leap year definition
//	'*
//	'* Desc:	 uses mod to determine if divisible by 4
//	'*
//	'*********************************************
//
   
if( year % 400 == 0 || (year % 4 == 0 && year % 100 != 0) )
     return true;
return false;
}
function validate_Date(date) {
//	*********************************************
//	* Purpose:  general routine for validating dates .
//	*
//	* Format:	 dd/mm/yyyy, dd/mm/yy
//	* Inputs:	 date - date
//	*********************************************

tDate = myTrim(date);
if (( tDate.length == 0 ))
{
	return "Please specify a valid date in yyyy/mm/dd." + "\n";
}  
if (( tDate.length == 0 ))	              
	return ;

temp = tDate.indexOf("/",0);
if (temp!= -1)	
{
	if (( tDate.length >10 )|| (tDate.length <8)) 
	{
		return "Date you've entered is unrecognizable." + "\n";
	} 

	dd = tDate.substring( 0,temp );
	mm = tDate.substring( temp+1, tDate.indexOf("/",temp+1) );
	yy = tDate.substring( tDate.indexOf("/",temp+1)+1, tDate.length );
				
	if( !isNumeric( mm ) || !isNumeric( dd ) || !isNumeric( yy ) )
	{
		return "Invalid date entry." + "\n" ;
	}
	else if( (mm <= 0) || (mm > 12) )
	{
		return "Invalid month entry." + "\n";
	}
	else if( (dd <= 0) || (dd > getDaysPerMonth( mm, yy ) ))
	{
		return "Invalid day entry." + "\n";
	}

	if ((yy.length != 4)) 
	{
		return "Invalid year entry." + "\n";		
	}
	return "true";

}
else
return "Date you've entered is unrecognizable.";
//	***** absence of '/' ******** 
//else {						 
//		if((tDate.length > 8 )|| (tDate.length < 6 ))
//		{
//			return "Date you've entered is unrecognizable." + "\n";
//		}
//		mm = tDate.substring( 0,2 );
//		tDate=tDate.substring(2,tDate.length);
//		dd=tDate.substring( 0,2 );
//
//		tDate=tDate.substring(2,tDate.length);
//		yy=tDate;
//
//		if( !isNumeric( mm ) || !isNumeric( dd ) || !isNumeric( yy ) )
//		{
//			return "Invalid date entry." + "\n";
//		}
//		else if( (mm <= 0 )|| (mm > 12 ))
//		{
//	 		return "Invalid month entry." + "\n";
//		}
//		else if( (dd <= 0) || (dd > getDaysPerMonth( mm, yy )) )
//		{
//			return "Invalid day entry." + "\n";
//		}
//			
//		if ((yy.length != 2) && (yy.length != 4) ) 
//		{
//			return "Invalid year entry." + "\n";
//		}
//	}
			
//	dateobj=new Date(yy,mm,dd);
//	currentdate=new Date();
//	var curyy=currentdate.getYear();
//	var tempcuryy=new String(curyy);
//	if (tempcuryy.length==2)
//		tempcuryy='19'+ tempcuryy; 
//	var curmm=currentdate.getMonth();
//	var curdd=currentdate.getDate();
//	dateobj=null;
//	currentdate=null;
}
function displayMsg(objGettingModified) {
	alert(userName+", please " + objGettingModified.desc);
}
function noModification(objGettingModified) {
	alert(userName+", you can not modify " + objGettingModified.desc);
}
function getCurrencyFormat(amt) {
	amt = "";
	return amt;
}
function highLightMenuItem(menuItem) {
	menuItem.style.color = "red";
	menuItem.style.textDecoration = "underline";
	menuItem.style.background = "yellow";
}
function unHighLightMenuItem(menuItem) {
	menuItem.style.color = "white";
	menuItem.style.textDecoration = "";
	menuItem.style.background = "";
}

function highLightLink(menuItem) {
	menuItem.style.color = "red";
	menuItem.style.textDecoration = "underline";
	menuItem.style.background = "yellow";
	
}
function unHighLightLink(menuItem) {
	menuItem.style.color = "black";
	menuItem.style.textDecoration = "";
	menuItem.style.background = "";
}

function takewidth() {
		screenWidth = document.body.clientWidth;
		return screenWidth ;
}

function tekeheight() {
		screenHeight = document.body.clientheight;
		return screenHeight;
}
var digitWords = new Array();
digitWords[0] = 'Zero';
digitWords[1] = 'One';
digitWords[2] = 'Two';
digitWords[3] = 'Three';
digitWords[4] = 'Four';
digitWords[5] = 'Five';
digitWords[6] = 'Six';
digitWords[7] = 'Seven';
digitWords[8] = 'Eight';
digitWords[9] = 'Nine';
digitWords[10] = 'Ten';
digitWords[11] = 'Eleven';
digitWords[12] = 'Twelve';
digitWords[13] = 'Thirteen';
digitWords[14] = 'Forteen';
digitWords[15] = 'Fifteen';
digitWords[16] = 'Sixteen';
digitWords[17] = 'Seventeen';
digitWords[18] = 'Eighteen';
digitWords[19] = 'Nineteen';
digitWords[20] = 'Twenty';
digitWords[21] = 'Twenty One';
digitWords[22] = 'Twenty Two';
digitWords[23] = 'Twenty Three';
digitWords[24] = 'Twenty Four';
digitWords[25] = 'Twenty Five';
digitWords[26] = 'Twenty Six';
digitWords[27] = 'Twenty Seven';
digitWords[28] = 'Twenty Eight';
digitWords[29] = 'Twenty Nine';
digitWords[30] = 'Thirty';
digitWords[31] = 'Thirty One';
digitWords[32] = 'Thirty Two';
digitWords[33] = 'Thirty Three';
digitWords[34] = 'Thirty Four';
digitWords[35] = 'Thirty Five';
digitWords[36] = 'Thirty Six';
digitWords[37] = 'Thirty Seven';
digitWords[38] = 'Thirty Eight';
digitWords[39] = 'Thirty Nine';
digitWords[40] = 'Forty';
digitWords[41] = 'Forty One';
digitWords[42] = 'Forty Two';
digitWords[43] = 'Forty Three';
digitWords[44] = 'Forty Four';
digitWords[45] = 'Forty Five';
digitWords[46] = 'Forty Six';
digitWords[47] = 'Forty Seven';
digitWords[48] = 'Forty Eight';
digitWords[49] = 'Forty Nine';
digitWords[50] = 'Fifty';
digitWords[51] = 'Fifty One';
digitWords[52] = 'Fifty Two';
digitWords[53] = 'Fifty Three';
digitWords[54] = 'Fifty Four';
digitWords[55] = 'Fifty Five';
digitWords[56] = 'Fifty Six';
digitWords[57] = 'Fifty Seven';
digitWords[58] = 'Fifty Eight';
digitWords[59] = 'Fifty Nine';
digitWords[60] = 'Sixty';
digitWords[61] = 'Sixty One';
digitWords[62] = 'Sixty Two';
digitWords[63] = 'Sixty Three';
digitWords[64] = 'Sixty Four';
digitWords[65] = 'Sixty Five';
digitWords[66] = 'Sixty Six';
digitWords[67] = 'Sixty Seven';
digitWords[68] = 'Sixty Eight';
digitWords[69] = 'Sixty Nine';
digitWords[70] = 'Seventy';
digitWords[71] = 'Seventy One';
digitWords[72] = 'Seventy Two';
digitWords[73] = 'Seventy Three';
digitWords[74] = 'Seventy Four';
digitWords[75] = 'Seventy Five';
digitWords[76] = 'Seventy Six';
digitWords[77] = 'Seventy Seven';
digitWords[78] = 'Seventy Eight';
digitWords[79] = 'Seventy Nine';
digitWords[80] = 'Eighty';
digitWords[81] = 'Eighty One';
digitWords[82] = 'Eighty Two';
digitWords[83] = 'Eighty Three';
digitWords[84] = 'Eighty Four';
digitWords[85] = 'Eighty Five';
digitWords[86] = 'Eighty Six';
digitWords[87] = 'Eighty Seven';
digitWords[88] = 'Eighty Eight';
digitWords[89] = 'Eighty Nine';
digitWords[90] = 'Ninty';
digitWords[91] = 'Ninty One';
digitWords[92] = 'Ninty Two';
digitWords[93] = 'Ninty Three';
digitWords[94] = 'Ninty Four';
digitWords[95] = 'Ninty Five';
digitWords[96] = 'Ninty Six';
digitWords[97] = 'Ninty Seven';
digitWords[98] = 'Ninty Eight';
digitWords[99] = 'Ninty Nine';
function showAmountInWords(x) {
	amt = x.split(".");
	if(amt.length>2) return false;//Currency is having two decimals.
	strRs = amt[0];
	strPaise = amt[1];
	while(strRs.indexOf(",") != -1) strRs.replace(",","");//Replace any commas if present.
	rsInInteger = parseInt(amt[0]);
	paiseInInteger = parseInt(amt[1]);
	if(rsInInteger>999999999)
		amtWords = "<FONT color=red><B>Out of range: </B>"+x;
	else
	{
		if(strRs.length==9) rsInWords = digitWords[parseInt(strRs.substring(0,2))] + " Crores " + digitWords[parseInt(strRs.substring(2,4))] + " Lacs " + digitWords[parseInt(strRs.substring(4,6))] + " Thousands " + digitWords[parseInt(strRs.substring(6,7))] + " Hundred " + digitWords[parseInt(strRs.substring(7,9))];
		if(strRs.length==8) rsInWords = digitWords[parseInt(strRs.substring(0,1))] + " Crores " + digitWords[parseInt(strRs.substring(1,3))] + " Lacs " + digitWords[parseInt(strRs.substring(3,5))] + " Thousands " + digitWords[parseInt(strRs.substring(5,6))] + " Hundred " + digitWords[parseInt(strRs.substring(6,8))];
		if(strRs.length==7) rsInWords = digitWords[parseInt(strRs.substring(0,2))] + " Lacs " + digitWords[parseInt(strRs.substring(2,4))] + " Thousands " + digitWords[parseInt(strRs.substring(4,5))] + " Hundred " + digitWords[parseInt(strRs.substring(5,7))];
		if(strRs.length==6) rsInWords = digitWords[parseInt(strRs.substring(0,1))] + " Lacs " + digitWords[parseInt(strRs.substring(1,3))] + " Thousands " + digitWords[parseInt(strRs.substring(3,4))] + " Hundred " + digitWords[parseInt(strRs.substring(4,6))];
		if(strRs.length==5) rsInWords = digitWords[parseInt(strRs.substring(0,2))] + " Thousands " + digitWords[parseInt(strRs.substring(2,3))] + " Hundred " + digitWords[parseInt(strRs.substring(3,5))];
		if(strRs.length==4) rsInWords = digitWords[parseInt(strRs.substring(0,1))] + " Thousands " + digitWords[parseInt(strRs.substring(1,2))] + " Hundred " + digitWords[parseInt(strRs.substring(2,4))];
		if(strRs.length==3) rsInWords = digitWords[parseInt(strRs.substring(0,1))] + " Hundred " + digitWords[parseInt(strRs.substring(1,3))];
		if(strRs.length==2) rsInWords = digitWords[parseInt(strRs.substring(0,2))];
		if(strRs.length==1) rsInWords = digitWords[parseInt(strRs.substring(0,1))];
		if(strRs.length==0) rsInWords = "Zero ";

		paiseInWords = digitWords[paiseInInteger];
		amtWords = rsInWords + " <B>Rupees </B> "+ paiseInWords +" <B>Paise</B> Only-";
	}
	return amtWords;
}
function compareDate(d1,d2) {
	d1 = d1.split("/");
	d2 = d2.split("/");
	
	if(d1[2]>d2[2])
	return true;
	if((d1[2]==d2[2])&&(d1[1]>d2[1]))
	return true;
	if((d1[2]==d2[2])&&(d1[1]==d2[1])&&(d1[0]>=d2[0]))
		return true;
	else
		return false;
}
function dateDiff(d1,d2,netDiffDays) {
	//In this function the assumption is that d1 is larger than d2, other wise function automatically toggles the dates.
	//There is a variable which maintains the information whether d1 was larger than d2 in dates supplied d1 and d2 or not.
	//alert("once again inside");
	var bIsD1LargerThanD2=true;
	//alert("d1="+ d1 +" d2="+ d2 +" compareDate(d1,d2)="+ compareDate(d1,d2));
	if(compareDate(d1,d2)){tempDate=d1;d1=d2;d2=tempDate;bIsD1LargerThanD2=false;}
	d1 = d1.split("/");
	d2 = d2.split("/");
	days1=parseInt(d1[0]);days2=parseInt(d2[0]);
	month1=parseInt(d1[1]);month2=parseInt(d2[1]);
	year1=parseInt(d1[2]);year2=parseInt(d2[2]);
	if(days1==days2 && month1==month2 && year1==year2)
		return netDiffDays;

	if(days1!=days2){
		netDiffDays+=days1-days2;
		newD1=days2+"/"+month1+"/"+year1;
		newD2=days2+"/"+month2+"/"+year2;
		//alert("Days:netDiffDays:="+netDiffDays);
		//alert("Days:newD1:="+newD1);
		//alert("Days:newD2:="+newD2);
		return dateDiff(newD1,newD2,netDiffDays);
	}
	//alert(month1 + " - " + month2);
	if(month1>month2){
		for(monthNo=month2;monthNo<month1;monthNo++)
		{
			alert(getDaysPerMonth(monthNo, year2) + " Days in monthNo/year2:="+monthNo + "/" + year2);
			netDiffDays+=getDaysPerMonth(monthNo, year2);
		}
		newD1=days1+"/"+month1+"/"+year1;
		newD2=days2+"/"+month1+"/"+year2;
		//alert("Month1:netDiffDays:="+netDiffDays);
		//alert("Month1:newD1:="+newD1);
		//alert("Month1:newD2:="+newD2);
		return dateDiff(newD1,newD2,netDiffDays);
	}
	if(month1<month2){
		for(monthNo=month1;monthNo<month2;monthNo++)
			netDiffDays-=getDaysPerMonth(monthNo, year1);
		newD1=days1+"/"+month2+"/"+year1;
		newD2=days2+"/"+month2+"/"+year2;
		//alert("Month2:netDiffDays:="+netDiffDays);
		//alert("Month2:newD1:="+newD1);
		//alert("Month2:newD2:="+newD2);
		netDiffDays = -1 * netDiffDays;
		return dateDiff(newD1,newD2,netDiffDays);
	}
	alert(year1 +" "+ year2);
	if(year1>year2)
		netDiffDays += 365*(year1-year2);
	else
		netDiffDays += 365*(year1-year2);
	return netDiffDays;
}
function checkNumeric(e,h) {
	str=h.value;
	if(e.keyCode==190)
	{
		len=str.indexOf('.');
		if(len!=-1)
		return false;
	}	
	if(((e.keyCode>=48)&&(e.keyCode<=57))||(e.keyCode==190)||(e.keyCode==8)||(e.keyCode==39)||(e.keyCode==36)||(e.keyCode==35)||(e.keyCode==37)||(e.keyCode==9))
		return true;
	else
		return false;
}

/*
	Below two functions perform max length operations on any textarea fields.
*/
function setMaxLength() {
	var x = document.getElementsByTagName('textarea');
	var counter = document.createElement('div');
	counter.className = 'counter';
	for (var i=0;i<x.length;i++) {
		if (x[i].getAttribute('maxlength')) {
			var counterClone = counter.cloneNode(true);
			counterClone.relatedElement = x[i];
			counterClone.innerHTML = '<span>0</span>/'+x[i].getAttribute('maxlength');
			x[i].parentNode.insertBefore(counterClone,x[i].nextSibling);
			x[i].relatedElement = counterClone.getElementsByTagName('span')[0];

			x[i].onkeyup = x[i].onchange = checkMaxLength;
			x[i].onkeyup();
		}
	}
}

function checkMaxLength() {
	var maxLength = this.getAttribute('maxlength');
	var currentLength = this.value.length;
	if (currentLength > maxLength){
		this.value = this.value.substring(0,maxLength);
		currentLength = maxLength;
		this.relatedElement.className = 'toomuch';
	} else
		this.relatedElement.className = '';
	this.relatedElement.firstChild.nodeValue = currentLength;
	// not innerHTML
}

function validateEmailFormat(emailId){
		/*
			Possible input email id formats
			1. "rishi@global.nastec.biz" <rishi@global.nastec.biz>
			2. rishi@global.nastec.biz
			3. "rishi.dev@global.nastec.biz" <rishi.dev@global.nastec.biz>
			4. rishi.dev@global.nastec.biz
		*/
		str = emailId;
		var at="@"
		var dot="."
		if(str.indexOf("<")!=-1){
			//It is either format 1 or 3.
			var nameandEmail = str.split("<");
			if(nameandEmail.length>1){
				str = nameandEmail[1].substring(0,nameandEmail[1].length-1);
			}else{
				return false;
			}
		}
		str = myTrim(str);
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   //errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Please enter valid "+ objForValidation.getAttribute("desc") +" .</B></font>";
		   return false;
		}
		if (str.indexOf(at)==0){
		   //errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Please enter valid "+ objForValidation.getAttribute("desc") +" .</B></font>";
		   return false;
		}
		if (str.indexOf(at)==lstr-1){
		   //errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Please enter valid "+ objForValidation.getAttribute("desc") +" .</B></font>";
		   return false;
		}
		if (str.indexOf(dot)==-1){
		   //errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Please enter valid "+ objForValidation.getAttribute("desc") +" .</B></font>";
		   return false;
		}
		if (str.indexOf(dot)==0){
		    //errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Please enter valid "+ objForValidation.getAttribute("desc") +" .</B></font>";
		    return false;
		}

		if (str.indexOf(dot)==lstr-1){
				//errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Please enter valid "+ objForValidation.getAttribute("desc") +" .</B></font>";
		    return false;
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    //errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Please enter valid "+ objForValidation.getAttribute("desc") +" .</font>";
		    return false;
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    //errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Please enter valid "+ objForValidation.getAttribute("desc") +" .</font>";
		    return false;
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    //errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Please enter valid "+ objForValidation.getAttribute("desc") +" .</font>";
		    return false;
		 }
		 if (str.indexOf(" ")!=-1){
		    //errMsg.innerHTML = "<font color='red' face='arial'><B>Error:</B> Please enter valid "+ objForValidation.getAttribute("desc") +" .</font>";
		    return false;
		 }
 		 return true;
}