//Function to validate the required fields before submitting
//===========================================================
function validate1(operation)
{
  var cansubmit=false;
  form=document.user_form;
   if (operation == "new")
	{
		
		cansubmit=ForceEntry(form.form_user_id, "Enter Valid User Id");
		if(cansubmit) cansubmit =isname(form.form_user_id,"Can not type special chars");
		if (cansubmit) cansubmit= MinLen(form.form_user_id,"User ID should have Greater than 6 characters",6);
		if(cansubmit) cansubmit =FirstChar(form.form_user_id,"First Character should be an alphabets");
		if(cansubmit) cansubmit =LastChar(form.form_user_id,"Invalid Last Character");
	
		
//		if (cansubmit) cansubmit= ForceEntry(form.user_password, "Enter Password");

		if (cansubmit) cansubmit= Checkpwd(form.user_password, "Enter valid Password");
		if (cansubmit) cansubmit= MinLen(form.user_password,"Password should have more than 6 characters",6);


//		if (cansubmit) cansubmit= ForceEntry(form.user_confirm_password, "Enter Confirm Password");

		if (cansubmit) cansubmit= Checkpwd(form.user_confirm_password, "Enter Confirm Password");
		if (cansubmit) cansubmit= issame(form.user_password,form.user_confirm_password,"Password and confirm password should be same");
	}
	else
	{
		cansubmit=true;
	}	

	if(cansubmit){
	if (form.user_title.selectedIndex == 0)
    {
        alert('Please select the title ');
        form.user_title.focus();
        cansubmit=false;
    }
	}
	
	if (cansubmit) cansubmit=ForceEntry(form.user_fname, "First Name accepts only Alphabets,Space and Period");
	if(cansubmit) cansubmit =FirstChar(form.user_fname,"First Character in First Name should be an alphabets");
	if(cansubmit) cansubmit =LastChar(form.user_fname,"Invalid Last Character First Name");

	if(cansubmit){
	var mname = trim(form.user_mname.value);
	if(mname != '')
	{
		if (mname.match("[^a-zA-Z \.]"))
    	{
        	alert('Middle Name accepts only Alphabets,Space and period');
        	form.user_mname.focus();
        	cansubmit=false;
    	}
	}
	}
	if(cansubmit) cansubmit =FirstChar(form.user_mname,"First Character in Middle Name should be an alphabets");
	if(cansubmit) cansubmit =LastChar(form.user_mname,"Invalid Last Character in Middle name");

	if (cansubmit) cansubmit=ForceEntry(form.user_lname, "Last Name accepts only Alphabets,Space and period");
	if(cansubmit) cansubmit =FirstChar(form.user_lname,"First Character in Last Name should be an alphabets");
	if(cansubmit) cansubmit =LastChar(form.user_lname,"Invalid Last Character in Last Name");

	if(cansubmit) cansubmit =checkValidDate(form.user_day,form.user_month,form.user_year,"Invalid Date of Birth",0,"Enter Valid Date");
	if(cansubmit) cansubmit =DateValid(form.user_day,form.user_month,form.user_year,"Your Date of Birth should be Lesser than Current date",0,"Select Date Of Birth");

//	checkValidDate
	if(cansubmit){
	if((form.user_phone.value) && (form.user_phone.value.match("[^0-9 \-\+()]")))
	{
		alert("Phone accepts only Numbers,(),+ and -");
		form.user_phone.focus();
		cansubmit=false;
	}
	}
	if(cansubmit){
	if((form.user_mobile.value) && (form.user_mobile.value.match("[^0-9 \-\+()]")))
	{
		alert("Mobile accepts only Numbers,(),+ and -");
		form.user_mobile.focus();
		cansubmit=false;
	}
	}
	if(cansubmit){
	if((form.user_fax.value) && (form.user_fax.value.match("[^0-9 \-\+()]")))
	{
		alert("Fax accepts only Numbers,(),+ and -");
		form.user_fax.focus();
		cansubmit=false;
	}
	}
	/*if(cansubmit){
if (form.user_address.value.match("[<>]"))
    {
        alert('Address should not contain < and >');
        form.user_address.focus();
        cansubmit=false;
    }
	}*/
	//if (cansubmit) cansubmit=ForceEntry(form.user_address, "Please enter the Address");
	if(cansubmit){
	if(form.user_address.value == "" )
	{
		alert ("Please Enter the Address");
		form.user_address.focus();
		cansubmit=false;
	}
	}
	if(cansubmit){
    if ((form.user_address.value) && (form.user_address.value.length >150))
    {
        alert("No of characters exceeds 150 for Address");
        form.user_address.focus();
        cansubmit=false;
    }
	}
	if(cansubmit){
	if ( form.user_countryid.value == "0" )
	{
		alert ( "Please select the Country");
		form.user_countryid.focus();
		cansubmit=false;
	}
	}
	if(cansubmit){
	if (form.user_stateid.value == "0" )
	{
		alert ( "Please select the State");
		form.user_stateid.focus();
		cansubmit=false;
	}
	}
	if(cansubmit){
	if (form.user_cityid.value == "0" )
	{
		alert ("Please select the City");
		form.user_cityid.focus();
		cansubmit=false;
	}}
	if(cansubmit){
	if((form.user_zip.value) && (form.user_zip.value.match("[^0-9 \-\+()]")))
	{
		alert("Zip Code accepts only Numbers and space");
		form.user_zip.focus();
		cansubmit=false;
	}
	}
	if(cansubmit){
	if(!(EmailValid(form.user_email,"Please enter a valid Email")))
		{
			cansubmit=false;
		}
	}

	if(cansubmit){
	var education = trim(form.user_education.value);
	if(education != '')
	{
		if (education.match("[^a-zA-Z \.0-9]"))
    	{
        	alert('Education accepts only Alphabets, Numbers, Space and period');
        	form.user_education.focus();
        	cansubmit=false;
    	}
	}
	}
	if(cansubmit){
	var industry = trim(form.user_industry.value);
	if(industry != '')
	{
		if (industry.match("[^a-zA-Z \.0-9]"))
    	{
        	alert('Industry accepts only Alphabets, Numbers, Space and period');
        	form.user_industry.focus();
        	cansubmit=false;
    	}
	}
	}
	if(cansubmit){
		var objElement =  document.getElementById('user_occupation');
		var category = trim(form.user_category.value);
		if (category=="1") 
		{
			if (objElement.selectedIndex == -1  ) {
				alert ("Please select atlease one Sub Category");
				objElement.focus();
				cansubmit=false;
			}
		}
	}
	/*if(cansubmit){
	var occupation = trim(form.user_occupation.value);
	if(occupation != '')
	{
		if (occupation.match("[^a-zA-Z \.0-9]"))
    	{
        	alert('Occupation accepts only Alphabets, Numbers, Space and period');
        	form.user_occupation.focus();
        	cansubmit=false;
    	}
	}
	}*/
	if(cansubmit){
		form.form_action.value='update';
		form.submit();
		return true;
	}
	 return cansubmit;
}

function lawform_validate(operation)

{

  var cansubmit=false;

  form=document.user_form;

   if (operation == "new")

        {

                cansubmit=ForceEntry(form.form_user_id, "Enter Valid User Id");

                if(cansubmit) cansubmit =isname(form.form_user_id,"Can not type special chars");

                if (cansubmit) cansubmit= MinLen(form.form_user_id,"User ID should have Greater than 6 characters",6);

                if(cansubmit) cansubmit =FirstChar(form.form_user_id,"First Character should be an alphabets");

                if(cansubmit) cansubmit =LastChar(form.form_user_id,"Invalid Last Character");



                if (cansubmit) cansubmit= Checkpwd(form.user_password, "Enter valid Password");

                if (cansubmit) cansubmit= MinLen(form.user_password,"Password should have more than 6 characters",6);



                if (cansubmit) cansubmit= Checkpwd(form.user_confirm_password, "Enter Confirm Password");

                if (cansubmit) cansubmit= issame(form.user_password,form.user_confirm_password,"Password and confirm password should be same");

        }

        else

        {

                cansubmit=true;

        }

        if(cansubmit){

        if (form.user_title.selectedIndex == 0)

    {

        alert('Please select the title ');

        form.user_title.focus();

        cansubmit=false;

    }

        }



        if (cansubmit) cansubmit=ForceEntry(form.user_fname, "First Name accepts only Alphabets,Space and Period");

        if(cansubmit) cansubmit =FirstChar(form.user_fname,"First Character in First Name should be an alphabets");

        if(cansubmit) cansubmit =LastChar(form.user_fname,"Invalid Last Character First Name");



        if(cansubmit){

        var mname = trim(form.user_mname.value);

        if(mname != '')

        {

                if (mname.match("[^a-zA-Z \.]"))

        {

                alert('Middle Name accepts only Alphabets,Space and period');

                form.user_mname.focus();

                cansubmit=false;

        }

        }

        }

        if(cansubmit) cansubmit =FirstChar(form.user_mname,"First Character in Middle Name should be an alphabets");

        if(cansubmit) cansubmit =LastChar(form.user_mname,"Invalid Last Character in Middle name");



        if (cansubmit) cansubmit=ForceEntry(form.user_lname, "Last Name accepts only Alphabets,Space and period");

        if(cansubmit) cansubmit =FirstChar(form.user_lname,"First Character in Last Name should be an alphabets");

        if(cansubmit) cansubmit =LastChar(form.user_lname,"Invalid Last Character in Last Name");



        if(cansubmit){

        if((form.user_phone.value) && (form.user_phone.value.match("[^0-9 \-\+()]")))

        {

                alert("Phone accepts only Numbers,(),+ and -");

                form.user_phone.focus();

                cansubmit=false;

        }

        }

        if(cansubmit){

        if((form.user_mobile.value) && (form.user_mobile.value.match("[^0-9 \-\+()]")))

        {

                alert("Mobile accepts only Numbers,(),+ and -");

                form.user_mobile.focus();

                cansubmit=false;

        }

        }

       if(cansubmit){

        if(form.user_address.value == "" )

        {

                alert ("Please Enter the Address");

                form.user_address.focus();

                cansubmit=false;

        }

        }

        if(cansubmit){

    if ((form.user_address.value) && (form.user_address.value.length >150))

    {

        alert("No of characters exceeds 150 for Address");

        form.user_address.focus();

        cansubmit=false;

    }

        }

	if(cansubmit){

        if(form.user_designation.value == "" )

        {

                alert ("Please Enter the Designation");

                form.user_designation.focus();

                cansubmit=false;

        }

        }

        if(cansubmit){

        if ( form.user_countryid.value == "0" )

        {

                alert ( "Please select the Country");

                form.user_countryid.focus();

                cansubmit=false;

        }

        }

        if(cansubmit){

        if (form.user_stateid.value == "0" )

        {

                alert ( "Please select the State");

                form.user_stateid.focus();

                cansubmit=false;

        }

        }

        if(cansubmit){

        if (form.user_cityid.value == "0" )

        {

                alert ("Please select the City");

                form.user_cityid.focus();

                cansubmit=false;

        }}

        if(cansubmit){

        if((form.user_zip.value) && (form.user_zip.value.match("[^0-9 \-\+()]")))

        {

                alert("Zip Code accepts only Numbers and space");

                form.user_zip.focus();

                cansubmit=false;

        }

        }

        if(cansubmit){

        if(!(EmailValid(form.user_email,"Please enter a valid Email")))

                {

                        cansubmit=false;

                }

        }



        if(cansubmit){

                var objElement =  document.getElementById('user_occupation');

                var category = trim(form.user_category.value);

                if (category=="1")

                {

                        if (objElement.selectedIndex == -1  ) {

                                alert ("Please select atlease one Sub Category");

                                objElement.focus();

                                cansubmit=false;

                        }

                }

        }

        if(cansubmit){

                form.form_action.value='update';

                form.submit();

                return true;

        }

         return cansubmit;

}
