// JavaScript Document
//To Check whether the user is valid or not
function zoomPic(gid,cid) {
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	
	winWidth = 800;
	winHeight = 600;
	
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;

	window.open("showZoom.php?galleryid=" + gid + "&category=" +cid, "picture", "width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=1,resizable=0");
	return;
}

function validateBooking1(){
	document.form1.txtFname.value = trimSpaces(document.form1.txtFname.value);
	if(document.form1.txtFname.value.length <= 0) {
		alert("Please enter the first name");
		document.form1.txtFname.focus();
		return false;
	}
	document.form1.txtLName.value = trimSpaces(document.form1.txtLName.value);
	if(document.form1.txtLName.value.length <= 0) {
		alert("Please enter last name");
		document.form1.txtLName.focus();
		return false;
	}
	document.form1.email.value = trimSpaces(document.form1.email.value);
	if(document.form1.email.value.length <= 0) {
		alert("Please enter the email");
		document.form1.email.focus();
		return false;
	}
	if(!checkEmail(document.form1.email.value)) {
		document.form1.email.focus();
		document.form1.email.select();
		return false;
	}
	document.form1.toDo.value="reserve";
	document.form1.submit();
	return true;
}
function checkLogin() {
	document.forms[1].uname.value = trimSpaces(document.forms[1].uname.value);
	if(document.forms[1].uname.value.length <= 0) {
		alert("Please enter the username");
		document.forms[1].uname.focus();
		return false;
	}
	document.forms[1].password.value = trimSpaces(document.forms[1].password.value);
	if(document.forms[1].password.value.length <= 0) {
		alert("Please enter password");
		document.forms[1].password.focus();
		return false;
	}
	document.forms[1].sbm.value="Y";
}

function closeWindow() {
	parent.window.opener.window.focus();
	parent.window.close();
}

function printWindow() 
{
	window.print();
}

function showCalendar(frmElement, dispElement) {
	sWidth = screen.availWidth;
	sHeight = screen.availHeight;
	
	winWidth = 375;
	winHeight = 300;
	
	sLeft = (sWidth - winWidth) / 2;
	sTop = (sHeight - winHeight) / 2;

	window.open("showCalendar.php?frmElement=" + frmElement + "&dispElement=" + dispElement, "Calendar", "width=" + winWidth + ",height=" + winHeight + ",top=" + sTop + ",left=" + sLeft + ",toolbar=0,menubar=0,status=0,scrollbars=0,resizable=0");
	return;
}

function checkFeedBack() {
	document.feedback.visitorName.value = trimSpaces(document.feedback.visitorName.value);
	if(document.feedback.visitorName.value.length <= 0) {
		alert("Please enter your name");
		document.feedback.visitorName.focus();
		return false;
	}

	document.feedback.emailAddress.value = trimSpaces(document.feedback.emailAddress.value);
	if(document.feedback.emailAddress.value.length <= 0) {
		alert("Please enter your email address");
		document.feedback.emailAddress.focus();
		return false;
	}
	if(!checkEmail(document.feedback.emailAddress.value)) {
		document.feedback.emailAddress.focus();
		document.feedback.emailAddress.select();
		return false;
	}

	document.feedback.visitorComments.value = trimSpaces(document.feedback.visitorComments.value);
	if(document.feedback.visitorComments.value.length <= 0) {
		alert("Please enter your comments");
		document.feedback.visitorComments.focus();
		return false;
	}
	document.feedback.frmAction.value = "update";
}

function checkContact()
{
	visitorName =  trimSpaces(document.feedbackForm.visitorName.value);
	visitorEmail =  trimSpaces(document.feedbackForm.visitorEmail.value);
	visitorPhone =  trimSpaces(document.feedbackForm.visitorPhone.value);
	visitorComments =  trimSpaces(document.feedbackForm.visitorComments.value);
	
	if(visitorName == "")
	{
		alert("Please enter your name");
		document.feedbackForm.visitorName.focus();
		return false;
	}
	if(visitorEmail == "")
	{
		alert("Please enter your email");
		document.feedbackForm.visitorEmail.focus();
		return false;
	}
	if(!checkEmail(visitorEmail))
	{
		document.feedbackForm.visitorEmail.select();
		return false;
	}
	if(visitorPhone == "")
	{
		alert("Please enter your phone number");
		document.feedbackForm.visitorPhone.focus();
		return false;
	}
	if(visitorComments == "")
	{
		alert("Please enter your comments");
		document.feedbackForm.visitorComments.focus();
		return false;
	}
	
	document.feedbackForm.frmAction.value="send";
	return true;
}
function checkLinks() {
	if(trimSpaces(document.forms[0].linkname.value).length <= 0) {
		alert("Please provide the Link Name name");
		document.forms[0].linkname.focus();
		return false;
	}
	if(trimSpaces(document.forms[0].linkurl.value).length <= 0) {
		alert("Please provide the Link URL name");
		document.forms[0].linkurl.focus();
		return false;
	}
document.forms[0].frmAction.value = "update";
document.forms[0].passLinkid.value = document.forms[0].elements["linkid[]"].options[document.forms[0].elements["linkid[]"].selectedIndex].value;
document.forms[0].parentlinkid.value = document.forms[0].elements["linkid[]"].options[document.forms[0].elements["linkid[]"].selectedIndex].value;
return true	
}
function submitThis()
{
	document.forms[0].passLinkid.value="0";
	document.forms[0].submit();
}
function downloadFile(file_id)
{
	document.downLoadForm.file_id.value=file_id;
	document.downLoadForm.toDo.value="download";
	document.downLoadForm.submit();
}
function checktellFriendFields(){
	friend=trimSpaces(document.forms[1].friend.value);
	sendTo=trimSpaces(document.forms[1].sendTo.value);
	name=trimSpaces(document.forms[1].name.value);
	mailFrom=trimSpaces(document.forms[1].mailFrom.value);
	if(friend.length<=0){
	 alert("Enter your friend's name");
	 document.forms[1].friend.focus();
	 return false;
	}
	if(sendTo.length<=0){
	 alert("Enter your friend's email");
	 document.forms[1].sendTo.focus();
	 return false;
	}else if(!checkEmail(sendTo)){
	  document.forms[1].sendTo.focus();
	  return false;
	}
	if(name.length<=0){
	 alert("Enter your name");
	 document.forms[1].name.focus();
	 return false;
	}
	if(mailFrom.length<=0){
	 alert("Enter your email");
	 document.forms[1].mailFrom.focus();
	 return false;
	}else if(!checkEmail(mailFrom)){
	  document.forms[1].mailFrom.focus();
	  return false;
	}
	document.forms[1].frmAction.value="send";
}

	function dateChange(){
		var ddCID,mmCID,yyyyCID;
		var ddCOD,mmCOD,yyyyCOD;
		var tempCID,tempCOD;
		ddCID=document.form1.in_day.value;
		mmCID=document.form1.in_month.value;
		yyyyCID=document.form1.in_year.value;
		tempCID="";
		tempCID=mmCID + "/" + ddCID + "/" + yyyyCID;
		if(!isValidDate(document.form1.in_day,tempCID))
		return false;
		tempCID=ddCID + "/" + mmCID + "/" + yyyyCID;
//		tempCOD = dateAdd1(tempCID,1);
//		ddCOD = tempCOD.substring(0,tempCOD.indexOf("/"));	
//		mmCOD = tempCOD.substring(tempCOD.indexOf("/") + 1,tempCOD.lastIndexOf("/"));
//		yyyyCOD = tempCOD.substring(tempCOD.lastIndexOf("/") + 1);
//		document.forms[1].out_day.value = ddCOD;
//		document.forms[1].out_month.value = mmCOD;
//		document.forms[1].out_year.value = yyyyCOD;
	}

	function dateValidate(){
		var ddCID,mmCID,yyyyCID;
		var ddCOD,mmCOD,yyyyCOD;
		var tempCID,tempCOD;
		ddCID=document.form1.in_day[document.form1.in_day.selectedIndex].value;
		mmCID=document.form1.in_month[document.form1.in_month.selectedIndex].value;
		yyyyCID=document.form1.in_year[document.form1.in_year.selectedIndex].value;
		tempCID="";
		tempCID=mmCID + "/" + ddCID + "/" + yyyyCID;
		
		ddCOD=document.form1.out_day[document.form1.out_day.selectedIndex].value;
		mmCOD=document.form1.out_month[document.form1.out_month.selectedIndex].value;
		yyyyCOD=document.form1.out_year[document.form1.out_year.selectedIndex].value;
		tempCOD="";
		tempCOD=mmCOD + "/" + ddCOD + "/" + yyyyCOD;
		
//		document.forms[1].hdnCurrType.value=document.forms[1].CmbBxCurrency[document.forms[1].CmbBxCurrency.selectedIndex].value;
		
		if(!isValidDate(document.form1.in_day,tempCID))
		return;
		if(!isValidDate(document.form1.out_day,tempCOD))
		return;
		
		/*************************/
		/* For arrival check days*/
		/*************************/
	
		var arrival_check_days;
//		arrival_check_days=document.forms[1].hdnarrival_check_days.value;
			
		tempCID=new Date(yyyyCID,mmCID-1,ddCID);
		tempCOD=new Date(yyyyCOD,mmCOD-1,ddCOD);
		today=new Date(2004,10,30);
		temp_day=parseInt(today.getDate())+ parseInt(arrival_check_days);
		
		//Create a variable temp date to check for the validation of arrival check days
		/*
		This section has been modified. The logic is to calculate the milliseconds of todays
		date and the number of milliseconds for arrival check days are added to it.
		Then the milliseconds are compared against milliseconds of the check-in-date and check-out-date.
		Also note that the check does not need to be applied for check-out date as check-out date has to be greater
		than the check-in date.
		*/
		d=(parseInt(arrival_check_days));
//		if(tempCID.getTime()<(today.getTime()+((d)*86400000)))
		if(tempCID.getTime()<(today.getTime())){
//			alert("Check-in date should be " + arrival_check_days + " days greater than current date")
			alert("Check-in Date should not be less than current Date")
			document.form1.in_day.focus()
			return false;
		}
		
		/************************/
		if(tempCOD<=tempCID){
			alert("Check-out Date should be greater than Check-in Date");
			return false;
		}
		
		/*******************************************************************************************/
		/* Check to see if the stay period is Greater than or equal to the minimum allowed stay period*/
		/*******************************************************************************************/
		
		if((tempCOD.getTime() - tempCID.getTime()) < 1*86400000){
			alert("The minimum stay period should not be less than 1 day");
			document.form1.out_day.focus();
			return false;
		}

		/*****************************/
		
		/*******************************************************************************************/
		/* Check to see if the stay period is less than or equal to the maximum allowed stay period*/
		/*******************************************************************************************/
		if((tempCOD.getTime()-tempCID.getTime())>60*86400000){
			alert("The maximum stay period should not be greater than 60 days");
			document.form1.out_day.focus();
			return false;
		}
		/*****************************/
		/*******************************************************************************************/
		/* Check to see if the check in date is less than the maxmimum booking date                */
		/*******************************************************************************************/

		tempMaxBookingDate=new Date("11/30/2007");
		if(tempCID.getTime()>tempMaxBookingDate.getTime()){
			alert("Check-in Date cannot be beyond Friday, November 30, 2007");
			document.form1.in_day.focus();
			return;
		}
		/*******************************************************************************************/
		/*******************************************************************************************/
		/* Check to see if the check in date is less than the maxmimum booking date                */
		/*******************************************************************************************/
		if(tempCOD.getTime()>tempMaxBookingDate.getTime()){
			alert("Check-out Date cannot be beyond Friday, November 30, 2007");
			document.form1.out_day.focus();
			return;
		}
		/*******************************************************************************************/
		document.form1.inDate.value=tempCID;
		document.form1.outDate.value=tempCOD;
		document.form1.frmAction.value='redirectIfLoggedIn';
		document.form1.action="onlineReserve2.php";
		document.form1.submit(); 
	}// dateValidate()

function isValidDate(obj,dt){
	newdt=new Date(dt);
	str=(newdt.getMonth()+1)+"/"+newdt.getDate()+"/"+newdt.getFullYear();
	if(dt==str) return true;
	alert("Invalid date.");
	obj.focus();
	return false;
}

function dateAdd1(objDate, intDays){

  var iSecond=1000;	 // Dates are represented in milliseconds
  var iMinute=60*iSecond;
  var iHour=60*iMinute;
  var iDay=24*iHour;

  var objReturnDate=new Date();
  objReturnDate.setTime(objDate.getTime()+(intDays*iDay));

  return objReturnDate;

}

function regValidate(){
	if(document.form2.loginid.value == ""){
		alert("Please enter Login id");
		document.form2.loginid.focus();
		return false;
	}
	if(document.form2.passwd.value == ""){
		alert("Please enter Password");
		document.form2.passwd.focus();
		return false;
	}
	if(document.form2.passwd2.value == ""){
		alert("Please re-enter Password");
		document.form2.passwd2.focus();
		return false;
	}
	if(document.form2.passwd2.value != document.form2.passwd.value){
		alert("Password Mismatch");
		document.form2.passwd2.focus();
		return false;
	}
	if(document.form2.email.value == ""){
		alert("Please enter email");
		document.form2.email.focus();
		return false;
	}
	if(!checkEmail(document.form2.email.value)){
		return false;
	}
	if(document.form2.fname.value == ""){
		alert("Please enter First Name");
		document.form2.fname.focus();
		return false;
	}
	if(document.form2.lname.value==""){
		alert("Please enter Last Name");
		document.form2.lname.focus();
		return false;
	}
	return true;
}

function loginValidate(){
	if(document.form1.loginid.value == ""){
		alert("Please enter Login id");
		document.form1.loginid.focus();
		return false;
	}
	if(document.form1.passwd.value == ""){
		alert("Please enter Password");
		document.form1.passwd.focus();
		return false;
	}
}