// JavaScript Document
//====================================================================================================
//	File Name		:	twoweek.js
//----------------------------------------------------------------------------------------------------
//	Purpose			:	Client side validation in JavaScript.

//
//====================================================================================================

//====================================================================================================
//	Function Name	:	Form_Submit()
//	Purpose			:	This function will executed when user submits a form. It checks validity of
//						every field in the form.
//
//	Parameters		:	frm  - form name
//	Return			:	true or false

//----------------------------------------------------------------------------------------------------

function Form_Submit(frm)
{
	
	with(frm)
	{	
				
		if(!IsEmpty(fname,F_Name_Empty))
		{
			
			return false;
		}
		if(!IsEmpty(lname,L_Name_Empty))
		{
			
			return false;
		}
				
		if(!IsEmpty(address,Address_Empty))
		{
			
			return false;
		}
		
		if(!IsEmpty(city,City_Empty))
		{
			
			return false;
		}
		if(!IsEmpty(state,State_Empty))
		{
			
			return false;
		}
						
		if(!IsEmpty(country,Country_Empty))
		{
			
			return false;
		}
		
		if(!IsEmpty(email,Email_Empty))
		{
			
			return false;
		}
		if(!IsEmail(email,Valid_Email))
		{
			
			return false;
		}
		if(!IsEmpty(day_phone,Phone_Empty))
		{
			
			return false;
		}
		if(!frm.condition.checked)
		{
			alert("You must confirm that you have read and agree to Terms & condition and Privacy Policy");
			return false;
		}
									 
	return true;
	}
}

//====================================================================================================
//	Function Name	:	Add_Click()
//	Purpose			:	This function will executed when user submits a form. It checks validity of 
//						every field in the form.
//----------------------------------------------------------------------------------------------------
function Add_Click()
{
	with(document.frmtwoweek)
	{
		Action.value = "Add";
		submit();
	}
}




function Show_Room(Adate)
{
	Stamp = new Date();
	
	with(document.frmweek)
	{
		var cdate="",cyear,cmonth="";
		var fulldate="";
		cmonth=Stamp.getMonth()+1;
		if(cmonth<10)
		{
			cmonth="0"+cmonth;
		}
		
		if(cdate<10)
		{
			cdate="0"+cdate;
		}
		fulldate=Stamp.getFullYear()+"-"+cmonth+"-"+cdate;
		
		if(Adate<fulldate)
		{		
			alert(L_Proper_Arrival_Date);
		}
		else
		{
			Action.value="Show_Room";
			submit();
		}
	}
}

function Change_Month(Month)
{ 
	 //alert(document.frmleftpanel.yearlist.value);
	 //alert(Month);
	 with(document.frmweek)
	 {
		 selected_month.value = Month;
		 selected_year.value = yearlist.value;
		 submit();
	 } 
}
function On_Change_Month(Month)
{ 
	 with(document.frmleftpanel)
	 {
		 selected_month.value = Month;
		 selected_year.value = yearlist.value;
		 submit();
	 } 
}
function Change_Year(Year)
{	
	 with(document.frmweek)
	 {
		  selected_year.value = Year;
		  submit();
	 } 
}

function New_Search()
{
	 with(document.frmweek)
	 {
		Action.value='Reset';
		submit();
	 	
	 }
}

function IsValidInteger(fld,msg)
{
	var regex = /^[0-9]*$/;
	if(!regex.test(fld.value))
	{
		alert(msg);
		fld.focus();
		return false;
	}
	return true;
}

//checking for other charges fields
function Submit_Form()
{
	with(document.frmothercharge)
	{	
		var roominventory = parseInt(room_inventory.value);
		var roomrequest = parseInt(no_of_room.value);		
		
		if(!IsEmpty(no_of_room,L_Empty_Room))
		{
			return false;
		}

		if(!IsValidInteger(no_of_room,L_Valid_Room))
		{
			
			return false;
		}

		if(no_of_room.value<=0)
		{
			alert(L_Zero_Room);
			no_of_room.focus();
			return false;
		}
		
		if(roominventory < roomrequest)
		{
			alert("Maxinum "+room_inventory.value+" Room Available.");
			no_of_room.focus();
			return false;
		}
		
		if(!IsValidInteger(extra_adult,L_Valid_Adult))
		{
			return false;
		}
		if(!IsValidInteger(extra_child,L_Valid_Child))
		{
			return false;
		}
			
	return true;
	}
}

function Privacy_Click(page_Id)
{
	with(document.frmtwoweek)
	{
		popupWindowURL("document.php?page_id="+page_Id, 'PageContent', 665, 500, false, false, true);
	}
}

function Terms_Click(page_Id)
{
	with(document.frmtwoweek)
	{
		popupWindowURL("document.php?page_id="+page_Id, 'PageContent', 665, 500, false, false, true);
	}
}
function View_Gallary(Room_Id,Total)
{
	with(document.frmroom)
	{
		popupWindowURL("gallary.php?room_id="+Room_Id+"&Action=View_Gallary&total="+Total, 'PageContent', 650, 500, false, false, true);
	}
}
function Next_Click()
{
		with(document.frmview)
		{
			action.value="Next";
			submit();
		}
}
function Previous_Click()
{
		with(document.frmview)
		{
			action.value="Previous";
			submit();
		}

}


