// 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(confirm_email,CEmail_Empty))
		{
			
			return false;
		}
		if(!IsEmail(confirm_email,CValid_Email))
		{
			
			return false;
		}
		if(email.value != confirm_email.value)
		{
		  alert(Match_Email);
		  confirm_email.focus();
		  return false;
		}		 	
		if(!IsValidInteger(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 Check_ava()
{
	with(document.frmweek)
	{ 
		Submit.value = "Check Availability";
		selected_month.value = monthlist.value;
		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)
{ 
	 with(document.frmweek)
	 {
		 selected_month.value = Month;
		 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(JM_Max_room+" "+room_inventory.value+" "+JM_Max_room_Avai);
			//"JM_Max_room"	=> "Maximum",
			//"JM_Max_room_Avai"	=>" Room Available."
			alert("Maximum"+" "+room_inventory.value+" "+"Room Available.");
			no_of_room.focus();
			return false;
		}
		if(!IsEmpty(extra_adult,L_Valid_Adult))
		{
			return false;
		}
		if(!IsValidInteger(extra_adult,L_Valid_Adult))
		{
			return false;
		}
		if(extra_adult.value<=0)
		{
			alert(L_Valid_Adult);
			extra_adult.focus();
			return false;
		}
		if(!IsEmpty(extra_child,L_Valid_Child))
		{
			return false;
		}
		if(!IsValidInteger(extra_child,L_Valid_Child))
		{
			return false;
		}
		var c=0;
		if(ChargeId.value!='')
		{
			var data=ChargeId.value;
			var arrdata=data.split(",");
			var i;
			var regex = /^[0-9]*$/;
			//alert(data);
			for(i=0; i< arrdata.length-1 ;i++)
				{
					var t="c_"+ arrdata[i];
					var a=eval(t + ".value");
					if(a!='')
					{
						if(!regex.test(a))
						{
							alert(L_Valid_Charge);
							eval(t+".focus()");
							eval(t+".select()");
							c++;
							return false;
							
						}
					}//if
				}
				if(c!=0)
					return false;
		}
			
	return true;
	}
}

function Privacy_Click(page_Id)
{
	with(document.frmtwoweek)
	{
		var hotel_id1=hotel_id.value;
		popupWindowURL("document.php?page_id="+page_Id+"&hotel_id="+hotel_id1, 'PageContent', 650, 500, false, false, true);
	}
}

function Terms_Click(page_Id)
{
	with(document.frmtwoweek)
	{
		var hotel_id1=hotel_id.value;
		popupWindowURL("document.php?page_id="+page_Id+"&hotel_id="+hotel_id1, 'PageContent', 650, 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();
		}

}