var isInternetExplorer = navigator.appName.indexOf("Microsoft") != -1;

function getadr( ) {
	var domain1 = "SeaCliffG";
	var domain2 = "ardens.com";
	var atsign = "&#64;";
	var adr = 'info' + atsign + domain1 + domain2;
	document.write( 
		"<" + "a" + " " + "href=" + "mai" + "lto:" + adr + ">" +
        adr +
        "<\/a>");
}

// home page thumbnails
function nav_toggle(id) {
	var strPath = new String(document.getElementById(id).src); 
	//alert(strPath);
	strExt = strPath.substring(strPath.length - 4, strPath.length);
	
	if(strPath.indexOf("off") > 0){
		document.getElementById(id).src = strPath.substring(0, strPath.length - 7) + "on" + strExt;
	}
	else if (strPath.indexOf("on") > 0){
		document.getElementById(id).src = strPath.substring(0, strPath.length - 6) + "off" + strExt;
	}
	
}

function selectImage(ID, image, num){
	nextImage = new Image() 
	nextImage.src = "images/" + image; 
	document.getElementById("img" + ID).src = nextImage.src;
	
	// Grab the appropriate div
	wDiv = document.getElementById("div" + ID);
  	links = wDiv.getElementsByTagName('a');
	thisLink = num-1; 
  	for (var i=0, len=links.length; i < len; i++) {
		if(i != thisLink){
        	links[i].className = "hid";
		} else{
			links[i].className = "shown";
		}
	}

}

// calendar pop-up
function launchCalendar() {
  var URL = "http://seacliffgardens.com/popup_calendar.php";
  //var winOpts = "toolbar=0,location=0,status=0,menubar=0,directories=0,resizable=0,scrollbars=0,width=790,height=260";
  var winOpts = "toolbar=1,location=1,status=1,menubar=1,directories=1,resizable=1,scrollbars=1,width=800,height=320";
  pw = window.open (URL, "sessionWin", winOpts);
  pw.focus();
}

// printable directions pop-up
function launchPrintDirections(start) {
  var URL = "http://seacliffgardens.com/directions-and-maps_print.php?s=" + start;
  var winOpts = "toolbar=1,status=1,menubar=1,directories=1,resizable=1,scrollbars=1,width=800,height=750";
  pw = window.open (URL, "sessionWin", winOpts);
  pw.focus();
}

function musicSP_DoFSCommand(command, args)
{
	// Escapes 'args' (to avoid special character conflicts) and splits it into an array of values (by comma - %2C)
	var DataArray = escape(args).split("%2C")

	if ( command == "set_cookie" )
	{
		// Creates a variable for expiry date
		var expdate = new Date ();
		expdate.setTime (expdate.getTime() + (DataArray[2] * 24 * 60 * 60 * 1000))
		// Creates the cookie
		document.cookie = DataArray[0] + "=" + DataArray[1] + ((expdate) ? "; expdate=" + expdate.toGMTString() : "") + "; path=/";
		//alert(DataArray[0] + "," + DataArray[1] + "," + DataArray[2]);
	}

	if ( command == "get_cookie" )
	{
		// Executes the GetCookie function
		GetCookie (DataArray[0],DataArray[1]);
	}

	if ( command == "del_cookie" )
	{
		// Sets the date on the cookie to expire immediately (deletes it)
		document.cookie = DataArray[0] + "=; expires=Thu, 01-Jan-70 00:00:01 GMT";
	}
}

function GetCookie(CookieName,FlashVariableName)
{
	
		
	var musicSPObj = isInternetExplorer ? document.all.musicSP : document.musicSP;
	CookieValue = document.cookie;
	CookieName += "=";

	// Finds the location of the value of the cookie specified in CookieName
	if (CookieValue.length > 0)
		{
		startString = CookieValue.indexOf(CookieName);

		if (startString != -1)
			{
				startString += CookieName.length;
				endString = CookieValue.indexOf(";", startString);

				if (endString == -1)
				{
					endString = CookieValue.length;
				}

				// Retrieves the cookie value
				CookieResult=unescape(CookieValue.substring(startString,endString));
				// Sends the cookie value back to Flash
				musicSPObj.SetVariable(FlashVariableName,CookieResult);
			}
			else
			{
			// If no value is is set (Internet Explorer) sends back the string 'undefined'
			musicSPObj.SetVariable(FlashVariableName,"undefined");
			}

		}
		else
		{
			//If no value is set (Netscape Navigator) sends back the string 'undefined'
			musicSPObj.SetVariable(FlashVariableName,"undefined");
		}
}

function toggleMute()
{          
	if(flashMute){
		flashMute = 0; 
		document.getElementById('btnSpeaker').src = speaker_on;
	} 
	else{
		flashMute = 1;
		document.getElementById('btnSpeaker').src = speaker_off;
	}
	
	if(window.introFlash) window.document.introFlash.SetVariable("muteSound",flashMute);
	else document.introFlash.SetVariable("muteSound",flashMute);
}

function gotoSlide(slide)
{       
	//document.getElementById('introFlash').SetVariable("slide",slide);
	if(window.introFlash) window.document.introFlash.SetVariable("slide",slide);
	else document.introFlash.SetVariable("slide",slide);
}

function getFlashMovieObject(movieName) {
    if (window.document[movieName]) {
        return window.document[movieName];
    }
    if (navigator.appName.indexOf("Microsoft Internet")==-1) {
        if (document.embeds && document.embeds[movieName]) {
            return document.embeds[movieName];
        }
    } else {
        return document.getElementById(movieName);
    }
}
function ReplayFlashMovie(mname) {
   var flashMovie=getFlashMovieObject(mname);
    flashMovie.Rewind();
    flashMovie.Play();
	show_mute();
	
	if(flashMute){
		flashMute = 0; 
		document.getElementById('btnSpeaker').src = speaker_on;
	} 
}


function show_replay(){
	document.getElementById('flashControl').innerHTML = "<a href=\"javascript:\" onClick=\"ReplayFlashMovie('introFlash')\"><img src=\"images/icn_replay.png\" alt=\"Replay\" name=\"btnReplay\" width=\"20\" height=\"20\" border=\"0\" id=\"btnReplay\"></a>";
}

function show_mute(){
	document.getElementById('flashControl').innerHTML = "<a href=\"javascript:\" onClick=\"toggleMute()\"><img src=\"images/icn_speaker_on.png\" alt=\"Mute\" name=\"btnSpeaker\" width=\"20\" height=\"20\" border=\"0\" id=\"btnSpeaker\"></a>";
}

function preload_img(img){
	pic= new Image(); 
	pic.src="images/" + img; 
}

function enforce_parent(parentframe){
	if(parentframe == ''){
		if (top.location == document.location){
      		top.location = "index.htm";
		    return;
    	}		
	}
	
    if (top.location == document.location){
      top.location = parentframe;
    }else{
      var parent_location=parent.location.href;
      var str_beginning=parent_location.length - parentframe.length;
      if (parent_location.substring(str_beginning, parent_location.length)!=parentframe){
        parent.location=parentframe;
      }
   }
}


function enforce_no_parent(altPage){
	if (top.location == document.location){
		return;
	}
	else{
		top.location = altPage;
	}
}


function resize_iframe(frameid, height){
	var objIframe = document.getElementById(frameid);
	objIframe.height = height;
	
}

// reservations and availability iframe only
function res_iframe_reset(){
	resize_iframe("frame1", 1600);
	document.getElementById("conditional").style.visibility = "hidden";
	
}



// BEGIN Webervations code
//Current date in form script
//By Lee Hinder (lee.hinder@ntlworld.com)
//Visit http://javascriptkit.com for this script and more
//set todays date
Now = new Date();
NowDay = Now.getDate() +1;
NowMonth = Now.getMonth();
NowYear = Now.getYear();
if (NowYear < 2000) NowYear += 1900; //for Netscape
//function for returning how many days there are in a month including leap years
function DaysInMonth(WhichMonth, WhichYear)
{
var DaysInMonth = 31;
if (WhichMonth == "Apr" || WhichMonth == "Jun" || WhichMonth == "Sep" || WhichMonth == "Nov") DaysInMonth = 30;
if (WhichMonth == "Feb" && (WhichYear/4) != Math.floor(WhichYear/4))
DaysInMonth = 28;
if (WhichMonth == "Feb" && (WhichYear/4) == Math.floor(WhichYear/4))
DaysInMonth = 29;
return DaysInMonth;
}
//function to change the available days in a months
function ChangeOptionDays(Which)
{
DaysObject = eval("document.Form1." + "zday");
MonthObject = eval("document.Form1."  + "zmonth");
YearObject = eval("document.Form1."  + "zyear");
Month = MonthObject[MonthObject.selectedIndex].text;
Year = YearObject[YearObject.selectedIndex].text;
DaysForThisSelection = DaysInMonth(Month, Year);
CurrentDaysInSelection = DaysObject.length;
if (CurrentDaysInSelection > DaysForThisSelection)
{
for (i=0; i<(CurrentDaysInSelection-DaysForThisSelection); i++)
{
DaysObject.options[DaysObject.options.length - 1] = null
}
}
if (DaysForThisSelection > CurrentDaysInSelection)
{
for (i=0; i<(DaysForThisSelection-CurrentDaysInSelection); i++)
{
NewOption = new Option(DaysObject.options.length + 1);
DaysObject.add(NewOption);
}
}
if (DaysObject.selectedIndex < 0) DaysObject.selectedIndex == 0;
}
//function to set options to today
function SetToToday(Which)
{
DaysObject = eval("document.Form1."  + "zday");
MonthObject = eval("document.Form1."  + "zmonth");
YearObject = eval("document.Form1."  + "zyear");
YearObject[0].selected = true;
MonthObject[NowMonth].selected = true;
ChangeOptionDays(Which);
DaysObject[NowDay-1].selected = true;
}
//function to write option years plus x
function WriteYearOptions(YearsAhead)
{
line = "";
for (i=0; i<YearsAhead; i++)
{
line += "<OPTION>";
line += NowYear + i;
}
return line;
}


//addLoadEvent("SetToToday('FirstSelect')")>

// END Weberations code

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}
