
//For Set Current Date in Quickbox : By Krunal
function callMe()
{
	var dDate;
	var iYear;
	var iMonth;
	var iDay;

	dDate = new Date();
	iDay = dDate.getDate();
	iMonth = dDate.getMonth() + 1;
	iYear = dDate.getFullYear();

	//if(document.frmBook.ArrivalDate != null)
	//alert("test");
	//alert(iDay + '/'+ iMonth + '/' +  iYear);
	document.getElementById('ArrivalDate').value = iDay + '/'+ iMonth + '/' +  iYear;

}

// Arrival Date Validation Starts Here ... : By Krunal
// Handles Date Format of dd/mm/yyyy and not allow date less than today and not allow blank also.
function checkDate(frm)
{
	var dArrival = document.getElementById('ArrivalDate').value;
	var field = eval(document.getElementById('ArrivalDate'));

	//============= Date < Today Checking(KP) ====================

	var now = new Date();
	var comps;	var jDay;	var jMonth;	var jYear;
	comps = dArrival.split("/");
	jDay = parseInt(comps[0],10);
	jMonth = parseInt(comps[1],10);
	jYear = parseInt(comps[2],10)

	var dDate; var iDay; var iMonth; var iYear;
	dDate = new Date();
	iDay = dDate.getDate();
	iMonth = dDate.getMonth()+1;
	iYear = dDate.getFullYear();

	var now = new Date(iYear,iMonth-1,iDay);
	var testdate = new Date(jYear,jMonth-1,jDay);
	//alert("Input: " + testdate + " \n Current:" + now );
	if (testdate < now)
	{
		alert( "Please select the Arrival Date greater than or equal to Today.");
		return false;
	}

	//============= Date < Today Checking End(KP) ====================


	//============= Date Format Checking(KP) ====================
	var s;
	if(dArrival != "")
	{
		s = datevalidator(field,'ddmmyyyy');
		if(!s)
		{
			alert("Invalid date value must be  DD/MM/YY or DD/MM/YYYY");
			return false;
		}
	}
	else
	{
		alert("Please Specify Arrival Date");
		return false;
	}
	return true;
}

function datevalidator(field,type)
{
	if (type == "ddmmyyyy")
	{
		var month;
		var day;
		var year;

		if (field.value.indexOf("/") == -1 && field.value.indexOf(".") == -1 && field.value.indexOf("-") == -1)
		{
			var l = field.value.length;
			day = parseInt(field.value.substr(0,2-l%2),10);
			month = parseInt(field.value.substr(2-l%2,2),10);
			year = parseInt(field.value.substr(4-l%2),10);
		}
		else
		{
			var comps;
			if (field.value.indexOf("/") != -1 ){
				comps = field.value.split("/");
			}else if(field.value.indexOf(".") != -1 ){
				comps = field.value.split(".");
			}else if( field.value.indexOf("-") != -1 ){
				comps = field.value.split("-");
			}

			day = parseInt(comps[0],10);
			month = parseInt(comps[1],10);
			year = parseInt(comps[2],10);

		}
		if (month >= 1 && month <= 12 && day >= 1 && day <=31 && ((year >= 0 && year < 100) || (year > 1900 && year <2100)))
		{
			if (year < 50)
			year += 2000;
			else if (year < 100)
			year += 1900;
			if(year <= 1900 ){
				//alert(" The Year Must Be Greater then 1900");
				validflag = false;
			}else{
				field.value = getDateString(new Date(year, month-1, day),'ddmmyy');
				validflag = true;
			}
		}
		else
		{
			//alert("Invalid date value must be  DD/MM/YY or DD/MM/YYYY");
			validflag = false;
		}
	}
	////////////////////////////////////////////// mm dd yyyy date
	else if (type == "mmyydate")
	{
		var month;
		var day = 0;
		var year;

		if (field.value.indexOf("/") == -1)
		{
			var l = field.value.length;
			month = parseInt(field.value.substr(0,2-l%2),10);
			year = parseInt(field.value.substr(2-l%2),10);
		}
		else
		{
			var comps = field.value.split("/");
			month = parseInt(comps[0],10);
			if (comps[2] != null)
			{
				day  = parseInt(comps[1],10);
				year = parseInt(comps[2],10);
			}
			else
			year = parseInt(comps[1],10);
		}
		if (month >= 1 && month <= 12 && ((year >= 0 && year < 100) || (year > 1900 && year <2100)))
		{
			if (year < 50)
			year += 2000;
			else if (year < 100)
			year += 1900;
			if (day == 0 || day > 31)
			{
				if (month == 2)
				{
					if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))
					day = 29;
					else
					day = 28;
				}
				else if (month == 4 || month == 6 || month == 9 || month == 11)
				day = 30;
				else
				day = 31;
			}
			Field.value = getDateString(new Date(year, month-1, mmddyy));
			validflag = true;
		}
		else
		{
			//alert("Invalid date Value (must be MMYY, MMYYYY, MM/DD/YY, MM/DD/YYYY)");
			validflag = false;
		}
	}
	return validflag;
}

function getDateString(date,format)
{
	if(format=='mmddyy'){
		return (date.getMonth()+1)+"/"+date.getDate()+"/"+date.getFullYear();
	}
	else if(format=='ddmmyy')
	{
		return date.getDate()+"/"+(date.getMonth()+1)+"/"+ date.getFullYear();
	}
}
// Arrival Date Validation Ends Here ... : By Krunal

function validate(frm)
{
	var s = checkDate(frm);
	if (!s)
	{
		return s;
	}

	if ( parseInt(frm.Rooms.options[frm.Rooms.selectedIndex].value) > parseInt(frm.Adults.options[frm.Adults.selectedIndex].value) )
	{
		alert("There should be one Adult Per Room.");
		frm.Adults.focus();
		return false;
	}

	//changeDIV(this);
}

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 used to toggle layers
var currDivObj = null;
function changeDIV(selObj)
{
	var divObj;
	if (document.getElementById)
	divObj = document.getElementById("div1");
	else if(document.all)
	divObj = document.all("div1");
	else if (document.layers)
	divObj = document.layers["div1"];

	if(document.getElementById || document.all)
	{
		divObj.style.display = "block";
	}
	currDivObj = divObj;

	var objDiv;

	if (document.getElementById)
	objDiv = document.getElementById("div0");
	else if(document.all)
	objDiv = document.all("div0");
	else if (document.layers)
	objDiv = document.layers["div0"];

	if(document.getElementById || document.all)
	{
		objDiv.style.display = "none";
	}

	// call progressbar function to generate progressbar
	progress();
}

// function used to generate progressbar on the page
function progress()
{
	intWidth = parseInt(document.getElementById("container").style.width) + 1;
	if(intWidth <= 440){
		document.getElementById("container").style.width = intWidth;
	}else{
		document.getElementById("container").style.width = 0;
	}
	setTimeout("progress()",150);
}
