function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
		curtop = obj.offsetTop
		while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
			curtop += obj.offsetTop
		}
	}
	return curleft + "," +curtop;
}

function mmOver(mm)
{
	mm.className = "leftmenu_over";
}

function mmOut(mm)
{
	mm.className = "";
}

function f_elim(val,e)
{
	if(val==1)
	{
		document.getElementById('branch_tr').style.display='';
		document.getElementById('branch_id').disabled=false;
	}
	else
	{
		document.getElementById('branch_tr').style.display='none';
	}
	frames['add'].location.href='if_elim.php?f='+val+'&e='+e;
}

function addp()
{
	pos = findPos(document.getElementById('addnewparish')).split(",");
	posx = pos[0] - 290;
	posy = pos[1] - 30;
	document.getElementById('addparish').style.left = posx + "px";
	document.getElementById('addparish').style.top = posy + "px";
	frames['addparish'].location.href='addparish.php'; 
	document.getElementById('addparish').style.display=''; 
}

function close_addp(d)
{
	document.getElementById('branch_id').disabled=false;  
	document.getElementById('addparish').style.display='none'; 
	document.getElementById('parish_id').disabled=false;
}

//for employment status
function employStatus()
{
	obj = document.frm_addreg;
	obj.employmentStatus_seleted.value = "1";
	//if unemployed
	if(obj.employment_status[0].checked == true)
	{
		document.getElementById('employmentTable').style.display = 'none';
		//Effect.Fade('employmentTable');
		obj.company_name.value		= '';
		obj.company_address.value	= '';
		obj.position_id.value		= '';
		obj.company_tel_no.value		= '';
		obj.business_type.value		= '';
	}
	//if self-employed
	else if(obj.employment_status[2].checked == true)
	{
		document.getElementById('employmentTable').style.display = '';
		document.getElementById('positionId').style.display = 'none';
		//Effect.Fade('employmentTable');
		obj.company_name.value		= '';
		obj.company_address.value	= '';
		obj.position_id.value		= '';
		obj.company_tel_no.value		= '';
		obj.business_type.value		= '';
		obj.company_name.focus();
	}
	//if employed
	else
	{
		document.getElementById('employmentTable').style.display = '';
		document.getElementById('positionId').style.display = '';
		//Effect.Appear('employmentTable');
		obj.company_name.focus();
	}
}



/*
 * Lodging Reservation Section
 * 
 */
 
// returns true if the string is empty
function isEmpty(str){
	
	if(str == "" || str.length == 0 || str == null)
	{
		return false;
	}
	
	return true;
}

//numbers only and one decimal point
function isFloatKey(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode;
	//if ((charCode > 31 && (charCode < 48 || charCode > 57)) && charCode != 46) // with dot
	if (charCode > 31 && (charCode < 48 || charCode > 57))
	return false;

	return true;
}

//numbers only
function isNumberKey(evt)
{
	var charCode = (evt.which) ? evt.which : event.keyCode;

	if (charCode > 31 && (charCode < 48 || charCode > 57))
	return false;

	return true;
}

function selectedMenu(obj,type)
{
	var submenu = "submenu_";
	//alert(obj.id);
	if(type == 1)
	{  obj.style.backgroundColor = '#1C4644'; obj.style.color = '#FFFFFF'; }
	else if(type == 0)
	{ obj.style.backgroundColor = '#FFFFFF'; obj.style.color = '#1C4644'; }
	
	
	if(type == 2) 
	{
		for(var i = 1; i <= 5; i++)
		{
			$(submenu+i).style.backgroundColor = '#FFFFFF';	
			$(submenu+i).style.color = '#1C4644';	
			
			$(submenu+i).onmouseover = function(){selectedMenu(this,1)};
			$(submenu+i).onmouseout = function(){selectedMenu(this,0)};
			$(submenu+i).onclick = function(){selectedMenu(this,2)};
			
		}
		//alert($('submenu_1').onmouseover);
		obj.onmouseover = '';
		obj.onmouseout = '';
		obj.onclick = '';
		obj.style.color = '#FFFFFF';
		obj.style.background = '#1C4644';
		var url = "concierge_content.php";
		var pars = "menu="+obj.id;
		var myAjax = new Ajax.Request( url, 
									  	{ method: 'POST', 
										  parameters: pars, 
									  	  onSuccess: function(data){
										  data = data.responseText;
											  $('main_container').innerHTML = data;
										  },
										  onFailure: function(){ alert('what?'); }
										} );
	}
}

function showContentResponse (originalRequest) {
	var newData = originalRequest.responseText;
	var update = new Array();
	
	if(newData.indexOf('|' != -1))
	{
		update = newData.split('|');

		if(update[0] == "elim_id")
		{
			$('elimID_status').style.display = '';
			if(update[2] == "success")
			{
				$(update[1]).innerHTML = "<strong>Name:</strong> " + update[3];
			}
			else
			{
				$(update[1]).innerHTML = "<strong>Error:</strong> " + update[2];
			}
		}
	}
}

function getAjaxData(url,pars)
{
	if(url == "ajax_data.php")
	{
		//document.getElementById('elimID_status').innerHTML = "checking...";
	}
	
	var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars, onComplete: showContentResponse} );
}


//check elim ID if available
function checkElimID(elimID)
{
	if(elimID == "" || elimID.length == 0)
	{
		alert("Please enter Elim ID Number.");
	}
	else
	{
		getAjaxData('ajax_data.php','type=elim_id&elim_id='+elimID);
	}
}

function totalPerson(totalPersons, selectedNum)
{
	var persons = "person_";
	for(var i = 1; i <= totalPersons; i++)
	{
		document.getElementById(persons+i).disabled = true;
		document.getElementById(persons+i).style.backgroundColor = "#CCCCCC";
	}
	
	for(var i = 1; i <= selectedNum; i++)
	{
		document.getElementById(persons+i).disabled = false;
		document.getElementById(persons+i).style.backgroundColor = "";
	}
}
 
function checkReservation(formObj, type)
{
	var check_in_month = formObj.check_in_month.value == "" ? "" : parseInt(formObj.check_in_month.value);
	var check_in_day = formObj.check_in_day.value == "" ? "" : parseInt(formObj.check_in_day.value);
	var check_in_year = formObj.check_in_year.value == "" ? "" : parseInt(formObj.check_in_year.value);
	
	var check_out_month = formObj.check_out_month.value = "" ? "" : parseInt(formObj.check_out_month.value);
	var check_out_day = formObj.check_out_day.value == "" ? "" : parseInt(formObj.check_out_day.value);
	var check_out_year = formObj.check_out_year.value == "" ? "" : parseInt(formObj.check_out_year.value);
	var elim_id = formObj.elim_id.value;
	var formError = "";
	
	//days of the month
	if(check_in_month == 2)
	{
		var check_in_days = ((check_in_year % 4) == 0) ? 29 : 28;
	}
	else if(check_in_month == 4 || check_in_month == 6 || check_in_month == 9 || check_in_month == 11)
	{
		var check_in_days = 30;
	}
	else
	{
		var check_in_days = 31;
	}
	
	//days of the month
	if(check_out_month == 2)
	{
		var check_out_days = ((check_out_year % 4) == 0) ? 29 : 28;
	}
	else if(check_out_month == 4 || check_out_month == 6 || check_out_month == 9 || check_out_month == 11)
	{
		var check_out_days = 30;
	}
	else
	{
		var check_out_days = 31;
	}
	
	
	if(isEmpty(elim_id) == false )
	{
		formError += "Please enter Elim ID No.\n";
	}
	
	if(isEmpty(check_in_month) == false 
		|| isEmpty(check_in_day) == false 
		|| isEmpty(check_in_year) == false
		|| check_in_day > check_in_days)
	{
		formError += "Please enter the correct Check-in Date\n";
	}
	
	if(isEmpty(check_out_month) == false 
	|| isEmpty(check_out_day) == false 
	|| isEmpty(check_out_year) == false
	|| check_out_day > check_out_days)
	{
		formError += "Please enter the correct Check-out Date\n";
	}

	if(isEmpty(check_in_month) == true && isEmpty(check_in_day) == true && isEmpty(check_in_year) == true
		&& isEmpty(check_out_month) == true && isEmpty(check_out_day) == true && isEmpty(check_out_year) == true)
	{
		if(check_in_month == check_out_month && check_in_day == check_out_day && check_in_year == check_out_year)
		{
			formError += "Check-out Date should be 1 or more days ahead1\n";
		}
		else if((check_in_year > check_out_year) 
					|| (check_in_year == check_out_year && check_in_month > check_out_month) 
					|| (check_in_year == check_out_year && check_in_month == check_out_month && check_in_day > check_out_day))
				{
					formError += "Check-out Date should be 1 or more days ahead\n";
				}
	}

	//for room reservation type
	if(type == "R")
	{
		var total_perons = formObj.total_persons.value;
		var persons = "person_";
		var stringError = 0;
		for(var i=1; i <= total_perons; i++)
		{
			if(document.getElementById(persons+i).value == "")
			{
				stringError = 1;
			}
		}
		
		if(stringError == 1)
		{
			formError += "Please fill-in the name(s) of the people.\n";
		}
	}
	
	if(formError != "")
	{
		alert(formError);
		return false;
	}
	
	return true;
}
