function disableSubmitButton (button) 
	{
	if (typeof button.disabled != 'undefined')
		button.disabled = true;
	else if (!button.buttonDisabled) 
		{
		button.oldValue = button.value;
		button.oldOnclick = button.onclick;
		button.value = 'DISABLED';
		button.onclick = cancelAction;
		button.buttonDisabled = true;
		}
	document.getElementById("submitbutton").className="";
	}
	
function enableSubmitButton (button) 
	{
	if (typeof button.disabled != 'undefined')
		button.disabled = false;
	else if (button.buttonDisabled) 
		{
		button.value = button.oldValue;
		button.onclick = button.oldOnclick;
		button.buttonDisabled = false;
		}
	var exists = document.getElementById("roomalert_top");
	if (exists != null) 
		{
		document.getElementById("submitbutton").className="oktobook";
		document.getElementById("roomalert_top").className="roomalert_off";
		document.getElementById("roomalert_bottom").className="roomalert_off";
		}
	document.getElementById('submitbutton').focus();
	}

	
function fadeIn(objId,opacity) {
	if (document.getElementById) {
		obj = document.getElementById(objId);
		if (opacity <= 100) {
			setOpacity(obj, opacity);
			opacity += 8;
			window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
		}
	}
}

function setOpacity(obj, opacity) 
	{
	opacity = (opacity == 100)?99.999:opacity;
	// IE/Win
	obj.style.filter = "alpha(opacity:"+opacity+")";
	// Safari 1.2, Konqueror
	obj.style.KHTMLOpacity = opacity/100;
	// Older Mozilla and Firefox
	obj.style.MozOpacity = opacity/100;
	// Safari 1.2, newer Firefox and Mozilla, CSS3
	obj.style.opacity = opacity/100;
	}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	 Show hide stuff
//////////////////////////////////////////////////////////////////////////////////////////////////////////////

function hidediv($elementName) 
	{
	if (document.getElementById) 
		{ // DOM3 = IE5, NS6
		document.getElementById($elementName).style.visibility = 'hidden';
		}
	else 
		{
		if (document.layers) 
			{ // Netscape 4
			document.$elementName.visibility = 'hidden';
			}
		else 
			{ // IE 4
		document.all.$elementName.style.visibility = 'hidden';
			}
		}
	}

function showdiv($elementName) 
	{
	if (document.getElementById) 
		{ // DOM3 = IE5, NS6
		document.getElementById($elementName).style.visibility = 'visible';
		}
	else 
		{
		if (document.layers) 
			{ // Netscape 4
			document.$elementName.visibility = 'visible';
			}
		else 
			{ // IE 4
			document.all.$elementName.style.visibility = 'visible';
			}
		}
	}

///////////////////////////////////////
//
//	Generic onload by Brothercake
//	http://www.brothercake.com/
//
///////////////////////////////////////

//onload function
function generic()
	{
	if ( toload.length > 0 )
		{
		for (x in toload)
			{
			eval(toload[x]);
			}
		}
	if ( document.ajaxform !=undefined ) 
		disableSubmitButton(document.ajaxform.confirmbooking);
	}
	
//setup onload function
var undefined;
var toload=new Array();
var templateVersion = 2.5;

if(typeof window.addEventListener != 'undefined')
{
	//.. gecko, safari, konqueror and standard
	window.addEventListener('load', generic, false);
}
else if(typeof document.addEventListener != 'undefined')
{
	//.. opera 7
	document.addEventListener('load', generic, false);
}
else if(typeof window.attachEvent != 'undefined')
{
	//.. win/ie

	window.attachEvent('onload', generic);
}

//** remove this condition to degrade older browsers
else
{
	//.. mac/ie5 and anything else that gets this far
	
	//if there's an existing onload function
	if(typeof window.onload == 'function')
	{
		//store it
		var existing = onload;
		
		//add new onload handler
		window.onload = function()
		{
		//call existing onload function
		existing();
		//call generic onload function
		generic();
		};
	}
	else
	{
		//setup onload function
		window.onload = generic;
	}
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	 Ajax get response stuff
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function getResponse_particulars(field,value) {
HideRoomsList();
AjaxRequest.get(
	{
	//'onLoading':function(req){showdiv("indicator"); hidediv("submitbutton");}
	'onLoading':function(req){showdiv("indicator"); }
	,'parameters':{ 'field':field,'value':value }
	,'url':livesite+'/index2.php?option=com_jomres&task=handlereq&no_html=1'
	,'timeout':20000
	,'onTimeout':function(req){ hidediv("indicator"); alert('Timed Out!'); }
	,'onSuccess':function(req){ hidediv("indicator"); showRoomsList(req); showdiv("selectedRooms"); show_log(field);}
	,'onError':function(req)	{ hidediv("indicator"); alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
	}
	);
}

function getResponse_guesttype(typeid,value) {
HideRoomsList();
AjaxRequest.get(
	{
	'onLoading':function(req){showdiv("indicator"); }	
	,'parameters':{ 'field':'guesttype','typeid':typeid,'value':value }
	,'url':livesite+'/index2.php?option=com_jomres&task=handlereq&no_html=1'
	,'timeout':20000
	,'onTimeout':function(req){ hidediv("indicator"); alert('Timed Out!'); }
	,'onSuccess':function(req){ hidediv("indicator"); showRoomsList(req); show_log('guesttype');}
	,'onError':function(req)	{ hidediv("indicator"); alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
		}
	);
}
function getResponse_rooms(field,value) {
HideRoomsList();
AjaxRequest.get(
	{
	'onLoading':function(req){showdiv("indicator"); }
	,'parameters':{ 'field':field,'value':value }
	,'url':livesite+'/index2.php?option=com_jomres&task=handlereq&no_html=1'
	,'timeout':20000
	,'onTimeout':function(req){ hidediv("indicator"); alert('Timed Out!'); }
	,'onSuccess':function(req){ hidediv("indicator"); showRoomsList(req); showdiv("extrascontainer");show_log(field);}
	,'onError':function(req)	{ hidediv("indicator"); alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
	}
	);
}
function getResponse(field,value) {
HideRoomsList();
AjaxRequest.get(
	{
	'onLoading':function(req){showdiv("indicator"); }
	,'parameters':{ 'field':field,'value':value }
	,'url':livesite+'/index2.php?option=com_jomres&task=handlereq&no_html=1'
	,'timeout':20000
	,'onTimeout':function(req){ hidediv("indicator"); alert('Timed Out!'); }
	,'onSuccess':function(req){ hidediv("indicator"); showRoomsList(req); showdiv("extrascontainer");show_log(field);}
	,'onError':function(req)	{ hidediv("indicator"); alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);
	}
	 }
	);
}

function getResponse_guest(field,value) {

AjaxRequest.get(
	{
	'onLoading':function(req){showdiv("indicator"); }
	,'parameters':{ 'field':field,'value':value }
	,'url':livesite+'/index2.php?option=com_jomres&task=handlereq&no_html=1'
	,'timeout':20000
	,'onTimeout':function(req){ hidediv("indicator"); alert('Timed Out!'); }
	,'onSuccess':function(req){ hidediv("indicator"); eval(req.responseText); showdiv("extrascontainer"); show_log(field);}
	,'onError':function(req){ hidediv("indicator"); alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
	}
	);
}

function getResponse_email(field,value) {
if (echeck(value) )
	{
	AjaxRequest.get(
		{
		'onLoading':function(req){showdiv("indicator"); }
		,'parameters':{ 'field':field,'value':value }
		,'url':livesite+'/index2.php?option=com_jomres&task=handlereq&no_html=1'
		,'timeout':20000
		,'onTimeout':function(req){ hidediv("indicator"); alert('Timed Out!'); }
		,'onSuccess':function(req){ hidediv("indicator"); eval(req.responseText); showdiv("extrascontainer");show_log(field);}
		,'onError':function(req)	{ hidediv("indicator"); alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);}
		}
		);
	}
else
	disableSubmitButton(document.ajaxform.confirmbooking);
}

function show_log(lastfield) {
AjaxRequest.get(
	 {
	'onLoading':function(req){showdiv("indicator"); }
	,'parameters':{ 'field':'show_log','lastfield':lastfield }
	,'url':livesite+'/index2.php?option=com_jomres&task=handlereq&no_html=1'
	,'timeout':20000
	 ,'onTimeout':function(req){ hidediv("indicator"); alert('Timed Out!'); }
	 ,'onSuccess':function(req){ hidediv("indicator"); eval(req.responseText); }
	 ,'onError':function(req)	{ hidediv("indicator"); alert('Error!\nStatusText='+req.statusText+'\nContents='+req.responseText);SRPcheckShowGuestDeetsNow();checkSelectRoomMessage();}
	}
	);
}

function showRoomsList(req)
	{
	var rooms = req.responseText.split("~");
	buildSelected(rooms[0]) ; 
	buildAvailable(rooms[1]); 
	ShowRoomsList();
	return false;
	}

function HideRoomsList()
	{
	jQuery("div.roomsListWrapper").find("div.roomsListInnerWrapper:visible").slideUp("slow"); 
	return false;
	}

function ShowRoomsList()
	{
	jQuery("div.roomsListWrapper").find("div.roomsListInnerWrapper").slideDown("slow");
	return false;
	}
	
function buildSelected(string)
	{
	if (string != undefined)
		{
		if ( string.length > 0 )
			document.getElementById("selectedRooms").innerHTML = string;
		}
	}

function buildAvailable(string)
	{	
	if (string != undefined)
		{	
		if ( string.length > 0 )
			document.getElementById("availRooms").innerHTML = string;
		}
	}
	
function checkSelectRoomMessage()
	{
	var exists = document.getElementById("roomalert_top");
	if (exists != null) 
		{
		if (document.getElementById("messages").innerHTML == selectroommessage )
			{
			jQuery("#bookingform_address").fadeTo("slow", 0.2);
			jQuery("#bookingform_footer").fadeTo("slow", 0.2);
			document.getElementById("roomalert_top").className="roomalert_on"
			document.getElementById("roomalert_bottom").className="roomalert_on"
			showdiv("roomalert_top");
			showdiv("roomalert_bottom");
			jQuery("#roomalert_top").Highlight(500, '#fc0000');
			jQuery("#roomalert_bottom").Highlight(500, '#fc0000');
			}
		else
			{
			document.getElementById("roomalert_top").className="roomalert_off";
			document.getElementById("roomalert_bottom").className="roomalert_off";
			hidediv("roomalert_top");
			hidediv("roomalert_bottom");	
			jQuery("#bookingform_address").fadeTo("slow", 1);
			jQuery("#bookingform_footer").fadeTo("slow", 1);			
			}
		}
	}

function SRPcheckShowGuestDeetsNow() {
	if (isSRP)
		{
		showdiv("extrascontainer");
		showdiv("guestdeets");
		}
	}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	 Departure date adjustment stuff
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
function ajaxADate(arrivalDate,dformat){
	var newday=0
	var day=0
	var mon=0
	var year=0
	if (dformat=="%d/%m/%Y"){
		dateArray=arrivalDate.split("/")
			day=dateArray[0]
			mon=dateArray[1]
			year=dateArray[2]
			}
	if (dformat=="%Y/%m/%d"){
		dateArray=arrivalDate.split("/")
		day=dateArray[2]
		mon=dateArray[1]
		year=dateArray[0]
		}
	if (dformat=="%m/%d/%Y"){
		dateArray=arrivalDate.split("/")
		day=dateArray[1]
		mon=dateArray[0]
		year=dateArray[2]
		}
	if (dformat=="%d-%m-%Y"){
		dateArray=arrivalDate.split("-")
		day=dateArray[0]
		mon=dateArray[1]
		year=dateArray[2]
		}
	if (dformat=="%Y-%m-%d"){
		dateArray=arrivalDate.split("-")
		day=dateArray[2]
		mon=dateArray[1]
		year=dateArray[0]
		}
	if (dformat=="%m-%d-%Y"){
		dateArray=arrivalDate.split("-")
		day=dateArray[1]
		mon=dateArray[0]
		year=dateArray[2]
		}
	if (dformat=="%d.%m.%Y"){
		dateArray=arrivalDate.split(".")
		day=dateArray[0]
		mon=dateArray[1]
		year=dateArray[2]
		}
		
	var d = new Date(year,mon-1,day); with (d) setDate(getDate()+mininterval);
		sday=String(d.getDate());
		smonth=String(d.getMonth()+1);
		if (sday.length == 1)
			fday="0"+sday;
		else
			fday=sday;
		if (smonth.length == 1)
			fmonth="0"+smonth;
		else
			fmonth=smonth;
		if (dformat=="%d/%m/%Y"){
			dd=fday+"/"+fmonth+"/"+String(d.getFullYear())
			}
		if (dformat=="%Y/%m/%d"){
			dd= String(d.getFullYear())+"/"+fmonth+"/"+fday
			}
		if (dformat=="%m/%d/%Y"){
			dd=fmonth+"/"+ fday+"/"+String(d.getFullYear())
			}
		if (dformat=="%d-%m-%Y"){
			dd=fday+"-"+fmonth+"-"+String(d.getFullYear())
			}
		if (dformat=="%Y-%m-%d"){
			dd= String(d.getFullYear())+"-"+fmonth+"-"+fday
			}
		if (dformat=="%m-%d-%Y"){
			dd=fmonth+"-"+ fday+"-"+String(d.getFullYear())
			}
			
	document.ajaxform.departureDate.value=dd;
	}	

	
///////////////////////////////////////
//
//	Validate the form input
//
///////////////////////////////////////

function validate(manager)
	{
		document.ajaxform.action = livesite+"/index.php?option=com_jomres&task=confirmbooking"
		document.ajaxform.submit();
	}

function submitenter(myfield,e)
	{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	if (!document.ajaxform.confirmbooking.disabled)
		{
		if (keycode == 13)
			 {
			 document.ajaxform.submit();
			 return false;
			 }
		else
			 return true;
			 }
	else
		return true;
	}	
			
/**
* DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
*/
function echeck(str) {
	var strlen = str.length
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (strlen==0){
		return false
		}	
	if (str.indexOf(at)==-1){
		//alert("Invalid E-mail ID")
		return false
		}
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
			//alert("Invalid E-mail ID");
		return false;
		}
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
			//alert("Invalid E-mail ID")
			return false
		}
	if (str.indexOf(at,(lat+1))!=-1){
			//alert("Invalid E-mail ID")
			return false
		}
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
			//alert("Invalid E-mail ID")
			return false
		}
	if (str.indexOf(dot,(lat+2))==-1){
			//alert("Invalid E-mail ID")
			return false
		}
	if (str.indexOf(" ")!=-1){
			//alert("Invalid E-mail ID")
			return false
		}
	return true
	}