// Default JS Content - Do Not Delete
var version4 = (navigator.appVersion.charAt(0) >= 4);
var popupHandle;

function newwindow(theURL)
{
	window.open(theURL,"nav")
}


function closePopup() 
	{
		if(popupHandle != null && !popupHandle.closed) popupHandle.close()
	}


function displayPopup(position,url,name,height,width,evnt)
	{
		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
	{
		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
			{
				leftprop = (leftvar - pageXOffset)
				topprop = (rightvar - pageYOffset)
			}
	}

if(evnt != null)
	{
		properties = properties+",left="+leftprop
		properties = properties+",top="+topprop
	}
		closePopup()
		popupHandle = open(url,name,properties)
	}

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;
		}
    }
}

function getValue()
{
	var bookingLink = "https://reservations.synxis.com/opbe/rez.aspx?flashOk=1&lang=1&hotel=12689&chain=6027";
	var dateformat = "euro";	
	var err = 0;
	var errMSG = "Please check the following fields:";
	//check to see if all of the fields have been selected
	//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));
	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();
		}
	//test the other possible scenarios
	if(err == 0)
		{
		//if the dates are legitimate test to see if the arrival is before the departure
		if( (DepartureDate <= ArrivalDate) )
			{err = 1; errMSG = errMSG + "\nYour Arrival Date must be prior to your Departure Date";}
		//test to see if the dates are in the furture
		if( (DepartureDate < todaysDate) || (ArrivalDate < todaysDate))
			{err = 1; errMSG = errMSG + "\nYour must select dates in the future";}
		//check to see if the total number of days is gt 20
		if(TotalDays > 20)
			{err = 1; errMSG = errMSG + "\nThe maximum number of nights is 20";}
		//if after all of that there is an error, show the message and return false to the form
		}
	//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
		{
			myBookingLink = bookingLink + "&arrive=" + escape(ArrivalDate_String) + "&depart=" + escape(DepartureDate_String) + "&Adult=" + document.form1.adults.value + "&Child=" + document.form1.children.value;
			//open the new window
			window.open(myBookingLink,'Synxis','toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,height=700,width=900');
			return false;
		}
}
