/*********
**	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  checkChars(obj,chars)
{
	if( obj.value.length >= chars )
	{
		alert("Entered "+obj.value.length+" characters. Maximum allowed "+chars+" charecters!");
	 	obj.focus();
		return false 
	}
	return true
}
function groupfun(cid,sel_name,msg)
{	
	alert('groupfun')
	cval = document.getElementById(cid).value;
	cname = document.getElementById(cid).name; //alert(cval);
	var obj = document.getElementsByTagName('select');
	for(i=0;i<obj.length;i++)
	{
//	alert(obj[i].name); alert(obj[i].type); alert(sel_name+'['+i+']');
//This above comment for checking all select box names and comparing required select box name's
		for(j=0;j<obj.length;j++)
		{
//	alert(obj[i].name+' * '+sel_name+'['+j+']');
//Comparing select box names
			if(obj[i].name == sel_name+'['+j+']')
			{
//	alert(obj[i].id);alert(obj[i].value);alert(cval);alert(obj[i].value+' * '+cval+' * '+obj[i].name+' * '+cname);
//Comparing values and do not comape selected select box (Focused select box)	
				if(obj[i].value == cval && obj[i].name != cname)
				{
					alert(msg);
					document.getElementById(cid).value='';
					document.getElementById(cid).focus();
					i = j = obj.length+1;
					return false;
				}
			}
		}
	}
	return true;
}

function gfuncp(obj)
{
	var cid = obj.id;
	var s_name =obj.name;
	var sel_name =s_name.split('[');
	//alert(cid+' * '+sel_name[0]+' * '+msg);
	return groupfun(cid,sel_name[0],'This CP name is already selected');
}
function gfun(obj,msg)
{
	var cid = obj.id;
	var s_name =obj.name;
	var sel_name =s_name.split('[');
	//alert(cid+' * '+sel_name[0]+' * '+msg);
	return groupfun(cid,sel_name[0],'This village is already selected');
}
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
}
// 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)
{
       // var charCode = evt.keyCode;
/*	    if(charCode !=9 && charCode !=8)
 		if ((charCode < 47 || charCode >57))
		{	
			return false
		}
			return true
*/
		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 !=47  && charCode > 31 && (charCode < 48 || charCode > 57) && (charCode !=37) && (charCode !=39)&& (charCode !=46)) {
			return false
		}
		return true
}
/*
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
}
var flcount=0; var prvtxtbox;
function checkfloat(evt,txtbox)
{
		evt = (evt) ? evt : window.event
		var charCode = (evt.which) ? evt.which : evt.keyCode
		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 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
		//alert(charCode)
		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
}

//this function is added by chary to enter names in name field
function checkname(evt,name)
{
		evt = (evt) ? evt : window.event
		var charCode = (evt.which) ? evt.which : evt.keyCode
		var val = name.value;
		var pos= val.lastIndexOf('.');
		var length=name.value.length;//alert(length);
		if(pos!=-1)
		{
			if((length-1==pos) && charCode==46 )
			return false;
		}
		if(name.value.length<1 && (charCode==46 || charCode==32))
		{
			return false;
		}
		if ( (charCode <31 || charCode>=33 ) && (charCode <= 45 || charCode >=47) && (charCode <= 64 || charCode >90) && (charCode < 97 || charCode > 122) )
		{
		return false
		}
		if(charCode !=9 && charCode !=8 && charCode !=13 && charCode!=39)
		return true
}
/*
 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 regDateCheck(obj)
	{		
		var val = futureDateCheck(obj);	
			if(val ==false) {
				alert("Future Date not acceptable here")
				return false
			}
			
		var val = validDate(obj);	
		
		if(val ==false)
			return false
		else {
			persistDate(obj);
		}
		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("/")				
		
		var val = futureDateCheck(obj);	
		if(val ==false) {
			alert("Future Date not acceptable here")
			return false
		}		
		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);
		//alert(myString)
		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;
}
// for getting the total values

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
	}   
}

	function checkFstDateLessSndDate(sDateid,eDateid,obj,durationId,msg) //this function validates Raise date and Claim date
	{			
		var checkFlag =validDate(obj,durationId);
		if(checkFlag == false) { //alert("hi");
			obj.focus();
			return false
		} else {
		if(checkFlag)
	  	 {	
		    
			//alert(sDateid);
			//alert(eDateid);
			//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);
			if(datediffvalue < 0)
			{
				if(msg)	 {
					alert(msg)
				} else {
					alert("Date of Claim settlement must be greater than Date of Claim raised");
				}
				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 chkComplaintDate(sDateid,eDateid,obj,durationId,msg) //this function validates date is > date of complaint
	{	//alert(obj.value);		
		var checkFlag =validDate(obj,durationId);
		if(checkFlag == false) { //alert("hi");
			obj.focus();
			return false
		} else {
		if(checkFlag)
	  	 {	
		//alert("hi");
		    //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);
			if(datediffvalue < 0)
			{
				if(msg)	 {
					alert(msg)
				} else {
					alert("Date should be greater than date of complaint");
				}
				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 checkDojDobDate(sDateid,eDateid,obj,durationId,msg) //this function validates Raise date and Claim date
	{	//alert(obj.value);		
		var checkFlag =validDate(obj,durationId);
		if(checkFlag == false) { //alert("hi");
			obj.focus();
			return false
		} else {
		if(checkFlag)
	  	 {	
		 //alert("hi");
		    //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);
			if(datediffvalue < 0)
			{
				if(msg)	 {
					alert(msg)
				} else {
					alert("DOB should be less than DOJ");
				}
				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
	  }
	  }
	}
	//This function allows alphabets and numeric
	function chkCharNum(evt)
	{
		evt = (evt) ? evt : window.event
		var charCode = (evt.which) ? evt.which : evt.keyCode
		//alert(charCode)
		 if ( (charCode >47 && charCode <56) || (charCode > 96 && charCode < 124) || (charCode > 64  && charCode < 91))
		 {
			return true
		 }
		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 chkFromToDate(sDateid,eDateid,obj,durationId,msg) //this function validates from date and to date
	{	//alert(obj.value);		
		var checkFlag =validDate(obj,durationId);
		if(checkFlag == false) { //alert("hi");
			obj.focus();
			return false
		} else {
		if(checkFlag)
	  	 {	
		//alert("hi");
		    //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);
			if(datediffvalue < 0)
			{
				if(msg)	 {
					alert(msg)
				} else {
					alert("To date  should be greater than From 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
	  }
	  }
	}
//Added by chary
//By using this function enterkey works like tab kay
function enterWorkAsTab(evt)
{
	if (window.event && window.event.keyCode == 13) 
	{
		window.event.keyCode = 9;
	}
}
/*Added by Chary
This function allows 'numbers','dot','tab' and 'backspace' only  */
function chkfloat(evt)
{
		evt = (evt) ? evt : window.event
		var charCode = (evt.which) ? evt.which : evt.keyCode
		//alert(charCode);
		if((charCode >=48 && charCode<=57) || (charCode==46) || (charCode==8) || (charCode==9))
			return true
		return false
}
function checknum_dot(evt)
{
	evt = (evt)?evt:window.event;
	var charCode = (evt.which)?evt.which:evt.keyCode;	//alert(charCode);
	if(charCode == 46 || (charCode >= 48 && charCode <= 57 ))
		return true;
	else
		return false;
}
function validDate(obj) // 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)) 
	{ 	
		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
	}			
	return true
}
// this function will allow numbers,alphabets,space and hyphen(-)
function checkcity2(evt)
{
		evt = (evt) ? evt : window.event
		var charCode = (evt.which) ? evt.which : evt.keyCode
		//alert(charCode)	;
 		if ((charCode >=45  && charCode <=57 && charCode !=46 && charCode !=47) ||  (charCode>=65 && charCode <=90) || (charCode >=97 && charCode <=122) || charCode ==32)
		{	
			//alert(charCode)
			return true
		}
		else
		{
			return false
		}
}

