// DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)

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;				
	}

function Validate(form)
{
	var email=form.txtEmail
	
	if ((email.value==null)||(email.value=="")){
		alert("Please Enter your Email Address");
		email.focus();
		return false;
	}
	if (echeck(email.value)==false){
		email.focus();
		return false;
	}
	return true;
}

//VRX Viewer
function launchViewer(mapid)
{
	var w = screen.width;
	var winwidth;
	var winurl;
	if (w >= 1000)
		{
			winwidth=880
			winurl = 'http://delivery.vrxstudios.com/destinations/vrxfullviewer_2021.asp?ident=AA2021-' + mapid + '&dmn=50071';
		}
	else
		{
			winwidth=546
			winurl = 'http://delivery.vrxstudios.com/destinations/vrxmap_2021_50071.asp?ident=AA2021-' + mapid;
		}
	var win = window.open(winurl,'vrxmap','width=' + winwidth + ',height=610,top=5,left=5,scrollbars=no,location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no');
	win.focus();
}

//Expedia Booking Scripts
function PopUpDest(what)//PopUp destination list
{
	window.open(what,'destinations','toolbar=no,location=no,directories=no,status=no,menubar=no, scrollbars=yes,resizable=no,width=574,height=400,top=20,left=20');
}


//Weather

function OpenWeather()
{
	if (document.getElementById('threedayweather').style.display == 'none')
	{
		document.getElementById('threedayweather').style.display = 'block';
		document.getElementById('weatherlink').innerHTML = 'Close';
	}
	else
	{
		document.getElementById('threedayweather').style.display = 'none';
		document.getElementById('weatherlink').innerHTML = '3-day Forecast';
	}
}

// Newsticker Startup
function startTicker()
{
	// Define run time values
	theCurrentStory     = -1;
	theCurrentLength    = 0;
	// Locate base objects
	if (document.getElementById) {	
		    theAnchorObject     = document.getElementById("tickerAnchor");
			runTheTicker();   	
		 }
	else {
            document.write("<style>.ticki{/*display:none;*/}.ticko{border:0px; padding:0px;}</style>");
            return true;
	}
}
// Ticker main run loop
function runTheTicker()
{
	var myTimeout;  
	// Go for the next story data block
	if(theCurrentLength == 0)
	{
		theCurrentStory++;
		theCurrentStory      = theCurrentStory % theItemCount;
		theStorySummary      = theSummaries[theCurrentStory].replace(/&quot;/g,'"');		
		theTargetLink        = theSiteLinks[theCurrentStory];
		theAnchorObject.href = theTargetLink;
		thePrefix 	     = "<span class=\"tickls\">" + theLeadString + "</span>";
	}
	// Stuff the current ticker text into the anchor
	theAnchorObject.innerHTML = thePrefix + 
	theStorySummary.substring(0,theCurrentLength) + whatWidget();
	// Modify the length for the substring and define the timer
	if(theCurrentLength != theStorySummary.length)
	{
		theCurrentLength++;
		myTimeout = theCharacterTimeout;
	}
	else
	{
		theCurrentLength = 0;
		myTimeout = theStoryTimeout;
	}
	// Call up the next cycle of the ticker
	setTimeout("runTheTicker()", myTimeout);
}
// Widget generator
function whatWidget()
{
	if(theCurrentLength == theStorySummary.length)
	{
		return theWidgetNone;
	}

	if((theCurrentLength % 2) == 1)
	{
		return theWidgetOne;
	}
	else
	{
		return theWidgetTwo;
	}
}


//Terms and conditions
strTerms = '<ol><li>All prices quoted herein are in <b>Canadian Dollars</b>.</li><li>By submitting my transaction online, I confirm that the spelling of all passenger names listed above are correct and is how they appear in their travel documentation. I understand that if any changes to the names are required after this booking is made supplier imposed charges will apply.</li><li>I also agree that it is my responsibility to ensure that I/we have the appropriate documentation <b>(Passport/Visa/ID card etc.)</b> to gain entry to the chosen destination and entry into Canada upon my/our return.</li><li>Prices, availability, and dates during this period are subject to change as per the airline rules and regulations.</li><li>For your protection, a <b>ToursYourWay.ca</b> representative will call or email you to confirm your details and delivery information.</li><li>I hereby authorize <b>ToursYourWay.ca</b> by submitting my transaction online.</li><li>It is important that you ensure that you check the names, destinations, dates, and hotel before completing your booking.</li><li>Cancellations will result in a 100% penalty.</li><li>Changes to bookings may result in 100% penalty, and/or an administration fee.</li><li>Proof of documents for bookings using a third party credit card, will be required, back and front of card and copy of drivers license.</li></ol>';


function Validate(form)
{
	var email=form.txtEmail
	
	if ((email.value==null)||(email.value=="")){
		alert("Please Enter your Email Address");
		email.focus();
		return false;
	}
	if (echeck(email.value)==false){
		email.focus();
		return false;
	}
	return true;
}
 
function ValidateAirport()
{
	 if((document.frmAirport.city.value=="")||(document.frmAirport.city.value==null))
	 {
	 	return false;
	 }
	else
	{
		document.frmAirport.submit();
	}
}

function ValidateDestination()
{
	if (document.frmDestination.id.value == "9999")
	{
		window.open("http://www.doorlando.com");
		return false;
	}
	else if ((document.frmDestination.id.value=="")||(document.frmDestination.id.value==null))
	{
		return false;
	}
	else
	{
		document.frmDestination.submit();
	}
}

function ValidateResort()
{
	if (document.frmResort.id.value == "9999")
	{
		window.open("http://www.doorlando.com");
		return false;
	}
	else if ((document.frmResort.id.value=="")||(document.frmResort.id.value==null))
	{
		return false;
	}
	else
	{
		document.frmResort.submit();
	}
}
function ValidateWeather()
{
	if ((document.frmWeather.drpWcode.value=="")||(document.frmWeather.drpWcode.value==null))
	{
		return false;
	}
	else
	{
		document.frmWeather.submit();
	}
}

function ValidateJumpTo()
{
	if ((document.frmJumpTo.id.value=="")||(document.frmJumpTo.id.value==null))
	{
		return false;
	}
	else
	{
		document.frmJumpTo.submit();
	}
}

function ValidateAPL()
{
	if ((document.frmAPLPackages.Gateway.value=="")||(document.frmAPLPackages.Gateway.value==null)||(document.frmAPLPackages.Destination.value=="")||(document.frmCCPackages.Destination.value==null))
	{
		alert('Please select a departure city and a destination');
		return false;
	}
	else
	{
		document.frmAPLPackages.submit();
	}
}

function ValidateCC()
{
	if ((document.frmCCPackages.city.value=="")||(document.frmCCPackages.city.value==null)||(document.frmCCPackages.locID.value=="")||(document.frmCCPackages.locID.value==null))
	{
		return false;
	}
	else
	{
		document.frmCCPackages.submit();
	}
}

function MM_findObj(n, d)
{
	var p,i,x;
	if (!d) d = document;
	if ((p = n.indexOf("?")) > 0 && parent.frames.length)
	{
		d = parent.frames[n.substring(p + 1)].document;
		n = n.substring(0,p);
	}
	if (!(x = d[n]) && d.all)
	{
		x = d.all[n];
	}
	for (i = 0; !x && i < d.forms.length; i++)
	{
		x = d.forms[i][n];
	}
	for (i = 0; !x && d.layers && i < d.layers.length; i++)
	{
		x = MM_findObj(n,d.layers[i].document);
	}
	if (!x && d.getElementById)
	{
		x = d.getElementById(n);
	}
	return x;
}
function MM_showHideLayers() //Works with display:block/none
{
	var i,
		p,
		v,
		obj,
		args = MM_showHideLayers.arguments;
	for (i = 0; i < (args.length - 2); i += 3) if ((obj = MM_findObj(args[i])) != null)
	{
		v = args[i + 2];
		if (obj.style)
		{
			obj = obj.style;
			v = (v == 'show') ? 'block' : (v == 'hide') ? 'none' : v;
		}
		obj.display = v;
	}
}

function SetCalendarParameters()
{
	SetCarCalendarParameters();
	SetFlightCalendarParameters();
	SetPackageCalendarParameters();
	SetHotelCalendarParameters();
	SetActivitiesCalendarParameters();
}

function SelectLabel(n)
{
	for(var i=4;i<=8;i++)
	{
		document.getElementById('label' + i).style.fontWeight = 'normal';
	}
	document.getElementById('label' + n).style.fontWeight = 'bold';
}

function SelectPackages()
{
	document.getElementById('label4').style.fontWeight = 'bold';
	document.getElementById('packages').checked = true;
	document.PackageSrch.PackageType.value = 2;
	MM_showHideLayers('sc1','','show','sc4','','hide','sc5','','hide','sc6','','hide','sc8','','hide');
}

function Packages1()
{
SelectLabel(4);
MM_showHideLayers('sc1','','show','sc4','','hide','sc5','','hide','sc6','','hide','sc8','','hide');
document.PackageSrch.PackageType.value = 2;
}

/*function Packages2()
{
SelectLabel(2);
MM_showHideLayers('sc1','','show','sc4','','hide','sc5','','hide','sc6','','hide','sc8','','hide');
document.PackageSrch.PackageType.value = 5;
}

function Packages3()
{
SelectLabel(3);
MM_showHideLayers('sc1','','show','sc4','','hide','sc5','','hide','sc6','','hide','sc8','','hide');
document.PackageSrch.PackageType.value = 1;
}

function Packages4()
{
SelectLabel(4);
MM_showHideLayers('sc1','','show','sc4','','hide','sc5','','hide','sc6','','hide','sc8','','hide');
document.PackageSrch.PackageType.value = 3;
}*/

function Hotels()
{
SelectLabel(5);
MM_showHideLayers('sc1','','hide','sc4','','show','sc5','','hide','sc6','','hide','sc8','','hide');
}

function Flights()
{
SelectLabel(6);
MM_showHideLayers('sc1','','hide','sc4','','hide','sc5','','show','sc6','','hide','sc8','','hide');
}

/*function Cruises()
{
SelectLabel(7);
MM_showHideLayers('sc1','','hide','sc4','','hide','sc5','','hide','sc6','','hide','sc7','','show', 'sc8','','hide');
}
*/
function Cars()
{
SelectLabel(7);
MM_showHideLayers('sc1','','hide','sc4','','hide','sc5','','hide','sc6','','show','sc8','','hide');
}

function Activities()
{
SelectLabel(8);
MM_showHideLayers('sc1','','hide','sc4','','hide','sc5','','hide','sc6','','hide','sc8','','show');
}

//News Ticker Base Script

function SelectPackaged() {
	document.getElementById('booking_wwte').style.display = 'none';
	document.getElementById('booking_softvoyage').style.display = 'block';
	document.getElementById('img_packaged').src = 'images/packaged_tab_on.gif';
	document.getElementById('img_custom').src = 'images/custom_tab_off.gif';
}

function SelectCustom() {
	document.getElementById('booking_wwte').style.display = 'block';
	document.getElementById('booking_softvoyage').style.display = 'none';
	document.getElementById('img_packaged').src = 'images/packaged_tab_off.gif';
	document.getElementById('img_custom').src = 'images/custom_tab_on.gif';
}