
function loadIframe(url) 
{
 Hide();	
 if( url.indexOf('flash') > -1)// this means i'm calling a flash file hide the reservation elements
 {
	 HideReservationAd(true);
 }
 else
 {
	 HideReservationAd(false);
 }

 var myFrame = window.frames['mainFrame'];

 if(myFrame == null)
 {
	myFrame = parent.window.frames['mainFrame'];	
 }

  if ( myFrame != null ) 
  {
    myFrame.location = url;   
    return false;
  }
  else return true;
}

function getDocHeight(doc) {
  var docHt = 0, sh, oh;
  if (doc.height) docHt = doc.height;
  else if (doc.body) {
    if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
    if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
    if (sh && oh) docHt = Math.max(sh, oh);
  }
  return docHt;
}

function setIframeHeight(iframeName) 
{
  var iframeWin = window.frames[iframeName];
  var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
  if ( iframeEl && iframeWin ) {
    iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous  
    var docHt = getDocHeight(iframeWin.document);
	
    // need to add to height to be sure it will all show
    //if (docHt) iframeEl.style.height = docHt + "px";
	var lnk = iframeWin.document.location.toString();
	if (lnk.indexOf('flash') > -1 ||  docHt > 790 )
	{
		iframeEl.style.height = docHt + "px";
	}
	else
	{
		iframeEl.style.height = 790 + "px";
	}
  }
}

function validate_form()
{	alert("validate");
	var array_input=document.getElementsByTagName("INPUT");
	var array_select=document.getElementsByTagName("SELECT");
	var array_textarea=document.getElementsByTagName("TEXTAREA");
	var alert_obj;
	var current_tabindex=1000; // init
	var checkbox_flag=false; // validation failed on checkbox?
	var radio_flag=false;
	var radio_buffer=0;
	var radio_buffer_checked=false;
	var radio_allchecked=false;
	var radio_first_tab=null;
	

	for(i=0; i<array_select.length; i++) { // select
		var buff=array_select[i].title;
		if(buff.substring(0,1)=='*' && array_select[i].disabled==false && array_select[i].value.length < 1) {
			if(array_select[i].tabIndex<current_tabindex) {
				alert_obj=array_select[i];
				current_tabindex=alert_obj.tabIndex;
			}
		}
	}
	for(i=0; i<array_input.length; i++) { // input
		var buff=array_input[i].title;
		if(array_input[i].type =='text' || array_input[i].type =='password') {
			if(buff.substring(0,1)=='*' && array_input[i].disabled==false && array_input[i].value.length < 1) {
				if(array_input[i].tabIndex<current_tabindex) {
					alert_obj=array_input[i];
					current_tabindex=alert_obj.tabIndex;
				}
			}
		} else if(array_input[i].type == 'radio' && radio_flag==false) {	// radio input
			if(buff.substring(0,1)=='*') {
				var radio_group=document.getElementsByName(array_input[i].name);
				var btn = valButton(radio_group);
				if (btn == null) {
					radio_flag=true;
					alert_obj=array_input[i];
					current_tabindex=alert_obj.tabIndex;
				}
			}
		} else if(array_input[i].type == 'checkbox') {
			if(buff.substring(0,1)=='*' && array_input[i].disabled==false && array_input[i].checked==false) {
				if(array_input[i].tabIndex<current_tabindex) {
					checkbox_flag=true;
					alert_obj=array_input[i];
					current_tabindex=alert_obj.tabIndex;
				}
			}
		} 
	}
	
	for(i=0; i<array_textarea.length; i++) {		// textarea
		var buff=array_textarea[i].title;
		if(buff.substring(0,1)=='*' && array_textarea[i].disabled==false && array_textarea[i].value.length < 1) {
			if(array_textarea[i].tabIndex<current_tabindex) {
				alert_obj=array_textarea[i];
				current_tabindex=alert_obj.tabIndex;
			}
		}
	}
	
	if(current_tabindex!=1000) {
		if(checkbox_flag==true) {
			alert('Please make sure you check '+alert_obj.title.substring(2, alert_obj.title.length));
		} else if(radio_flag==true) {
			alert('Please make sure you select '+alert_obj.title.substring(2, alert_obj.title.length));
		} else {
			alert('Please make sure you enter '+alert_obj.title.substring(2, alert_obj.title.length));
		}
		alert_obj.focus();
		return false;
	} else {
		//alert('something up');
	}
	
	/*var obj_pass=document.getElementById('password');
	var obj_pass2=document.getElementById('password_again');
	
	if(obj_pass.value!=obj_pass2.value) {
		alert('Please make sure both password fields are the same!');
		return false;
	}*/
	
	var obj_email=document.getElementById('email');
	return echeck(obj_email.value);
}

function echeck(str) {

	var at="@";
	var dot=".";
	var lat=str.indexOf(at);
	var lstr=str.length;
	var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1){
	   alert("Invalid E-mail Address");
	   return false;
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   alert("Invalid E-mail Address");
	   return false;
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	    alert("Invalid E-mail Address");
	    return false;
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	    alert("Invalid E-mail Address");
	    return false;
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	    alert("Invalid E-mail Address");
	    return false;
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	    alert("Invalid E-mail Address");
	    return false;
	 }
	
	 if (str.indexOf(" ")!=-1){
	    alert("Invalid E-mail Address");
	    return false;
	 }
 	 return true;				
}
var timerId = null;
var selectionId = null;

function Expand(menuitem,submenudiv)
{
	var submenuitem = document.getElementById(submenudiv);
	Hide();
	selectionId = menuitem;
	menuitem.className = 'Clicked';
	submenuitem.style.display = 'block';
	timerId = window.setTimeout(TimeOutDiv, 5000);
}

function ClearMainSelection(selectedItem)
{
	var array_links = document.getElementsByTagName("a");
	for (var i = 0; i < array_links.length; i++)
	{
		/*** checking links to see if i am part of navigation div ***/
		if(array_links[i].parentNode.className == "Navigation" || 
		   array_links[i].parentNode.parentNode.className == "Navigation" ||
		   array_links[i].parentNode.className == "Links") 
		{
			array_links[i].className = "";
		}
	}
	if(selectedItem != undefined)
	{
		//selectedItem.className = "Clicked";
		selectedItem.className = "Selected";
	}
}

function Hide()
{	
	window.clearTimeout(timerId);
	var array_div = document.getElementsByTagName("div");

	for (var i = 0; i < array_div.length; i++)
	{
		if(array_div[i].id == "liquids" || 
		   array_div[i].id == "menus" ||
		   array_div[i].id == "gallery" ||
		   array_div[i].id == "privatefunctions")
		{
			array_div[i].style.display = 'none';
		}
	}	
}

function TimeOutDiv()
{
	Hide();
	ClearMainSelection();
}

function HideReservationAd(bool)
{
	var the_div = document.getElementById('Elements');
	if(the_div == null)
	{
		the_div = parent.document.getElementById('Elements')	
	}

	if(bool == true)
	{
		// we don't want to call CSS to hide again if it's already hidden
		if(the_div.style.display  == 'block')
		{
			the_div.style.display = 'none';
		}
	}
	else
	{
		the_div.style.display = 'block';
	}
}

function SelectClose(divid,linkid)
{
	document.getElementById(linkid).className = 'Selected';
}

function writLink(combo_id, link_id, append_url)
{
	var combo = document.getElementById(combo_id);
	var value = combo.options[combo.selectedIndex].value;
	var link_id = document.getElementById(link_id);
	link_id.href = append_url + value;
}

function setCalendarRTEOptions(rte, width, height)
{	
	rte.cmdFormatBlock = true;
	rte.cmdFontName = false;
	rte.cmdFontSize = false;
	rte.cmdIncreaseFontSize = false;
	rte.cmdDecreaseFontSize = false;
	
	rte.cmdBold = true;
	rte.cmdItalic = true;
	rte.cmdUnderline = true;
	rte.cmdStrikethrough = false;
	rte.cmdSuperscript = false;
	rte.cmdSubscript = false;
	
	rte.cmdJustifyLeft = false;
	rte.cmdJustifyCenter = false;
	rte.cmdJustifyRight = false;
	rte.cmdJustifyFull = false;
	
	rte.cmdInsertHorizontalRule = false;
	rte.cmdInsertOrderedList = false;
	rte.cmdInsertUnorderedList = false;
	
	rte.cmdOutdent = false;
	rte.cmdIndent = false;
	rte.cmdForeColor = false;
	rte.cmdHiliteColor = false;
	rte.cmdInsertLink = true;
	rte.cmdInsertImage = false;
	rte.cmdInsertSpecialChars = false;
	rte.cmdInsertTable = true;
	rte.cmdSpellcheck = false;
	
	rte.cmdCut = true;
	rte.cmdCopy = true;
	rte.cmdPaste = true;
	rte.cmdUndo = true;
	rte.cmdRedo = true;
	rte.cmdRemoveFormat = false;
	rte.cmdUnlink = true;
	
	rte.toggleSrc = true;
	
	rte.width=width;
	rte.height=height;
	rte.build();
}

function addToArray(ar, str)
{
	var l
	l = ar[0] + 1
	ar[l] = str
	ar[0] = l
}
function makeArray()
{
	array = new Object();
	array[0] = 0;
	return array;
}
function confirmDelete() 
{
	
	if(confirm("Are you sure you would like to delete?")) 
	{
		return true;
	} 
	else 
	{
		return false;
	}
}


/*********** capones reservation js ****************/

function ShowDay() {
	var ryear = document.r.ResYear.selectedIndex;
	if(ryear < 0)
		ryear= 0;
	ryear= document.r.ResYear.options[ryear].value - 0;
	var rmonth = document.r.ResMonth.selectedIndex;
	var rdate = document.r.ResDate.selectedIndex + 1;
	var rnow = new Date(ryear,rmonth,rdate);
	var now = new Date();

	var rday = rnow.getDay() + 1;
	document.r.dayweek.value = dayNames[rday]

}

function setDate() {

	// extract date from literal..
	var now = new Date();
	var closestTime = (now.getTime() + (30 * 60000)); //1/2 hour in advance...
	var nearest = new Date(closestTime)
	var nearmonth = nearest.getMonth();
	var neardate = nearest.getDate();
	var nearyear = nearest.getFullYear();

	document.r.ResMonth.selectedIndex = nearmonth
	document.r.ResDate.selectedIndex = neardate - 1
	document.r.ResYear.selectedIndex = nearyear-2009;
}


