var version4 = (navigator.appVersion.charAt(0) >= 4);

var popupHandle;

function closePopup() {

if(popupHandle != null && !popupHandle.closed) popupHandle.close()

}
function displayPopup(position,url,name,height,width,evnt)
{
// Nannette Thacker http://www.shiningstar.net
// position=1 POPUP: makes screen display up and/or left,
//    down and/or right
// depending on where cursor falls and size of window to open
// position=2 CENTER: makes screen fall in center

var properties = "toolbar=0,location=0,height="+height
properties = properties+",width="+width

var leftprop, topprop, screenX, screenY, cursorX, cursorY, padAmt

if(navigator.appName == "Microsoft Internet Explorer")
{
	screenY = document.body.offsetHeight
	screenX = window.screen.availWidth
}
else
{ // Navigator coordinates
//		screenY = window.outerHeight
//		screenX = window.outerWidth
	// change made 3/16/01 to work with Netscape:
		screenY = screen.height;
		screenX = screen.width;
}

if(position == 1)	// if POPUP not CENTER
{
	cursorX = evnt.screenX
	cursorY = evnt.screenY
	padAmtX = 10
	padAmtY = 10
	
	if((cursorY + height + padAmtY) > screenY)	
	// make sizes a negative number to move left/up
	{
		padAmtY = (-30) + (height*-1);	
		// if up or to left, make 30 as padding amount
	}
	if((cursorX + width + padAmtX) > screenX)
	{
		padAmtX = (-30) + (width*-1);	
		// if up or to left, make 30 as padding amount
	}

	if(navigator.appName == "Microsoft Internet Explorer")
	{
		leftprop = cursorX + padAmtX
		topprop = cursorY + padAmtY
	}
	else
	{ // adjust Netscape coordinates for scrolling
		leftprop = (cursorX - pageXOffset + padAmtX)
		topprop = (cursorY - pageYOffset + padAmtY)
	}
}
else	// CENTER
{
	leftvar = (screenX - width) / 2
	rightvar = (screenY - height) / 2
		
	if(navigator.appName == "Microsoft Internet Explorer")
	{
		leftprop = leftvar
		topprop = rightvar
	}
	else
	{ // adjust Netscape coordinates for scrolling
		leftprop = (leftvar - pageXOffset)
		topprop = (rightvar - pageYOffset)
	}
}

if(evnt != null)
{
properties = properties+",left="+leftprop
properties = properties+",top="+topprop
}
closePopup()
popupHandle = open(url,name,properties)
}

//drop down URL jump for the spa section
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//pop up code for flash banner
function openNewWindow(URLtoOpen, windowName, windowFeatures) {
newWindow=window.open(URLtoOpen, windowName, windowFeatures); }

function calcMonth(selectedValue)	
	{
		var todaysDate 	= 	new Date();
		var todaysYear 	= 	todaysDate.getFullYear();
		var baseDate 	= 	new Date(todaysYear, todaysDate.getMonth(), 1);
		var myMonth 	= 	(baseDate.getMonth()*1)+(selectedValue*1) - 1;
		var myYear 		= 	todaysYear;
		
		if(myMonth > 12)
			{
				myMonth = myMonth - 12;
				myYear = (todaysYear*1) + (1*1);
			}
		
		//calculate the number of days in this month/year
		return days_in_month(myYear,myMonth);
	}

function reloadSelectStart(selectCount)
	{
		var myDayField	=	window.document.form1.day1;
		//clear out the current field
		for (var i = myDayField.length; i >= 0; i--)
			{
			myDayField.options[i] = null;
			}
		//reload the field
		for (var t = 1; t <= selectCount; t++)
			{
				SubTopic = new Option( t, t, false, false );
				myDayField.options[t-1] = SubTopic;
			}
	}

function days_in_month (year, month) 
	{
		return 32 - new Date(year, month, 32).getDate();
	}

//check to see if the correct number of days are loaded into the day field for the selected month

function validateStart()
	{
		//setup the base values
		var myStartField	=	window.document.form1.month1;
		var myStartDayField	=	window.document.form1.day1;
		var myStartValue	=	myStartField[myStartField.selectedIndex].value;
		//calculate the current month selected and the number of days in that month
		var startDays		=	calcMonth(myStartValue);
		//if days != select box THEN update it
		if(startDays 		!= 	myStartDayField.length)
			{
				//alert('The wrong number of days are in the select box: ' + startDays + ' ' + window.document.form1.day2.length)
				//store the selected index to re apply it later
				var currentIndex = myStartDayField.selectedIndex;
				//reload the select box with the correct number of days
				reloadSelectStart(startDays);
				//reset the selected index
				if( (currentIndex+1) > (startDays))
					{
						myStartDayField.selectedIndex = (startDays*1) - (1*1);
					}
				else
					{
						myStartDayField.selectedIndex = currentIndex;
					}
				
			}
	}



function getValue()

{
	var bookingLink = 'https://booking.ihotelier.com/istay/istay.jsp?HotelID=15156';
	
	var err = 0;
	var errMSG = "Please check the following fields:";
	
	//if the form is filled out all of the way, compile the date objects
	todaysDate = new Date();
	todaysYear = todaysDate.getFullYear();
	
	//string dates
	AymValue = document.form1.month1[document.form1.month1.selectedIndex].value;
	AdValue = document.form1.day1[document.form1.day1.selectedIndex].value;
	
	baseDate = new Date(todaysYear, todaysDate.getMonth(), 1);
	//assemble the string dates first and then test their validity
	ArrivalDate_StringTemp_Day = AdValue;
	ArrivalDate_StringTemp_Month = (baseDate.getMonth()*1)+(AymValue*1);
	if(ArrivalDate_StringTemp_Month > 12)
		{
		ArrivalDate_StringTemp_Year = (todaysYear*1) + (1*1);
		ArrivalDate_StringTemp_Month = ArrivalDate_StringTemp_Month - 12;
		}
	else
		{
		ArrivalDate_StringTemp_Year = todaysYear;
		}
	ArrivalDate_StringTemp 		=  ArrivalDate_StringTemp_Month + "/" + ArrivalDate_StringTemp_Day + "/" + ArrivalDate_StringTemp_Year;
	//alert(ArrivalDate_StringTemp);
	if(!isDate(ArrivalDate_StringTemp))
				{err = 1; errMSG = errMSG + "\nYour Arrival Date is not valid";}
	
	//these are the real dates
	ArrivalDate = new Date(todaysYear, (baseDate.getMonth()*1)+(AymValue*1)-(1*1) , AdValue);
	
	TotalDays = document.form1.nights[document.form1.nights.selectedIndex].value;
	
	if (ArrivalDate.getYear()>2000)
		{
		ArrivalDate_String =  ((ArrivalDate.getMonth()*1)+(1*1))+ "/" + AdValue + "/" + ArrivalDate.getYear();
		}
	else
		{
		ArrivalDate_String =  ((ArrivalDate.getMonth()*1)+(1*1)) + "/" + AdValue + "/" + ArrivalDate.getFullYear();
		}

	
	//if there are any errors show the error messages
	if(err == 1)
		{
			alert(errMSG);
			//return false;
		}
	
	//no errors, send them to the booking engine
	else
	{
		//&DateIn=3/18/2008&Length=4&Adults=2&Children=0&Rooms=1
		myBookingLink = bookingLink + "&DateIn=" + escape(ArrivalDate_String) + "&Length=" + TotalDays + "&Adults=" + document.form1.adults.value + "&Children=" + document.form1.children.value + "&Rooms=" + document.form1.rooms.value;
		//open the new window
		window.open(myBookingLink,'iHotelier','toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,height=680,width=1150');
		//return false;
	}
	
	
		
}

function CheckDates()
{
foo = 1;
}
function popupPostcard(href,width,height,scroll)
			{
			postCard= window.open(href,'myPostcard','resizable=no,toolbar=no,left=200,top=200,status=no,location=no,height=' + height + ',width=' + width + ',scrollbars=' + scroll + "'");
			};

$(document).ready(function(){
var collapse = function(){
    $('.collapseButton').unbind('click',collapse);
$('.collapsible table:eq(0),.collapsible table:eq(1)').fadeOut(800,function(){
$('.collapsible').css({left:808});
$('.collapsible table:eq(0)').fadeIn(800);
        $('.collapsible').parent().bind('click',expand);
});
};
var expand = function(){
    $('.collapsible').parent().unbind('click',expand);
    $('.collapsible table:eq(0)').fadeOut(800,function(){
        $('.collapsible').css({left:396});
        $('.collapsible table:eq(0),.collapsible table:eq(1)').fadeIn(800);
        $('.collapseButton').bind('click',collapse);
    });
};
$('.collapseButton').bind('click',collapse);
});





jQuery.flvlightbox = function(options){
        
    var c = '';
    if(typeof(options)=='string')c=options;
    
    var o = {
        height: '400',
        width: '600',
        content: c,
        modalcss: {
            background:'#000000',
            filter: 'alpha(opacity=70)',
            opacity: .7
        },
        wincss: {
            background: '#FFFFFF',
            border: '1px solid #000000',
            zIndex: '9999'
        }
    };
    $.extend(o,options);
    
    $(document.body).css('overflow','hidden');
    var removeIt = function(){
        $(modal).remove();
        $(win).remove();
        $(window).unbind('resize scroll',moveIt);
        $(document.body).css('overflow','');
    };
    var modal = document.createElement('div');
    $(modal).css($.extend(o.modalcss,{
        position:	'absolute',
        top: $(document).scrollTop()+'px',
        left: $(document).scrollLeft()+'px',
        height: $(window).height()+'px',
        width: $(window).width()+'px'
    })).click(removeIt).appendTo(document.body);
    
    var closebox = document.createElement('div');
    $(closebox).css({
        position: 'absolute',
        cursor: 'pointer',
        top: '-12px',
        left:  (o.width-8)+'px'
    }).html('<img src="/i/SITE_090210_09180337_N8I1W/templates/btn_close.gif"').click(removeIt);
    
    var win = document.createElement('div');
    $(win).css($.extend(o.wincss,{
        position: 'absolute',
        top: ($(document).scrollTop()+($(window).height()-o.height)/2)+'px',
        left: ($(document).scrollLeft()+($(window).width()-o.width)/2)+'px',
        height: o.height+'px',
        width: o.width+'px'
    })).html(o.content).prepend(closebox).appendTo(document.body);
    var moveIt = function(){
        $(win).css({
            top: ($(document).scrollTop()+($(this).height()-o.height)/2)+'px',
            left: ($(document).scrollLeft()+($(this).width()-o.width)/2)+'px'
        });
        $(modal).css({
            top: $(document).scrollTop()+'px',
            left: $(document).scrollLeft()+'px',
            height: $(this).height()+'px',
            width: $(this).width()+'px'
        });
    };
};



$(document).ready(function(){ 
$("#arrive").datepicker({
			minDate:0,
			showAnim: "fadeIn",
			showOn: 'both',
			buttonText: 'Select Check In Date',
			buttonImage: '/i/SITE_080114_16132618_N1KS2/templates/btn_calculator.gif',
			buttonImageOnly: true
			
		});

$("#arrive").datepicker('setDate',addDays(new Date(),1));
});

function addDays(myDate,days) {
//myDate = starting	date, days = no. days to add.
	var temp_date = new Date();
	var i = 0;
	var days_to_add = 0;
	while (i < (days)){
		temp_date = new Date(myDate.getTime() +	(days_to_add*24*60*60*1000));
			i+=1;
		days_to_add += 1;
	}
	return new Date(myDate.getTime() + days_to_add*24*60*60*1000);
}
