function Trim(s)
{
        var temp = " ";
        var i = 0;

        while ((temp == " ") && (i <= s.length)) {
                temp = s.charAt(i);
                i++;
        }
        s = s.substring(i - 1, s.length);
        return(s);
}


function CheckReservation()
{	
	var f = document.chkres;
	var adult = f.adult.value;
	var children = f.children.value;
	var title = f.title.value;
	var first_name = f.first_name.value;
	var last_name = f.last_name.value;
	var home_address = f.home_address.value;
	var city = f.city.value;
	var state = f.state.value;
	var country = f.country.value;
	var post_code = f.post_code.value;
	var phone_no = f.phone_no.value;
	var email_address = f.email_address.value;
	var errMsg = "";
	var objFocus="";
	
	f.adult.value=Trim(f.adult.value);
	f.children.value=Trim(f.children.value);
	f.title.value=Trim(f.title.value);
	f.first_name.value=Trim(f.first_name.value);
	f.last_name.value=Trim(f.last_name.value);
	f.home_address.value=Trim(f.home_address.value);
	f.city.value=Trim(f.city.value);
	f.state.value=Trim(f.state.value);
	f.country.value=Trim(f.country.value);
	f.post_code.value=Trim(f.post_code.value);
	f.phone_no.value=Trim(f.phone_no.value);
	f.email_address.value=Trim(f.email_address.value);

	if(f.adult.value == "")
	{
		errMsg += "Please enter adult no.\n";
		if(!objFocus)
			objFocus = f.adult;
	}
	if(f.children.value == "")
	{
		errMsg += "Please enter children no.\n";
		if(!objFocus)
			objFocus = f.children;
	}
	if(f.title.value == "")
	{
		errMsg += "Please select title\n";
		if(!objFocus)
			objFocus = f.title;
	}

	if(f.first_name.value == "")
	{
		errMsg += "Please enter first name\n";
		if(!objFocus)
			objFocus = f.first_name;
	}
	if(f.last_name.value == "")
	{
		errMsg += "Please enter last name\n";
		if(!objFocus)
			objFocus = f.last_name;
	}
	if(f.home_address.value == "")
	{
		errMsg += "Please enter home address \n";
		if(!objFocus)
			objFocus = f.home_address;
	}
	if(f.city.value == "")
	{
		errMsg += "Please enter city \n";
		if(!objFocus)
			objFocus = f.city;
	}
	if(f.state.value == "")
	{
		errMsg += "Please enter state \n";
		if(!objFocus)
			objFocus = f.state;
	}
	if(f.country.value == "")
	{
		errMsg += "Please select country \n";
		if(!objFocus)
			objFocus = f.country;
	}
	if(f.post_code.value == "")
	{
		errMsg += "Please enter post code \n";
		if(!objFocus)
			objFocus = f.post_code;
	}
	if(f.phone_no.value == "")
	{
		errMsg += "Please enter phone no \n";
		if(!objFocus)
			objFocus = f.phone_no;
	}
	if(f.email_address.value == "")
	{
		errMsg += "Please enter your email address \n";
		if(!objFocus)
			objFocus = f.email_address;
	}
	else
	{
	 if (f.email_address.value.length < 5 || f.email_address.value.indexOf ('@', 0) == -1 || f.email_address.value.indexOf ('.', 0) == -1 || (f.email_address.value.substring(1,0)=='@'))
		{
			errMsg += "Your email address is incorrect\n";
			if(!objFocus)
				objFocus = f.email_address;
		}
	}
	if(errMsg == "")
	{
		return true;
	}
	else
	{
		alert(errMsg);
		objFocus.focus();
		return false;
	}
}

function CheckCanReservation()
{	
	var f = document.chkcanres;
	var title = f.title.value;
	var first_name = f.first_name.value;
	var last_name = f.last_name.value;
	var arr_date = f.arr_date.value;
	var dep_date = f.dep_date.value;
	var email_address = f.email_address.value;
	var errMsg = "";
	var objFocus="";
	
	f.title.value=Trim(f.title.value);
	f.first_name.value=Trim(f.first_name.value);
	f.last_name.value=Trim(f.last_name.value);
	f.arr_date.value=Trim(f.arr_date.value);
	f.dep_date.value=Trim(f.dep_date.value);
	f.email_address.value=Trim(f.email_address.value);

	if(f.title.value == "")
	{
		errMsg += "Please select title\n";
		if(!objFocus)
			objFocus = f.title;
	}

	if(f.first_name.value == "")
	{
		errMsg += "Please enter first name\n";
		if(!objFocus)
			objFocus = f.first_name;
	}
	if(f.last_name.value == "")
	{
		errMsg += "Please enter last name\n";
		if(!objFocus)
			objFocus = f.last_name;
	}
	if(f.arr_date.value == "")
	{
		errMsg += "Please enter Arrival Date \n";
		if(!objFocus)
			objFocus = f.arr_date;
	}
	if(f.dep_date.value == "")
	{
		errMsg += "Please enter Departure Date \n";
		if(!objFocus)
			objFocus = f.dep_date;
	}
	if(f.email_address.value == "")
	{
		errMsg += "Please enter your email address \n";
		if(!objFocus)
			objFocus = f.email_address;
	}
	else
	{
	 if (f.email_address.value.length < 5 || f.email_address.value.indexOf ('@', 0) == -1 || f.email_add.value.indexOf ('.', 0) == -1 || (f.email_address.value.substring(1,0)=='@'))
		{
			errMsg += "Your email address is incorrect\n";
			if(!objFocus)
				objFocus = f.email_address;
		}
	}
	if(errMsg == "")
	{
		return true;
	}
	else
	{
		alert(errMsg);
		objFocus.focus();
		return false;
	}
}

function TotalPAX()
{
	var TotalPax;
	TotalPax = (parseInt(document.chkres.adult.options.value)+parseInt(document.chkres.children.options.value));
	document.chkres.total_pax.value = parseInt(TotalPax);  
}

function TotalRT(roomtype)
{
	var j = document.chkres;
	totalpax=(parseInt(j.depDate.options.value)-parseInt(j.arrDate.options.value));
	switch(roomtype){
		case "1":
			totalrate=j.R01.options.value*1800;
			j.GTOTAL.value=parseInt(totalrate)*totalpax;
			break;
		case "2":
			totalrate=j.R02.options.value*2500;
			j.GTOTAL.value=(parseInt(j.GTOTAL.value)+parseInt(totalrate*totalpax));
			break;
		case "3":
			totalrate=j.R03.options.value*12000;
			j.GTOTAL.value=(parseInt(j.GTOTAL.value)+parseInt(totalrate*totalpax));
			break;
		case "4":
			totalrate=j.R04.options.value*4000;
			j.GTOTAL.value=(parseInt(j.GTOTAL.value)+parseInt(totalrate*totalpax));
			break;
		default:
			totalrate=0;
			totalpax=0;
	}
	j.GTOTAL.value=parseInt(j.GTOTAL.value);
}

function TotalExtraBed()
{
	var x = document.chkres;
	if(x.Extra_Bed.options.value==0)
	{
		x.GTOTAL.value=0;
	}
	else
	{
		x.GTOTAL.value=parseInt(x.Extra_Bed.options.value)*13;
	}
}

function CheckOutOneNight()
{
	var q = document.chkres;
	q.depDate.options.value=(parseInt(q.arrDate.options.value)+1);
}


function ViewForm(link)
{
	window.open(link,'','toolbar=no,menubar=no,location=no,height=500,width=720,scrollbars=yes,dependent=yes');
}

