function trim (strVar) { 
	if(strVar.length >0)
	{
		while(strVar.charAt(0)==" ")			//remove left spaces
			strVar=strVar.substring(1,strVar.length);
		while(strVar.charAt(strVar.length-1)==" ")			//remove right spaces
			strVar=strVar.substring(0,strVar.length-1);
	}
	return strVar;
}

function check(thisForm)
{
	var arrivalDt	= thisForm.arrivalDt.value;
	var duration	= thisForm.duration.value;
	var adult		= thisForm.adult.value;
	var budget		= thisForm.budget.value;
	var tour_type	= thisForm.tour_type.value;
	var name		= trim(thisForm.name.value);
	var email		= trim(thisForm.email.value);
	var country		= trim(thisForm.country.value);
	var phone		= trim(thisForm.phone.value);
	var description	= trim(thisForm.description.value);

	if(arrivalDt.length==0)
	{
		alert("Please select Checkin Date!")
		thisForm.arrivalDt.focus();
		return false;
	}
/*	if(duration.length==0)
	{
		alert("Please select Duration!")
		thisForm.duration.focus();
		return false;
	}
	if(adult.length==0)
	{
		alert("Please select Adult!")
		thisForm.adult.focus();
		return false;
	}
	if(budget.length==0)
	{
		alert("Please select Budget!")
		thisForm.budget.focus();
		return false;
	}
	if(tour_type.length==0)
	{
		alert("Please select Tour Style!")
		thisForm.tour_type.focus();
		return false;
	}
	if(description.length==0)
	{
		alert("Please enter Requirements & Travel Plan:!")
		thisForm.description.focus();
		return false;
	}
*/
	if (name.length==0)
	{
		alert("Please enter your name!")
		thisForm.name.focus();
		return false;	
	}

	if (email.length==0)
	{
		alert("Please enter your email address!")
		thisForm.email.focus();
		return false;	
	}
	if(checkEmail(email) == false)
	{
		alert("Invalid email! Please re-enter.");
		thisForm.email.select();
		return false;
	}
/*	if (country.length==0)
	{
		alert("Please enter your Country!");
		thisForm.country.focus();
		return false;
	}
	if (phone.length==0)
	{
		alert("Please enter your Phone!");
		thisForm.phone.focus();
		return false;
	}
*/
	return true;
}
function checkEmail(email) 
{
	if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(email))
	{
		return (true);
	}
	return false;
}

/* CALENDER JS*/
var HighlightToday	= true;
var DisablePast		= true;
var MonthNames = new Array("January","February","March","April","May","June","July","August","September","October","November","December");

// Global Vars
var now	 = new Date();
var dest = null;
var pos	 = null;
var sDate= null;
var ny = now.getFullYear(); 
var nm = now.getMonth();
var nd = now.getDate();
var sy = 0; 
var sm = 0;
var sd = 0;
var y = now.getFullYear(); 
var m = now.getMonth();
var d = now.getDate();
var l = 0;
var t = 0;
var MonthLengths = new Array(31,28,31,30,31,30,31,31,30,31,30,31);

function getXCoord(el) {
	x = 0;
	while(el){
		x += el.offsetLeft;
		el = el.offsetParent;
	}
	return x;
}
function getYCoord(el) {
	y1 = 0;
	while(el){
		y1 += el.offsetTop;
		el = el.offsetParent;
	}
	return y1;
}

function GetDate() {
	EnsureCalendarExists();
	DestroyCalendar();

	if(arguments[0] == null || arguments[0] == "") {
		alert("ERROR: Destination control required in funciton call GetDate()");
		return;
	}
	else
	{
		dest = arguments[0];
		pos	= arguments[1];
		sDate = arguments[2];
	}
	y = now.getFullYear();
	m = now.getMonth();
	d = now.getDate();
	sm = 0;
	sd = 0;
	sy = 0;
	var cdval = dest.value;
 
	if(/\d{1,2}.\d{1,2}.\d{4}/.test(dest.value)) {
		var vParts = cdval.split("/"); // assume mm/dd/yyyy
		sd = vParts[0];
		sm = vParts[1] - 1;
		sy = vParts[2];
		m = sm;
		d = sd;
		y = sy;
	}
	if(sDate != null){
		var sdval = sDate.value;
		if(/\d{1,2}.\d{1,2}.\d{4}/.test(sDate.value)) {
			var vParts = sdval.split("/"); 
			sd = vParts[0];
			sm = vParts[1] - 1;
			sy = vParts[2];
			m = sm;
			d = sd;
			y = sy;
		}
	}

	l = getXCoord(pos);
	t = getYCoord(pos);

	if(t < 0) t = 0; 
	DrawCalendar();
}

function DestroyCalendar() {
	var cal = document.getElementById("dpCalendar");
	if(cal != null) {
		cal.innerHTML = null;
		cal.style.display = "none";
	}
	return
}

function DrawCalendar() {
	DestroyCalendar();
	cal = document.getElementById("dpCalendar");

	cal.style.position = 'absolute';
	cal.style.left = l + "px";
	cal.style.top = t + "px";

	var sCal = "<table><tr><td class=\"cellButton\"><a href=\"javascript: PrevMonth();\" title=\"Previous Month\">&laquo;</a></td>"+
		"<td class=\"cellMonth\" width=\"80%\" colspan=\"5\">"+MonthNames[m]+" "+y+"</td>"+
		"<td class=\"cellButton\"><a href=\"javascript: NextMonth();\" title=\"Next Month\">&raquo;</a></td></tr>"+
		"<tr align=center><td>S</td><td>M</td><td>T</td><td>W</td><td>T</td><td>F</td><td>S</td</tr>"+
		"<tr><td height=1 bgcolor=\"#000066\" colspan=\"7\"></td</tr>";
	var wDay = 1;
	var wDate = new Date(y, m, wDay);

	if(isLeapYear(wDate)) {
		MonthLengths[1] = 29;
	} else {
		MonthLengths[1] = 28;
	}
	var dayclass = "";
	var isToday = false;
	for(var r=1; r<7; r++) {
		sCal = sCal + "<tr>";
		for(var c=0; c<7; c++) {
			var wDate = new Date(y, m, wDay);
			if(wDate.getDay() == c && wDay<=MonthLengths[m]) {
			if(wDate.getDate()==sd && wDate.getMonth()==sm && wDate.getFullYear()==sy) {
				dayclass = "cellSelected";
				isToday = true; // only matters if the selected day IS today, otherwise ignored.
			} else if(wDate.getDate()==nd && wDate.getMonth()==nm && wDate.getFullYear()==ny && HighlightToday) {
				dayclass = "cellToday";
				isToday = true;
			} else {
			dayclass = "cellDay";
			isToday = false;
		}

		if(sDate != null && wDay < sd && wDate.getMonth()==sm && wDate.getFullYear()==sy)
		{
			sCal = sCal + "<td class=\""+dayclass+"\" style=text-decoration:line-through;>"+wDay+"</td>";
		}
		else if(((now > wDate) && !DisablePast) || (now <= wDate) || isToday) { // >

			sCal = sCal + "<td class=\""+dayclass+"\"><a href=\"javascript: ReturnDay("+wDay+");\">"+wDay+"</a></td>";
			} else {
				sCal = sCal + "<td class=\""+dayclass+"\" style=text-decoration:line-through;>"+wDay+"</td>";
			}
			wDay++;
		} else {
			sCal = sCal + "<td class=\"unused\"></td>";
		}
	}
	sCal = sCal + "</tr>";
	}
	sCal = sCal + "<tr><td colspan=\"5\" class=\"unused\"></td><td colspan=\"3\" class=\"cellCancel\"><a href=\"javascript: DestroyCalendar();\"><b>close</b></a></td></tr></table>"
	cal.innerHTML = sCal; 
	cal.style.display = "inline";
}

function PrevMonth() {
	m--;
	if(m==-1) {
		m = 11;

		y--;
	}
	DrawCalendar();
}

function NextMonth() {
	m++;
	if(m==12) {
		m = 0;
		y++;
	}
	DrawCalendar();
}

function ReturnDay(day) {
	cDest = document.getElementById(dest);
	var a = m+1;
	var b = day;
	if(a<10) var a = '0' + a;
	if(b<10) var b = '0' + day;
	//dest.value = day+"/"+(m+1)+"/"+y;
	dest.value = b+"/"+a+"/"+y;

	DestroyCalendar();
}

function EnsureCalendarExists() {
	if(document.getElementById("dpCalendar") == null) {
		var eCalendar = document.createElement("div");
		eCalendar.setAttribute("id", "dpCalendar");
		document.body.appendChild(eCalendar);
	}
}

function isLeapYear(dTest) {
	var y = dTest.getYear();
	var bReturn = false;

	if(y % 4 == 0) {
		if(y % 100 != 0) {
			bReturn = true;
		} else {
			if (y % 400 == 0) {
				bReturn = true;
			}
		}
	}
	return bReturn;
}
function checkCity(value, S_city, S_city1, S_city2)
{
	S_city1	= document.getElementById(S_city1);
	S_city2	= document.getElementById(S_city2);
	S_city	= document.getElementById(S_city);

	if(value=="India")
	{
		S_city1.style.display = 'block';
		S_city.style.display = 'none';
	}
	else
	{
		S_city1.style.display = 'none';
		S_city2.style.display = 'none';
		S_city.style.display = 'block';
	}
}
function checkCityOther(value, S_city2)
{
	S_city2	= document.getElementById(S_city2);

	if(value=="Other")
		S_city2.style.display = 'block';
	else
		S_city2.style.display = 'none';
}

function num_of_room(val)
{
	document.getElementById('room_req').style.display = "";
	document.getElementById('room2').style.display = "none";
	document.getElementById('room3').style.display = "none";
	document.getElementById('room4').style.display = "none";
	if(val.length==1)
	{
		if(val>1)
			document.getElementById('room2').style.display = "";
		if(val>2)
			document.getElementById('room3').style.display = "";
		if(val>3)
			document.getElementById('room4').style.display = "";
	}
	else if(val.length==2)
		document.getElementById('room_req').style.display = "none";
}



function child_age(childs, row)
{
	ch1.style.display = "none";
	ch2.style.display = "none";
	ch3.style.display = "none";
	ch4.style.display = "none";

	childRoom1 = document.f1.childRoom1.value;
	childRoom2 = document.f1.childRoom2.value;
	childRoom3 = document.f1.childRoom3.value;
	childRoom4 = document.f1.childRoom4.value;

	if(childRoom1>0 || childRoom2>0 || childRoom3>0 || childRoom4>0)
		ch1.style.display = "";
	if(childRoom1>1 || childRoom2>1 || childRoom3>1 || childRoom4>1)
		ch2.style.display = "";
	if(childRoom1>2 || childRoom2>2 || childRoom3>2 || childRoom4>2)
		ch3.style.display = "";
	if(childRoom1>3 || childRoom2>3 || childRoom3>3 || childRoom4>3)
		ch4.style.display = "";
	if(row==1)
	{
		r10.style.display = "none";
		r11.style.display = "none";
		r12.style.display = "none";
		r13.style.display = "none";
		r14.style.display = "none";

		if(childs>0)
		{
			r10.style.display = "";
			r11.style.display = "";
			if(childs>1)
				r12.style.display = "";
			if(childs>2)
				r13.style.display = "";
			if(childs>3)
				r14.style.display = "";
		}
	}
	if(row==2)
	{
		r20.style.display = "none";
		r21.style.display = "none";
		r22.style.display = "none";
		r23.style.display = "none";
		r24.style.display = "none";

		if(childs>0)
		{
			r20.style.display = "";
			r21.style.display = "";
			if(childs>1)
				r22.style.display = "";
			if(childs>2)
				r23.style.display = "";
			if(childs>3)
				r24.style.display = "";
		}
	}
	if(row==3)
	{
		r30.style.display = "none";
		r31.style.display = "none";
		r32.style.display = "none";
		r33.style.display = "none";
		r34.style.display = "none";

		if(childs>0)
		{
			r30.style.display = "";
			r31.style.display = "";
			if(childs>1)
				r32.style.display = "";
			if(childs>2)
				r33.style.display = "";
			if(childs>3)
				r34.style.display = "";
		}
	}
	if(row==4)
	{
		r40.style.display = "none";
		r41.style.display = "none";
		r42.style.display = "none";
		r43.style.display = "none";
		r44.style.display = "none";

		if(childs>0)
		{
			r40.style.display = "";
			r41.style.display = "";
			if(childs>1)
				r42.style.display = "";
			if(childs>2)
				r43.style.display = "";
			if(childs>3)
				r44.style.display = "";
		}
	}
}

