function isPhone(str)
{
	var i,ch,j,flag;
	var validchar="/+(),- 0123456789";
	if(str.length<4 && str.length!=0)
	{
		return true;	
	}
	for(i=0;i<str.length;i++)
	{
		ch=str.charAt(i);
		for(j=0;j<17;j++)
		{
			if(ch==validchar.charAt(j))
			{
				flag=1;
				break;
			}
			else
			{
				flag=2;
			}
		}
		if(flag==2)
		{
			return true
		}
	}
	return false;
}

function validate()
{
	if (document.form1.name.value=="")
	{
		alert("Please Enter Name.");
		document.form1.name.focus();
		return false;
	}

	if (document.form1.address.value=="")
	{
		alert("Please Enter Address.");
		document.form1.address.focus();
		return false;
	}
	if (isPhone(document.form1.phone.value))
	{
		alert("Please Enter Valid Phone No.");
		document.form1.phone.focus();
		return false;
	}

	if (isPhone(document.form1.mobile.value))
	{
		alert("Invalid Mobile Phone No.");
		document.form1.mobile.focus();
		document.form1.mobile.select();
		return false;
	}
	if (document.form1.eml.value=="")
	{
		alert("Please Enter email.");
		document.form1.eml.focus();
		return false;
	}
	if (document.form1.eml.value!="")
	{
		var str=document.form1.eml.value;	
		var reg1 = /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/; // not valid
		var reg2 = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/; // valid
		if (!(!reg1.test(str) && reg2.test(str))) 
			{
				alert('Invalid Email Address.');
				document.form1.eml.focus();
				document.form1.eml.select();
				return false;
			}
	}
	if (document.form1.month.selectedIndex==0)
	{
		alert("Please Select Month.");
		document.form1.month.focus();
		return false;
	}
	if (document.form1.date.selectedIndex==0)
	{
		alert("Please Select Date.");
		document.form1.date.focus();
		return false;
	}
	
	/*var x=document.form1.in_date.value;
	var y=document.form1.out_date.value;
	var year1=parseInt(document.form1.inyear.value);
	var year2=parseInt(document.form1.outyear.value);
	var month1=document.form1.in_month.selectedIndex;
	var month2=document.form1.out_month.selectedIndex;

	/*if(month1>month2)
	{
	alert("error");
	document.form1.in_month.focus();
	return false;
	}
	if((month1>=month2)&&(parseInt(x) >= parseInt(y)) && (year1 >= year2))
	{
	alert("Check Out Date is not Valid");
	document.form1.in_date.focus();
	return false;
	}*/

	var x=check_time();
	if(x==false)
	{
		alert("Please Enter Valid Time.");
		document.form1.from1.focus();
		document.form1.from1.select();
		return false;
	}
		
return true;	
}

function check_time()
{
var from1=document.form1.from1.value;
var from2=document.form1.from2.value;
	var time1=parseInt(from1+from2);
var from3=document.form1.from3.value;

var to1=document.form1.to1.value;
var to2=document.form1.to2.value;
	var time2=parseInt(to1+to2);
var to3=document.form1.to3.value;
	if(from3==to3)
		if(time1>=time2)
		return false;
		//alert(time1);
}

function validate_empty1(frm,str)
{
	var val=str.split(",");
	
	var type1, rdo, flag, e_name1;
	for(i=0;i<val.length;i++)
	{
		box=frm.elements[val[i]]
		ename=box.name;
		type1=box.type;
		ename=ename.replace("_"," ");
		e_name=upper_case_first_letters(ename);

		if(type1=="radio")		
		{
			rdo="y";
			e_name1=e_name;
			if(box.checked || flag==1)	{	flag=1;		}
			else{	flag=2;		}
		}
		else
		{
			if(rdo=="y")
			{
				if(flag==2)
				{	rdo="";
					flag=5;
					alert('Please Select '+e_name1);
					box1=frm.elements[val[i-1]]					
					box1.focus();
					return false;
				}
			}
			if(box.value=="" || box.value==0)
			{
				alert(e_name + ' can not be empty.');
				box.focus();
				return false;
			}
		}
	}
	return true;
}

function upper_case_first_letters(str)
{
		STRING=str;	
		var strReturn_Value = "";
		var iTemp = STRING.length;
		if(iTemp==0){
		return"";
		}
		var UcaseNext = false;
		strReturn_Value += STRING.charAt(0).toUpperCase();
		for(var iCounter=1;iCounter < iTemp;iCounter++){
		if(UcaseNext == true){
		strReturn_Value += STRING.charAt(iCounter).toUpperCase();
		}
		else{
		strReturn_Value += STRING.charAt(iCounter).toLowerCase();
		}
		var iChar = STRING.charCodeAt(iCounter);
		if(iChar == 32 || iChar == 45 || iChar == 46){
		UcaseNext = true;
		}
		else{
		UcaseNext = false
		}
		if(iChar == 99 || iChar == 67){
		if(STRING.charCodeAt(iCounter-1)==77 || STRING.charCodeAt(iCounter-1)==109){
		UcaseNext = true;
		}
		}
		
		
		} //End For
		
		return strReturn_Value;
		//	alert(strReturn_Value);
		
} //End Function


