// PLEASE REFER THE TEST.HTM FILE 
// function for validating whether the value is not null..For all the fields call this function only once.
// set the id also with the name in the input tag of the field.
// Ex <input type="text" name="fieldname" id="First Name" >
// the input parameter has to be the  fieldname(s) .... 
// Ex .. value= document.formname.fieldname(,document.formname.fieldname1,document.formname.fieldname2)

function fnvalidatenull(name)
{
  for(i=0;i <fnvalidatenull.arguments.length;i++)
  {
      name= fnvalidatenull.arguments[i] ;
	if( (name.value=="") || (name.value.length< 1))
	{  
		 alert(name.id+" has to be filled");
		 name.focus();
		 return false;
    }
  }  
}

// function for validating whether the value is not null..For all the fields call this function only once.
// the input parameter has to be the  field name(s).... 
// Ex .. value= document.formname.fieldname,document.formname.fieldname,

function fnvalidateidnull(name)
{
  for(i=0;i <fnvalidateidnull.arguments.length;i++)
  {
      name= fnvalidateidnull.arguments[i] ;
	if( (name.value=="") || (name.value.length< 1))
	{  
		 alert(name.id+" has to be filled");		 
		 return false;
    }
  }  
}

// function for validating whether the value is a corrrect date  or not ... 
// the input parameter has to be the  field name(s).... 
// Ex .. value= document.formname.fieldname,document.formname.fieldname,


function fnvalidatedate(value)
{
  
 for(i=0;i<fnvalidatedate.arguments.length;i++)
  {
    indatefieldtext= fnvalidatedate.arguments[i];
    indatefield=indatefieldtext.value;
	if (indatefield.indexOf("-")!=-1)
	{
		var sdate = indatefield.split("-");
	}
	else
	{  
		var sdate = indatefield.split("/");
	}
	var cmpDate;
	var chkDate=new Date(Date.parse(indatefield))
	
	var cmpDate1=(chkDate.getMonth()+1)+"/"+(chkDate.getDate())+"/"+(chkDate.getFullYear());
	var cmpDate2=(chkDate.getMonth()+1)+"/"+(chkDate.getDate())+"/"+(chkDate.getYear());
	var indate2=(Math.abs(sdate[0]))+"/"+(Math.abs(sdate[1]))+"/"+(Math.abs(sdate[2]));
	var num=sdate[2];
	var num1=num+"8";

	var num2=num1.length 
    if(num2==3)
    {
        cmpDate=cmpDate2;
    }
    if(num2==5)
    {  
        cmpDate=cmpDate1;
    }
    if(indate2!=cmpDate)
	{
		alert("Invalid date or date format on field "+indatefieldtext.id);
		indatefieldtext.focus();
		return false;
	}
	else 
	{
		if (cmpDate=="NaN/NaN/NaN")
		{
			alert("Invalid date or date format on field "+indatefieldtext.id);
			indatefieldtext.focus();
			return false;
		}
	}
 }
 
}	
	
// function for resetting  the form
// To reset the form values

function fnreset(formname,actiontaken)
{
    x=eval('document.'+ formname)
    x.action=actiontaken;
    x.reset();
    return false;
}

function fndelete(formname,actiontaken)
{
	
	 a = confirm("Do You Really Want to Delete")
	 if(a==true ) 
	  {
		x=eval('document.'+ formname)
		//a = "'"+actiontaken+"'";
		x.action=actiontaken;
		x.submit();
		// alert(a);
		return true;
	 }	
}

  
// function for submitting the form
// Ex .. formname=formname... and actiontaken = the Full path of the Asp/html file where we r submitting the form


  
function fnsubmit(formname,actiontaken)
{
	
     x=eval('document.'+ formname)
     //a = "'"+actiontaken+"'";
     x.action=actiontaken;
     x.submit();
    // alert(a);
    return false;
}


// function for validating whether the value is a corrrect email id  or not ... 
// the input parameter has to be the the field name(s).... 
// Ex .. value= document.formname.fieldname


function fnvalidateemail(valmail)
{

  for(i=0;i<fnvalidateemail.arguments.length;i++)
   {
    valmailtext= fnvalidateemail.arguments[i];
    valmail=valmailtext.value;
    if( (valmail!="") || (valmail.length > 0 ))
    {
	var n,atCount,dotCount,temp_1,temp_2,temp_ascii;
	var temp_3=0;
	atCount=0;
	dotCount=0;
	n=0;
	var st=new String;
	st = valmail.split(" ");
	st = st.join("");
	st = st.toLowerCase();
	temp_1 = st.charAt(0);
	temp_ascii = st.charCodeAt(0);
	
	for(n=0;n<st.length;n++)
	{
		temp_2 = st.charCodeAt(n);
		if ((temp_2<48) || (temp_2>57))
		{
			if ((temp_2<97) || (temp_2>122))
			{ 
				if ((temp_2 == 95) || (temp_2==46) || (temp_2==64)||(temp_2==45))
				{
				//alert("special but correct");
				}
				else
				{ 
				alert("Invalid Email Address");
				valmailtext.focus();
				count=0;
				return false;
				}
			}
		}
		if(st.charAt(n)=='@' && n==0) atCount=atCount+1;
		if(st.charAt(n)=='@' && st.charAt(n+1)=='.') atCount=atCount+1;
		if(st.charAt(n)=='@') atCount=atCount+1;
		if(st.charAt(n)=='.') 
		{
			if(st.charAt(n+1)=='.' || n==st.length-1 ) atCount=2;
			dotCount=dotCount+1;
		}
	}
	
	if(atCount!=1 || dotCount<1) 
	{
	   alert("Invalid Email Address");
	   valmailtext.focus();
		return false;
	}
	else if ((temp_ascii < 48) || (temp_ascii > 122)) 
	{
	   
		alert("Invalid Email Id on Field "+valmailtext.id);
		valmailtext.focus();
		count=0;
		return false;
	}
	else
	{
		x=st.lastIndexOf("@");
		y=st.lastIndexOf(".");
		if(y < x )
		{
			alert("Invalid Email Address");
			valmailtext.focus();
			return false;
		}
		
	}
  }	
 }	
 
}

// function for validating whether the value is number or not ... 
// the input parameter has to be  the field name(s).... 
// Ex .. value= document.formname.fieldname

function fnvalidatenumber(value)
{ 
  	for(i=0;i<fnvalidatenumber.arguments.length;i++)
	{
	    nameid= fnvalidatenumber.arguments[i];
		namevalue=nameid.value;
		if (isNaN(namevalue))   
		{
			alert("Enter a numeric value in Field "+nameid.id);
			nameid.focus();
			return false;
		}  
	}
}

// function for validate whether the input is an + integer or not.

function fnvalidatepositive(value)
{ 
  	for(i=0;i<fnvalidatepositive.arguments.length;i++)
	{
	    nameid= fnvalidatepositive.arguments[i];
		namevalue=nameid.value;

	  b= fnvalidatenumber(nameid)
	  if(b!=false)
	   {
        if (namevalue<0)
			{
			alert("Enter a positive value In field "+nameid.id);
			nameid.focus();
		    return false;
			} 
       }		
       else 
        return false ;
   }
}  

// Stop hiding -->



function fnvalidatefmdate(date1,date2)
{

var sd;
		var ed;
		sd=date1.value
		ed=date2.value
		sdate = new Array();
		edate = new Array();
		sdate=sd.split("/");
		edate=ed.split("/");
		ss=new Date(sdate[2],sdate[0],sdate[1]);
		e=new Date(edate[2],edate[0],edate[1]);
		if (e.valueOf() < ss.valueOf())
			{
			  alert("From Date Should Not be greater Than End date");
			  date1.focus();
			  return false;
			}

}

function fnvalidatefmchar(val1,val2)
{
		if (val1.value.toUpperCase() > val2.value.toUpperCase())
			{
			  alert(val1.id+" Should Not be greater Than "+val2.id);
			  val1.focus();
			  return false;
		 }	
}


function showtext()
{
   window.status='Clarendon Parker';
   return true;
}

function hidetext()
{
   window.status='';   
}
