//Loop Variables
		var i;		
		var count;
		var j=0;	
		
		//Message variable for confirming before deletion
		var strConfirmMsg="Are you sure to Delete ";
		
		//Element position to place key field
		var strElementPos=0;
		
		var objName;	// Object Name
		var objType;	// Object Type i.e text,select etc.
		
		var semi_chk;	// To know semi-colon is present or not
		var typ_chk;    // Data validation type ie. nos./chars etc.
		var len_chk;	// Length check eg. max. 10 chars etc.
		var fldName;	// Field Name
		
		var comp;		// Compulsory or not
		var tmp;		// Temporary variables
		
		// Flag variable - true/false
		var flag;		
		var rflag;	   // Radio button flag
		var cboflag;   // Combo Flag
		
		var errmsg;		// Error message
				
		var relements; // No. of objects comprising same name i.e. array of objects
		
		
		var pFormName;
		var pFieldList;
	
	errmsg = "The fields marked * is/are compulsory ";
	function checkfields(parFormName,parFieldList,blnTrim)
	{	
		var ret_val;	// Hold the Return value invoked by type_checking function
		
		//Copy the parameters passed to function to Global variables
		pFormName  = parFormName;
		pFieldList = parFieldList;
		
		j=0;
		i=0;
		
		//Extract the individual fields
		// Field List is in the form : txtname,txtamt etc.
		pFieldList = pFieldList.split(",")
		
		//Know the no. of elements present in the form
		count = document.forms[pFormName].elements.length;
		extract();
		//alert(fldName);
		
		for(i=0;i<count;i++)
		{	//Begining of for Loop
		
			//Extract the object Name for the current element
			objName= new String(document.forms[pFormName].elements[i].name);
			flag = true;
		    cboflag = false;
		    
		    // Date Validation : when fldName has check_date,
		    // invoke is_validdate() function
		    
		    if(fldName == "date_check")
		    {
				with(document.forms[pFormName])
				{	
				   //alert(" date ok");
				   flag = is_validdate(elements[comp],elements[typ_chk],elements[len_chk]);
					if(flag==false)
					{
						alert(errmsg);
						return false;
					}
				   
				}
		    }
		    
		    // If current elment matches with given field
			if(objName == fldName)
				{//Begining of Field Comparision(if1)	
					
			    	//Get the type for current object ie. text or radio etc.
					objType= new String(document.forms[pFormName].elements[i].type);
					//Increment j for the next element i.e field for validation
					j++;
				
				if(blnTrim=="")
					Trim(document.forms[pFormName].elements[i]);					
				
				if(comp=="y")
				{	//Begining of Compulsory (if2)
						
						//alert(objType + " " + fldName);
						
						//Comparision with "text" & "textarea"	
						if(objType=="text" || objType=="textarea")
						{ // Begining of if3
							//Trim(document.forms[pFormName].elements[i]);
							if(document.forms[pFormName].elements[i].value=="")
							{ // Begining of if4
							   
							   if(errmsg=="")
							   {
								errmsg="The fields marked with * is/are compulsory";
							   }
							   flag=false;
							   //break;
							   
							} //Closing of if4
						} // Closing of if3
							
						//Comparision with "select" i.e comboBox
						if(objType=="select-one")
						{ // Begining of  if5
							//alert("select "+ document.forms[pFormName].elements[i].selectedIndex);	
							//Modified on 12th July, Index for combo
						   if(document.forms[pFormName].elements[i].selectedIndex<=0)
								{ // Beg. of if6
								
									document.forms[pFormName].elements[i].selectedIndex=0;
									//errmsg="Please Choose any value ";
									flag=false;
									//break;
									
								} // Closing of if6
								
						 } // Closing of if5
							
							
						if(objType=="checkbox" || objType=="radio")
							{ //Beg. of if7
								//alert(" if7 " + objType);
								/*if(chk_radio()==false)								
									break;
								*/
									chk_radio();
							} //Closing of if7
								
						
				}   //Closing of if2
					
					//alert( " j=" + j + " Fld.List " + pFieldList.length);
		

			
			// When the Condition fails while Validation 
					if(flag==false)
					{
					//When error message is provided, display it
					if(errmsg != null)
						{
							alert(errmsg);
							document.forms[pFormName].elements[i].focus();
							return false;
						}
					}
					else
						flag=type_check(document.forms[pFormName].elements[i]);					
					if(flag==false)
					{
						return false;
					}
				
				} //Closing of if1
					
				extract();	


		} // Closing of "for" loop
		
		return true;
	} //function ends here
	
	
	
	function extract()
	{
		// For the first field check whether it is prefixed 
		// with typ_chk and
		
		//When loop count does not exceed total no. of fields passed
		if(eval(j)>=eval(pFieldList.length))
		{
			return;
		}
		semi_chk = pFieldList[j].indexOf(";")
		//When array is created with more than 1 element
		if(semi_chk>=0)
		{
			tmp = pFieldList[j].split(";")
			
			fldName = tmp[0];
			
			if(tmp.length==4)
			{
				comp    = tmp[1];
				typ_chk = tmp[2];
				len_chk = tmp[3];
			
			}
			else if(tmp.length==3)
			 {
				comp    = tmp[1];
				typ_chk = tmp[2];
				len_chk = 0;
			 }
			else
			 {			
				comp = tmp[1];
				typ_chk="";
				len_chk=0;
			 }
					
	     }
		 else
		    fldName = pFieldList[j]
	
	}
	
	function chk_radio()
	{
		var first_elm_chk;
		var k;
		
		//alert(" rad. func. called ");
				
		relements=document.forms[pFormName].elements[fldName].length;
		
		
		if (relements==null)
			errmsg = "Please select the "
		else if(eval(relements)>1)
			{
			errmsg = "Please Choose any one of the ";
			//i+=eval(relements);
			}
	
		if(objType=="radio")
			errmsg = errmsg + " radio button "
		else if(objType=="checkbox")
			errmsg = errmsg + " checkbox "
		
		//alert("function radio called " +relements) ;		
			
		if (relements==null)
			{
				if(document.forms[pFormName].elements[fldName].checked==false)
				{
					flag=false;
					return false;
				} 
				else
				{
				flag=true;
				return true;
				}
				
			}
			
		
		first_elm_chk =document.forms[pFormName].elements[fldName][0].checked;
		
		if(first_elm_chk==true)
			{
				flag=true;
				return true;
			}
		
		for(k=1;k<relements;k++)
			{
				if(document.forms[pFormName].elements[fldName][k].checked==true)
				{
					flag=true;
					return true;
				}
			}
			
		flag=false;
		return false;
	}
	

function type_check(mObj)
{
  var fMsg;
  var ret_val;
  ret_val=true;
  	//alert(mObj.name);
	if(typ_chk=="allow_num")
	{
		ret_val=chkNumbers(mObj);
		fMsg = "Enter Nos. Only ";
	}
	
	if(typ_chk=="allow_cur")
	{
		if(isNaN(mObj.value))
			ret_val=false;
		else
		    ret_val=true;
		fMsg = "Enter Nos. with Decimal ";
	}
	
	if(typ_chk=="allow_char")
	{
		ret_val = is_special(mObj,0);
		fMsg = " Special Characters are not allowed.\nPlease type a-z,A-Z,0-9,/-_ ";
	}
	
	if(typ_chk=="date_check")
	{
		ret_val = is_date(mObj,comp);
		fMsg = "";
	}
		
	if(ret_val==false)
		{
		  if(fMsg.length>0)	
			alert(fMsg);
			mObj.focus();
			mObj.select();
			return false;
		}
	
	if(len_chk>0)
		{
			var sLen = new String(mObj.value);
			if(sLen.length > len_chk)
			{
				alert("Cannot exceed " + len_chk + " characters ");
				mObj.focus();
				mObj.select();
				return false;
			}
		}						
}
					

function is_validdate(dd,mm,yy)
{
  //Get the values from (Day,Month & Year) Combo box
  var day  = new String(dd.value);
  var mon  = new String(mm.value);
  var year = new String(yy.value);
  
  
  //To know whether the starting item is choosable flag i.e --Choose--
  var topFlag=false;
  
  errmsg = " Invalid Date ! \nPlease Choose valid date ";
  if(dd.length==32 && dd.value=="")
	topFlag=true;
  
  /* *********************************************************************** */ 
  // when the index is 0  
  if(topFlag==true)
	{				
		// Check for Day
		if(dd.selectedIndex==0)
		{
			//alert("Please Choose Day ");
			return false;
		}
		
		// Check for Month
		if(mm.selectedIndex==0)
		{
			//alert("Please Choose Month ");
			return false;
		}
		
		// Check for Year
		if(yy.selectedIndex==0 && yy.value=="")
		{
			//alert("Please Choose Year ");
			return false;
		}
	}
/* *************************************************************************/

//	Check for Months : Feb,Apr,Jun,Sep,Nov
//  These months do not have 31 days
//  Check whether user has selected 31 Days and any one of the above month
/* **************************************************************************/

	//Convert the month to Lower Case
	mon = mon.toLowerCase()
	
	if((mon == "feb" || mon == "apr" || mon == "jun" || mon == "sep" || mon == "nov") && day == 31)
	{
		//alert("The month  " + "'" + mon.toUpperCase() + "'" + " does not have 31 Days ");
		errmsg=("The month  " + "'" + mon.toUpperCase() + "'" + " does not have 31 Days ");
		mm.focus();
		return false;
	}
	
//  Check for Febr. month
	if(mon=="feb" && day==30)
	{
		errmsg = " The month '" + mon.toUpperCase() + "' does not have 30 Days ";
		mm.focus();
		return false;
	}

// Check Whether it is Leap Year or not
	if(year%4 !=0 && day==29 & mon=="feb")
	{
		errmsg = " The year " + year + " is not a Leap Year ";
		return false;
	}

}

//Submitting the form exclusively by Hyperlink
// Data is String delimeted by pipes(|)
// eg. strData mey be a|b|c
function submitdata(objForm,strData)
	{
	var s = new String(strData);
	var arrStr;
	var i=0;
	arrStr=s.split("|");
	for(i=0;i<arrStr.length;i++)
		{
		objForm.elements[i].value=arrStr[i];
		}
	}

// *********************************************

// The below function is used to delete the record, after confirming
function confirm_delete(objForm)
	{
	var ok;
	var objVal=confirm_delete.arguments[1];
		
	ok=confirm( strConfirmMsg + "'"+objVal +"'");
	if(ok==true)
	{
		//place the keyfield inside first field
		objForm.elements[strElementPos].value=objVal;
		//Place the "del" value inside hidden field
		
		
		//Modified : For Master i.e key fld, not reqd.
		//  Composite Key requires two elements
		if(confirm_delete.arguments.length==3)
		 {
		  var k;
		  k=confirm_delete.arguments[1];
		  objForm.elements[1].value=k;
		 }
		objForm.d.value="del";
		objForm.s.value="del";		
		objForm.submit();
	}
	}
	
// *********************************************
	
function any_one_compulsory()
{

}

function Trim(item)
{
  var tmp = "";
  var item_length = item.value.length;
  var item_length_minus_1 = item.value.length - 1;
  for (index = 0; index < item_length; index++)
  {
    if (item.value.charAt(index) != ' ')
    {
      tmp += item.value.charAt(index);
    }
    else
    {
      if (tmp.length > 0)
      {
        if (item.value.charAt(index+1) != ' ' && index != item_length_minus_1)
        {
          tmp += item.value.charAt(index);
        }
      }
    }
  }
  item.value = tmp;
}

// Usage: Ex: chkNumbers(document.form.name)
function chkNumbers(w1)
{   
    w=w1.value   
    var str1="0123456789"
    var i        
    var len=w.length
    for(i=0;i<len;i++)
    {
	if(str1.indexOf(w.substring(i,i+1))==-1)
        {
	    return false;
        }
    }
	w=w1.value*1
	return true
}

// Usage: Ex: chkCurrency(document.form.name)
function chkCurrency(w1)
{
	if(w1.value.length==1)
	  if(w1.value.charAt(0)==".")								// start of if
           	{
			return false
		}											// end of if
    //alert("round value : "+Math.round(w1.value));
	s="0123456789.";
	count = 0;
	val = 0;
	for(i=0;i<w1.value.length;i++)								// start of for loop
	{
		n=w1.value.charAt(i);
		if(n==".")
		count = count +1;

		if(s.indexOf(n)==-1)								// start of if
		{
				val = 1;
				break;

		}										// end of if 
        }												// end of for loop
	
	if( val==1 || count>1 )									// start of if
	{
		return false			
	}												// end of if		
	else
	return true
}

// Usage: Ex: is_special(document.form.name)
function is_special(w1,opt)
{
    w=w1.value   
    var str1="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ .-_()*\/&,"
    var i        
    var len=w.length
    flag=true;
    
    if(opt==0)
    {
	if(len>0)
	{
	
    	for(i=0;i<len;i++)
	{
	//alert(w.substring(i,i+1).charCodeAt(0))
	if(w.substring(i,i+1).charCodeAt(0)!=13 && w.substring(i,i+1).charCodeAt(0)!=10)
	{
		if(str1.indexOf(w.substring(i,i+1))==-1)
	        {
		    return false
      	  }
		  else
		  {
			flag=false;
		  }	
	}	  
	}
	}
	
	flag=false;	
    }	
    else
    {	
		var cntchar=0;
    	for(i=0;i<len;i++)
	{
		if(str1.indexOf(w.substring(i,i+1))==-1 )
	        {
		    return false
      	  }
		  else
		  {
			cntchar=cntchar+1;	
		  }	
	
	}

    }	

	if(flag==true)
	{
		if(cntchar<0)
		return false;
	}


   return true
}


//Unused Function
function voidfun()
{
//Dummy function
}

//Clearing the elements

function allclear(objForm)
{
var iCount=objForm.elements.length;
var iLoop;
var objType;
	
	for(iLoop =0 ;iLoop<iCount;iLoop++)
	{
	  objType=objForm.elements[iLoop].type;
	 
		if(objType=="text" || objType=="textarea")
		{
			objForm.elements[iLoop].value="";
		}	
		else if(objType=="select-one")
		{
			objForm.elements[iLoop].selectedIndex=0;
		}
		else if(objType=="radio" || objType=="checkbox")
		{
			objForm.elements[iLoop].checked=false;
		}
	
	}

}

//Function for placing object's focus
//Parameter "elementpos" is of integer type
//eg. setfocus(0)

// Modified on 25th Nov. 
// Purpose : Disabled Objects does not focus
function setfocus(objForm,elementpos)
{
   if(window.event.keyCode==13)
   {
	  if(objForm.elements[elementpos].disabled==true)
	  {
		objForm.elements[elementpos+1].focus();
		window.event.keyCode=0;
	  }
	  else
	  {
		objForm.elements[elementpos].focus();
		window.event.keyCode=0;
	  }
	  //alert("ok");
    }
}

// Added on 26th Nov. 
// Purpose : Except Enter, all the keys are disabled
function setfocusD(objForm,elementpos)
{
   if(window.event.keyCode==13)
   {
	  if(objForm.elements[elementpos].disabled==true)
	  {
		objForm.elements[elementpos+1].focus();
		window.event.keyCode=0;
	  }
	  else
	  {
		objForm.elements[elementpos+1].focus();
		window.event.keyCode=0;
	  }
    }
    else
    {
		objForm.elements[elementpos].value="";
		window.event.keyCode=0;
	}
}

function is_date(objDate,strComp)
 {
	//Date Variable, get the Value from Object
	var strDate = new String(objDate.value);
	//Change the Delimeter i.e. / Or - 
	var strDateDelimeter = "/";
	// No. of Delimeter found
	var countDelimeter = 0;
	
	//Loop Variable
	var i = 0;
	var j = 0;
	
	//Flag variables
	var flgDay   = false;
	var flgMonth = false;
	
	var flgMonthFormat = -1;
	
	var curYear ;
		
	//Array for Holding Day for Months
	var arrDays    = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
	//String Array for Months
	var arrSMonths = new Array("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec"); 
	var arrIMonths = new Array(1,2,3,4,5,6,7,8,9,10,11,12);
	
	var arrValues;
	var cntNoDays;
			
	//When Compulsory
	if(strComp=="y")
	{
		if(strDate=="")
		{
			alert("Date is Compulsory ");
			objDate.select();
			objDate.focus();
			return false;
		}
	}
	
	//When Date Exists
	if(strDate != "")
	{
		//Split the Date into Parts i.e day,month and year
		arrValues = strDate.split(strDateDelimeter);
	
		if(arrValues.length == 1)
		{
			strDateDelimeter = "-";
			arrValues = strDate.split(strDateDelimeter);
		}	
	
		if(arrValues.length!=3)
		{
			alert("Invalid Date ");
			objDate.select();
			objDate.focus();
			return false;
		}
	
		//Check for Year
		if(arrValues[2].length==2 || arrValues[2].length==4)
		{
			flgDay=false;
			for(i=0;i<arrValues[2].length;i++)
			{
				if(arrValues[2].substring(i,1)>="0" && arrValues[2].substring(i,1)<="9")
				{
					flgDay = true;
				}
			}
				
			if(flgDay==false)
			{
				objDate.select();
				alert("Invalid Year ");
				objDate.focus();
				return false;	
			}	
		}
		else
		{
				alert("Invalid Year ");
				objDate.select();
				objDate.focus();
				return false;	
		}
	
		//Two Digited Year
		//Turn On Century
		if(arrValues[2].length==2)
		{  
		  if (arrValues[2]<50)
			curYear = "20" + arrValues[2];
		  else
		     curYear="19"+arrValues[2];
		}     
	
		else
		  curYear = arrValues[2];

		if(curYear > new Date().getFullYear())
		{
			alert("Year cannot exceed " + new Date().getFullYear());
			objDate.focus();
			objDate.select();
			return false;
		}
		//Check the Month
		//Ensure that given month lies between 1 and 12
		//	alert(arrValues[1]);
	
		for(i=0;i<arrIMonths.length;i++)
		{
			if(parseInt(arrValues[1])==parseInt(arrIMonths[i]))
			{
				flgMonth  = true;
				cntNoDays = arrDays[i];			
				flgMonthFormat = i;
				if(curYear%4==0 || curYear%100==0)
					cntNoDays++;
						
				break;	
			}
		}
	
		//Probably  Check, whether user has type 3-char date i.e jan etc.
		if(flgMonth==false)
		{
			for(i=0;i<arrIMonths.length;i++)
			{
				if(arrValues[1].toLowerCase()==arrSMonths[i])
				{
					flgMonth  = true;
					cntNoDays = arrDays[i];			
					if(curYear%4==0 || curYear%100==0)
						cntNoDays++;
							
					break;	
				}
			}
		}
	
		if(flgMonth==false)
		{
			alert("Invalid Month ");
			objDate.focus();
			objDate.select();
			return false;
		}
	
		//Check for Valid No. of Days for the specified month
		if(arrValues[0].length>2)
		{
			alert("Invalid Day ");
			objDate.focus();
			objDate.select();
			return false;
		}
	
		flgDay=false;
		for(i=0;i<arrValues[0].length;i++)
		{
			if(arrValues[0].substring(i,1)>="0" && arrValues[0].substring(i,1)<="9")
			{
				flgDay = true;
			}
		}
	
		if((flgDay==false) || parseInt(arrValues[0]) > cntNoDays)
		{
			alert("Invalid No. of Days ");
			objDate.focus();
			return false;
		}
	
		if(flgMonthFormat>=0)
			arrValues[1] = arrSMonths[flgMonthFormat];
				
		objDate.value= arrValues.join("/");
	
	}
 }

function CompareDates(oDate1,oDate2)
	{
		var pDate1 = oDate1.value;
		var pDate2 = oDate2.value;
		
		var vD1 = new String(pDate1);
		var vD2 = new String(pDate2);
		
		var flgDGt = false;
		var flgMGt = false;
		var flgYGt = false;
		
		var monPos1 = 0;
		var monPos2 = 0;
				
		var arrD1 = vD1.split("/");
		var arrD2 = vD2.split("/");
		
		var pD1 = arrD1[0];
		var pM1 = arrD1[1];
		var pY1 = arrD1[2];
		
		var pD2 = arrD2[0];
		var pM2 = arrD2[1];
		var pY2 = arrD2[2];
		
		var i;
		
		var monArr = new Array("JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP","OCT","NOV","DEC");
		
		if (parseInt(pY1) < parseInt(pY2))			return true;
		if (parseInt(pY1) > parseInt(pY2)) 
		{
			alert("Year1 Exceeds Year2");
			oDate1.focus();
			oDate1.select();
			return false;
		}
		
		monPos1 = 0;		
		//alert(pM1.toUpperCase()+" "+pM2.toUpperCase());
		for(i=0;i<=11;i++)
		  {
			if(pM1.toUpperCase() == monArr[i])
				{
				 	monPos1 = i+1;
					break;
				}
		  }					
		
		monPos2 = 0;		
		for(i=0;i<=11;i++)
		  {
			if(pM2.toUpperCase() == monArr[i])
				{
					monPos2 = i+1;
					break;
				}
		  }					
		
		//alert (monPos1+' ' +monPos2);
		if (parseInt(monPos1)<parseInt(monPos2)) 			return true;
		if (parseInt(monPos1)>parseInt(monPos2)) 			
		{
			alert("Month11 Exceeds Month2 "+ monPos1+" "+monPos2);
			oDate1.focus();
			oDate1.select();
			return false;
		}
		
		if(parseInt(pD1) <= parseInt(pD2)) 		
			return true;
		else
		{
			alert("Day1 Exceeds Day2");
			oDate1.focus();
			oDate1.select();
			return false;
		}
	}


function echeck(str) {

		var at="@"
		var dot="."
		var lat=str.indexOf(at)
		var lstr=str.length
		var ldot=str.indexOf(dot)
		if (str.indexOf(at)==-1){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("Invalid E-mail ID")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("Invalid E-mail ID")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("Invalid E-mail ID")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("Invalid E-mail ID")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("Invalid E-mail ID")
		    return false
		 }

 		 return true					
	}

