

		
//function to validate the form in flight-registration.php page
function chkreservfrm()
{	
if(document.frmf.firstname.value == "")
	{
	alert("Please enter Enter the first name for CONTACT INFORMATION");
	document.frmf.firstname.focus();
	return(false);
	}
if(document.frmf.lastname.value == "")
	{
	alert("Please enter Enter the last name for CONTACT INFORMATION");
	document.frmf.lastname.focus();
	return(false);
	}
if(document.frmf.email.value == "")
	{
	alert("Please enter Enter the email for CONTACT INFORMATION");
	document.frmf.email.focus();
	return(false);
	}
if(document.frmf.phone.value == "")
	{
	alert("Please enter Enter the phone number for CONTACT INFORMATION");
	document.frmf.phone.focus();
	return(false);
	}
if(document.frmf.streetadd1.value == "")
	{
	alert("Please enter Enter the streetadd1 for CONTACT INFORMATION");
	document.frmf.streetadd1.focus();
	return(false);
	}
if(document.frmf.state.value == "")
	{
	alert("Please enter Enter the state for CONTACT INFORMATION");
	document.frmf.state.focus();
	return(false);
	}
if((document.frmf.pin.value == ""))
	{
	alert("Please enter Enter the pin code for CONTACT INFORMATION");
	document.frmf.pin.focus();
	return(false);
	}
if(document.frmf.country.value == "")
	{
	alert("Please enter Enter the country for CONTACT INFORMATION");
	document.frmf.country.focus();
	return(false);
	}
if(document.frmf.country.value == "")
	{
	alert("Please enter Enter the country for CONTACT INFORMATION");
	document.frmf.country.focus();
	return(false);
	}
if(document.frmf.idtype.value == "Choose one")
	{
	alert("Please enter Enter the Type of ID");
	document.frmf.idtype.focus();
	return(false);
	}
if(document.frmf.idcard.value == "")
	{
	alert("Please enter Enter NO on ID card");
	document.frmf.idcard.focus();
	return(false);
	}
if(document.frmf.idauth.value == "")
	{
	alert("Please enter name of the Authority issuing ID card");
	document.frmf.idauth.focus();
	return(false);
	}
var num_val1=document.frmf.adult.value;
	
	 for(i=1;i<=num_val1;i++)
		{
           //alert(i);

			if(document.getElementById('afname'+i).value=="")
			{
				alert("Please enter all the required fields");
				document.getElementById('afname'+i).focus();
				return false;
				//break;
			}
			if(document.getElementById('alname'+i).value=="")
			{
				alert("Please enter all the required fields");
				document.getElementById('alname'+i).focus();
				return false;
				//break;
			}
			if(document.getElementById('aage'+i).value=="")
			{
				alert("Please enter all the required fields");
				document.getElementById('aage'+i).focus();
				return false;
				//break;
			}
			if(document.getElementById('aberth'+i).value=="Choose")
			{
				alert("Please enter all the required fields");
				document.getElementById('aberth'+i).focus();
				return false;
				//break;
			}

		}

var num_val2=document.frmf.child.value;	
	 for(i=1;i<=num_val2;i++)
		{
           //alert(i);

			if(document.getElementById('cfname'+i).value=="")
			{
				alert("Please enter all the required fields");
				document.getElementById('cfname'+i).focus();
				return false;
				//break;
			}
			if(document.getElementById('clname'+i).value=="")
			{
				alert("Please enter all the required fields");
				document.getElementById('clname'+i).focus();
				return false;
				//break;
			}
			if(document.getElementById('cage'+i).value=="")
			{
				alert("Please enter all the required fields");
				document.getElementById('cage'+i).focus();
				return false;
				//break;
			}
			if(document.getElementById('cberth'+i).value=="Choose")
			{
				alert("Please enter all the required fields");
				document.getElementById('cberth'+i).focus();
				return false;
				//break;
			}
		}

var num_val3=document.frmf.senior.value;	
	 for(i=1;i<=num_val3;i++)
		{
           //alert(i);

			if(document.getElementById('sfname'+i).value=="")
			{
				alert("Please enter all the required fields");
				document.getElementById('sfname'+i).focus();
				return false;
				//break;
			}
			if(document.getElementById('slname'+i).value=="")
			{
				alert("Please enter all the required fields");
				document.getElementById('slname'+i).focus();
				return false;
				//break;
			}
			if(document.getElementById('sage'+i).value=="")
			{
				alert("Please enter all the required fields");
				document.getElementById('sage'+i).focus();
				return false;
				//break;
			}
			if(document.getElementById('sberth'+i).value=="Choose")
			{
				alert("Please enter all the required fields");
				document.getElementById('sberth'+i).focus();
				return false;
				//break;
			}
		}
//if (!valid_email()) return false;
//if (!valid_phone(document.frmf.phone)) return false;
document.frmf.submit();
}

//end of above function
function valid_email()
			{	   	
				
					var emailval=document.frmf.email.value;
					var ret=CheckMails(emailval)
					if(ret==false)
					{
						document.frmf.email.focus();
						//alert("Please Enter a Valid Email ");
						return false
					}
				return true;
			}

function valid_phone(obj)
			{
				if(obj.value!="")
				{
					var phone_number = obj.value;
					var ret = checkInternationalPhone(phone_number);
					//alert(ret);
					if(ret == false)
					{
						alert("Enter a Valid Phone Number");
						//obj.value="";
						obj.focus();
						return false;
					}
					else
					{
						return true;
					}
				}
				//alert("in`side function") ;
			}
function editAdult()
{
	var i=0;
	var j=document.frmf.adult.value;
	//alert(j);
	document.getElementById('divAdult').innerHTML="";
	for (i=0;i<j;i++)
	{
		document.getElementById('divAdult').innerHTML=document.getElementById('divAdult').innerHTML+"<TABLE class='reservation'><tr><td width='15%'>Adult &nbsp;"+(i+1)+":</td>											  <td width='10%'>Title<br><select name='asex"+(i+1)+"' class='form1'><option value='Male'>Mr.</option><option value='Female'>Ms.</option></select></td></td> <td width='18%'>First Name<br><input type='text' class='field_edit' name='afname"+(i+1)+"' value='' size='13'></td>						  <td width='18%'>Middle Name<br><input type='text' class='field_edit' name='amname"+(i+1)+"' value='' size='13'></td><td width='18%'>Last Name<br><input type='text' class='field_edit' name='alname"+(i+1)+"' value='' size='13'></td>								<td width='20%' class='label2'>Choose Berth<br>															<select name='aberth"+(i+1)+"' class='form1'>															  <option value='Choose'>Choose</option>															  <? if ($classes=='First Class AC (A1)') {?>															  <option value='Upper'>Upper</option><option value='Lower'>Lower</option><? } else if ($classes=='AC 2 - tier Sleeper (2A)') {?><option value='Upper'>Upper</option><option value='Lower'>Lower</option><option value='Side Upper'>Side Upper</option><option value='Side Lower'>Side Lower</option><? } else if ($classes=='AC 3 - tier (3A)') {?><option value='Upper'>Upper</option><option value='Middle'>Middle</option>															  <option value='Lower'>Lower</option>															  <option value='Side Upper'>Side Upper</option>															  <option value='Side Lower'>Side Lower</option>															  <? } else if ($classes=='AC Chair Car (CC)') {?>															  <option value='Window Seat'>Window Seat</option>															  <option value='No Choise'>No Choise</option>															  <? } else if ($classes=='Sleeper Class (SL)') {?>															  <option value='Upper'>Upper</option>															  <option value='Middle'>Middle</option>															  <option value='Lower'>Lower</option>															   <option value='Side Upper'>Side Upper</option>															  <option value='Side Lower'>Side Lower</option>															  <? } else if ($classes=='Second Sitting (SL)') {?>															  <option value='Window Seat'>Window Seat</option>															  <option value='No Choise'>No Choise</option>															  <?}?></select></td>													  <td width='5%' class='label2'>Age<br><input type='text' id='aage"+(i+1)+"' name='aage"+(i+1)+"' size='2' class='form1'></td></tr></TABLE>";
	}
}
function editChild()
{
	var k=0;
	var l=document.frmf.child.value;
	//alert(l);
	document.getElementById('divChild').innerHTML="";
	for (k=0;k<l;k++)
	{
		document.getElementById('divChild').innerHTML=document.getElementById('divChild').innerHTML+"<TABLE class='reservation'><tr><td width='15%'>Adult &nbsp;"+(k+1)+":</td>											  <td width='10%'>Title<br><select name='csex"+(k+1)+"' class='form1'><option value='Male'>Mr.</option><option value='Female'>Ms.</option></select></td></td> <td width='18%'>First Name<br><input type='text' class='field_edit' name='cfname"+(k+1)+"' value='' size='13'></td>						  <td width='18%'>Middle Name<br><input type='text' class='field_edit' name='cmname"+(k+1)+"' value='' size='13'></td><td width='18%'>Last Name<br><input type='text' class='field_edit' name='clname"+(k+1)+"' value='' size='13'></td>								<td width='20%' class='label2'>Choose Berth<br>															<select name='cberth"+(k+1)+"' class='form1'>															  <option value='Choose'>Choose</option>															  <? if ($classes=='First Class AC (A1)') {?>															  <option value='Upper'>Upper</option><option value='Lower'>Lower</option><? } else if ($classes=='AC 2 - tier Sleeper (2A)') {?><option value='Upper'>Upper</option><option value='Lower'>Lower</option><option value='Side Upper'>Side Upper</option><option value='Side Lower'>Side Lower</option><? } else if ($classes=='AC 3 - tier (3A)') {?><option value='Upper'>Upper</option><option value='Middle'>Middle</option>															  <option value='Lower'>Lower</option>															  <option value='Side Upper'>Side Upper</option>															  <option value='Side Lower'>Side Lower</option>															  <? } else if ($classes=='AC Chair Car (CC)') {?>															  <option value='Window Seat'>Window Seat</option>															  <option value='No Choise'>No Choise</option>															  <? } else if ($classes=='Sleeper Class (SL)') {?>															  <option value='Upper'>Upper</option>															  <option value='Middle'>Middle</option>															  <option value='Lower'>Lower</option>															   <option value='Side Upper'>Side Upper</option>															  <option value='Side Lower'>Side Lower</option>															  <? } else if ($classes=='Second Sitting (SL)') {?>															  <option value='Window Seat'>Window Seat</option>															  <option value='No Choise'>No Choise</option>															  <?}?></select></td>													  <td width='5%' class='label2'>Age<br><input type='text' id='aage"+(k+1)+"' name='cage"+(k+1)+"' size='2' class='form1'></td></tr></TABLE>";
	}
}
function editInfant()
{
	var i=0;
	var j=document.frmf.senior.value;
	//alert(j);
	document.getElementById('divInfant').innerHTML="";
	for (i=0;i<j;i++)
	{
		document.getElementById('divInfant').innerHTML=document.getElementById('divInfant').innerHTML+"<TABLE class='reservation'><tr><td width='15%'>Adult &nbsp;"+(i+1)+":</td>											  <td width='10%'>Title<br><select name='ssex"+(i+1)+"' class='form1'><option value='Male'>Mr.</option><option value='Female'>Ms.</option></select></td></td> <td width='18%'>First Name<br><input type='text' class='field_edit' name='sfname"+(i+1)+"' value='' size='13'></td>						  <td width='18%'>Middle Name<br><input type='text' class='field_edit' name='smname"+(i+1)+"' value='' size='13'></td><td width='18%'>Last Name<br><input type='text' class='field_edit' name='slname"+(i+1)+"' value='' size='13'></td>								<td width='20%' class='label2'>Choose Berth<br>															<select name='sberth"+(i+1)+"' class='form1'>															  <option value='Choose'>Choose</option>															  <? if ($classes=='First Class AC (A1)') {?>															  <option value='Upper'>Upper</option><option value='Lower'>Lower</option><? } else if ($classes=='AC 2 - tier Sleeper (2A)') {?><option value='Upper'>Upper</option><option value='Lower'>Lower</option><option value='Side Upper'>Side Upper</option><option value='Side Lower'>Side Lower</option><? } else if ($classes=='AC 3 - tier (3A)') {?><option value='Upper'>Upper</option><option value='Middle'>Middle</option>															  <option value='Lower'>Lower</option>															  <option value='Side Upper'>Side Upper</option>															  <option value='Side Lower'>Side Lower</option>															  <? } else if ($classes=='AC Chair Car (CC)') {?>															  <option value='Window Seat'>Window Seat</option>															  <option value='No Choise'>No Choise</option>															  <? } else if ($classes=='Sleeper Class (SL)') {?>															  <option value='Upper'>Upper</option>															  <option value='Middle'>Middle</option>															  <option value='Lower'>Lower</option>															   <option value='Side Upper'>Side Upper</option>															  <option value='Side Lower'>Side Lower</option>															  <? } else if ($classes=='Second Sitting (SL)') {?>															  <option value='Window Seat'>Window Seat</option>															  <option value='No Choise'>No Choise</option>															  <?}?></select></td>													  <td width='5%' class='label2'>Age<br><input type='text' id='aage"+(i+1)+"' name='sage"+(i+1)+"' size='2' class='form1'></td></tr></TABLE>";
	}
}

function showindex()
{
	//alert(document.frmf.classes.options[2].value);
	for(var a=0;a<7;a++)
	{if(document.frmf.classes.options[a].value=='<? echo($classes);?>')
		{var index=a;
			document.frmf.classes.selectedIndex=index;
				break;
		}
	}
}
function showid()
{
	//alert(document.frmf.classes.options[2].value);
	for(var a=0;a<6;a++)
	{if(document.frmf.idtype.options[a].value=='<? echo($idtype);?>')
		{var index=a;
			document.frmf.idtype.selectedIndex=index;
				break;
		}
	}
}

function chkform()
{
	if(document.frmf.trip[0].checked==true)
	{
	if(document.frmf.from.value=="")
			{
				alert("Please enter the name of the city you are starting from.");
				document.frmf.from.focus();
				return false;
			}
	if(document.frmf.to.value=="")
			{
				alert("Please enter the name of the city you are heading to.");
				document.frmf.to.focus();
				return false;
			}
	if(document.frmf.outbound_date.value=="")
			{
				alert("Please enter date of journey.");
				document.frmf.outbound_date.focus();
				return false;
			}
	}
	if((document.frmf.trip[1].checked==true)&&(document.frmf.inbound_date.value==""))
			{
				alert("Please enter the date of return journey.");
				document.frmf.inbound_date.focus();
				return false;
			}
	
	if(document.frmf.classes.value=="0")
			{
				alert("Please Choose a Class.");
				document.frmf.classes.focus();
				return false;
			}
	if(document.frmf.resident.value=="0")
			{
				alert("Please provide you country of residence.");
				document.resident.classes.focus();
				return false;
			}
	checkdates1();
}

function checkdates1()
{
//alert("hi");
var  arrFromDate = document.frmf.outbound_date.value.split("-");
	var  arrToDate = document.frmf.inbound_date.value.split("-");
	if (!isDate(document.frmf.outbound_date.value)){alert("invalid date. enter a proper date using the calendar.");document.frmf.outbound_date.value="";return false;}
	if(document.frmf.trip[1].checked==true)//(document.frm.trip[1].selected==true)
	{
			if (!isDate(document.frmf.inbound_date.value)){alert("invalid date. enter a proper date using the calendar.");document.frmf.inbound_date.value="";return false;}
	}
	var useFromDate=new Date(arrFromDate[0], arrFromDate[1]-1, arrFromDate[2]);
	var useToDate=new Date(arrToDate[0], arrToDate[1]-1, arrToDate[2]);
	//alert(useFromDate);
	//alert(useToDate);
	if(useFromDate >= useToDate){alert("The Departure date must not precede Return date ");return false;}
	document.frmf.action="rail-reservation.php";
	document.frmf.submit();
	//window.parent.location="flight-reservation.php";
	
}

var dtCh= "-";
var minYear=2008;
var maxYear=2010;

function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}

function isDate(dtStr){
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strYear=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strDay=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		alert("The date format should be : YYYY-mm-dd")
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		return false
	}
return true
}
