/*********
**	These functions are usefull to check the charecters and numbers.
**  checknum alows numbers only and checkchar allows charecters only.
**  For these developers has to pass the event as an aurgument.
*********/
function restrictspecial(obj)
{
	var len=obj.value.length;
	for(i=0; i<len; i++)
	{	
		var code = obj.value.charCodeAt(i);
		//alert(code);
		if(code == 46 || code == 45 || (code>=97 && code<=122) || (code>=65 && code<=90) || code==32 )
		{	
			true;				
		}else
		{
			alert('special characters are not allowed');
			i=len+1;
			obj.focus();
			return false;
		}
	}
}
function  checkChars(obj,chars)
{
	//alert(obj.value.length);
	var size=eval(parseInt(obj.value.length)+parseInt(1))
	var chars=chars;
	if( size > chars )
	{
		//alert(obj.value.length-1)
		alert("Entered "+size+" characters. Maximum allowed "+chars+" characters!");
		
	 	obj.focus();
		return false 
	}
	return true
}
function restrict(evt)
{
	evt = (evt) ? evt : window.event
	var charCode = (evt.which) ? evt.which : evt.keyCode		
	if(charCode==17)
	{
		alert("Copy operation is not valid here")	;
		return false;
	}	
}
function spltxtarea(obj)
{
	var len=obj.value.length;
	for(i=0; i<len; i++)
	{	
		var code = obj.value.charCodeAt(i);
		//alert(code);
		if(code == 40 || code == 41 || code == 46 || code == 35 || (code>=97 && code<=122) || (code>=65 && code<=90) || code==32 ||(code >= 48 && code <=57))
		{	
				true;				
		}else
		{
				alert('special characters are not allowed except # ( )');
				obj.focus();i=len+1;
				return false;
		}
	}
}
function txtarea(evt)
{
	evt = (evt) ? evt : window.event
	var charCode = (evt.which) ? evt.which : evt.keyCode		
//alert(charCode);	
	if(charCode==17)
	{
		alert("Copy operation is not valid here")	;
		return false;
	}	
	//
	if(charCode == 40 || charCode == 41 || charCode == 46 || charCode == 35 || (charCode>=97 && charCode<=122) || (charCode>=65 && charCode<=90) || charCode==32 ||(charCode >= 48 && charCode <=57))
		return true
	else
		return false
}
function chkName(evt)
{
	evt = (evt) ? evt : window.event
	var charCode = (evt.which) ? evt.which : evt.keyCode		
  //alert(charCode);	
	if(charCode==17)
	{
		alert("Copy operation is not valid here")	;
		return false;
	}	
	//
	if(charCode == 40 || charCode == 41 || charCode == 46 || charCode == 45 || (charCode>=97 && charCode<=122) || (charCode>=65 && charCode<=90) || charCode==32 )
		return true
	else
		return false
}
function checknum(evt)
{
		evt = (evt) ? evt : window.event
		var charCode = (evt.which) ? evt.which : evt.keyCode		
		//alert(charCode)
		if(charCode !=9 && charCode !=8 )
		 if ((charCode <=46 || charCode >=47) && charCode > 31 && (charCode < 48 || charCode > 57) ) {
			return false
		}
		return true
}
function checknum1(evt)
{
		evt = (evt) ? evt : window.event
		var charCode = (evt.which) ? evt.which : evt.keyCode
		//alert(charCode);
		if((charCode != 45) && ((charCode < 48) || (charCode > 57)))
			return false;
		return true;
		//alert(charCode)
		/*if(charCode !=9 && charCode !=8 )
		 if ((charCode <=46 || charCode >=47) && charCode > 31 && (charCode < 48 || charCode > 57) ) 
		 {
			return false
		}
		return true*/
}
/*function checkrange(obj)
{
	//alert(obj.value);	
	var value1=obj.value; //	alert(value1.length);
	var flag=true;
	for(var i=0;i<=value1.length;i++)
	{
		//alert(value1.indexOf('-'));
		//alert(value1.indexOf(value1.charAt(i)));
		if(value1.indexOf('-') == -1)
	  	{
			  flag=false;
	  	}
	}
	if(flag==false)
	{
		alert("Enter range correctly");
		return false;
	}
	return true;	
}*/
// this function will allow numbers,alphabets and hyphen(-)
function checkcity(evt)
{
		evt = (evt) ? evt : window.event
		var charCode = (evt.which) ? evt.which : evt.keyCode				
 		if ((charCode >=45  && charCode <=57 && charCode !=46 && charCode !=47) ||  (charCode>=65 && charCode <=90) || (charCode >=97 && charCode <=122))
		{	
			//alert(charCode)
			return true
		}
		else
		{
			return false
		}
}

// this function will allow alphabets and comma(,) and space
function checkexpertise(evt)
{
		evt = (evt) ? evt : window.event
		var charCode = (evt.which) ? evt.which : evt.keyCode			
 		if (charCode==44 || (charCode>=65 && charCode <=90) || (charCode >=97 && charCode <=122) || charCode==32) {				
			return true
		} else {
			return false
		}
}
/*
This function will allow only numbers from 0-9  and /(slash)
*/
function checkNumSlash(evt)
{
		evt = (evt) ? evt : window.event
		var charCode = (evt.which) ? evt.which : evt.keyCode	
		//alert(charCode)
 		if (charCode >45 && charCode <=57 && charCode!=46 || (charCode ==9 || charCode ==8))
		{	
			//alert(charCode)
			return true
		}
		else
		{
			return false
		}
}
function chekAlpha(evt)
{
		var charCode = evt.keyCode;
       //alert(charCode)
	   if((charCode>=65 && charCode <=90) || (charCode >=97 && charCode <=122))
	   {
		   return true;
	   }
	   return false;
}
function checkAlphaandspace(evt)
{
	//alert(evt.value);
	evt = (evt) ? evt : window.event
	var charCode = (evt.which) ? evt.which : evt.keyCode
	//alert(charCode)
	if((charCode >=65 && charCode<=90) || (charCode >= 97 && charCode <= 122) || (charCode == 32))
		return true
	return false
}
/*
This function will allow only numbers from 0-9 ,-(hyphen) and /(slash)
*/
function checkNumHyphenSlash(evt)
{
		evt = (evt) ? evt : window.event
		var charCode = (evt.which) ? evt.which : evt.keyCode				
 		if (charCode >=45 && charCode <=57&& charCode!=46)
		{	
			//alert(charCode)
			return true
		}
		else
		{
			return false
		}
}
/*
This function will allow only Alphabets,-(hyphen) and /(slash)
*/
function checkAlphaHyphenSlash(evt)
{
		evt = (evt) ? evt : window.event
		var charCode = (evt.which) ? evt.which : evt.keyCode
		//alert(charCode)
 		if (charCode ==45 || charCode==47 || (charCode>=65 && charCode <=90) || (charCode >=97 && charCode <=122))
		{	
			//alert(charCode)
			return true
		}
		else
		{
			return false
		}
}

function checkalnum(evt)
{
		evt = (evt) ? evt : window.event
		var charCode = (evt.which) ? evt.which : evt.keyCode
}
function checkreceipt(evt)
{
		evt = (evt) ? evt : window.event
		var charCode = (evt.which) ? evt.which : evt.keyCode
		//alert(charCode)
 		if (charCode ==45 || charCode==47 || charCode !=9 || charCode !=8 ||(charCode>=65 && charCode <=90) || (charCode >=97 && charCode <=122)|| (charCode >=48 && charCode <=58))
		{	
			//alert(charCode)
			return true
		}
		else
		{
			return false
		}
}
function chksplchars(evt)
{
		evt = (evt) ? evt : window.event
		var charCode = (evt.which) ? evt.which : evt.keyCode
		//alert(charCode)
 		if (charCode ==40 || charCode==41 || charCode==46 || charCode==44 || charCode==32 || (charCode>=65 && charCode <=90) || (charCode >=97 && charCode <=122)|| (charCode >=48 && charCode <=58))
		{	
			//alert(charCode)
			return true
		}
		else
		{
			return false
		}
}
var flcount=0; var prevtxtbox='';
function checkfloat(evt,txtbox)
{
		evt = (evt) ? evt : window.event
		var charCode = (evt.which) ? evt.which : evt.keyCode
		//alert(charCode);
		if( (this.prevtxtbox != txtbox ))
		{
			this.flcount=0;
			this.prevtxtbox = txtbox;
	    }

		if(charCode==46)	
		{
			if( this.flcount >= 1 )
                  return false;
			 this.flcount=1;
		}
		if(charCode !=9 && charCode !=8 && charCode !=46)
		{
		    if ((charCode <=45 || charCode >= 47) && charCode > 31 && (charCode < 48 || charCode > 57) )
			{ 
			   return false
		    }
		   if( this.flcount<=2 )
			this.flcount = (this.flcount >= 1)? this.flcount+1 : 0;
	      else if( this.flcount >2 )
           return false;
		}
		return true
}

function checkfloat1(evt)
{
	evt = (evt) ? evt : window.event
	var charCode = (evt.which) ? evt.which : evt.keyCode
	if((charCode!=46) && (charCode <48 || charCode>57))
		return false;
	return true;
}

function OtherChars(evt,type)
{
		evt = (evt) ? evt : window.event
		var charCode = (evt.which) ? evt.which : evt.keyCode
		var code = false;
		switch(type)
		{
				case "R" : if(charCode!=43 && charCode!=45)
						 	code = true;    break;
				case "N" : if(charCode!=47 && charCode!=95)			
							code = true;	break;
		}
		if(charCode !=9 && charCode !=8 && charCode !=46 && charCode !=13 && charCode!=39 && code)
		 if ( (charCode <31 || charCode>=33 ) && charCode <= 64 || charCode >90 && (charCode < 97 || charCode > 123)&&(charCode != 9 &&charCode!=39) )
			return false;
		 return true;
}
function checkchar(evt)
{
		evt = (evt) ? evt : window.event
		var charCode = (evt.which) ? evt.which : evt.keyCode
		if(charCode==17)
		{
			alert("Copy operation is not valid here")	;
			return false;
		}		
		if(charCode !=9 && charCode !=8 && charCode !=46 && charCode !=13 && charCode!=39)
		 if ( (charCode <31 || charCode>=33 ) && charCode <= 64 || charCode >90 && (charCode < 97 || charCode >= 123)&&(charCode != 9 && charCode!=39))
		 {
			return false
		 }
		 return true
}
function checkcode(evt)
{
		evt = (evt) ? evt : window.event
		var charCode = (evt.which) ? evt.which : evt.keyCode
		//alert(charCode)
		//if(charCode !=9 && charCode !=8 && charCode !=46 && charCode !=13 && charCode!=39)
		 if ( (charCode>=65 && charCode <=90) || (charCode >=97 && charCode <=122) || charCode==32 || charCode==40 || charCode==41 || charCode==45 || charCode==8 )
		 {
			return true
		 }
		 return false
}
/*
 This function used to validate the percentage.
 @Param  : obj :Object of the textbox , limit : Integer 
 @Return : true| false : Bool
*/
function validPercentage(obj,limit)
{
	if(obj.value >limit)
	{
		alert("Enter valid percentage")
		obj.value =""
		obj.focus();
		return false
	}
	return true
}
function rangeValidation(obj,limit,msg)
{
	if(obj.value >limit || obj.value=="")
	{
		alert(msg)		
		obj.focus();
		//obj.value =""
		return false
	}
	return true
}

var count = 0
function checkphone(evt)
{
		evt = (evt) ? evt : window.event
		var charCode = (evt.which) ? evt.which : evt.keyCode		
		 if(charCode ==45)
		 {
		 	this.count++
			if(count>1)
				return false
		 }
			
		if(charCode !=9 && charCode !=8 )
		 if ((charCode <=44 || charCode >= 47 || charCode==46) && charCode > 31 && (charCode < 48 || charCode > 57) ) {
			return false
		}
		return true
}

	function checkStartEndDate(sDateid,eDateid,obj,durationId,msg) //this function validates start date and end date
	{			
		var checkFlag =validDate(obj,durationId);
		if(checkFlag == false) {
			obj.focus();
			return false
		} else {
			//alert(eDateid.id)
			if(eDateid.id!="id_edate") { // this is hard code, it will may causes some problem if we use the same id
				var checkFlag =futureDateCheck(obj);
				if(checkFlag == false) {
					alert("Future Date not acceptable here")
					obj.focus();
					return false
				}
			}
		}
		
		
		if(checkFlag)
	  	 {	  		
		    var sDateArr = sDateid.value.split("/")
  		    var eDateArr = eDateid.value.split("/")

			var startDate=new Date(sDateArr[2],sDateArr[1]-1,sDateArr[0]);
			var endDate=new Date(eDateArr[2],eDateArr[1]-1,eDateArr[0]);
			var datediffvalue= Math.round(( endDate.getTime() - startDate.getTime() ) / (86400000*30));
			if(datediffvalue < 0)
			{
				if(msg)	 {
					alert(msg)
				} else {
					alert("Date of leaving must be greater than Date of Joining");
				}
				obj.value='';
				obj.focus();
				return false
			} else {
				if(isNaN(endDate)){
					//alert("ssdsds")
					var today = new Date();
					var datediffvalue= Math.round(( today.getTime() - startDate.getTime() ) / (86400000*30));
					
				}
				//alert(datediffvalue)
				if(durationId) {
					if(!isNaN(datediffvalue)) {
						durationId.value = datediffvalue;
					} else {
						durationId.value = "";
					}
				}
			}
			return true
	  }
	}
	function futureDateCheck(obj)
	{
		var a2=obj.value.split("/")
		
		var now = new Date();						
		var nowDate=new Date(now.getFullYear(),now.getMonth(),now.getDate());
		var enteredDate=new Date(a2[2],a2[1]-1,a2[0]);		
		if(enteredDate.getTime()>nowDate.getTime()) {			
			obj.value = '';
		    obj.focus();
		    return false
		}		
		return true
	}
	function formationDateCheck(obj,Dateid)
	{
		var InsDate = document.getElementById(Dateid).value;
		var validDate = obj.value;
		//alert(InsDate)
		//alert(validDate)
		var flag=0		
		var a1=obj.value.split("/")				
		
		if ((a1.length==3)) 
		{ 	
			var day = a1[0]
			var month = a1[1]				
			var year = a1[2]				
			
		if((day.length>0 && day.length<3) && (month.length>0 && month.length<3) && (year>1900 && year.length==4))
			{						
					v=new Date(month+"/"+day+"/"+year); 						
					if(v.getMonth() == (month-1) && v.getDate() == day)
						flag = 1
					else
						flag =0					
			}
			else
				flag =0			
		}
		else
			flag =0			
		
		if(!flag)
		{
			alert("Invalid Date")
			obj.value=''
			obj.focus();
			return false
		}

		var val = futureDateCheck(obj);	
			if(val ==false) {
				alert("Formation date  should not be greater than the system date")
				obj.value=''
				obj.focus();
				return false
			}
			return true
			
		var val = validDate(obj);	
		
		if(val ==false)
			
			return false
		else {
			persistDate(obj);
		}
		return true
	}
	function regDateCheck(obj,Dateid)
	{
		var InsDate = document.getElementById(Dateid).value;
		var validDate = obj.value;
		//alert(InsDate)
		//alert(validDate)
		var flag=0		
		var a1=obj.value.split("/")				
		
		if ((a1.length==3)) 
		{ 	
			var day = a1[0]
			var month = a1[1]				
			var year = a1[2]				
			
		if((day.length>0 && day.length<3) && (month.length>0 && month.length<3) && (year>1900 && year.length==4))
			{						
					v=new Date(month+"/"+day+"/"+year); 						
					if(v.getMonth() == (month-1) && v.getDate() == day)
						flag = 1
					else
						flag =0					
			}
			else
				flag =0			
		}
		else
			flag =0			
		
		if(!flag)
		{
			alert("Invalid Date")
			obj.value=''
			obj.focus();
			return false
		}

		var val = futureDateCheck(obj);	
			if(val ==false) {
				alert("Future Date not acceptable here")
				obj.value=''
				obj.focus();
				return false
			}
			return true
			
		var val = validDate(obj);	
		
		if(val ==false)
			
			return false
		else {
			persistDate(obj);
		}
		return true
	}
	
	function regDateCheck1(obj)
	{
		//var InsDate = document.getElementById(Dateid).value;
		var validDate = obj.value;
		//alert(InsDate)
		//alert(validDate)
		var flag=0		
		var a1=obj.value.split("/")				
		
		if ((a1.length==3)) 
		{ 	
			var day = a1[0]
			var month = a1[1]				
			var year = a1[2]				
			
		if((day.length>0 && day.length<3) && (month.length>0 && month.length<3) && (year>1900 && year.length==4))
			{						
					v=new Date(month+"/"+day+"/"+year); 						
					if(v.getMonth() == (month-1) && v.getDate() == day)
						flag = 1
					else
						flag =0					
			}
			else
				flag =0			
		}
		else
			flag =0			
		
		if(!flag)
		{
			alert("Invalid Date")
			obj.value=''
			obj.focus();
			return false
		}

		var val = futureDateCheck1(obj);	
			if(val ==false) {
				alert("Previous Date not acceptable here")
				obj.value=''
				obj.focus();
				return false
			}
			return true
			
		var val = validDate(obj);	
		
		if(val ==false)
			
			return false
		else {
			persistDate(obj);
		}
		return true
	}
	
	function formationDateCheckstaff(obj,Dateid,stfdate)
	{
		//alert(stfdate);
		var InsDate = document.getElementById(Dateid).value;
		//alert(InsDate);
		
		//var stfdate = stfdate;
		var validDate = obj.value;
		//alert(InsDate)
		//alert(validDate)
		var flag=0		
		var a1=obj.value.split("/")				
		
		if ((a1.length==3)) 
		{ 	
			var day = a1[0]
			var month = a1[1]				
			var year = a1[2]				
			
		if((day.length>0 && day.length<3) && (month.length>0 && month.length<3) && (year>1900 && year.length==4))
			{						
					v=new Date(month+"/"+day+"/"+year); 						
					if(v.getMonth() == (month-1) && v.getDate() == day)
						flag = 1
					else
						flag =0					
			}
			else
				flag =0			
		}
		else
			flag =0			
		
		if(!flag)
		{
			alert("Invalid Date")
			obj.value=''
			obj.focus();
			return false
		}

		var val = futureDateCheck(obj);	
			if(val ==false) {
				alert("Formation date  should not be greater than the system date")
				obj.value=''
				obj.focus();
				return false
			}
			//return true
			
/*		var val = validDate(obj);	
		alert(val)
		if(val ==false)
			
			return false
*//*		else {
			persistDate(obj);
		}
*/		//return true
		//alert('ajax.php?stfdate='+stfdate+'&actdate='+InsDate+'')
		http.open('get','ajax.php?stfdate='+stfdate+'&actdate='+InsDate+'');
		http.onreadystatechange = function ()
		{
			if(http.readyState == 4)
			{
				var response = http.responseText;
				//alert(response);
				if(response == 1)
				{
					alert('Date should be greater than the staff joining date')
					document.getElementById(Dateid).value = '';
					document.getElementById(Dateid).focus();
				}
				else
				{
					 return true;
				}
			}
		}
		http.send(null);
	}
	
	function arrDateCheck1(obj,id_tname)
	{
		//var InsDate = document.getElementById(Dateid).value;
		var validDate = obj.value;
		//alert(InsDate)
		//alert(validDate)
		var flag=0		
		var a1=obj.value.split("/")				
		
		if ((a1.length==3)) 
		{ 	
			var day = a1[0]
			var month = a1[1]				
			var year = a1[2]				
			
		if((day.length>0 && day.length<3) && (month.length>0 && month.length<3) && (year>1900 && year.length==4))
			{						
					v=new Date(month+"/"+day+"/"+year); 						
					if(v.getMonth() == (month-1) && v.getDate() == day)
						flag = 1
					else
						flag =0					
			}
			else
				flag =0			
		}
		else
			flag =0			
		
		if(!flag)
		{
			alert("Invalid Date")
			obj.value=''
			obj.focus();
			return false
		}

		var val = futureDateCheck1(obj);	
			if(val ==false) {
				alert("Arrival date must be greater than booking date")
				obj.value=''
				obj.focus();
				return false
			}
			sample(obj,id_tname);
			return true
			
		var val = validDate(obj);	
		
		if(val ==false)
			
			return false
		else {
			persistDate(obj);
		}
		return true
	}
	function futureDateCheck1(obj)
	{
		var a2=obj.value.split("/")
		
		var now = new Date();						
		var nowDate=new Date(now.getFullYear(),now.getMonth(),now.getDate());
		var enteredDate=new Date(a2[2],a2[1]-1,a2[0]);		
		if(enteredDate.getTime()<nowDate.getTime()) {			
			obj.value = '';
		    obj.focus();
		    return false
		}		
		return true
	}
	
	function futureDateCheck20(obj,abc)
	{
		var a2=obj.value.split("/");
		var now = new Date();						
		var nowDate=new Date(now.getFullYear(),now.getMonth(),now.getDate());
		var enteredDate=new Date(a2[2],a2[1]-1,a2[0]);
		if(enteredDate.getTime()>nowDate.getTime())
		{	
			obj.value = '';
			alert("Future dates are not accepted");
		    obj.focus();
		    return false
		}
		noMonths(obj,abc);
		return true
	}
	
	function noMonths(obj,id_txt_no_months)
{	
	var txt=document.getElementById(id_txt_no_months);
	var doj=obj.value;
	var doj1=doj.split("/",3);
	//alert(doj1[0]);
	var doj2=new Date(doj1[2],(doj1[1]-1),doj1[0]);
	//alert(doj2);
	var today=new Date();
	var diff=(today-doj2)/2631312000;
	//alert(diff);
	//alert(txt);
	//txt.value=diff;
//	alert("with in noMonths");
}
	
	function regDateCheck2(obj)
	{
		var validDate = obj.value;
		//alert(InsDate)
		//alert(validDate)
		var flag=0		
		var a1=obj.value.split("/")				
		
		if ((a1.length==3)) 
		{ 	
			var day = a1[0]
			var month = a1[1]				
			var year = a1[2]				
			
		if((day.length>0 && day.length<3) && (month.length>0 && month.length<3) && (year>1900 && year.length==4))
			{						
					v=new Date(month+"/"+day+"/"+year); 						
					if(v.getMonth() == (month-1) && v.getDate() == day)
						flag = 1
					else
						flag =0					
			}
			else
				flag =0			
		}
		else
			flag =0			
		
		if(!flag)
		{
			alert("Invalid Date")
			obj.value=''
			obj.focus();
			return false
		}

		var val = futureDateCheck2(obj);
			if(val == false) {
				alert("Previous Date not acceptable here")
				//return false

			}
			return true
			
		var val1 = validDate(obj);	
		
		if(val1 == false)
			
			return false
		else {
			persistDate(obj);
		}
		return true
	}
	
	function futureDateCheck2(obj)
	{

		
		var a2=obj.value.split("/")
		var now = new Date();						
		var nowDate=new Date(now.getFullYear(),now.getMonth(),now.getDate());
		var enteredDate=new Date(a2[2],a2[1]-1,a2[0]);		
		if(enteredDate.getTime()<nowDate.getTime()) {			
			obj.value = '';
		    obj.focus();
		    return false
		}		
		return true
	}
	
	
	function validDate(obj,duration) // this validates the date in dd/mm/yyyy format or not and also validate right date or not
	{	
		var flag=0		
		var a1=obj.value.split("/")				
		
		if ((a1.length==3)) 
		{ 	
			//if (isInteger(a1[0]) && isPositiveInteger(a1[1]) && isPositiveInteger(a1[2])) 
			//{				
				//alert(a1)
				var day = a1[0]
				var month = a1[1]				
				var year = a1[2]				
				
				if((day.length>0 && day.length<3) && (month.length>0 && month.length<3) && (year>1900 && year.length==4))
				{						
						v=new Date(month+"/"+day+"/"+year); 						
						if(v.getMonth() == (month-1) && v.getDate() == day)
							flag = 1
						else
							flag =0					
				}
				else
					flag =0			
		/*	}
			else
				flag =0			*/
		}
		else
			flag =0			
		
		if(!flag)
		{
			alert("Invalid Date")
			if(duration)
				duration.value = ""
			obj.value=''
			obj.focus();
			return false
		}			
		return true
	}


	
//this function finds the total of fields
//here count value is the total fields u want to count 

	function totAssets(obj,count)
	{
		 var strid   = obj.id;
		 if(count>=10)
		 {
			var val 	  = strid.substr(strid.length-2)
		 	var tmp_str = strid.substr(0,strid.length-2)	
		 }
		 else
		 {			 
			var val 	  = strid.substr(strid.length-1)
		 	var tmp_str = strid.substr(0,strid.length-1)	
		 }
		 var Tot =  document.getElementById(tmp_str+count)			  
		if( val >=0 && val <=count-1 ) 
		{
			var tot=0;
			for(i=0;i<=count-1;i++)
			{
				var ele = parseInt(document.getElementById(tmp_str+i).value);
				if(isNaN(ele))
				   ele=0
				tot += ele
			}
			
			if(strid =='asserts0' || strid =='asserts1' || strid =='asserts2' || strid =='asserts3')
			{
					 var netloan =  document.getElementById('asserts4') //here this is hard coded
					 Tot.value = parseInt(netloan.value) +parseInt(tot)
			}
			else
			  Tot.value = tot
		}   
	}
	
	
	function findTotal(obj,count) 
	{	
		 var strid   = obj.id;
		 if(count>=10)
		 {
			var val   = strid.substr(strid.length-2)
		 	var tmp_str = strid.substr(0,strid.length-2)	
		 }
		 else
		 {			 
			var val 	  = strid.substr(strid.length-1)
		 	var tmp_str = strid.substr(0,strid.length-1)	
		 }
		 var Tot =  document.getElementById(tmp_str+count)			  
		if( val >=0 && val <=count-1 ) 
		{
			var tot=0;
			for(i=0;i<=count-1;i++)
			{
				var ele = parseInt(document.getElementById(tmp_str+i).value);
				if(isNaN(ele))
				   ele=0
				tot += ele
			}					
				if(strid =='asserts0' || strid =='asserts1' || strid =='asserts2' || strid =='asserts3')
				{
						 var netloan =  document.getElementById('loan2') //here this is hard coded
						 var netfixed =  document.getElementById('fixed2').value						
						 Tot.value = parseInt(netfixed)+parseInt(netloan.value) +parseInt(tot)
				}
				else
				  Tot.value = tot
		}   
	}
	
	// this function caliculates the differense between two text fields
	function findDiff(first,second,result) 
	{			
		var t1 =  document.getElementById(first)
		var t2 =  document.getElementById(second)
		var diff =  document.getElementById(result)
		var totAssets =  document.getElementById('asserts4') //here this is hard coded
		  
			if(!t1.value)
				t1.value = 0	
			if(!t2.value)
				t2.value = 0
		var res = parseInt(t1.value)-parseInt(t2.value)			
			diff.value = isNaN(res)?0:res;
			if(t1.id == 'loan0' || t2.id == 'loan1') {
				var val =  document.getElementById('fixed2').value				
			} else {
				var val =  document.getElementById('loan2').value
			  }
			
				var asserts = "asserts"
				var sum=parseInt(diff.value);
				sum+=parseInt(val);
				for(var i=0;i<=3;i++)
				{				
				 	var assert =  document.getElementById(asserts+i) //here this is hard coded
					if(!isNaN(parseInt(assert.value)))
					 sum += parseInt(assert.value);
				}
				totAssets.value=parseInt(sum);
			//}
	}
	
	//this function caliculates the total and also the surplus
	var income=0;
	var expendature =0;
	function findIETotal(obj,count,flag) 
	{	
		
		var strid   = obj.id
		 var val 	  = strid.substr(strid.length-1)
		 var tmp_str = strid.substr(0,strid.length-1)				  
		 var Tot =  document.getElementById(tmp_str+count)	
		 var surplus =  document.getElementById("exp9") //here we hard code the id
		 
		
		if( val >=0 && val <=count-1 ) 
		{
			var tot=0;
			for(i=0;i<=count-1;i++)
			{
				var ele = parseInt(document.getElementById(tmp_str+i).value);
				if(isNaN(ele))
				   ele=0
				tot += ele
			} 
			
				 Tot.value = parseInt(tot)
			if(flag == 'i')	
			{
				this.income= parseInt(Tot.value)
				var expen =  document.getElementById("exp8") //here we hard code the id
				if(expen.value)
					this.expendature = expen.value
			}
			
			if(flag == 'e')			
			{				
				this.expendature= parseInt(Tot.value)	
				var inc =  document.getElementById("income4") //here we hard code the id				
				if(inc.value)
					this.income = inc.value
				else
				this.income = 0
			}
			surplus.value = parseInt(this.income) - parseInt(this.expendature)				 
		}   
	}

	function checkShname(evt)
	{
			evt = (evt) ? evt : window.event
			
			var charCode = (evt.which) ? evt.which : evt.keyCode
			if(charCode !=9 && charCode !=8 && charCode !=46 && charCode !=13 && charCode !=45  )
			 if ( (charCode <31 || charCode>=33 ) && charCode <= 64 || charCode >90 && (charCode < 97 || charCode > 123)&&(charCode != 9 && charCode != 95)||(charCode == 32) )
				return false
			 return true
	}
	function notLess(moreId,lessId)
	{		
		var more =  document.getElementById(moreId)	
		var less =  document.getElementById(lessId)	
		alert(more.value)
		return true 
	}	
	
	function validEmail(obj)
	{				
		var id = obj.id.substr(obj.id.length-1);			
		if (obj.value != '') {			
			//alert("email")
			 if (obj.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1)
			 {
				alert("Enter Valid Email")
			  	return false;
			 }					  				 	
				obj.focus();					
		}		
			return true
	 }
	// this function validates the year 
	function validYear(obj)
	{
	  var date = new Date();
	  if(obj.value) {
		if(obj.value.length!=4 || !(obj.value>=1901 && obj.value<=2155) )
		{			
			alert("Invalid Year! \n Year Range should be in between 1901 - 2155")					
			return false
		}
	  }
		return true		
	}
	// this function changes the lowercase letters to uppercase letters (onKeyUp event handler)
	function changeUpperCase(obj){
		var myString = new String(obj.value);
		obj.value = myString.toUpperCase();
	}
	 
var count;	 
function newDateValidations(dayId,monthId,yearId,mode)
{	
	var day =  document.getElementById(dayId)	
	var month =  document.getElementById(monthId)
	var year =  document.getElementById(yearId)
	if(mode == 'y') {
		if(day.value=='Select') {
			alert("Select Day")
			day.focus()
			return false
		}
		if(month.value=='Select') {
			alert("Select Month")
			month.focus()
			return false
		}
	}
	
	if(day.value!='Select' && month.value!='Select' && year.value!='Select')
		alert(day.value+month.value+year.value)
}
// this function adds two fields data display in another field 
function addTwoFields(firstid,secondid,displayid)
{
	var first =  document.getElementById(firstid)	
	var second =  document.getElementById(secondid)	
	var disp =  document.getElementById(displayid)	
	
	if(!first.value)
		first.value = 0	
	if(!second.value)
		second.value = 0
	var res = parseInt(first.value)+parseInt(second.value)			
		disp.value = isNaN(res)?0:res;
}
	
	function checkStartEndDate1(sDateid,eDateid,obj,durationId,msg) //this function validates start date and end date
	{			
		var checkFlag =validDate(obj,durationId);
//		alert(checkFlag);
		if(checkFlag == false) {
			obj.focus();
			return false
		} 
		//else {
			//alert(eDateid.id)
//			if(eDateid.id!="id_edate") { // this is hard code, it will may causes some problem if we use the same id
//				var checkFlag =futureDateCheck(obj);
//				if(checkFlag == false) {
//					alert("Future Date not acceptable here")
//					obj.focus();
//					return false
//				}
//			}
//		}
		
		
		if(checkFlag)
	  	 {	  		
		    var sDateArr = sDateid.value.split("/")
  		    var eDateArr = eDateid.value.split("/")

			var startDate=new Date(sDateArr[2],sDateArr[1]-1,sDateArr[0]);
			var endDate=new Date(eDateArr[2],eDateArr[1]-1,eDateArr[0]);
			var datediffvalue= Math.round(( endDate.getTime() - startDate.getTime() ) / (86400000*30));
			if(datediffvalue < 0)
			{
				if(msg)	 {
					alert(msg)
				} else {
					alert("Date of registation must be greater than Date of agreement");
				}
				obj.value='';
				obj.focus();
				return false
			} else {
				if(isNaN(endDate)){
					//alert("ssdsds")
					var today = new Date();
					var datediffvalue= Math.round(( today.getTime() - startDate.getTime() ) / (86400000*30));
					
				}
				//alert(datediffvalue)
				if(durationId) {
					if(!isNaN(datediffvalue)) {
						durationId.value = datediffvalue;
					} else {
						durationId.value = "";
					}
				}
			}
			return true
	  }
//			return true
	}


function validDate1(obj,Dateid) // this validates the date in dd/mm/yyyy format or not and also validate right date or not
	{
	   // alert("+++++++++++");
		var InsDate = document.getElementById(Dateid).value;
		var validDate = obj.value;
		//alert(InsDate)
		//alert(validDate)
		var flag=0		
		var a1=obj.value.split("/")				
		var a2=InsDate.split("/")				
		
		if ((a1.length==3)) 
		{ 	
			var day = a1[0]
			var month = a1[1]				
			var year = a1[2]				
			
		if((day.length>0 && day.length<3) && (month.length>0 && month.length<3) && (year>1900 && year.length==4))
			{						
					v=new Date(month+"/"+day+"/"+year); 						
					if(v.getMonth() == (month-1) && v.getDate() == day)
						flag = 1
					else
						flag =0					
			}
			else
				flag =0			
		}
		else
			flag =0			
		
		if(!flag)
		{
			alert("Invalid Date")
			obj.value=''
			obj.focus();
			return false
		}
//		alert(a1[0]+a1[1]+a1[2])
//		alert(a2[0]+a2[1]+a2[2])
		if(a1[2] ==a2[2])
		{
			if(a1[1] == a2[1])
			{
				if(a1[0] < a2[0])
				{
					alert("Effective date should be greater than Registered date")
					obj.value=''
					obj.focus();
					return false
				}
			}else if ( a1[1] < a2[1])
			{
				alert("Effective date should be greater than Registered date")
				obj.value=''
				obj.focus();
				return false
			}
		}
		if(a1[2] < a2[2])
		{
			alert("Effective date should be greater than Registered date")
			obj.value=''
			obj.focus();
			return false
		}
//		if(InsDate != '')
//		if(InsDate > validDate)	
//		{
//			alert("validity date should be greater than Registered date")
//			obj.value=''
//			obj.focus();
//			return false
//		}
		return true
		
	}

function validDatevalidity(obj,Dateid) // this validates the date in dd/mm/yyyy format or not and also validate right date or not
	{
	   // alert("+++++++++++");
		var InsDate = document.getElementById(Dateid).value;
		var validDate = obj.value;
		//alert(InsDate)
		//alert(validDate)
		var flag=0		
		var a1=obj.value.split("/")				
		var a2=InsDate.split("/")				
		
		if ((a1.length==3)) 
		{ 	
			var day = a1[0]
			var month = a1[1]				
			var year = a1[2]				
			
		if((day.length>0 && day.length<3) && (month.length>0 && month.length<3) && (year>1900 && year.length==4))
			{						
					v=new Date(month+"/"+day+"/"+year); 						
					if(v.getMonth() == (month-1) && v.getDate() == day)
						flag = 1
					else
						flag =0					
			}
			else
				flag =0			
		}
		else
			flag =0			
		
		if(!flag)
		{
			alert("Invalid Date")
			obj.value=''
			obj.focus();
			return false
		}
//		alert(a1[0]+a1[1]+a1[2])
//		alert(a2[0]+a2[1]+a2[2])
		if(a1[2] ==a2[2])
		{
			if(a1[1] == a2[1])
			{
				if(a1[0] < a2[0])
				{
					alert("Validity date should be greater than Registered date")
					obj.value=''
					obj.focus();
					return false
				}
			}else if ( a1[1] < a2[1])
			{
				alert("Validity date should be greater than Registered date")
				obj.value=''
				obj.focus();
				return false
			}
		}
		if(a1[2] < a2[2])
		{
			alert("Validity date should be greater than Registered date")
			obj.value=''
			obj.focus();
			return false
		}
//		if(InsDate != '')
//		if(InsDate > validDate)	
//		{
//			alert("validity date should be greater than Registered date")
//			obj.value=''
//			obj.focus();
//			return false
//		}
		return true
		
	}


function checkdatediff(obj,Dateid,msg) // this validates the date in dd/mm/yyyy format or not and also validate right date or not
	{
	   // alert("+++++++++++");
		var InsDate = document.getElementById(Dateid).value;
		var validDate = obj.value;
//		alert(InsDate+validDate)
		var flag=0		
		var a1=obj.value.split("/")				
		var a2=InsDate.split("/")				
		
		if ((a1.length==3)) 
		{ 	
			var day = a1[0]
			var month = a1[1]				
			var year = a1[2]				
			
		if((day.length>0 && day.length<3) && (month.length>0 && month.length<3) && (year>1900 && year.length==4))
			{						
					v=new Date(month+"/"+day+"/"+year); 						
					if(v.getMonth() == (month-1) && v.getDate() == day)
						flag = 1
					else
						flag =0					
			}
			else
				flag =0			
		}
		else
			flag =0			
		
		if(!flag)
		{
			alert("Invalid Date")
			obj.value=''
			obj.focus();
			return false
		}
//		alert(a1[0]+a1[1]+a1[2])
//		alert(a2[0]+a2[1]+a2[2])
		if(a1[2] ==a2[2])
		{
			if(a1[1] == a2[1])
			{
				if(a1[0] < a2[0])
				{
					alert(msg)
					obj.value=''
					obj.focus();
					return false
				}
			}else if ( a1[1] < a2[1])
			{
				alert(msg)
				obj.value=''
				obj.focus();
				return false
			}
		}
		if(a1[2] < a2[2])
		{
			alert(msg)
			obj.value=''
			obj.focus();
			return false
		}
//		if(InsDate != '')
//		if(InsDate > validDate)	
//		{
//			alert("validity date should be greater than Registered date")
//			obj.value=''
//			obj.focus();
//			return false
//		}
		return true
	}

function checkdatediffReverse(obj,Dateid,msg) // this validates the date in dd/mm/yyyy format or not and also validate right date or not
	{
	   // alert("+++++++++++");
		var InsDate = document.getElementById(Dateid).value;
		var validDate = obj.value;
//		alert(InsDate+validDate)
		var flag=0		
		var a2=obj.value.split("/")				
		var a1=InsDate.split("/")				
		
		if ((a2.length==3)) 
		{ 	
			var day = a2[0]
			var month = a2[1]				
			var year = a2[2]				
			
		if((day.length>0 && day.length<3) && (month.length>0 && month.length<3) && (year>1900 && year.length==4))
			{						
					v=new Date(month+"/"+day+"/"+year); 						
					if(v.getMonth() == (month-1) && v.getDate() == day)
						flag = 1
					else
						flag =0					
			}
			else
				flag =0			
		}
		else
			flag =0			
		
		if(!flag)
		{
			alert("Invalid Date")
			obj.value=''
			obj.focus();
			return false
		}
//		alert(a1[0]+a1[1]+a1[2])
//		alert(a2[0]+a2[1]+a2[2])
		if(a1[2] ==a2[2])
		{
			if(a1[1] == a2[1])
			{
				if(a1[0] < a2[0])
				{
					alert(msg)
					obj.value=''
					obj.focus();
					return false
				}
			}else if ( a1[1] < a2[1])
			{
				alert(msg)
				obj.value=''
				obj.focus();
				return false
			}
		}
		if(a1[2] < a2[2])
		{
			alert(msg)
			obj.value=''
			obj.focus();
			return false
		}
//		if(InsDate != '')
//		if(InsDate > validDate)	
//		{
//			alert("validity date should be greater than Registered date")
//			obj.value=''
//			obj.focus();
//			return false
//		}
		return true
	}


function validDatetourbooking(obj,Dateid) // this validates the date in dd/mm/yyyy format or not and also validate right date or not
	{
	   // alert("+++++++++++");
		var InsDate = document.getElementById(Dateid).value;
		var validDate = obj.value;
		//alert(InsDate)
		//alert(validDate)
		var flag=0		
		var a1=obj.value.split("/")				
		
		if ((a1.length==3)) 
		{ 	
			var day = a1[0]
			var month = a1[1]				
			var year = a1[2]				
			
		if((day.length>0 && day.length<3) && (month.length>0 && month.length<3) && (year>1900 && year.length==4))
			{						
					v=new Date(month+"/"+day+"/"+year); 						
					if(v.getMonth() == (month-1) && v.getDate() == day)
						flag = 1
					else
						flag =0					
			}
			else
				flag =0			
		}
		else
			flag =0			
		
		if(!flag)
		{
			alert("Invalid Date")
			obj.value=''
			obj.focus();
			return false
		}
		if(InsDate != '')
		if(InsDate > validDate)	
		{
			alert("Tour booking date should be greater than Registered date")
			obj.value=''
			obj.focus();
			return false
		}
		return true
		
	}
	

function validDate11(obj,Dateid) // this validates the date in dd/mm/yyyy format or not and also validate right date or not
	{
	   // alert("+++++++++++");
		var InsDate = document.getElementById(Dateid).value;
		var validDate = obj.value;
		//alert(InsDate)
		//alert(validDate)
		var flag=0		
		var a1=obj.value.split("/")				
		
		if ((a1.length==3)) 
		{ 	
			var day = a1[0]
			var month = a1[1]				
			var year = a1[2]				
			
		if((day.length>0 && day.length<3) && (month.length>0 && month.length<3) && (year>1900 && year.length==4))
			{						
					v=new Date(month+"/"+day+"/"+year); 
					if(v.getMonth() == (month-1) && v.getDate() == day)
						flag = 1
					else
						flag =0					
			}
			else
				flag =0			
		}
		else
			flag =0			
		
		if(!flag)
		{
			alert("Invalid Date")
			obj.value=''
			obj.focus();
			return false
		}
		if(InsDate != '')
		if(InsDate > validDate)	
		{
			alert("Validity / Effective date should be greater than Registered date")
			obj.value=''
			obj.focus();
			return false
		}
		return true
		
	}
function validDateAndNoMonths(obj,abc,id_estdate)
{
	var validDate = obj.value;
	//alert(InsDate)
	//alert(validDate)
	var flag=0		
	var a1=obj.value.split("/")	
	if ((a1.length==3)) 
	{ 	
		var day = a1[0]
		var month = a1[1]				
		var year = a1[2]
		if((day.length>0 && day.length<3) && (month.length>0 && month.length<3) && (year>1900 && year.length==4))
		{						
				v=new Date(month+"/"+day+"/"+year); 						
				if(v.getMonth() == (month-1) && v.getDate() == day)
					flag = 1
				else
					flag =0					
		}
		else
			flag =0			
	}
	else
		flag =0
	if(!flag)
	{
		alert("Invalid Date")
		obj.value=''
		obj.focus();
		return false
	}
	var val = futureDateCheck(obj);	
		if(val ==false) {
			alert("Future Date not acceptable here")
			obj.value=''
			obj.focus();
			return false
		}
		noMonths(obj,abc,id_estdate);
		return true		
}
//to calculate difference of months between todays date and selected date
function noMonths(obj,id_txt_no_months,id_estdate1)
{
	var txt=document.getElementById(id_txt_no_months);//	alert(txt);
	var estdate=document.getElementById(id_estdate1);//	alert(estdate.value);
	if(estdate.value=='')
	{
		alert("Enter established date");
		obj.value='';
		estdate.focus();
		return false;
	}
	var doj1=obj.value.split("/",3);				 //alert(doj1[0]);
	var doj2=new Date(doj1[2],(doj1[1]-1),doj1[0]);  //	alert(doj2);
	var estdate1=estdate.value.split("/",3); //	alert(estdate1);
	var estdate2=new Date(estdate1[2],(estdate1[1]-1),estdate1[0]);//	alert(estdate2);
	if(doj2<estdate2)
	{
		alert("Join date should be greater than the establishment date");
		//document.getElementById(id_estdate1).value='';
		obj.value="";
		obj.focus();
		return false;
	}
	var today=new Date();
	var diff=(today-doj2)/2631312000;
	//alert(diff);
	//alert(txt);	
	txt.value=Math.round(diff);	
	
	/*var txt=document.getElementById(id_txt_no_months);
	var doj=obj.value;
	var doj1=doj.split("/",3);
	//alert(doj1[0]);
//	alert("with in noMonths");
	var doj2=new Date(doj1[2],(doj1[1]-1),doj1[0]);
	//alert(doj2);
	var today=new Date();
	var diff=(today-doj2)/2631312000;
	//alert(diff);
	//alert(txt);	
	txt.value=Math.round(diff);*/
}

function delconfirm()
  {
	if(confirm("Are you sure you want to delete?"))
	   return true;
	  else
	return false;	
}

function alphanumeric(obj)
{
	var count=0;
  for(var  i=0;i<obj.value.length;i++)
  {
	  if((((((obj.value.charCodeAt(i)<32))&&(obj.value.charCodeAt(i)<44)||(obj.value.charCodeAt(i)>47))&&(obj.value.charCodeAt(i)<48 )||(obj.value.charCodeAt(i)>57))  && (obj.value.charCodeAt(i)<65)||(obj.value.charCodeAt(i)>90)) &&(obj.value.charCodeAt(i)<97)||(obj.value.charCodeAt(i)>122))
	  {
		  count++;
	  }
  }if(count==0)
	  return true;
	  else
	  {
		  alert("enter address");
		  obj.focus();
		  return false;
	  }
}
function fillthis(obj)
{
	
	if((obj.value)=='')
	{
		alert("Enter no of irrigation");
		obj.focus();
		return false;
	}
}
function checkcharspace(evt)
{
		evt = (evt) ? evt : window.event
		var charCode = (evt.which) ? evt.which : evt.keyCode
		//alert(charCode);
		if(charCode !=9 && charCode !=8 && charCode !=46 && charCode !=13 && charCode!=39)
		 if ( (charCode <31 || charCode>=32 ) && charCode <= 64 || charCode >90 && (charCode < 97 || charCode > 123)&&(charCode != 9 &&charCode!=39) )
		 {
			return false
		 }
		 return true
}
function checkspace(obj)
{
	//alert(obj.value.charAt(0));
	if(obj.value.charAt(0)==' ')
	{
		alert("Enter first letter with out space");
		obj.focus();
		return false
	}
}
	function chkSpace(evt)
	{
		evt = (evt) ? evt : window.event
		var charCode = (evt.which) ? evt.which : evt.keyCode
		//alert(charCode)
		 if (charCode == 32)
		 {
			return false
		 }
		return true
		
	}
	
	function scheduleDates(sDateid,eDateid,obj,durationId,msg) //this function validates Insurance date and validity date
	{	//alert(obj.value);	
		var val = futureDateCheck(obj);	
		if(val ==false) {
			alert("Future Date not acceptable here")
			obj.value=''
			obj.focus();
			return false
		}
		var checkFlag =validDate(obj,durationId);
		if(checkFlag == false) { //alert("hi");
			obj.focus();
			return false
		} else {
		if(checkFlag)
	  	 {	
			var sDateArr = document.getElementById(sDateid).value.split("/")
  		    var eDateArr = document.getElementById(eDateid).value.split("/")
			var startDate=new Date(sDateArr[2],sDateArr[1]-1,sDateArr[0]);
			var endDate=new Date(eDateArr[2],eDateArr[1]-1,eDateArr[0]);
			var datediffvalue= ( endDate.getTime() - startDate.getTime() ) / (86400000*30);

			if(datediffvalue < 0 || datediffvalue == 0 )
			{
				if(msg)	 {
					alert(msg)
				} else {
					alert("DOJ date should be greater than DOB date");//
				}
				obj.value='';
				obj.focus();
				return false
			} else {
				if(isNaN(endDate)){
					//alert("ssdsds")
					var today = new Date();
					var datediffvalue= Math.round(( today.getTime() - startDate.getTime() ) / (86400000*30));
				}
				//alert(datediffvalue)
				if(durationId) {
					if(!isNaN(datediffvalue)) {
						durationId.value = datediffvalue;
					} else {
						durationId.value = "";
					}
				}
			}
			return true
		  }
		  }
	}
function scheduleDatesCSC(sDateid,eDateid,id_stdate,obj,durationId,msg) //this function validates Insurance date and validity date
	{	//alert(obj.value);		
		var checkFlag =validDate(obj,durationId);
		 var eDateArr1 = document.getElementById(eDateid).value;
		if(checkFlag == false) { //alert("hi");
			obj.focus();
			return false
		} else {
		if(checkFlag)
	  	 {	
		  // alert(document.getElementById(sDateid).value);//alert(document.getElementById(eDateid).value);
		    //var sDateArr = sDateid.value.split("/") // var eDateArr = eDateid.value.split("/")
			var sDateArr = document.getElementById(sDateid).value.split("/")
  		    var eDateArr = document.getElementById(eDateid).value.split("/")
            //alert(sDateArr);	//alert(eDateArr);
			var startDate=new Date(sDateArr[2],sDateArr[1]-1,sDateArr[0]);
			var endDate=new Date(eDateArr[2],eDateArr[1]-1,eDateArr[0]);
			//alert(startDate);	//alert(endDate);
			//alert(startDate.getTime());	//alert(endDate.getTime());
			//var datediffvalue= Math.round(( endDate.getTime() - startDate.getTime() ) / (86400000*30));
			var datediffvalue= ( endDate.getTime() - startDate.getTime() ) / (86400000*30);
			//alert(datediffvalue);
			var start_date=document.getElementById(id_stdate);
			//alert(start_date.value);
				//var cmp_date=document.getElementById(id_endate);
			var end_date=obj;
			//alert(end_date.value);
			//alert(start_date.value);
			//alert(cmp_date.value);
			var start_date1=start_date.value.split('/',3);
			var end_date1=end_date.value.split('/',3);
			//var cmp_date1=cmp_date.value.split('/',3);
			var txt_sch_start_date=new Date(start_date1[2],(start_date1[1]-1),start_date1[0]);//alert(txt_sch_start_date);
			var txt_sch_date=new Date(end_date1[2],(end_date1[1]-1),end_date1[0]);//alert(txt_sch_date);
//			var txt_end_date=new Date(cmp_date1[2],(cmp_date1[1]-1),cmp_date1[0]);
			//alert(txt_end_date);
			//alert(txt_sch_start_date);
			//alert(txt_sch_date);
			//alert(endDate);
			//if(txt_sch_date<=txt_sch_start_date && txt_sch_date>=txt_end_date )
			if(txt_sch_start_date > txt_sch_date || txt_sch_date < endDate)
			{
				alert("Date should be selected greater than "+ start_date.value +"");
				//start_date.value='';
				end_date.value='';
				obj.focus();
				return false;
			}
			if(datediffvalue < 0 || datediffvalue == 0 )
			{
				if(msg)	 {
					alert(msg)
				} else {
					alert("DOJ date should be greater than DOB date");
				}
				obj.value='';
				obj.focus();
				return false
			} else {
				if(isNaN(endDate)){
					//alert("ssdsds")
					var today = new Date();
					var datediffvalue= Math.round(( today.getTime() - startDate.getTime() ) / (86400000*30));
				}
				//alert(datediffvalue)
				if(durationId) {
					if(!isNaN(datediffvalue)) {
						durationId.value = datediffvalue;
					} else {
						durationId.value = "";
					}
				}
			}
			return true
	  }
	  }
	}	
	
function scheduleDatesCSC1(sDateid,eDateid,id_stdate,obj,durationId,msg) //this function validates Insurance date and validity date
{	//alert(obj.value);		
		var checkFlag =validDate(obj,durationId);
		 var eDateArr1 = document.getElementById(eDateid).value;
		if(checkFlag == false) { //alert("hi");
			obj.focus();
			return false
		} else {
		if(checkFlag)
	  	 {	
		  	//alert(document.getElementById(sDateid).value);//alert(document.getElementById(eDateid).value);
		    //var sDateArr = sDateid.value.split("/") // var eDateArr = eDateid.value.split("/")
			var sDateArr = document.getElementById(sDateid).value.split("/")
  		    var eDateArr = document.getElementById(eDateid).value.split("/")
            //alert(sDateArr);	//alert(eDateArr); 
			var startDate=new Date(sDateArr[2],sDateArr[1]-1,sDateArr[0]);
			var endDate=new Date(eDateArr[2],eDateArr[1]-1,eDateArr[0]);
			//alert(startDate);	//alert(endDate);
			//alert(startDate.getTime());	//alert(endDate.getTime());
			//var datediffvalue= Math.round(( endDate.getTime() - startDate.getTime() ) / (86400000*30));
			var datediffvalue= (endDate.getTime() - startDate.getTime() ) / (86400000*30);
			//alert(datediffvalue);
			var start_date=document.getElementById(id_stdate);
			alert(start_date.value);
			//var cmp_date=document.getElementById(id_endate);
			var end_date=obj;
			//alert(end_date.value); 
			//alert(start_date.value);
			//alert(cmp_date.value);
			var start_date1=start_date.value.split('/',3);
			var end_date1=end_date.value.split('/',3);
			//var cmp_date1=cmp_date.value.split('/',3);
			var txt_sch_start_date=new Date(start_date1[2],(start_date1[1]-1),start_date1[0]);//alert(txt_sch_start_date);
			var txt_sch_date=new Date(end_date1[2],(end_date1[1]-1),end_date1[0]);//alert(txt_sch_date);
//			var txt_end_date=new Date(cmp_date1[2],(cmp_date1[1]-1),cmp_date1[0]);
			//alert(txt_end_date);
			alert(txt_sch_start_date);
			//alert(txt_sch_date);
			//if(txt_sch_date<=txt_sch_start_date && txt_sch_date>=txt_end_date)
			if(txt_sch_start_date < txt_sch_date || txt_sch_date > endDate)
			{
				alert("Date should be selected below this "+ start_date.value +"date");
				//start_date.value='';
				end_date.value='';
				return false;
			}
			if(datediffvalue < 0 || datediffvalue == 0 )
			{
				if(msg)	 {
					alert(msg)
				} else {
					alert("Start date should be less than completion date");
				}
				obj.value='';
				obj.focus();
				return false
			} else {
				if(isNaN(endDate)){
					//alert("ssdsds")
					var today = new Date();
					var datediffvalue= Math.round(( today.getTime() - startDate.getTime() ) / (86400000*30));
				}
				//alert(datediffvalue)
				if(durationId) {
					if(!isNaN(datediffvalue)) {
						durationId.value = datediffvalue;
					} else {
						durationId.value = "";
					}
				}
			}
			return true
	  }
	  }
}	
function commision(evt)
{
	evt = (evt) ? evt : window.event
	var charCode = (evt.which) ? evt.which : evt.keyCode		
	//alert(charCode);
	if(charCode !=9 && charCode !=8)
	//if ((charCode <46 || charCode >=47) && charCode > 31 && (charCode < 48 || charCode > 57) )
	if(charCode == 46 || (charCode > 47 && charCode <58))
	{
		return true;
	}else
		return false;
}
function commision_val(obj)
{
	var val = obj.value;
	//alert(val);
	var val_s = val.split('.');
	//alert(val_s.length);
	if(val_s.length >2)
	{
		alert('Please enter valid commision');
		obj.value='';
		obj.focus();
		return false;
	}
	if(val_s[1] > -1 && val_s[1] < 100)
	{
		return true;
	}else
	{
		alert('Please enter valid commision');
		obj.value='';
		obj.focus();
		return false;
	}
}

/************* Developed by Naresh Reddy G *************/
/******* This function is for Transaction screen ********/
/*********** Function to allow valid amount and to allow only 2 digits after '.' **********/
function amount_coll(obj)
{
	var val = obj.value;
	if(val==0 || parseInt(val) > 99999.99)
	{
		alert("please enter valid amount")
		obj.focus();
		return false;
	}
	//alert(val)
	var pos= val.indexOf('.');
	//alert(pos) 
	if(pos!=-1)
	{
		var li=val.lastIndexOf('.');
		var val_s = val.split('.');
		var total=val.length;
		//alert(total)
		var T=total-li;
		if(val_s.length > 2 || T > 3 )//|| val==0 || parseInt(val) > 99999.99
		{
			alert('Please enter valid amount');
			//obj.value='';
			obj.focus();
			return false;
		}
	}
	else
		return true;
}
/******** End of function ********/
function checkCharacter(evt,id1)
{
	evt = (evt) ? evt : window.event
	var charCode = (evt.which) ? evt.which : evt.keyCode
	if(charCode !=9 && charCode !=8)
	//if ((charCode <46 || charCode >=47) && charCode > 31 && (charCode < 48 || charCode > 57) )
	if(charCode == 46 || (charCode > 47 && charCode <58))
	{
		val = id1.value;
		//alert(val)
		var li=val.lastIndexOf('.');
		//alert(li)
		var val_s = val.split('.');
		var total=val.length;
		var T=total-li;
		//alert(T)
		if (charCode == 46) 
		{
			val = id1.value;		
			for(var i = 0; i < val.length; i++) 
			{
				if (val.charCodeAt(i) == 46)
				return false;
			}
		}
		//status = ""
		return true
	}
	else
	{
		return false
	}
}
function checkSpaceandControl(evt)
{
	var evt = evt?evt:window.event;
	var charCode = (evt.which)?evt.which:evt.keyCode;//	alert(charCode); 
	if(charCode == 17)
	{
		alert("Control operation is not allowed");
		return false;
	}
	if(charCode == 32)
		return false;
	else
		return true;
}
function checkSpace(evt)
{
	var evt = evt?evt:window.event;
	var charCode = (evt.which)?evt.which:evt.keyCode;//	alert(charCode); 
	if(charCode == 32)
		return false;
	else
		return true;
}
function checkCharacteru(evt,id1)
{	
	evt = (evt) ? evt : window.event
	var charCode = (evt.which) ? evt.which : evt.keyCode
	if (charCode == 46 || (charCode > 47 && charCode <58))
	{
		idv = id1.value;
		if (charCode == 46 ) 
		{
			idv = id1.value;
			//alert(T)
			for(var i = 0; i < idv.length; i++) 
			{
				var val = id1.value;
				//alert(val)paatale chevulalo thene varsham
				var li=val.lastIndexOf('.');
				var val_s = val.split('.');
				var total=val.length;
				//alert(total)
				var T=total-li;
				
				if (idv.charCodeAt(i) == 46 || T != 2)
				return false;
			}
		}
		status = ""
		return true
	}
	else
	{
		return false
	}
}
function checkdates(obj,Dateid,f)
{
	var InsDate = document.getElementById(Dateid).value;
	var validDate = obj.value;
	var flag=0		
	var a1=obj.value.split("/")				
	if ((a1.length==3)) 
	{ 	
		var day = a1[0]
		var month = a1[1]				
		var year = a1[2]				
		if((day.length>0 && day.length<3) && (month.length>0 && month.length<3) && (year>1900 && year.length==4))
		{						
				v=new Date(month+"/"+day+"/"+year); 						
				if(v.getMonth() == (month-1) && v.getDate() == day)
					flag = 1
				else
					flag =0					
		}
		else
			flag =0			
	}
	else
		flag =0			
	
	if(!flag)
	{
		alert("Invalid Date")
		obj.value=''
		obj.focus();
		return false
	}

	var val = futureDateCheck(obj);	
		if(val ==false) {
			alert("Future Date not acceptable here")
			obj.value=''
			obj.focus();
			return false
		}
		from=document.frmtransaction.txt_date_tranlist
		to=document.frmtransaction.txt_to_date
		if(from.value != '' && to.value != ''){
				var x=ComDates(from,to,f);
				if(x){obj.value='';obj.focus();}else{callsubmit1();}
		}
		else
		return true
}
function ComDates(from,to,f) 
{ 
//alert(f)
	var str1 = document.frmtransaction.txt_date_tranlist.value;
	var str2 = document.frmtransaction.txt_to_date.value;
	var dt1 = parseInt(str1.substring(0,2),10); 
	var mon1 = parseInt(str1.substring(3,5),10)-1;
	var yr1 = parseInt(str1.substring(6,10),10); 
	var dt2 = parseInt(str2.substring(0,2),10); 
	var mon2 = parseInt(str2.substring(3,5),10)-1; 
	var yr2 = parseInt(str2.substring(6,10),10); 
	var date1 = new Date(yr1, mon1, dt1); 
	var date2 = new Date(yr2, mon2, dt2);	
	if(date2 < date1)
	{
	  if(f == 2)
			alert("To date should not be less than from date");
		else
			alert("From date should not be greater than to date");
		return true; 
	} 
	else 
	{ 
		return false;
	}
} 
	
