// JavaScript Functions common for all the forms.
/*
   Workfile			: JSFunctions.js
   Description		: Contains JavaScript Functions common for all the forms.

   Name and the description of the Functions used : 

   1.    gfi_CheckEmpty(field,label,tags) - Function checks whether a particular field is empty or not.
   2.    gfi_ValidateNumSpace(field,label,tags) - Function verifies whether the value entered is a number or space.
   3.    gfi_ValidateAlphaSpace(field,label) - Function to checks the field that can have only alphabets and spaces.
   4.    gfi_ValidateAlphaNumeric(field,label,tags) - Function allows only Alphabets and Numbers to be entered as the value.
   5.    gfi_ValidatePhoneNumber(field,label,tags) - Function verifies whether the value entered is a number or space.
   6.    gfi_FormatDate(field,Keycode,direction) - to add slashes dynamically for date field.
   7.    gfi_ValidateDate(field) - Function verifies whether the date is valid or not[lesser than or equal current date].
   8.    gfi_ValidateFDate(field) - Function verifies whether the date is valid or not[greater than or equal current date].
   9.    gfi_ValidateDateDiff(date1,date2) - Function to validate the 2 date fields for date differance.
   10.   gfi_ValidateEmail(field) - Function to validate Email.
   11.   gfi_ValidateNumSlash(field,label) - Function verifies whether the value entered is a number or forward slash.
   12. 	 gfi_ValidateNumDot(field,label) - Function verifies whether the value entered contains numbers and dots.
   13.   gfi_ValidateNumber(field,label,tags) - Function verifies whether the value entered contains numbers.
   14.   gfi_ValidateCombo(field,label) - Function to check atleast one option is selected.
   15.   gfi_VisibleOthers(listfield,textfield,listfieldvalue) - Function to make the textbox visible when partucular value is selected in the listbox.
   16.	 gfi_ValidateDateCombo(fromMonth,fromYear,toMonth,toYear) - Fucntion to check the date diff of the listboxes. 
   17.   gfi_fillcombo(field,startYear,endYear) - Function to fill the year in the list box.
   18.	 gf_Search(field,label) -- Function to open Search Page.
   19.   gfi_ValidateAnyDate(field) - Function verifies whether the date is valid or not[takes both future date and the past date].
   20.   gfb_ValidateCheckBox(NoRecords,ctrl,ErrorMsg)-
   21.	 gf_loadDCombo(ctrname,arrayname,value) - loads the dependent combo
   22.	 gf_selCombo(combo,selVal)-function to select a combo for a given value author : Vomc
   23.   gf_ValidateFromToDate(date1,date2) - function to verify whether From Date is less than To Date

*/

// Including the file which contains messages for all the modules.
//document.write('<script language=javascript src="TTS_Messages.js"><\/' + 'script>');

//document.write('<script language=javascript src="Includes\\'+'TTS_Messages.js"><\/' + 'script>');
//document.write('<script src="http://cmssrv/inetpub/cms_mcds_p/Includes/CMSMessages.js"><\/' + 'script>');
//document.write('<SCRIPT LANGUAGE="JavaScript" SRC="http://cmssrv/inetpub/cms_mcds_p/Includes/CMSMessages.js"><\/SCRIPT>');


//******************************************************************************
//BASIC FORM VALIDATION FUNCTIONS
//******************************************************************************

// Trim Function is the general function which is used in the other functions.
// Trim Function to elminate the spaces at the first and last of the field value.

function LTrim(Text1)
 {
 
 var i=0;  
 
 var text = Text1.value  
 
  while(text.charAt(i)==' ')
   {   
     if((i==0) && (text.length==1))
      {
       text="";
      }
     else
      {
       text=text.substring(1,text.length)       
      }               
   } 
 Text1.value=text; 
 return Text1;
 } 

function RTrim(Text1)
 {
 var i=0;   
 var text=Text1.value;
  while(text.charAt(text.length-1)==' ')
   {
    if(((text.length-1)==0) && (text.length==1))
     {
      text="";
     }
    else
     {
      text=text.substring(0,text.length-1)       
     }
   }
Text1.value=text
return Text1;
 }
 
function trim(text)
 { 
  text=RTrim(LTrim(text));  
 }

//******************************************************************************
//1


function gfi_CheckEmpty(field,label,tags) 
{
	// This function checks whether a particular field is empty or not.
	// pass the object and label to this function
	// give appropriate labels in your program
	// for eg: if your form name is frmEnqiry and your text field is txtEnq and the label as Enquiry
	// then call "CheckEmpty(frmEnquiry.txtEnq,"Enquiry")"

	var FieldValue;   // variable to store value of the object
	var FieldLength;  // variable to store length of the value
	var Onechar;      // variable to store one character from the value
	var x;
	
    trim(field);   
    
	FieldValue =field.value;  // store the value of the object to the variable
		
	if(FieldValue == "" || FieldValue == null) 
	{		
		  // if value in the field is empty or null
		  alert(label);
          // set the cursor to that field itself
            if(tags==null || tags=="")
			   { 
				 field.focus();	
			   }
			   else
			   {
			      tags+field.focus();
			   } 
		  return false;
	}
return true;
}

//******************************************************************************
//2
function gfi_ValidateNumSpace(field,label,tags) 
{
	// This function verifies whether the value entered is a number or space
	// if it is not a number it will return false
	
	var FieldValue;
	var FieldLength;
	var Onechar;

    trim(field);  
	FieldValue=field.value;
   	FieldLength=FieldValue.length;
 	Onechar=FieldValue.charAt(0);
	//to check each charecter lies in between the numbers and space.
	for(IntCount=0;IntCount<FieldLength; IntCount++)
	{
	   Onechar=FieldValue.charAt(IntCount);
	   if((Onechar<"0" || Onechar>"9") && Onechar != " ") 
		  {
		   alert(label);

		   // set the cursor to that field itself
            if(tags==null || tags=="")
			   { 
				 field.focus();	
			   }
			   else
			   {
			      tags+field.focus();
			   } 
		   return false;
	      }
	}        
 return true;
}
//**************************************************************************
//3
function gfi_ValidateAlphaSpace(field,label)
{     
	// Function to check fields that can have only alphabets and spaces
	// This won't allow you to enter special characters and numbers

	var FieldValue;         // variable to store value of the object
	var FieldLength;        // variable to store length of the value
	var Onechar;			// variable to store one character from the value

	trim(field);  
	
	
	FieldValue=field.value;			// store the value of the object to the variable
    FieldLength=FieldValue.length;  // store the length of the value to the variable
 	Onechar=FieldValue.charAt(0);	// store the first character of the value in the variable
	
	//to check each charecter lies in between the alphabets and Space.
	for(IntCount=0;IntCount<FieldLength; IntCount++) 
		{   
	       Onechar=FieldValue.charAt(IntCount);  // extract the characters one by one from the value
			//check whether the character is alphabet
			if((Onechar<"a" || Onechar>"z") && (Onechar<"A" || Onechar>"Z")) // && (Onechar!=" ")) 
			 {
		       //alert(label);
               //field.focus();	
 		       return false;
			 }
		}        
  return true;
}     

//******************************************************************************
//4
function gfi_ValidateAlphaNumeric(field,label,tags) {

	// This function allows only Alphabets and Numbers to be entered as the value

	var FieldValue;         // variable to store value of the object
	var FieldLength;        // variable to store length of the value
	var Onechar;			// variable to store one character from the value
	
	trim(field);  
	FieldValue=field.value;			// store the value of the object to the variable
   	FieldLength=FieldValue.length;  // store the length of the value to the variable
 	Onechar=FieldValue.charAt(0);	// store the first character of the value in the variable
	
	for(IntCount=0;IntCount<FieldLength; IntCount++) 
		{   
			Onechar=FieldValue.charAt(IntCount);  // extract the characters one by one from the value
	    	//check whether the character is alphabet,space or a number
     	    if((Onechar<"a" || Onechar>"z") && (Onechar<"A" || Onechar>"Z") && (Onechar < "0" || Onechar > "9") && (Onechar!=" ") && (Onechar!= "'"))
			{
				 alert(label);
				 //field.value="";
	   		   // set the cursor to that field itself
				  if(tags==null || tags=="")
				   { 
					 field.focus();	
				   }
				   else
				   {
					  tags+field.focus();
				   } 
				 return false;
			}
		}        
  return true;
}

//**************************************************************************
//5
// fuction to validaate phone number - allows numbers,(,),- and spaces only.
function gfi_ValidatePhoneNumber(field,label,tags)
{
// This function verifies whether the value entered is a number or space
// if it is not a number it will return false
	
	var FieldValue;
	var FieldLength;
	var Onechar;

    trim(field);    
	FieldValue=field.value;
   	FieldLength=FieldValue.length;
 	Onechar=FieldValue.charAt(0);
 	
   	//check whether the character is alphabet,space,-,(,) or a number
	for(IntCount=0;IntCount<FieldLength; IntCount++) {
	   Onechar=FieldValue.charAt(IntCount);
	    if((Onechar<"0" || Onechar>"9") && (Onechar != " ")&& (Onechar != "+") && (Onechar != "-") && (Onechar != "(") && (Onechar != ")")) {
				 alert(label);
	   		   // set the cursor to that field itself
				  if(tags==null || tags=="")
				   { 
					 field.focus();	
				   }
				   else
				   {
					  tags+field.focus();
				   } 
		 return false
	   }
	}        
	return true;
}

//**************************************************************************
//6
//to add slashes dynamically for date
function gfi_FormatDate(field,Keycode,direction) 
{
  if (field.value.length < 10) 
	 {
  	  if (Keycode!=9) 
		  { //tab
	  	   if(Keycode!=8 && Keycode!=46 && Keycode!=16 &&  !(Keycode>36 && Keycode<41))
			   { //if the delete, backspace, shift, are not the keys that caused the keyup event.
  			     var fieldLen = field.value.length
   			      if ((Keycode >= 48 && Keycode <= 57) || (Keycode >= 96 && Keycode <=105)) 
					 {
		   				if (fieldLen == 2 || fieldLen == 5) {
      					field.value = field.value + "/";
				     }
   			  } 
			  else 
			  {
   				if (direction == "up") 
					{
     				 if (field.value.length == 0) 
					   {
      					field.value = ""
	     			   } 
					 else 
						{
		      			field.value = field.value.substring(0,field.value.length-1)
	   				    }
    			     }
	 		 }
  			field.focus()
	  	 }
 	} 
	else 
	 {
 	   if (direction == "down") 
	   	{
	 	  parseDates(field.value)
  		}
     }
   }
}

function parseDates(DateString)
{
//-- Pass in "01/01/2000" and it returns true if it is a valid date.
	var intNdx, intLastNdx, bReturn;
	var day, month, year;

	bReturn = true;
	
	if (DateString.length==0) return bReturn;
	
	intNdx = DateString.indexOf('/', 0);
	intLastNdx = DateString.indexOf('/', (intNdx + 1));

	//Get Day, Month, and Year
	day = DateString.substr(0, intNdx);
	month= DateString.substr(intNdx + 1, (intLastNdx -intNdx - 1));
	year = DateString.substr(intLastNdx + 1,(DateString.length - intLastNdx));

//	bReturn = isDate(year, month, day);
	return bReturn;
}
//******************************************************************************
//7
//function to validate date
function gfi_ValidateDate(field,tags)
{ 
   val = field.value;
   val_Length = val.length;

	  if(val != "")
       {
         t1 = val.split("/");
         if (t1.length == 3) 
         {
          //To Check For Dot,Space,+,e,E In Date		
				for(i=0;i<val.length;i++)
				{ 
		      		  str=val.charCodeAt(i);
					   if((str == 46)||(str == 32)||(str == 45)||(str == 43)||(str == 69))
						{	  
						 alert(ERR[03])
						  if(tags==null || tags=="")
						   { 
							 field.focus();	 // set the cursor to that field itself
						   }
						   else
						   {
							  tags+field.focus();  // set the cursor to that field in its respective tab
						   } 
						 return false; 
					    }
				}
        
          //check if the date is valid
          if(t1[0] > 31 || t1[0] < 1 || t1[0]=="" ||isNaN(t1[0])==true)
		   { 
		      alert(ERR[03]);
			  if(tags==null || tags=="")
			   { 
				 field.focus();	 // set the cursor to that field itself
			   }
			   else
			   {
				  tags+field.focus();  // set the cursor to that field in its respective tab
			   } 
		     return false;
	       } 
	      //check if the Month is valid  
		  else if(t1[1] > 12 || t1[1] < 1 || t1[1]=="" || isNaN(t1[1])==true)
			 {
			   alert(ERR[03]);
			   if(tags==null || tags=="")
			   { 
				 field.focus();	 // set the cursor to that field itself
			   }
			   else
			   {
				  tags+field.focus();  // set the cursor to that field in its respective tab
			   } 
		     return false;
		   } 
	     //check if the year is valid 
		 else if( t1[2]<1900 || t1[2] >2100 ||t1[2]=="" || isNaN(t1[2])==true || t1[2].length < 2 || t1[2].length > 4 || t1[2] == 3)
		   {
		     alert(ERR[03]);
		     if(tags==null || tags=="")
			   { 
				 field.focus();	 // set the cursor to that field itself
			   }
			   else
			   {
				  tags+field.focus();  // set the cursor to that field in its respective tab
			   } 
		     return false;
		   }
		 else if ((t1[1] == 1)||(t1[1] == 3)||(t1[1] == 5)||(t1[1] == 7)||(t1[1] == 8)||(t1[1] == 10)||(t1[1] == 12))
          {
    	//Check for 31 days in the month
			if (t1[0] > 31)
			{ 
			  alert(ERR[03]);
		      if(tags==null || tags=="")
			   { 
				 field.focus();	 // set the cursor to that field itself
			   }
			   else
			   {
				  tags+field.focus();  // set the cursor to that field in its respective tab
			   } 
		      return false;
			}
          }
        else if ((t1[1] == 4)||(t1[1] == 6)||(t1[1] == 9)||(t1[1] == 11))
		{
	   //Check for 30 days in the month
		  if (t1[0] >30)
		  {
		     alert(ERR[03]);
		     if(tags==null || tags=="")
			   { 
				 field.focus();	 // set the cursor to that field itself
			   }
			   else
			   {
				  tags+field.focus();  // set the cursor to that field in its respective tab
			   } 
		     return false;
		  }
		}
		else if(t1[1] == 2)
		{
	   //check for leap year
		  if (( (t1[2] % 4 == 0) && (t1[2] % 100 !=0)) || (t1[2] % 400 == 0))
		  {
		     if (t1[0] > 29)
		     {
		       alert(ERR[03]);
		      if(tags==null || tags=="")
			   { 
				 field.focus();	 // set the cursor to that field itself
			   }
			   else
			   {
				  tags+field.focus();  // set the cursor to that field in its respective tab
			   } 
		      return false;
		     }
		  }
		  else
		  {
		    if (t1[0] > 28)
		     {
		       alert(ERR[03]);
		       if(tags==null || tags=="")
			   { 
				 field.focus();	 // set the cursor to that field itself
			   }
			   else
			   {
				  tags+field.focus();  // set the cursor to that field in its respective tab
			   } 
		       return false;
		     }
		  }
	    }

		   d=new Date();

		   d1=new Date(t1[1]+"/"+t1[0]+"/"+t1[2])
		   if(d < d1)
            {
              alert(ERR[04]); 
      	      if(tags==null || tags=="")
			   { 
				 field.focus();	 // set the cursor to that field itself
			   }
			   else
			   {
				  tags+field.focus();  // set the cursor to that field in its respective tab
			   } 
      	      return false;
		    }
                   
        }
        else
        {
		   alert(ERR[03]);
		   if(tags==null || tags=="")
			   { 
				 field.focus();	 // set the cursor to that field itself
			   }
			   else
			   {
				  tags+field.focus();  // set the cursor to that field in its respective tab
			   } 
		   return false;
		   
		}
		 
	 }
	 else 
	 {
	   return true;
	 }
	 return true;       
    }

//******************************************************************************
//8 
//Function verifies whether the date is valid or not[greater than or equal current date].

function gfi_ValidateFDate(field)
{ 
   val = field.value;
   val_Length = val.length;

	  if(val != "")
       {
         t1 = val.split("/");
         if (t1.length == 3) 
         {
          //To Check For Dot,Space,+,e,E In Date		
				for(i=0;i<val.length;i++)
				{ 
		      		  str=val.charCodeAt(i);
					   if((str == 46)||(str == 32)||(str == 45)||(str == 43)||(str == 69))
						{	  
						 alert(ERR[03])
						 field.focus();
						 return false; 
					    }
				}
        
          //check if the date is valid
          if(t1[0] > 31 || t1[0] < 1 || t1[0]=="" ||isNaN(t1[0])==true)
		   { 
		     alert(ERR[03]);
		     field.focus();
		     return false;
	       } 
	      //check if the Month is valid  
		  else if(t1[1] > 12 || t1[1] < 1 || t1[1]=="" || isNaN(t1[1])==true)
			 {
		     alert(ERR[03]);
		     field.focus();
		     return false;
		   } 
	     //check if the year is valid 
		 else if( t1[2]<1900 || t1[2] >2100 ||t1[2]=="" || isNaN(t1[2])==true || t1[2].length < 2 || t1[2].length > 4 || t1[2] == 3)
		   {
		     alert(ERR[03]);
		     field.focus();
		     return false;
		   }
		 else if ((t1[1] == 1)||(t1[1] == 3)||(t1[1] == 5)||(t1[1] == 7)||(t1[1] == 8)||(t1[1] == 10)||(t1[1] == 12))
          {
    	//Check for 31 days in the month
			if (t1[0] > 31)
			{ 
			  alert(ERR[03]);
		      field.focus();
		      return false;
			}
          }
        else if ((t1[1] == 4)||(t1[1] == 6)||(t1[1] == 9)||(t1[1] == 11))
		{
	   //Check for 30 days in the month
		  if (t1[0] >30)
		  {
		     alert(ERR[03]);
		     field.focus();
		     return false;
		  }
		}
		else if(t1[1] == 2)
		{
	   //check for leap year
		  if (( (t1[2] % 4 == 0) && (t1[2] % 100 !=0)) || (t1[2] % 400 == 0))
		  {
		     if (t1[0] > 29)
		     {
		       alert(ERR[03]);
		      field.focus();
		      return false;
		     }
		  }
		  else
		  {
		    if (t1[0] > 28)
		     {
		       alert(ERR[03]);
		       field.focus();
		       return false;
		     }
		  }
	    }
	    
	       d=new Date();
		// to separete time from the new date.
		   d2= new Date(eval(d.getMonth()+1) + "/" + d.getDate() + "/" + d.getYear())
		   d1=new Date(t1[1]+"/"+t1[0]+"/"+t1[2])
					
		   if(d1 < d2)
            {
              alert(ERR[05]); 
      	      field.focus();
      	      return false;
		    }
                   
        }
        else
        {
		   alert(ERR[03]);
		   field.focus();
		   return false;
		}
	 }
	 else 
	 {
	   return true;
	 }
	 return true;       
    }
/******************************************************************************/
//9 To validate the 2 date fields for date differance.
function gfi_ValidateDateDiff(date1,date2)
{
    var mm2,dd2,yy2;
    var mm, dd, yy;
    var intNdx, intLastNdx, bReturn;
	var yourage, months;
	
	months=0;
	yourage=0.00;
    
    //First date split 
    intNdx = date1.indexOf('/', 0);
	intLastNdx = date1.indexOf('/', (intNdx + 1));
     
    //Get Day, Month, and Year
	dd = date1.substr(0, intNdx);
	mm= date1.substr(intNdx + 1, (intLastNdx -intNdx - 1));
	yy = date1.substr(intLastNdx + 1,(date1.length - intLastNdx));
	
	//Second date split 
	intNdx = date2.indexOf('/', 0);
	intLastNdx = date2.indexOf('/', (intNdx + 1));
   
    //Get Day, Month, and Year
	dd2 = date2.substr(0, intNdx);
	mm2 = date2.substr(intNdx + 1, (intLastNdx -intNdx - 1));
	yy2 = date2.substr(intLastNdx + 1,(date2.length - intLastNdx));
	mm2=parseInt(mm2) + parseInt(1);

    if (yy2 > yy) { yourage = yy2 - yy; }
    if (mm2 < mm)  { yourage = yourage - 1; months = parseInt(12) + parseInt(mm2);}
  
    //if (mm2 == mm)  
    if (mm == months)
       { 
         months=parseInt(months) - parseInt(mm);
       }
    else 
       {   
         alert("months" + months);
         if (parseInt(months) != 0) 
         { 
			  yourage = parseInt(yourage)  + ((parseInt(months) - parseInt(mm)) / parseInt(100));          
         }         
       }
       
    agestring = yourage + " ";
    //document.write(agestring)
    return agestring 
}
/******************************************************************************/
//10 Email validation

function gfi_ValidateEmail(field,label) 
{
	var str = field.value;
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
		alert(label);
		field.focus(); 
		return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		alert(label);
		field.focus(); 
		return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		alert(label);
		field.focus(); 
		return false
	}

		if (str.indexOf(at,(lat+1))!=-1){
		alert(label);
		field.focus(); 
		return false
		}

		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		alert(label);
		field.focus(); 
		return false
		}

		if (str.indexOf(dot,(lat+2))==-1){
		alert(label);
		field.focus(); 
		return false
		}
	
		if (str.indexOf(" ")!=-1){
		alert(label);
		field.focus();
		return false
		}

 		return true					
}

//  End -->
/******************************************************************************/
//11
function gfi_ValidateNumSlash(field,label) 
{
	// This function verifies whether the value entered is a number or forward slash.
	// if it is not a number it will return false
	
	var FieldValue;
	var FieldLength;
	var Onechar;
    var IntSlash=0;
	
	trim(field);  
	FieldValue=field.value;
   	FieldLength=FieldValue.length;
 	Onechar=FieldValue.charAt(0);
	
	//to check each charecter lies in between the numbers and slash.
	for(IntCount=0;IntCount<FieldLength; IntCount++)
	{
	   Onechar=FieldValue.charAt(IntCount);
	   // to check if the number has more than three  slash.
	   if (Onechar == "/") IntSlash = IntSlash+1; 
	   if(IntSlash >3)
		   {
				alert(label);
				field.focus();     // set the cursor to that field itself
				return false;
		   }
       // to check only for numbers and slash.
	   if((Onechar<"0" || Onechar>"9") && (Onechar != "/") && (Onechar != "S")&& (Onechar != "s")&& (Onechar != "Y")&& (Onechar != "y")&& (Onechar != "C")&& (Onechar != "c") )
		  {
        	   alert(label);
    	       field.focus();	  // set the cursor to that field itself
		       return false;
	      }
  	}
	// to check whether atlest one slash exits or not.
	if ((IntSlash == "0") && (FieldLength != "0"))
	{
		alert(label);
		field.focus();	  // set the cursor to that field itself
        return false;
	}
 return true;
}
//**************************************************************************
//12
function gfi_ValidateNumDot(field,label) 
{
	// This function verifies whether the value entered contains numbers and dots.
		
	var FieldValue;
	var FieldLength;
	var Onechar;
      
    trim(field);
	FieldValue=field.value;
   	FieldLength=FieldValue.length;
 	Onechar=FieldValue.charAt(0);
	//to check each charecter lies in between the numbers and dots.
	for(IntCount=0;IntCount<FieldLength; IntCount++)
	{
	   Onechar=FieldValue.charAt(IntCount);
	   if((Onechar<"0" || Onechar>"9") && Onechar != ".") 
		  {
			   alert(label);
			   field.focus();	   		   // set the cursor to that field itself
			   return false;
	      }
	}        
 return true;
}
//**************************************************************************
//13
function gfi_ValidateNumber(field,label,tags) 
{
	// This function verifies whether the value entered contains numbers.
		
	var FieldValue;
	var FieldLength;
	var Onechar;
      
    trim(field);
	FieldValue=field.value;
   	FieldLength=FieldValue.length;
 	Onechar=FieldValue.charAt(0);
	//to check each charecter lies in between the numbers.
	for(IntCount=0;IntCount<FieldLength; IntCount++)
	{
	   Onechar=FieldValue.charAt(IntCount);
	   if((Onechar<"0" || Onechar>"9")) 
		  {
		   alert(label);
	   		   // set the cursor to that field itself
				  if(tags==null || tags=="")
				   { 
					 field.focus();	
				   }
				   else
				   {
					  tags+field.focus();
				   } 
		   return false;
	      }
	}        
 return true;
}
//**************************************************************************
//14 function to validate combo's

function gfi_ValidateCombo(field,label)
 {
   if((field.selectedIndex<=0)&& (field.options[field.selectedIndex].value<=0))
	   {
			 alert(label);
			 field.focus();      // set the cursor to that field itself
			 return false;
	   }
  else
   {
     return true;
   } 
}
//**************************************************************************
//15
//Function to make the textbox visible when partucular value is selected in the listbox.
//see the jsfunction.htm for sample code.

function gfi_VisibleOthers(listfield,textfield,listfieldvalue)
{ 
	arrListFieldValue = listfieldvalue.split(",");
	for(var i=0;i<=arrListFieldValue.length;i++)
	{
		if(listfield.options[listfield.selectedIndex].value==arrListFieldValue[i])
		{ 
			textfield.style.visibility="visible";
			break;
		}
		else
		{ 
			textfield.style.visibility="hidden";
		}
	}
}

//**************************************************************************
//16
// fucntion to check the date diff of the listboxes.

function gfi_ValidateDateCombo(fromMonth,fromYear,toMonth,toYear)
 {  
  if(fromYear.options[fromYear.selectedIndex].value == toYear.options[toYear.selectedIndex].value)
   {
    if(fromMonth.selectedIndex > toMonth.selectedIndex)
     {
      alert(ERR[48]);
      fromMonth.focus();
      return false;
     }
   }
  else if(fromYear.options[fromYear.selectedIndex].value > toYear.options[toYear.selectedIndex].value)
   {    
    alert(ERR[49]);
    fromYear.focus();    
    return false;
   } 
  else
   {
    return true;
   }
 }
//**************************************************************************
//17 
//Function to fill the year in the list box.

function gfi_fillcombo(field,startYear,endYear)
 {
  var intStart;
  var intSelIndex;
  var intIndex=0;
  var d=new Date();
  var strcurrYear=d.getFullYear();
  field.options.length=0;
  for(intStart=startYear;intStart <= endYear;intStart++)
   {
    field.options.length=(intIndex);
    field.options[field.options.length]=new Option(intStart,intStart)
    if (strcurrYear==intStart)
     {
      intSelIndex=intIndex;
     }
    intIndex++;
   }
  field.selectedIndex=intSelIndex;
 }

//**************************************************************************


//*************************************************************************************************
//18.
// Function to open Search Page.
function gf_Search(field,label)
{
	window.open("frm_CRN_SearchResult.htm","newwin","height=350,width=550,status=yes,toolbar=no,menubar=no,location=no,resize=no,fullscreen=no,scrollbars")
}
//***************************************************************************
//19
//Function verifies whether the date is valid or not[takes both future and past date].

function gfi_ValidateAnyDate(field)
{ 
   val = field.value;
   val_Length = val.length;
	  if(val != "")
       {
         t1 = val.split("/");
         if (t1.length == 3) 
         {
          //To Check For Dot,Space,+,e,E In Date		
				for(i=0;i<val.length;i++)
				{ 
		      		  str=val.charCodeAt(i);
					   if((str == 46)||(str == 32)||(str == 45)||(str == 43)||(str == 69))
						{	  
						 alert(ERR[03])
						 //field.focus();
						 return false; 
					    }
				}
        
          //check if the date is valid
          if(t1[1] > 31 || t1[1] < 1 || t1[1]=="" ||isNaN(t1[1])==true)
		   { 
		     alert(ERR[03]);
		     //field.focus();
		     return false;
	       } 
	      //check if the Month is valid  
		  else if(t1[0] > 12 || t1[0] < 1 || t1[0]=="" || isNaN(t1[0])==true)
			 {
		     alert(ERR[03]);
		     //field.focus();
		     return false;
		   } 
	     //check if the year is valid 
		 else if( t1[2]<1900 || t1[2] >2100 ||t1[2]=="" || isNaN(t1[2])==true || t1[2].length < 2 || t1[2].length > 4 || t1[2] == 3)
		   {
		     alert(ERR[03]);
		     //field.focus();
		     return false;
		   }
		 else if ((t1[0] == 1)||(t1[0] == 3)||(t1[0] == 5)||(t1[0] == 7)||(t1[0] == 8)||(t1[0] == 10)||(t1[0] == 12))
          {
    	//Check for 31 days in the month
			if (t1[1] > 31)
			{ 
			  alert(ERR[03]);
		      //field.focus();
		      return false;
			}
          }
        else if ((t1[0] == 4)||(t1[0] == 6)||(t1[0] == 9)||(t1[0] == 11))
		{
	   //Check for 30 days in the month
		  if (t1[1] >30)
		  {
		     alert(ERR[03]);
		     //field.focus();
		     return false;
		  }
		}
		else if(t1[0] == 2)
		{
	   //check for leap year
		  if (( (t1[2] % 4 == 0) && (t1[2] % 100 !=0)) || (t1[2] % 400 == 0))
		  {
		     if (t1[1] > 29)
		     {
		       alert(ERR[03]);
		      //field.focus();
		      return false;
		     }
		  }
		  else
		  {
		    if (t1[1] > 28)
		     {
		       alert(ERR[03]);
		       //field.focus();
		       return false;
		     }
		  }
	    }
        }
        else
        {
		   alert(ERR[03]);
		   //field.focus();
		   return false;
		   }
	 }
	 else 
	 {
	   return true;
	 }
	 return true;       
    }
/******************************************************************************/



function gfb_checkSpecChar(vString,tags)
 {
  var intAsciiArray=new Array(92,34,126,96,94,33)
  var inttxtIndex
  var intArrIndex
  var blnSpecChar
  var lstrString
  var intLength 
  lstrString= vString.value
  intLength =lstrString.length
  blnSpecChar=true
    
  for (inttxtIndex=0;inttxtIndex < intLength;inttxtIndex++)
   {
    for (intArrIndex=0;intArrIndex < intAsciiArray.length ;intArrIndex++)
     {
      
      if (lstrString.charCodeAt(inttxtIndex)== intAsciiArray[intArrIndex])
       {        
        alert(ERR[32])
       tags+vString.focus()                
        return false 
       } 
     }
   }
  return true
 }
 
 //**************************************************************************************
  
function gfb_ValidateCheckBox(NoRecords,ctrl,ErrorMsg)
{
	var NoRecords = NoRecords;
	var i = 0;
	var p = 0;
	if (NoRecords > 1)
	{
		for (i = 0; i < NoRecords; i++)
		{
			if(ctrl[i].checked == false)
			{
				 p = p + 1
			}
		}
	}
	else
	{
		if(ctrl.checked == false)
		{
				 p = 1
		}
	}
	if (p == NoRecords)
	{
		alert(ErrorMsg)
		return false;
	}
	else
	{
		return true;
	}	
}

 //**************************************************************************************
//function to load dependent combo , author : vomc
function gf_loadDCombo(ctrname,arrayname,value)
{
	//var len=(ctrname.length)+1;
	
	ctrname.options.length=0;
	j=0;
	var oOption = new Option();
	oOption.text = "-";
	oOption.value = 0;
	ctrname.options[j] = oOption;
	
	j = j + 1;
	
	for (i=0;i<arrayname.length;i++)
	{
		if (arrayname[i][0] == value)
	    {
			var oOption = new Option();
			oOption.text = arrayname[i][2];
			oOption.value = arrayname[i][1];
			ctrname.options[j] = oOption;
			
			j = j + 1;
			
	    }
	}
//ctrname.options[0].selected=true
}

//function to select a combo for a given value author : Vomc
function gf_selCombo(combo,selVal)
{
  	 var pComLen=combo.length;
	 for(var i=0;i<pComLen;i++)
	 {
		  if (selVal==combo.options[i].value)
		  {
			   combo.options[i].selected=true;
			   break;
		  }
	 }

}

 //**************************************************************************************
 function gfb_ValidateAlphabets(ctrlText,label) 
 {
	  var val=ctrlText.value;
	  var val_Length=ctrlText.value.length;
	  
	  for(i=0;i<val_Length;i++)
	  { 
			str=val.charCodeAt(i);
			if((isNaN(val.charAt(i)) == false) || (str>=9 && str<=38) ||(str>=40 && str<=47)|| (str>=58 && str<=64) ||(str>=91 && str<=96) || (str>122 && str<=255))
			{	  
				alert(label);
				ctrlText.focus();
				return false;
			}
	 }
	 return true;	  
}
//**********************************************
 function gfb_ValidateNumbers(ctrlText,label) 
 {
	var val=ctrlText.value;
	var val_Length=ctrlText.value.length;
	if(isNaN(val) || (val < 1))
    {
		alert(label)
		ctrlText.focus();
		return false;
	}
	for(i=0;i<val_Length;i++)
	{ 
		str=val.charCodeAt(i);
		if((str == 101)||(str == 32)||(str == 45)||(str == 43))
		{	  
			alert(label);
			ctrlText.focus();
			return false;
		}
	}
	return true;
}
//**********************************************
 function gfb_ValidateCurrency(ctrlText,label) 
 {
	var val=ctrlText.value;
	var val_Length=ctrlText.value.length;
	if (val_Length > 0)
	{
		if(isNaN(val) || (val < 0))
		{
			alert(label)
			ctrlText.focus();
			return false;
		}
	}
	else
	{
		return true;
	}	
return true;
}
//*************************************************
function gfb_chkFromDate(ctrl,check,label)
{
   
	var ctrldate=ctrl.value;
	var checkdate=check.value;

	var ctrldd,ctrlmm,ctrlyy;
	
	//splitting the first date into dd,mm,yyyy
	ctrldd=ctrldate.charAt(0)+ctrldate.charAt(1);
	ctrlmm=ctrldate.charAt(3)+ctrldate.charAt(4);
	  
	ctrlyy=ctrldate.charAt(6)+ctrldate.charAt(7)+ctrldate.charAt(8)+ctrldate.charAt(9);

	var checkdd,checkmm,checkyy;
	//splitting the second date into dd,mm,yyyy
	checkdd=checkdate.charAt(0)+checkdate.charAt(1);
	checkmm=checkdate.charAt(3)+checkdate.charAt(4);
	  
	checkyy=checkdate.charAt(6)+checkdate.charAt(7)+checkdate.charAt(8)+checkdate.charAt(9);

	if(checkyy<ctrlyy)
	{
		return true;
	}

	if(checkyy>ctrlyy)//checking whether check year is greater than ctrl year
	{
		alert(label);
		//check.value="";
	    //check.focus();
	    //check.select();
	    //ctrl.focus();
	    //ctrl.select();
	    return false;
	}
	else if(checkyy==ctrlyy)//checking year
	{
		if(checkmm>ctrlmm)//checking whether month is greater than month
		{
			alert(label);
			
			//check.value="";
			//check.focus();
			//check.select();
			//ctrl.focus();
			//ctrl.select();
			return false;
	    }

	    if(checkmm<ctrlmm)//checking whether check month is less than ctrl month 
	    {
			return true;
	    }

		if(checkmm==ctrlmm)//checking whether check month is equal to ctrl month 
		{
			if(checkdd<ctrldd)//checking whether date of purchase  is less than date of delivery
			{
				return true;
			}
			if(checkdd>ctrldd)//checking whether date of purchase  greater than date of delivery
			{
				alert(label);
				//check.value="";
				//check.focus();
				//check.select();
				//ctrl.focus();
				//ctrl.select();
				return false;
			}
			if(checkdd==ctrldd)//checking whether check date is equal to ctrl date 
			{
				return true;
			}
		}
	}
	
}
//**************************************************************************
function gfi_ValidateNumSlashAppl(field,label) 
{
	// This function verifies whether the value entered is a number or forward slash.
	// if it is not a number it will return false
	
	var FieldValue;
	var FieldLength;
	var Onechar;
    var IntSlash=0;
	
	trim(field);  
	FieldValue=field.value;
   	FieldLength=FieldValue.length;
 	Onechar=FieldValue.charAt(0);
	
	//to check each charecter lies in between the numbers and slash.
	for(IntCount=0;IntCount< 14; IntCount++)
	{
	   Onechar=FieldValue.charAt(IntCount);
	   // to check if the number has more than three  slash.
	   if (Onechar == "/") IntSlash = IntSlash+1; 
	   if(IntSlash >3)
		   {
				alert(label);
				field.focus();     // set the cursor to that field itself
				return false;
		   }
       // to check only for numbers and slash.
	   if((Onechar<"0" || Onechar>"9") && (Onechar != "/") && (Onechar != "S")&& (Onechar != "s")&& (Onechar != "Y")&& (Onechar != "y")&& (Onechar != "C")&& (Onechar != "c") )
		  {
        	   alert(label);
    	       field.focus();	  // set the cursor to that field itself
		       return false;
	      }
  	}
  	
  	for(IntCount=15;IntCount< FieldLength; IntCount++)
	{
	   Onechar=FieldValue.charAt(IntCount);
	   // to check if the number has more than three  slash.
	   
	   // to check only for numbers and slash.
	   if((Onechar<"0" || Onechar>"9") && (Onechar != "/") && (Onechar<"a" || Onechar>"z")&&(Onechar<"A" || Onechar>"Z"))
		  {
        	   alert(label);
    	       field.focus();	  // set the cursor to that field itself
		       return false;
	      }
  	}
 return true;
}
//**************************************************************************
function gf_DoPrint() {
  //save existing user's info
  var h = factory.printing.header;
  var f = factory.printing.footer;
  //hide the button
  document.all("printbtn").style.visibility = 'hidden';
  //set header and footer to blank
  factory.printing.header = "";
  factory.printing.footer = "";
  
  //factory.printing.copies ='<%=dblnoc%>'; 
   //print page without prompt
    factory.DoPrint(false);
  //restore user's info
  factory.printing.header = h;
  factory.printing.footer = f;
  //show the print button
  document.all("printbtn").style.visibility = 'visible';
}

//-----------------------------------------------------------------------------
//added by sudheer on 3/5/01
function gfb_chkMarrDate(ctrl,check,label)
{
   
	var ctrldate=ctrl.value;
	var checkdate=check.value;

	var ctrldd,ctrlmm,ctrlyy;
	//splitting the first date into dd,mm,yyyy
	ctrldd=ctrldate.charAt(0)+ctrldate.charAt(1);
	ctrlmm=ctrldate.charAt(3)+ctrldate.charAt(4);
	  
	ctrlyy=ctrldate.charAt(6)+ctrldate.charAt(7)+ctrldate.charAt(8)+ctrldate.charAt(9);

	var checkdd,checkmm,checkyy;
	//splitting the second date into dd,mm,yyyy
	checkdd=checkdate.charAt(0)+checkdate.charAt(1);
	checkmm=checkdate.charAt(3)+checkdate.charAt(4);
	  
	checkyy=checkdate.charAt(6)+checkdate.charAt(7)+checkdate.charAt(8)+checkdate.charAt(9);

	if(checkyy<ctrlyy)
	{
		return true;
	}

	if(checkyy>ctrlyy)//checking whether check year is greater than ctrl year
	{
		alert(label);
	    return false;
	}
	else if(checkyy==ctrlyy)//checking year
	{
		if(checkmm>ctrlmm)//checking whether month is greater than month
		{
			alert(label);
			return false;
	    }

	    if(checkmm<ctrlmm)//checking whether check month is less than ctrl month 
	    {
			return true;
	    }

		if(checkmm==ctrlmm)//checking whether check month is equal to ctrl month 
		{
			if(checkdd<ctrldd)//checking whether date of purchase  is less than date of delivery
			{
				return true;
			}
			if(checkdd>ctrldd)//checking whether date of purchase  greater than date of delivery
			{
				alert(label);
				return false;
			}
			if(checkdd==ctrldd)//checking whether check date is equal to ctrl date 
			{
				return true;
			}
		}
	}
}
//**************************************************************************

//Added by Sheik on 16/06/2001
//function to check the length of the characters entered in a given text area
 function gfi_checkTextAreaLength(txtACtrl,txtLength,label)
 {
	var strTxtArea= txtACtrl.value;
	if (strTxtArea.length > txtLength)
	{
		alert(label + ERR[98] + txtLength );
		txtACtrl.focus();
		return false;
	}	
	else	
		return true; 
 }
 
 //*************************************************
function gfb_chkFromDate(ctrl,check,label)
{
   
	var ctrldate=ctrl.value;
	var checkdate=check.value;

	var ctrldd,ctrlmm,ctrlyy;
	//splitting the first date into dd,mm,yyyy
	ctrldd=ctrldate.charAt(0)+ctrldate.charAt(1);
	ctrlmm=ctrldate.charAt(3)+ctrldate.charAt(4);
	  
	ctrlyy=ctrldate.charAt(6)+ctrldate.charAt(7)+ctrldate.charAt(8)+ctrldate.charAt(9);

	var checkdd,checkmm,checkyy;
	//splitting the second date into dd,mm,yyyy
	checkdd=checkdate.charAt(0)+checkdate.charAt(1);
	checkmm=checkdate.charAt(3)+checkdate.charAt(4);
	  
	checkyy=checkdate.charAt(6)+checkdate.charAt(7)+checkdate.charAt(8)+checkdate.charAt(9);

	if(checkyy<ctrlyy)
	{
		return true;
	}

	if(checkyy>ctrlyy)//checking whether check year is greater than ctrl year
	{
		alert(label);
	    //check.value="";
	    //check.focus();
	    //check.select();
	    ctrl.focus();
	    ctrl.select();
	    return false;
	}
	else if(checkyy==ctrlyy)//checking year
	{
		if(checkmm>ctrlmm)//checking whether month is greater than month
		{
			alert(label);
			//check.value="";
			//check.focus();
			//check.select();
			ctrl.focus();
			ctrl.select();
			return false;
	    }

	    if(checkmm<ctrlmm)//checking whether check month is less than ctrl month 
	    {
			return true;
	    }

		if(checkmm==ctrlmm)//checking whether check month is equal to ctrl month 
		{
			if(checkdd<ctrldd)//checking whether date of purchase  is less than date of delivery
			{
				return true;
			}
			if(checkdd>ctrldd)//checking whether date of purchase  greater than date of delivery
			{
				alert(label);
				//check.value="";
				//check.focus();
				//check.select();
				ctrl.focus();
				ctrl.select();
				return false;
			}
			if(checkdd==ctrldd)//checking whether check date is equal to ctrl date 
			{
				return true;
			}
		}
	}
}
//**************************************************************************

// Added by Anitha
 // function to verify whether From Date is less than To Date
 
function gf_ValidateFromToDate(date1,date2)
{
var text1,text2;
var d1,m1,y1;
var d2,m2,y2;
text1=date1.value;
text2=date2.value;
d1=text1.substring(0,2);
m1=text1.substring(3,5);
y1=text1.substring(6,10);

d2=text2.substring(0,2);
m2=text2.substring(3,5)
y2=text2.substring(6,10);
if (y1 > y2)
	{
	return false;
	}
else if ((y1==y2) && (m1>m2))
	{
	return false;
	}
else if((y1==y2) && (m1==m2) && (d1>d2))
	{
	return false;
	}
else
	{
		return true;
	}
}


//Author: Anitha D
//function to validate if single quote is present
function gf_CheckSingleQuote(field)
{
	var FieldValue;
	var FieldLength;
	var OneChar;
	trim(field);
	
	FieldValue=field.value;
	FieldLength=FieldValue.length;
	OneChar=FieldValue.charAt(0);
	for(IntCount=0;IntCount<FieldLength;IntCount++)
	{
		OneChar=FieldValue.charAt(IntCount);
		if (OneChar=="'")
		{
			alert(ERR[96]);
			field.focus();
			return false;
		}
	}
return true;
}
//*************************************************************************************
//Author: Anitha D
//Function to check if the check date lies between from date and to date

function gfb_chkFromToDate(ctrl1,ctrl2,check)
{
   
	var ctrl1date=ctrl1.value;
	var ctrl2date=ctrl2.value
	var checkdate=check.value;

	var ctrl1dd,ctrl1mm,ctrl1yy;
	var ctrl2dd,ctrl2mm,ctrl2yy;
	var checkdd,checkmm,checkyy;
	
	//splitting the first date into dd,mm,yyyy
	ctrl1dd=ctrl1date.charAt(0)+ctrl1date.charAt(1);
	ctrl1mm=ctrl1date.charAt(3)+ctrl1date.charAt(4);
	ctrl1yy=ctrl1date.charAt(6)+ctrl1date.charAt(7)+ctrl1date.charAt(8)+ctrl1date.charAt(9);
	
	
	//splitting the second date into dd,mm,yyyy
	ctrl2dd=ctrl2date.charAt(0)+ctrl2date.charAt(1);
	ctrl2mm=ctrl2date.charAt(3)+ctrl2date.charAt(4);
	ctrl2yy=ctrl2date.charAt(6)+ctrl2date.charAt(7)+ctrl2date.charAt(8)+ctrl2date.charAt(9);

	
	//splitting the check date into dd,mm,yyyy
	checkdd=checkdate.charAt(0)+checkdate.charAt(1);
	checkmm=checkdate.charAt(3)+checkdate.charAt(4);
	checkyy=checkdate.charAt(6)+checkdate.charAt(7)+checkdate.charAt(8)+checkdate.charAt(9);

	if((checkyy>ctrl1yy) && (checkyy<ctrl2yy))
	{
		return true;
	}

	if((checkyy<ctrl1yy) || (checkyy>ctrl2yy)) //checking whether check year is greater than ctrl year
	{
		return false;
	}
	else if((checkyy==ctrl1yy) && (checkyy==ctrl2yy)) //checking year
	{
		if((checkmm<ctrl1mm) || (checkmm>ctrl2mm)) //checking whether month is greater than month
		{
			return false;
	    }

	    if((checkmm>ctrl1mm) && (checkmm<ctrl2mm)) //checking whether check month is less than ctrl month 
	    {
			return true;
	    }

		if((checkmm==ctrl1mm) && (checkmm==ctrl2mm)) //checking whether check month is equal to ctrl month 
		{
			if((checkdd>ctrl1dd) && (checkdd<ctrl2dd))//checking whether date of purchase  is less than date of delivery
			{
				return true;
			}
			if((checkdd<ctrl1dd) || (checkdd>ctrl2dd))//checking whether date of purchase  greater than date of delivery
			{
				return false;
			}
			if((checkdd==ctrl1dd) || (checkdd==ctrl2dd))//checking whether check date is equal to ctrl date 
			{
				return true;
			}
		}
	}
	
}

//function to verify the from date is less than to date
function gf_ValidateFromToDate1(date1,date2)
{
var text1,text2;
var d1,m1,y1;
var d2,m2,y2;
text1=date1.value;
text2=date2.value;
d1=text1.substring(0,2);
m1=text1.substring(3,5);
y1=text1.substring(6,10);
d2=text2.substring(0,2);
m2=text2.substring(3,5)
y2=text2.substring(6,10);
if (y1 > y2)
	{
	return false;
	}
else if ((y1==y2) && (m1>m2))
	{
	return false;
	}
else if((y1==y2) && (m1==m2) && (d1>d2))
	{
	return false;
	}
else if((y1==y2) && (m1==m2) && (d1=d2))
	{
	return false;
	}
else
	{
		return true;
	}
}

function lf_format_date(date_val)
{
	if (window.event.keyCode!=8 && (date_val.value.length==2 || date_val.value.length==5)){date_val.value = date_val.value + "/"}
}

function gfi_CheckPasswordForSpace(field,label) 
{
	// This function verifies whether the value entered contains numbers.
		
	var FieldValue;
	var FieldValue1;
	var FieldLength;
	var FieldLength1;
	var Onechar;
    
    FieldValue1=field.value;
    FieldLength1=FieldValue1.length;
    trim(field);
	FieldValue=field.value;
   	FieldLength=FieldValue.length;
	if (FieldLength != FieldLength1)
	{
		alert(label);
		return false;
	}  	
	return true;
}
function ValidateMaxLength(txactrl,intmaxlen)
{
	//Limit number of characters entered in text area
	//by its maximumlength

	var txalen;
	txalen = Number(eval("document.forms(0)."+txactrl+".value.length"));
	if(txalen>intmaxlen)
	{
		eval("document.forms(0)."+txactrl+".value=document.forms(0)."+txactrl+".value.substring(0,"+intmaxlen+");");
	}
}

// function to validate whether the given date is in 'MM/DD/YYYY', 'DD/MM/YYYY' format 

function val_Date(ctrlText,dtFormat)
{ 
	val = ctrlText.value;
	// To Get the Format of Date
	var Date=0;
	var Month=1;
	var Year=2;
	var OrigFormat,FSplit;
	var YearLength=4;
	var isMName=false;

	OrigFormat=dtFormat;
      
	// Convert into Upper Case
	 var  Format=OrigFormat.toUpperCase();
	   

	// Split the date by / Seperated
	 var FSplit=Format.split("/");
    
 
		val_Length = val.length;
	if(val != "")
	    {
			t1 = val.split("/");
			if (t1.length == 3) 
			{
			//To Check For Dot,Space,+,e In Date		
 					for(i=0;i<val.length;i++)
 					{ 
 	      				str=val.charCodeAt(i);
 						 if((str == 46)||(str == 32)||(str == 45)||(str == 43))
	 					{	  
 							alert("Enter A Valid Date")
 							ctrlText.focus();
 							return false; 
	 				    }
 					}
 		    
			if (FSplit[0]=="DD")
			{
				Date=0;
				if ((FSplit[1]=="MM") || (FSplit[1]=="MMM"))
					{
					 Month=1;
					 Year=2;
					 
					 if (FSplit[1]=="MMM") {isMName=true;} else {isMName=false;}
					 if (FSplit[2]=="YY") {YearLength=2;}
					 else if (FSplit[2]=="YYYY") {YearLength=4;}
					 }
				if (FSplit[1]=="YY") 
					{
					Month=2;
					Year=1;
					YearLength=2
					 if (FSplit[2]=="MMM") {isMName=true;} else {isMName=false;}
					}
				if (FSplit[1]=="YYYY")
				 {
				  Month=2;
				  Year=1;
				  YearLength=4
  				 if (FSplit[2]=="MMM") {isMName=true;} else {isMName=false;}

				  }
			}
			else if ((FSplit[0]=="MM") || (FSplit[0]=="MMM"))
			{
				Month=0;
				if (FSplit[0]=="MMM") {isMName=true;} else {isMName=false;}
				if (FSplit[1]=="DD")
					 {
					  Date=1;
					  Year=2;
  	  				  if (FSplit[2]=="YY") { YearLength=2;} else {YearLength=4;}
					 }
				if (FSplit[1]=="YY") {Date=2;Year=1; YearLength=2}
				if (FSplit[1]=="YYYY") { Date=2;Year=1; YearLength=4}

			}	
			else if ((FSplit[0]=="YY") || (FSplit[0]=="YYYY"))
			{
				Year=0;
				if (FSplit[0]=="YY") { YearLength=2;} else {YearLength=4;}
				
				if (FSplit[1]=="DD")
					 { Date=1;
					   Month=2; // Month will be the third column. So check is it MM/MMM
					   if (FSplit[2]=="MM") {isMName=false;} 
					   else if (FSplit[2]=="MMM") {isMName=true;}
					 }
				if (FSplit[1]=="MM") {Date=2; Month=1;isMName=false}
				if (FSplit[1]=="MMM") { Date=2; Month=1;isMName=true}

			}	 
		 
			if (isMName) // if the Entered Value is Month Name
			{
			 
			  t1[Month]=getMonth(t1[Month]);
				 if (t1[Month]==0)
				 {
 				  alert("Enter the Correct Month (" + OrigFormat + ")");
 				  ctrlText.focus();
 				  return false;
 				} 
			}
            
			
			
			//check if the date is valid
			if(t1[Date] > 31 || t1[Date] < 1 || t1[Date]=="" ||isNaN(t1[Date])==true)
 			{ 
 			  alert("Enter the Correct Date (" + OrigFormat + ")");
 			  ctrlText.focus();
 			  return false;
			 } 

			 //check if the Month is valid  
 			else if(t1[Month] > 12 || t1[Month] < 1 || t1[Month]=="" || isNaN(t1[Month])==true)
			  {
 			   alert("Enter the Correct Month (" + OrigFormat + ")");
 			   ctrlText.focus();
 			   return false;
 			 } 
			 
			 //check if the year is valid 
 			else if( (t1[Year]<1900 && YearLength==4) || t1[Year] >2078 ||t1[Year]=="" || isNaN(t1[Year])==true || t1[Year].length < YearLength || t1[Year].length > YearLength )
 			  {
 			    alert("Enter the Correct Year (" + OrigFormat + ")");
 			    ctrlText.focus();
 			    return false;
 			  }

 			 else if ((t1[Month] == 1)||(t1[Month] == 3)||(t1[Month] == 5)||(t1[Month] == 7)||(t1[Month] == 8)||(t1[Month] == 10)||(t1[Month] == 12))
			   {
 			//Check for 31 days in the month
 				if (t1[Date] > 31)
 				{ 
 				  alert("Enter the Correct Date (" + OrigFormat + ")");
 			      ctrlText.focus();
 			      return false;
 				}
			   }
			 else if ((t1[Month] == 4)||(t1[Month] == 6)||(t1[Month] == 9)||(t1[Month] == 11))
 			{
			//Check for 30 days in the month
 			  if (t1[Date] >30)
 			  {
 			     alert("Enter the Correct Date (" + OrigFormat + ")");
 			     ctrlText.focus();
 			     return false;
 			  }
 			}
 			else if(t1[Month] == 2)
 			{
			//check for leap year
 			  if (( (t1[Year] % 4 == 0) && (t1[Year] % 100 !=0)) || (t1[Year] % 400 == 0))
 			  {
 			     if (t1[Date] > 29)
 			     {
 			       alert("Enter the Correct Date (" + OrigFormat + ")");
 			      ctrlText.focus();
 			      return false;
 			     }
 			  }
 			  else
 			  {
 			    if (t1[Date] > 28)
 			     {
 			       alert("Enter the Correct Date (" + OrigFormat + ")");
 			       ctrlText.focus();
 			       return false;
 			     }
 			  }
			 }
	    
		             
	    
	 }
		 else
		 {
 		   alert("Enter the Correct Date (" + OrigFormat +  ")");
 		   ctrlText.focus();
 		   return false;
			   
 		}
		 
  }
  else
  {
    return true;
  }
  return true;       
}

function EnterPressed()
{
	e = window.event;
	var key;
	key = e.keyCode;
	if(key == 13)
	{
		return false;
	}
}
function entsub(myform) 
{
	if (window.event && window.event.keyCode == 13)
		myform.submit();
	else
		return true;
}


//Disable right mouse click Script
//By Maximus (maximus@nsimail.com) w/ mods by DynamicDrive
//For full source code, visit http://www.dynamicdrive.com

var message="Function Disabled!";

///////////////////////////////////
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}

function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}

if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}

document.oncontextmenu=new Function("return false")
