// JavaScript Document
/**********************************************************************************************************************************************/
function SiteJump(URL) 
{
	self.location.href = URL;	
	return true;
}
/**********************************************************************************************************************************************/
function process_login_focus(tbid,action)
{
	if (action == 'focus')
	{
		if (tbid == 'user_name')
			$(tbid).value = '';
		else if (tbid == 'default_password')
		{
			$('password').style.display = 'inline-block';			
			$(tbid).style.display = 'none';		
			$('password').focus();
		}
	}
	else if (action == 'blur')
	{		
		if (tbid == 'user_name' && $(tbid).value == '')
			$(tbid).value = 'e-mail';
		else if (tbid == 'password' && $(tbid).value == '')
		{
			$(tbid).style.display = 'none';
			$('default_password').style.display = 'inline-block';			
		}
	}	
}
/**********************************************************************************************************************************************/
function display_error(msg)
{
	alert_msg ="_______________________________________________________________\n";
	alert_msg += "The form has not been submitted because there are problem(s) with the form.\n";
	alert_msg += "Please correct the problem(s) and re-submit the form.\n";
	alert_msg +="_______________________________________________________________\n\n";
	alert_msg += "The following field(s) need to be corrected:-\n";
	
	msg += alert(alert_msg + msg + "\n\n");
}
/**********************************************************************************************************************************************/
function isBlank(val)
{	
	if(val==null){return true;}
	for(var i=0;i<val.length;i++) {
		if ((val.charAt(i)!=' ')&&(val.charAt(i)!="\t")&&(val.charAt(i)!="\n")&&(val.charAt(i)!="\r")){return false;}
	}
	return true;
}
/**********************************************************************************************************************************************/
function isInteger(val)
{
	if (isBlank(val)){return false;}
	for(var i=0;i<val.length;i++){
		if(!isDigit(val.charAt(i))){return false;}
	}
	return true;
}
/**********************************************************************************************************************************************/
function isDecimal(val)	
{
	var DecimalFound;
	DecimalFound = false;
	
	if (isBlank(val)){val = 0;}
	for(var i=0;i<val.length;i++){
		if(!isDigit(val.charAt(i)))
		{
			if (DecimalFound == false)
			{
				if (!isDecimalPoint(val.charAt(i)))
				{
					return false;
				}
				else
				{
					DecimalFound = true;
				}
			}
			else
			{
				return false;
			}
		}
	}
	return true;
}
/**********************************************************************************************************************************************/
function isDigit(num) 
{
	if (num.length>1){return false;}
	var string="1234567890";
	if (string.indexOf(num)!=-1){return true;}
	return false;
}
/**********************************************************************************************************************************************/
function isDecimalPoint(num) 
{
	if (num.length>1){return false;}
	var string=".";
	if (string.indexOf(num)!=-1){return true;}
	return false;
}
/**********************************************************************************************************************************************/
function setup_scroller()
{
	var scrollbar = new Control.ScrollBar('scrollbar_content','scrollbar_track');  	  	
}
/**********************************************************************************************************************************************/
var W3CDOM = (document.createElement && document.getElementsByTagName);

function initFileUploads() {
	if (!W3CDOM) return;		
	
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'fakefile';
	var tbl = document.createElement('table');
	tbl.setAttribute('cellpadding','0');
	tbl.setAttribute('cellspacing','0');
	fakeFileUpload.appendChild(tbl);
	var row = tbl.insertRow(0);
	// cell_1
	var cell_1 = row.insertCell(0);
	cell_1.appendChild(document.createElement('input'));
	// cell_2
	var cell_2 = row.insertCell(1);
	var image = document.createElement('img');
	image.src='../images/browse_btn.png';
	var spacer = document.createElement('span');	
	spacer.innerHTML = "&nbsp;&nbsp;"
	cell_2.appendChild(spacer);
	cell_2.appendChild(image);
	
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++) {
		if (x[i].type != 'file') continue;
		if (x[i].parentNode.className != 'fileinputs') continue;
		x[i].className = 'file hidden';
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		x[i].onchange = x[i].onmouseout = function () {
			this.relatedElement.value = this.value;
		}
	}
}
/**********************************************************************************************************************************************/
function check_lb()
{				
	if($('lightbox'))
	{
		$('lightbox').appear({ duration: 1.0 });				
		var t=setTimeout(disappear,3500);
	}				
}
/**********************************************************************************************************************************************/
function disappear()
{
	$('lightbox').fade({ duration: 1.0 });
}
/**********************************************************************************************************************************************/
function checkAll(form,field)
{	
	var field = form.elements[field]; 
	if(field)
	{
		if (field.length > 0)	
		{
			for (i = 0; i < field.length; i++)
			{
				if (field[i].checked == true)									
					field[i].checked = false;
				else
					field[i].checked = true;
			}
		}
		else
		{
			field.checked = true;									
		}									
	}
}
/**********************************************************************************************************************************************/
function process_section(sid)
{
	var num_reg = /^[0-9]+?/;
	if(num_reg.test(sid.value))
	{
		$('section_pics').innerHTML = '';
		$('section_pics').setStyle({			
			border: '1px',
			borderStyle: 'solid',
			borderColor: '#5a1112',
			padding: '5px'
		});
		url = "../ajax/get_images.php?section_id="+sid.value;				
		new Ajax.Request(url, {
		  method: 'get',
		  onCreate: function(){
			$('section_pics').insert({
				top: new Element('img', {src: '../images/ajax-loader.gif',border:'0',id:'loader'})
			});
		  },
		  onSuccess: function(response) {	
		  	Element.remove('loader');
			response = response.responseText;			
			var data = response.evalJSON();		
			for(i=0;i<data['images'].length;i++)
			{					
				$('section_pics').insert({
					top: new Element('a', {href: '../images/vip_sections/'+data['images'][i].image,rel:'ltbox[roadtrip]',id:'image'+i})
				});
				$('image'+i).insert({
					top: new Element('img', {src: '../images/vip_sections/thumbs/'+data['images'][i].image,border:'0'})
				});
			}							
		  },
		  onComplete: function(){/*get_vip_tables(sid.value,$('party_size').value)*/},
		  onFailure: function(){alert('There was a problem accessing the information needed.');}
		});		
	}
	else
	{
		$('section_pics').setStyle({			
			border: '0px',
			padding: '0px'
		});
		$('section_pics').innerHTML = '';
		//for(i=$('table_id').options.length-1;i>=0;i--)
		//{
		//	$('table_id').remove(i);
		//}
		//var opt = document.createElement('option');
		//opt.text = 'Any';
		//opt.value = 'Any';
		//$('table_id').options.add(opt);
		//$('table_id').disabled = true;
	}
}
/**********************************************************************************************************************************************/
function get_vip_tables(s,ps)
{
	url = "../ajax/get_tables.php?section_id="+s+"&party_size="+ps;	
	new Ajax.Request(url, {
		method: 'get',	  
		onCreate: function(){
			for(i=$('table_id').options.length-1;i>=0;i--)
			{
				$('table_id').remove(i);
			}
			var opt = document.createElement('option');
			opt.text = 'Any';
			opt.value = 'Any';
			$('table_id').options.add(opt);
		},
		onSuccess: function(response) {	
			response = response.responseText;
			var data = response.evalJSON();		
			for(i=0;i<data['tables'].length;i++)
			{	
				var opt = document.createElement('option');
				opt.text = data['tables'][i].table_name;
				opt.value = data['tables'][i].table_id;
				$('table_id').options.add(opt);
			}	
			$('table_id').disabled = false;
		},
		onFailure: function(){alert('There was a problem accessing the information needed.');}
	});
}
/**********************************************************************************************************************************************/