var version4 = (navigator.appVersion.charAt(0) == "4");
var popupHandle;
function closePopup() {
if(popupHandle != null && !popupHandle.closed) popupHandle.close()
}

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)
}


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 reloadSelectEnd(selectCount)
	{
		var myDayField	=	window.document.form1.day2;
		//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)
			{
				//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 validateEnd()
	{
		//setup the base values
		var myEndField		=	window.document.form1.month2;
		var myEndDayField	=	window.document.form1.day2;
		var myEndValue		=	myEndField[myEndField.selectedIndex].value;
		//calculate the current month selected and the number of days in that month
		var endDays			=	calcMonth(myEndValue);
		//if days != select box THEN update it
		if(endDays 			!= 	myEndDayField.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 = myEndDayField.selectedIndex;
				//reload the select box with the correct number of days
				reloadSelectEnd(endDays);
				//reset the selected index
				if( (currentIndex+1) > (endDays))
					{
						myEndDayField.selectedIndex = (endDays*1) - (1*1);
					}
				else
					{
						myEndDayField.selectedIndex = currentIndex;
					}
				
			}
	}


function CheckDates()
{
    /*if (window.document.form1.month2.selectedIndex < window.document.form1.month1.selectedIndex)
    {
		window.document.form1.month2.selectedIndex=window.document.form1.month1.selectedIndex;
    }
    if (window.document.form1.day2.selectedIndex <= window.document.form1.day1.selectedIndex && window.document.form1.month1.selectedIndex == window.document.form1.month2.selectedIndex)
    {
		if (window.document.form1.day1.selectedIndex+2 <= window.document.form1.day1.length)
		{
		window.document.form1.day2.selectedIndex=window.document.form1.day1.selectedIndex+1;
		}
		else
		{
		window.document.form1.day2.selectedIndex=window.document.form1.day1.selectedIndex;
		}
    }*/
	
	validateStart();
	//validateEnd();
}

function getValue()

{
	/*var bookingLink = 'http://reservations.ihotelier.com/istay.cfm?hotelid=15318&Language=1';*/
	var bookingLink = 'https://www.phgsecure.com/IBE/bookingRedirect.ashx?propertyCode=EGELC';

	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;
	//DymValue = document.form1.month2[document.form1.month2.selectedIndex].value;
	//DdValue = document.form1.day2[document.form1.day2.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";}
	//assemble the depart date string
	//DepartureDate_StringTemp_Day = DdValue;
	//DepartureDate_StringTemp_Month = (baseDate.getMonth()*1)+(DymValue*1);
	/*if(DepartureDate_StringTemp_Month > 12)
		{
		DepartureDate_StringTemp_Year = (todaysYear*1) + (1*1);
		DepartureDate_StringTemp_Month = DepartureDate_StringTemp_Month - 12;
		}
	else
		{
		DepartureDate_StringTemp_Year = todaysYear;
		}*/
	//DepartureDate_StringTemp 	=  DepartureDate_StringTemp_Month + "/" + DepartureDate_StringTemp_Day + "/" + DepartureDate_StringTemp_Year;
	/*if(!isDate(DepartureDate_StringTemp))
				{err = 1; errMSG = errMSG + "\nYour Departure Date is not valid";}*/
	//these are the real dates
	ArrivalDate = new Date(todaysYear, (baseDate.getMonth()*1)+(AymValue*1)-(1*1) , AdValue);
	//DepartureDate = new Date(todaysYear, (baseDate.getMonth()*1)+(DymValue*1)-(1*1), DdValue);
	//TotalDays = (( (DepartureDate.getTime() * 1) - (ArrivalDate.getTime() * 1) ) / (86400000));
	TotalDays = document.form1.NumNights.value;
	if (ArrivalDate.getYear()>2000)
		{
		ArrivalDate_String =  ((ArrivalDate.getMonth()*1)+(1*1))+ "/" + AdValue + "/" + ArrivalDate.getYear();
		//DepartureDate_String = ((DepartureDate.getMonth()*1)+(1*1)) + "/" + DdValue + "/" + DepartureDate.getYear();
		}
	else
		{
		ArrivalDate_String =  ((ArrivalDate.getMonth()*1)+(1*1)) + "/" + AdValue + "/" + ArrivalDate.getFullYear();
		//DepartureDate_String = ((DepartureDate.getMonth()*1)+(1*1)) + "/" + DdValue + "/" + DepartureDate.getFullYear();
		}
	
	//if there are any errors show the error messages
	if(err == 1)
		{
			alert(errMSG);
		}
	
	//no errors, send them to the booking engine
	else
	{
		//myBookingLink = bookingLink + "&DateIn=" + escape(ArrivalDate_String) + "&Length=" + TotalDays + "&Adults=" + document.form1.adults.value + "&Children=" + document.form1.children.value + "&Rooms=" + document.form1.rooms.value;
		myBookingLink = bookingLink + "&arrivalDate=" + escape(ArrivalDate_String) + "&numberOfNights=" + TotalDays;
		//open the new window
		window.open(myBookingLink,'iHotelier','toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,height=630,width=1000');
		//return false;
	}
	
	
		
}
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 + "'");

			};