function Validate()
{ 
   if(
	
	IsValidEntry("title",1,30,"","Please select your initials") &&
	IsValidEntry("name",1,40,"ABCDEFGHIJKLMNOPQRSTUVWXYZ.,-() ","Please specify your  Name") &&  
	IsValidEntry("ddn",1,2,"","Please select date of birth ") &&
	IsValidEntry("mmn",1,3,"","Please select Month of birth") && 
	IsValidEntry("yyn",1,4,"","Please select year of birth") &&
	
	
	IsValidEntry("hdeg",2,30,"ABCDEFGHIJKLMNOPQRSTUVWXYZ/.,-()  ","Please specify your Degree") &&
	IsValidEntry("emp_status",1,30,"","Please select your employement status") &&
	IsValidEntry("desig",1,6,"ABCDEFGHIJKLMNOPQRSTUVWXYZ/.,-()  ","Please specify your Designation") && 
	IsValidEntry("oaffi",1,40,"","Please specify Organization Affiliation") && 
	IsValidEntry("institute",1,40,"ABCDEFGHIJKLMNOPQRSTUVWXYZ/.,-() ","Please specify the Institue Name ") &&
	IsValidEntry("pay",1,9,"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-, ","Please specify scale of pay ") &&
	IsValidEntry("rph",1,15,"0123456789","Please specify Residence phone number with STD code ") &&
	IsValidEntry("hadd",1,30,"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/-.,-()  ","Please specify the Residential Address.") &&
	
	IsValidEntry("hcity",1,30,"ABCDEFGHIJKLMNOPQRSTUVWXYZ.,-()  ","Please specify the Residential City ") &&
	IsValidEntry("hstate",1,30,"ABCDEFGHIJKLMNOPQRSTUVWXYZ.,-()  ","Please specify the State") &&
	IsValidEntry("hpin",6,6,"1234567890","Please specify the PinCode ") &&
	IsValidEntry("ms1",3,30,"","Please specify the Major Specialization  ") && 
	IsValidEntry("os1",3,50,"","Please specify other area of specialization") 
)
        return true;
    else
        return false;
   
}

function IsValidEntry(strFieldName, intMinLen, intMaxLen, strValidChars, Message)
{
  var obj;
  switch (strFieldName)
  {
    
	case "title": { obj=document.form1.title; break; }
	case "name": { obj=document.form1.name; break; }
	
    case "ddn": { obj=document.form1.ddn; break; }
    case "mmn": { obj=document.form1.mmn; break; }
    case "yyn": { obj=document.form1.yyn; break; }
    case "hdeg": { obj=document.form1.hdeg; break; }
    case "emp_status": { obj=document.form1.emp_status; break; }    
    case "desig": { obj=document.form1.desig; break; }
    case "oaffi": { obj=document.form1.oaffi;break; }
    case "institute": { obj=document.form1.institute; break; }
    case "pay": { obj=document.form1.pay; break; }
    case "rph": { obj=document.form1.rph; break; }
    case "hadd": { obj=document.form1.hadd; break; }
    case "hcity": { obj=document.form1.hcity; break; }
    case "hstate": { obj=document.form1.hstate; break; }   
	case "hpin": { obj=document.form1.hpin; break; }   
	case "ms1": { obj=document.form1.ms1; break; }   
    case "os1": { obj=document.form1.os1; break; }    
    
	default: {alert('Error-Visit The site for more Details.');
	return true;}
  }
   // if ValidChars is Empty string than any input can be taken  
  
  if (document.forms['form1'].elements[strFieldName])
      {
        if(obj.value == ""||obj.value =="Select") 
	       {
		      alert(Message +".");
		      obj.focus();
		      return false;
           }
       var strChars;
       if (strValidChars == "0123456789") 
          {
	       strChars = " digits."; }
       else
           { 
    	   strChars = " characters.";
    	   }
	
	      ReturnString = removeSpaces(obj.value);
	      obj.value = ReturnString;
	      str = obj.value;
	      strInputWithUcase = str.toUpperCase();
    
      if(ReturnString.length == 0 && intMinLen != 0)
        {
		      alert(Message +".");
		      obj.focus();
              return false;
         }  
     	//Checking for min len when min len = max len
      if(ReturnString.length < intMinLen && intMinLen == intMaxLen)
         {
		      alert(Message + " in " + intMinLen + strChars);
		      obj.focus();
		      obj.select();      
		      return false;
          }  

        //   checking for minlen
      if(ReturnString.length < intMinLen)
         {
		      alert(Message + " in atleast " + intMinLen + strChars);
		      obj.focus();
		      obj.select();      
		      return false;
           }  
      
         //   checking for maxlen
   
  /* if(obj.value.length > intMaxLen)
          {
		      alert(Message + " in not more than " + intMaxLen + strChars);
		      obj.focus();
		      obj.select();      
		      return false;
           }*/
    
       // if ValidChars is Empty string than any input can be taken  
       if(strValidChars == "") 
           {
              return true;
           }
     //  checking for invalid characters 
       for (i = 0; i < obj.value.length; i++) 
           {          
    	   // Searching through string
           var c = strInputWithUcase.charAt(i);
           if (strInputWithUcase.charCodeAt(i) != 13 && strInputWithUcase.charCodeAt(i) != 10) 
              {
                if (strValidChars.indexOf(c) == -1)
                    {
				          alert(Message + " correctly (Invalid Character: " + c + ").");
				          obj.focus();
				          obj.select();      
				          return false;
                     }  
               }
            }
     }
   return true;  
  }


////


 


////
  // fn is required with IsValidEntry
  function removeSpaces(string) 
       {
		  var temp;
		  temp = string;

		  while((temp.charCodeAt(0) == 13 || temp.charCodeAt(0) == 10 || temp.charCodeAt(0) == 32))
		        {
			     temp = temp.substring(1, temp.length);
		         }
		  if (temp.charAt(0)  == ' ' || temp.charCodeAt(0) == 13 || temp.charCodeAt(0) == 10)
		       {
		         temp = temp.substring(1, temp.length);
		       }
		  if (temp.charAt(temp.length - 1)  == ' ' || temp.charCodeAt(temp.length-1) == 13 || temp.charCodeAt(temp.length-1) == 10)
		      {
		        temp = temp.substring(0, temp.length - 1);
		      }
		   return temp;
        }

  
  //---------------------
  
   
 
function removeAllOptions(selectbox)
{
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)
	{
		//selectbox.options.remove(i);
		selectbox.remove(i);
	}
}


function addOption(selectbox, value, text )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;

	selectbox.options.add(optn);
}

//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////


