// JavaScript Document
/*******************************************************************/
/***                                                             ***/
/***   register_mail.js - JavaScript Form Validations	         ***/
/***   Author	 : Sundarrajan S.                                ***/
/***                                                             ***/
/***   Version   : 1.2                                           ***/
/***   Date      : 12.02.2009                                    ***/
/***   Copyright : Lbn Tech Solutions                            ***/
/***   Website   : http://www.localbiznetwork.com/               ***/
/***                                                             ***/
/*******************************************************************/
function formValidate()
{
	var student_email_id=document.form1.student_email_id;
	var skypeid=document.form1.skypeid;
	var firstname=document.form1.firstname;
	var lastname=document.form1.lastname;
	var studentgender=document.form1.studentgender;
	var studentage=document.form1.studentage;
	var studentdob=document.form1.studentdob;
	var mothertongue=document.form1.mothertongue;
	var studentfathername=document.form1.studentfathername;
	var studentfatheroccupation=document.form1.studentfatheroccupation;
	
	//Address  of communication
	
	var studentaddress1=document.form1.studentaddress1;
	var studentcity=document.form1.studentcity;
	var studentstate=document.form1.studentstate;
	var studentcountry=document.form1.studentcountry;
	var studentpincode=document.form1.studentpincode;
	var studentphone=document.form1.studentphone;
	var studentmobile=document.form1.studentmobile;
	
	//School details
	
	var studentschoolname=document.form1.studentschoolname;	
	var affiliation=document.form1.affiliation;
	//var Course1=document.form1.Course1;	
	//var one2one=document.form1.one2one;
	//Subject
	
	var forVedic=document.form1.forVedic;	
	var forDoubt=document.form1.forDoubt;	
	var MATHEMATICS=document.form1.MATHEMATICS;
	var CHEMISTRY=document.form1.CHEMISTRY;
	var PHYSICS=document.form1.PHYSICS;
	var emvm=document.form1.emvm;
	var hwdc=document.form1.hwdc;
		
	///Additional Information
	
	var system=document.form1.system;
	var internet=document.form1.internet;
	var msoffice=document.form1.msoffice;
	var powerpoint=document.form1.powerpoint;
	var chat=document.form1.chat;
	var typing=document.form1.typing;
	var remarks=document.form1.remarks;
	
	
	if(empty_check(student_email_id.value,"Please enter your Email ID")==0){student_email_id.focus();return false;}
	if(email(student_email_id.value,"Please enter a valid  Email ID")==0){student_email_id.focus();return false;}
	
	if(empty_check(skypeid.value,"Please enter your Skype ID")==0){skypeid.focus();return false;}
	//if(email(skypeid.value,"Please enter a valid Skype ID")==0){skypeid.focus();return false;}
	
	if(empty_check(firstname.value,"Please enter your First Name")==0){firstname.focus();return false;}
	//if(user_check(firstname.value,"Please check First Name (Not allowed special character)")==0){firstname.focus();return false;}	
	if(empty_check(lastname.value,"Please enter your Last Name")==0){lastname.focus();return false;}
	//if(user_check(lastname.value,"Invalid Entry! Please check and re-enter!")==0){lastname.focus();return false;}	
	if(select_check(studentgender.value,"Please select Gender")==0){studentgender.focus();return false;}
	
	if(empty_check(studentfathername.value,"Please enter your Parent's Name (Father/Mother)")==0){studentfathername.focus();return false;}
	//if(user_check(studentfathername.value,"Invalid Entry! Please check and re-enter!")==0){studentfathername.focus();return false;}	
	
	if(empty_check(studentaddress1.value,"Please enter your Address")==0){studentaddress1.focus();return false;}
	if(empty_check(studentcity.value,"Please enter City")==0){studentcity.focus();return false;}
	if(empty_check(studentstate.value,"Please enter State")==0){studentstate.focus();return false;}
	if(empty_check(studentcountry.value,"Please enter Country")==0){studentcountry.focus();return false;}
	if(empty_check(studentpincode.value,"Please enter Pin Code")==0){studentpincode.focus();return false;}
	//if(number_check(studentpincode.value,"Invalid Entry! Please check and re-enter! (Enter Numericals Only [0-9])")==0){studentpincode.focus();return false;}
	if(empty_check(studentphone.value,"Please enter your Residence Phone Number")==0){studentphone.focus();return false;}
	//if(number_check(studentphone.value,"Please enter a valid Residence Phone Number (Enter Numericals Only [0-9])")==0){studentphone.focus();return false;}
	
	
	if(empty_check(studentschoolname.value,"Please enter your School Name")==0){studentschoolname.focus();return false;}
	if(select_check(affiliation.value,"Please select your Board")==0){affiliation.focus();return false;}
	//if(select_check(Course1.value,"Please select your Class/Standard")==0){Course1.focus();return false;}
	var radio_choice1=true;
	for (counter = 0; counter < emvm.length; counter++)
	{
		if (emvm[counter].checked)
		radio_choice1 = false; 
	}
	var radio_choice2=true;
	for (counter1 = 0; counter1 < hwdc.length; counter1++)
	{
		if (hwdc[counter1].checked)
		radio_choice2 = false; 
	}
		
	if((radio_choice1) && (radio_choice2))
	{
		alert("Please select at least one coaching programme\n \nFor Speed Math/Vedic Math - Select Standard & Hours \nFor Home Work/Doubt Clearing/Intensive Coaching - Select Standard, Subject & Hours");
		return false;
	}
	if(!radio_choice1)
	{
		if(forVedic.value=="")
		{
				alert("Please select standard for Speed Math/Vedic Math");
				forVedic.focus();
				return false;
		}
	}
	if(!radio_choice2)
	{
		if(forDoubt.value=="")
		{
				alert("Please select standard for Home Work/Doubt Clearing");
				forDoubt.focus();
				return false;
		}
		if(!MATHEMATICS.checked && !CHEMISTRY.checked && !PHYSICS.checked)
		{
				alert("Please select subject for Home Work/Doubt Clearing");
				CHEMISTRY.focus();
				return false;
		}
		
	}
	return true;
}


function empty_check(val_check,str)
{
	if(val_check==0)
	{
		alert(str);
		return 0;
	}else
	{
		return 1;
	}
	
}

function select_check(val_check,str)
{
	if(val_check=="")
	{
		alert(str);
		return 0;
	}else
	{
		return 1;
	}
}

function user_check(str,msg)
{
		var s;
		var c=str;
		var fl = 0;
		for(var i=0;i<c.length;i++)
		{
			s=c.charAt(i);
			if( (s>='0' && s<='9') || (s=='-') ||  (s=='_')  ||  (s=='.') || (s>='a' &&s<='z') || (s>='A' &&s<='Z') ) 		
			{}
			else
			{
				fl = 1;
			}
		}
		
		if(fl == 1)
		{
			alert(msg);
			return 0;
		}
		else
		{
			return 1;	
		}
}

function email(email1,msg)
	{
		
		var e3,e4;
		var err1 = new Array(0,0);
		e3 = email1.indexOf("@");
		e4 = email1.lastIndexOf("@");
		
		if(e3 != -1 && e3 == e4)
		{
			var a = email1.indexOf(".",e3);
			if((a-e3) < 2)
			err1[0] = 1;
		}
		else{	err1[0] = 1;		}
		
		if(err1[0] == 1)
		{
			alert(msg);
			return 0;			
		}else
		{
			return 1;
		}
		
}

function number_check(str,msg)
{
		var s;
		var c=str;
		var fl = 0;
		for(var i=0;i<c.length;i++)
		{
			s=c.charAt(i);
			if( (s>='0' && s<='9') ) 		
			{}
			else
			{
				fl = 1;
			}
		}
		
		if(fl == 1)
		{
			alert(msg);
			return 0;
		}
		else
		{
			return 1;	
		}
}
