// function fixFloat(lblName,fld)

	/** start trim function**/
	function trim(Str) {
	
		if((Str != "") && (Str.indexOf(" ",0)!=-1))	{
			var iMax = Str.length;
			var end = Str.length;
			var c;
			for(i=0;1<iMax;i++) {
				c = Str.substring(0,1);
				if (c == " "){
					Str=Str.substring(1,end);
					end = Str.length;
				}
				else
					break;
			}
			iMax = Str.length;
			end = Str.length;
			for(i=iMax;i>0;i--)	{
				c = Str.substring(end-1,end)
				if (c == " "){				
					Str=Str.substring(0,end-1);
					end = Str.length;
				}
				else
					break;
			}
		}
		return Str;
	}

		

	/**Check for Empty***/
	function isEmpty(str)
	{
		var trimmed = trim(str);
		return((trimmed==null) || (trimmed.length==0))
	}


	/***
	* Check For the special Characters..
	**/

	function check_Junk(lblName,txtName,junkType){
    
		l_value=txtName.value;

		if (junkType=='Name'){
								
					var junkchar = new Array(100);
					    junkchar[0]="~";   junkchar[1]="`";  junkchar[2]="!";  junkchar[3]="@";  junkchar[4]="#";
						junkchar[5]="$";   junkchar[6]="%";  junkchar[7]="^";  junkchar[8]="*";  junkchar[9]="_";
						junkchar[10]="+";  junkchar[11]="|"; junkchar[12]="="; junkchar[13]="\\"; junkchar[14]=":";
						junkchar[15]="\"";  junkchar[16]=";"; junkchar[17]="'"; junkchar[18]="<"; junkchar[19]=">";
						junkchar[20]="?";	junkchar[21]="1"; junkchar[22]="2"; junkchar[23]="3"; junkchar[24]="4";
						junkchar[25]="5";  junkchar[26]="6"; junkchar[27]="7"; junkchar[28]="8"; junkchar[29]="9";
						junkchar[30]="0";	
		}
		
		
		if (junkType=='SpeChar'){
								
					var junkchar = new Array(100);
					    junkchar[0]="~";   junkchar[1]="`";  junkchar[2]="!";  junkchar[3]="@";  junkchar[4]="#";
					    junkchar[5]="%";  junkchar[6]="^";  junkchar[7]="*";  
						junkchar[8]="+";  junkchar[9]="|"; junkchar[10]="="; junkchar[11]="\\"; 
						junkchar[12]="\"";  junkchar[13]=";"; junkchar[14]="<"; junkchar[15]=">";
						junkchar[16]="?";	
		}
		
		
		if (junkType=='Names'){						
					var junkchar = new Array(100);
					    junkchar[0]="~";   junkchar[1]="`";  junkchar[2]="!";  junkchar[3]="@";  junkchar[4]="#";
						junkchar[5]="$";   junkchar[6]="%";  junkchar[7]="^";  junkchar[8]="*";  junkchar[9]="_";
						junkchar[10]="+";  junkchar[11]="|"; junkchar[12]="="; junkchar[13]="\\"; junkchar[14]=":";
						junkchar[15]="\"";  junkchar[16]=";";junkchar[17]="<"; junkchar[18]=">";
						junkchar[19]="?";	junkchar[20]="1"; junkchar[21]="2"; junkchar[22]="3"; junkchar[23]="4";
						junkchar[24]="5";  junkchar[25]="6"; junkchar[26]="7"; junkchar[27]="8"; junkchar[28]="9";
						junkchar[29]="0";	
					
		}		
			
		if (junkType=='NameSearch'){					
					var junkchar = new Array(100);
					    junkchar[0]="~";   junkchar[1]="`";  junkchar[2]="!";  junkchar[3]="@";  junkchar[4]="#";
						junkchar[5]="$";   junkchar[6]="%";  junkchar[7]="^";  junkchar[8]="";  junkchar[9]="_";
						junkchar[10]="+";  junkchar[11]="|"; junkchar[12]="="; junkchar[13]="\\"; junkchar[14]=":";
						junkchar[15]="\"";  junkchar[16]=";"; junkchar[17]="'"; junkchar[18]="<"; junkchar[19]=">";
						junkchar[20]="?";
					
		}
							
		if (junkType=='Code'){		
					var junkchar = new Array(100);
					    junkchar[0]="~";   junkchar[1]="`";  junkchar[2]="!";  junkchar[3]="@";  junkchar[4]="#";
						junkchar[5]="$";   junkchar[6]="%";  junkchar[7]="^";  junkchar[8]="*";  junkchar[9]="_";
						junkchar[10]="+";  junkchar[11]="|"; junkchar[12]="="; junkchar[13]="\\"; junkchar[14]=":";
						junkchar[15]="\"";  junkchar[16]=";"; junkchar[17]="'"; junkchar[18]="<"; junkchar[19]=">";
						junkchar[20]="(";  junkchar[21]=")"; junkchar[22]="-"; junkchar[23]="{"; junkchar[24]="}";
						junkchar[25]="[";  junkchar[26]="]"; junkchar[27]=","; junkchar[28]="/";
						junkchar[29]="&";junkchar[30]="?";
						
		}
		if (junkType=='Code1'){		
					var junkchar = new Array(100);
					    junkchar[0]="~";   junkchar[1]="`";  junkchar[2]="!";  junkchar[3]="@";  junkchar[4]="#";
						junkchar[5]="$";   junkchar[6]="%";  junkchar[7]="^";  junkchar[8]="*";  junkchar[9]="_";
						junkchar[10]="+";  junkchar[11]="|"; junkchar[12]="="; junkchar[13]="\\"; junkchar[14]=":";
						junkchar[15]="\"";  junkchar[16]=";"; junkchar[17]="'"; junkchar[18]="<"; junkchar[19]=">";
						junkchar[20]="(";  junkchar[21]=")"; junkchar[22]="{"; junkchar[23]="}";
						junkchar[24]="[";  junkchar[25]="]"; junkchar[26]=","; junkchar[27]="/";
						junkchar[28]="&";junkchar[29]="?";
						
		}
		if (junkType=='Codes'){		
					var junkchar = new Array(100);
					    junkchar[0]="~";   junkchar[1]="`";  junkchar[2]="!";  junkchar[3]="@";  junkchar[4]="#";
						junkchar[5]="$";   junkchar[6]="%";  junkchar[7]="^";  junkchar[8]="*";  junkchar[9]="_";
						junkchar[10]="+";  junkchar[11]="|"; junkchar[12]="="; junkchar[13]="\\"; junkchar[14]=":";
						junkchar[15]="\"";  junkchar[16]=";";junkchar[17]="<"; junkchar[17]=">";
						junkchar[19]="(";  junkchar[20]=")"; junkchar[21]="-"; junkchar[22]="{"; junkchar[23]="}";
						junkchar[24]="[";  junkchar[25]="]"; junkchar[26]=","; junkchar[27]="/";
						junkchar[28]="&";junkchar[29]="?";
						
		}
			
		if (junkType=='CodeSearch')	{						
					var junkchar = new Array(100);
					    junkchar[0]="~";   junkchar[1]="`";  junkchar[2]="!";  junkchar[3]="@";  junkchar[4]="#";
						junkchar[5]="$";   junkchar[6]="%";  junkchar[7]="^";  junkchar[8]="_";
						junkchar[9]="+";  junkchar[10]="|"; junkchar[11]="="; junkchar[12]="\\"; junkchar[13]=":";
						junkchar[14]="\"";  junkchar[15]=";"; junkchar[16]="'"; junkchar[17]="<"; junkchar[18]=">";
						junkchar[19]="(";  junkchar[20]=")"; junkchar[21]="-"; junkchar[22]="{"; junkchar[23]="}";
						junkchar[24]="[";  junkchar[25]="]"; junkchar[26]=","; junkchar[27]="/";
						junkchar[28]="&";junkchar[29]="?";
		}
			
		if (junkType=='Email') {	
						
					var junkchar = new Array(100);
					    junkchar[0]="~";   junkchar[1]="`";  junkchar[2]="!";  junkchar[3]="";  junkchar[4]="#";
						junkchar[5]="$";   junkchar[6]="%";  junkchar[7]="^";  junkchar[8]="*";  junkchar[9]="?";
						junkchar[10]="+";  junkchar[11]="|"; junkchar[12]="="; junkchar[13]="\\"; junkchar[14]=":";
						junkchar[15]="\"";  junkchar[16]=";"; junkchar[17]="'"; junkchar[18]="<"; junkchar[19]=">";
						junkchar[20]="(";  junkchar[21]=")"; junkchar[22]="-"; junkchar[23]="{"; junkchar[24]="}";
						junkchar[25]="[";  junkchar[26]="]"; junkchar[27]=""; junkchar[28]="/";junkchar[29]=" ";
						junkchar[30]="&";				
		}
		
		if (junkType=='Tilde') {	
		var junkchar = new Array(3);
		junkchar[0]="~";   junkchar[1]="&"; junkchar[2]="'";  junkchar[3]='"';  junkchar[4]="_";
		}
									
		if (junkType=='Other'){						
					var junkchar = new Array(100);
					    junkchar[0]="~";   junkchar[1]="`";  junkchar[2]="#";  junkchar[3]="^";  junkchar[4]="|"; 
					    junkchar[5]="\"";					
		}			
		
		strtext= l_value;
		var sJunkList = "";
			
		for(i=0 ; i<junkchar.length; i++){
				if(strtext.indexOf(junkchar[i])>-1)	{
						
						if (sJunkList.length == "0"){
								sJunkList = junkchar[i];
						}
						else {
								sJunkList = sJunkList + ", "  + junkchar[i];
						}						
				}
		}  
			
		if (sJunkList != ""){
				if(junkType =='Name' || junkType =='Names') {
				//alert("if");
					status= 'No Special Character(s) or numbers like '+sJunkList+' in ' + lblName + ' field are allowed';
				}
				else {
				//if(junkType =='Email'){
				for(var j = 0;j<sJunkList.length;j++) {
				if(sJunkList.charAt(j)==" ") {
				 status= 'No Spaces are allowed in ' + lblName + ' field ';
				 break;
				}
				else {
				 status= 'No Special Character(s) like '+sJunkList+' in ' + lblName + ' field are allowed';
				 break;
				}
				}
			
					//status= 'No Special Character(s) like '+sJunkList+' in ' + lblName + ' field are allowed';
				}
				return false;
		}				
	}
	/*****************************/
	/*Validation for float values*/
	
	function fixFloat(lblName,fld) { // decimal number check/complainer 
		if(!fld.value) 
			return true; // blank fields are the domain of requireValue 
		//var val= parseDouble(fld.value);
		var val= parseFloat(fld.value);
		 // if(((fld.value - val) != 0) || isNaN(val))
		if(((fld.value - val) != 0) || isNaN(val) || val<=0.0 || val<=0) { // parse error 
			status= 'The ' + lblName + ' field must contain a non zero number.';
			return false;
		}
		fld.value= val;
		return true;
	}


function fixDate1(fld)
{ // tenacious date correction 
  if(!fld.value.length||fld.disabled) return true; // blank fields are the domain of requireValue 
  var val= fld.value;
  var dt= new Date(val.replace(/\D/g,'/'));
  if(!dt.valueOf())
  { // the date was unparseable 
    status= 'The '+fieldname(fld)+' field has the wrong date.';
    return false;
  }
  fld.value= (dt.getMonth()+1)+'/'+dt.getDate()+'/'+dt.getFullYear();
  return true;
}

var dtCh= "/";
var minYear=1900;
var maxYear=2100;
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}
function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function isCreaditCardExpDate(dtStr){
var minCrdYear=1;
var maxCrdYear=99;
//alert("prats");
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	
	var strMonth=dtStr.substring(0,pos1)
	var strYear=dtStr.substring(pos1+1)
	strYr=strYear
	
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 2; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	year=parseInt(strYr)
	if (pos1==-1 ){
		status= 'The date format should be : mm/yy';
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12){
		status= 'Please enter a valid month';
		return false;
	}

	if (strYear.length != 2 || year==0 || year<minCrdYear || year>maxCrdYear){
		status= 'Please enter a valid 2 digit year';// between "+minYear+" and "+maxYear';
		return false;
	}
	if (dtStr.indexOf(dtCh,pos1+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		status= 'Please enter a valid date';
		return false;
	}
return true;
}

function isDate(dtStr){
//alert("prats");
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		//alert("The date format should be : dd/mm/yyyy");
		status= 'The date format should be : dd/mm/yyyy';
		return false;
	}
	if (strMonth.length<1 || month<1 || month>12){
		//alert("Please enter a valid month");
		status= 'Please enter a valid month';
		return false;
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		//alert("Please enter a valid day");
		status= 'Please enter a valid day';
		return false;
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		//alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear);
		status= 'Please enter a valid 4 digit year';// between "+minYear+" and "+maxYear';
		return false;
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		//alert("Please enter a valid date");
		status= 'Please enter a valid date';
		return false;
	}
return true;
}
function fixDate(lbl,fld)
{ // tenacious date correction 
//alert("Pratima");
  if(!fld.value) return true; // blank fields are the domain of requireValue 
  var val= fld.value;
  var dt= new Date(val.replace(/\D/g,'/'));
 // alert("dt date "+dt);
  if(!dt.valueOf())
  { // the date was unparseable 
    status= 'The' + lbl + ' field has the wrong date.';
    return false;
  }
  //fld.value= (dt.getMonth()+1)+'/'+dt.getDate()+'/'+dt.getFullYear();
  return true;
}

/*VALIDATION fOR INTEGER VALUES*/

function fixInt(lblName,fld)
{ // integer check/complainer 

  if(!fld.value) return true; // blank fields are the domain of requireValue 

  val= parseInt(fld.value);
  if(fld.value.charAt(0)=='0') {
	 	status= 'The ' + lblName + ' field must not start with zero';
        return false;
	}
/* if(fld.value.length > 9) {
	 	status= 'The ' + lblName + ' field must contain only 9 digits';
        return false;
	 }*/
  if(((fld.value - val) != 0) || isNaN(val) || val <= 0)
  { // parse error 
    status= 'The ' + lblName + ' field must contain only numeric values.';
   
    return false;
  }
  fld.value= val;
  return true;
}

function fixInt1(lblName,fld)
{ // integer check/complainer 
  if(!fld.value) return true; // blank fields are the domain of requireValue 

  val= parseInt(fld.value);
  /* if(fld.value.length > 9) {
	 	status= 'The ' + lblName + ' field must contain only 9 digits';
        return false;
	 }*/
  if(((fld.value - val) != 0) || isNaN(val) || val <= 0)
  { // parse error 
    status= 'The ' + lblName + ' field must contain only numeric values.';
   
    return false;
  }
  fld.value= val;
  return true;
}

	/**
	* 	Validation function Mail address.
	***/
	
	function checkEmail(lblName,txtName)
	{
		var count =0;
		var cnt = 0;
		var dotAndUnderScore = 0;
		var atTheRate = 0;
		var dot = 0;
		var lastDot = 0;
		var firstat = 0;
		var firstdot = 0;
		l_value = txtName.value;
		len = l_value.length;
		len1 = len - 1;
		var p1 = 0, p2 = 0,lastunderscore = 0,lastat = 0;
		
		newstr= new String(l_value);
		//alert("newstr :"+newstr);
		//alert("aaaa :"+newstr.charAt(0));
  
    	if (newstr!=""){
			/******
			*		Check for every Character for Email Validation
			****/
			for (var chk = 0;chk<l_value.length;chk++) { 
				if (newstr.charAt(chk) != "." && newstr.charAt(chk) != "_")  {
					status= 'Please enter correct email in ' + lblName + ' field.';
				}else {
					dotAndUnderScore = 1;
				}
				if (newstr.charAt(chk) != ".") {
					status= 'Please enter correct email in ' + lblName + ' field.';
				}else {
					dot = 1;
				} 
				if (newstr.charAt(chk) != "@") {
					status= 'Please enter correct email in ' + lblName + ' field.';
				}else {
					atTheRate = 1;
				} 
				///////////////////////////////
				if (newstr.charAt(chk) == "@") {
				
				count = count + 1;
				
				}
				
				
			}
			
			if(count >=2) {
			
			  cnt = 0;
			  status= 'Please enter correct email in ' + lblName + ' field.';
			}
			else {
			
			cnt = 1;
			}
			
			if(newstr.lastIndexOf(".") == len1) {
			lastDot = 0;
				status= 'Please enter correct email in ' + lblName + ' field.';
			}
			else {
				lastDot = 1;
			}
			
			if((newstr.indexOf(".") == (newstr.indexOf("@")+1)) || (newstr.indexOf("@") == (newstr.indexOf(".")+1))) {
			p1 = 0;
				status= 'Please enter correct email in ' + lblName + ' field.';
			}
			else {
				p1 = 1;
			}
			
			if(newstr.lastIndexOf("@") == len1) {
			lastat = 0;
				status= 'Please enter correct email in ' + lblName + ' field.';
			}
			else {
				lastat = 1;
			}
			
			if(newstr.charAt(0) == "@") {
			//alert("Prt");
			firstat = 0;
				status= 'Please enter correct email in ' + lblName + ' field.';
			}
			else {
				firstat = 1;
			}
			
			if(newstr.charAt(0) == ".") {
			firstdot = 0;
				status= 'Please enter correct email in ' + lblName + ' field.';
			}
			else {
				firstdot = 1;
			}
			
			if(newstr.lastIndexOf("_") == len1) {
			lastunderscore = 0;
				status= 'Please enter correct email in ' + lblName + ' field.';
			}
			else {
				lastunderscore = 1;
			}
			
			if(newstr.lastIndexOf(".") < newstr.indexOf("@")) {
			p2 = 0;
				status= 'Please enter correct email in ' + lblName + ' field.';
			}
			else {
				p2 = 1;
			}
			
			//alert("dotAndUnderScore "+dotAndUnderScore+"atTheRate "+atTheRate+"dot "+dot+" cnt :"+cnt+" lastDot :"+lastDot+" p1 :"+p1+" lastat :"+lastat+" lastunderscore :"+lastunderscore+" p2 :"+p2)
			if (dotAndUnderScore == 1 && atTheRate == 1 && dot == 1 && cnt == 1 && lastDot == 1 && p1 == 1 && lastat == 1 && lastunderscore == 1 && p2 == 1 && firstdot == 1 && firstat == 1) {
			
				return true
			}else {
			
				return false;
			}
		}		
	}



	/*************
	*		Check For Telephone Number
	*************/
	function fixPhone(lblName,fld,defaultAreaCode) { 
	// tenacious phone # correction 
	var count = 0;
  	if(!fld.value) 	return true; // blank fields are the domain of requireValue 
		var val= fld.value.replace(/\D/g,'');
		var  l_value = fld.value;
		newstr= new String(l_value);
	
	  for(var chk=0;chk<l_value.length;chk++) {
	  	if(newstr.charAt(chk)=='0') {
	  	
	  	 count = count + 1;
	  
	  	}
	   }
	  
	 if(count == 10) {
	
	 status= 'The ' + lblName + ' field must contain only nonzero numeric values.';
	 return false;
	 }
	 
 		if(isNaN(fld.value)) { // parse error 
    		status= 'The ' + lblName + ' field must contain only numeric values.';
   			return false;
  		} 
		if(val.length == 10) {
		 // fld.value= '(' + val.substring(0,3) + ')' + val.substring(3,6) + '-' + val.substring(6,20);
		 	
			fld.value=   val.substring(0,3)  + val.substring(3,6) +  val.substring(6,10);
		    return true;
		}
		if(val.length < 10)	{
			status= 'The number you supplied for the ' + lblName + ' field was too short.';
		    return false;
		}
		if(val.length > 10) {
		    status= 'The number you supplied for the ' + lblName + ' field was too long.';
		    return false;
		}
		status= 'The number you supplied for the ' + lblName + ' field was wrong.';
		return false;
	}
	
	/*****
	*	Checks for the Telephone Number 	
	*****/
	function nameContains(name,str) { 
	
		if(name == str || name.toLowerCase() == str.toLowerCase()) return true;
		var nlen= name.length;
  		var slen= str.length;
  		var endat= nlen - slen;

  		// too small to fit?
  		if(nlen > str) return false;
		  		
  		if(name.toLowerCase() == name || name.toUpperCase() == name) { 
    		
    		if(name.indexOf('_') == -1) return false;
    		str= str.toLowerCase();
    		if( name.indexOf(str + '_') == 0 ||
      		name.indexOf('_' + str + '_') > -1 ||
      		name.substring(endat-1,nlen+1) == ('_' + str) )
      		return true;
  		}
  		else { // proper case name? uppercase starts new words 
    		
    		var sep= name.substring(slen,slen+1);
		    if( name.indexOf(str) == 0 && sep == sep.toUpperCase() ) return true;
		    if( name.indexOf(str.toLowerCase()) == 0 && sep == sep.toUpperCase() ) return true;
		    var sep= name.substring(endat-1,endat);
		    if( name.substring(endat,nlen+1) == str ) return true;
		    
		    // for each occurence of the word, is it followed by a non-lowercase char? 
		    
		    for(var index= name.indexOf(str); index > -1; index= name.indexOf(str,index+1)) { 
		    	endat= index+slen;
	      		sep= name.substring(endat,endat+1);
      			if(sep == sep.toUpperCase()) return true;
    		}
  		}
  		return false;
	}


	/*var message ="";
	var displayId ="";*/
	
	
	/****
	*		Empty the message	
	***/
	function emptyMessg (id) {
		document.getElementById(id).innerHTML = "";
		displayId = "";
	}
	
	
	/**
	*		Attach the FontSytle
	***/
	function fontStyle (messg) {
		messg = "<font face='Arial' size='2' color='red'>"+messg+"</font>"
		return messg;
	}
	
/**********END OF THE FILE********************/

