/* Unica Page Tagging Script v7.4.0
 * Copyright 2004-2006 Unica Corporation.  All rights reserved.
 * Visit http://www.unica.com for more information.
 */

var NTPT_IMGSRC = '/js/ntpagetag.gif';
var NTPT_FLDS = new Object();
NTPT_FLDS.lc = false; // Document location
NTPT_FLDS.rf = false; // Document referrer
NTPT_FLDS.rs = false; // User's screen resolution
NTPT_FLDS.cd = false; // User's color depth
NTPT_FLDS.ln = false; // Browser language
NTPT_FLDS.tz = false; // User's timezone
NTPT_FLDS.jv = false; // Browser's Java support
NTPT_FLDS.ck = false; // Cookies

var NTPT_MAXTAGWAIT = 1.0; // Max delay (secs) on link-tags and submit-tags

// Optional variables:
var NTPT_HTTPSIMGSRC = '';
var NTPT_GLBLEXTRA = '';
var NTPT_GLBLREFTOP = false;
var NTPT_GLBLCOOKIES = [ ];

/*** END OF USER-CONFIGURABLE VARIABLES ***/

var selectedID = 0;
selectedThumbID = 'thumb1';
destinationID = '';

function open_win(theURL, winName, features) {
	var mainWin = self;
	if (window.winName == null || window.winName.closed) // If the window has never been opened or If the window was open but has been closed
		winName = window.open(theURL, winName, features);
	else // The window is already open
		winName.location.href = theURL;
	winName.opener = mainWin;
	winName.focus();
}

function SwapImage(img, state) {
	eval("document." + img + ".src='/images/" + img + "_" + state + ".gif'");
}

function SwapImage1(img, state) {
	eval("document." + img + ".src='/images/partner_img/" + img + "_" + state + ".gif'");
} 

function SwapImageJPG(img, state, ext) {
	if (typeof(ext) == "undefined" || ext == null)
		ext = ".jpg";
	eval("document." + img + ".src='/images/" + img + "_" + state + ext + "'");
}

function SwapImagePage(img,state) {
	//Function for Descriptoin.cfm page images Had to add this because this becaue just numbers didnt work 
	eval("document." + img + ".src='/Timages/" + img + "-" + state + ".jpg'");
}

function highlite(a, b){
	if(a != destinationID){
		a = document.getElementById(a);
		if (a != null)
			a.style.backgroundImage = b == 1 ? 'URL(/images/tab_background_on.jpg)' : '';
	}
}

function highliteSelected(id){
	if(destinationID != id  )
		document.getElementById(id).style.backgroundImage = 'URL(/images/tab_background_on.jpg)';
	if(destinationID.length > 0)
		document.getElementById(destinationID).style.backgroundImage = '';
	destinationID = id;
}

function highliteRow(id){
	if(selectedID != id){
		var el = document.getElementById(id);
		el.style.backgroundColor = el.style.backgroundColor == '' ? '#dfe7ea' : '';
	}
}


function selectedRow2(id){
	 if(selectedID != 0){
		document.getElementById(selectedID).style.backgroundColor = '';
	}
	document.getElementById(id).style.backgroundColor = '#ffffff';
	selectedID = id;
}

function selectedRow(id, package_id, theDate, tour_id, isSoldOut) {
	selectedRow2(id);
	GetItineraryData(package_id, theDate,tour_id, isSoldOut);
}

function highliteThumb(a,b){
	if(selectedThumbID != a){
		if (b == 1 ){
			document.getElementById(a).style.backgroundImage = 'URL(/images/descript-orange-back.gif)'; 
		}
		else{
			document.getElementById(a).style.backgroundImage = 'URL(/images/descript-white-back.gif)'; 
		}
	}
	
}

function selectedThumb(id){
	 if(selectedThumbID != id){
		document.getElementById(selectedThumbID).style.backgroundImage = 'URL(/images/descript-white-back.gif)';
	 }
		document.getElementById(id).style.backgroundImage = 'URL(/images/descript-orange-back.gif)';
		 selectedThumbID = id;
}


function linkPop(div){
	var style1 = document.getElementById(div).style;	
		if (style1.display == "block"){
		style1.display = style1.display="none";
		}
		else{
		style1.display = style1.display="block";
   }
}

var slideshow2_noFading = false;
var slideshow2_timeBetweenSlides = 4000;	// Amount of time between each image(1000 = 1 second)
var slideshow2_fadingSpeed = 10;	// Speed of fading	(Lower value = faster)
var slideshow2_stats = new Array();
var slideshow2_slideIndex = new Array();	// Index of current image shown
var slideshow2_slideIndexNext = new Array();	// Index of next image shown
var slideshow2_imageDivs = new Array();	// Array of image divs(Created dynamically)
var slideshow2_currentOpacity = new Array();	// Initial opacity
var slideshow2_imagesInGallery = new Array();	// Number of images in gallery
var Opera = navigator.userAgent.indexOf('Opera')>=0?true:false;
var reverseShow = false;


function createParentDivs(imageIndex,divId)
{
	if(imageIndex==slideshow2_imagesInGallery[divId]){	
		showGallery(divId);
	}else{
		var imgObj = document.getElementById(divId + '_' + imageIndex);	
		if(Opera)imgObj.style.position = 'static';
		if(!slideshow2_imageDivs[divId])slideshow2_imageDivs[divId] = new Array();
		slideshow2_imageDivs[divId][slideshow2_imageDivs[divId].length] =  imgObj;

		imgObj.style.visibility = 'hidden';	
		imageIndex++;
		createParentDivs(imageIndex,divId);	
	}		
}

function showGallery(divId){
	
	if(reverseShow){
		slideshow2_slideIndex[divId]--;	// Index of next image to show
		if(slideshow2_slideIndex[divId] == -1)
			slideshow2_slideIndex[divId] = slideshow2_imageDivs[divId].length - 1;
		slideshow2_slideIndexNext[divId] = slideshow2_slideIndex[divId] - 1;// Index of the next next image
		if(slideshow2_slideIndexNext[divId] == -1)
			slideshow2_slideIndexNext[divId] = slideshow2_imageDivs[divId].length -1;
	} else {
		if(slideshow2_slideIndex[divId]==-1)
			slideshow2_slideIndex[divId]=0; 
		else 
			slideshow2_slideIndex[divId]++;	// Index of next image to show
		if(slideshow2_slideIndex[divId]==slideshow2_imageDivs[divId].length)
			slideshow2_slideIndex[divId]=0;
		slideshow2_slideIndexNext[divId] = slideshow2_slideIndex[divId]+1;	// Index of the next next image
		if(slideshow2_slideIndexNext[divId]==slideshow2_imageDivs[divId].length)
			slideshow2_slideIndexNext[divId] = 0;    //alert(slideshow2_slideIndexNext[divId]);
	}

	slideshow2_currentOpacity[divId]=100;	// Reset current opacity

	// Displaying image divs
	
	slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.visibility = 'visible';
	if(Opera)slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.display = 'inline';
	if(navigator.userAgent.indexOf('Opera')<0){
		
		slideshow2_imageDivs[divId][slideshow2_slideIndexNext[divId]].style.visibility = 'visible';
	}
	
	if(document.all){	// IE rules
		slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.filter = 'alpha(opacity=100)';
		slideshow2_imageDivs[divId][slideshow2_slideIndexNext[divId]].style.filter = 'alpha(opacity=1)';
	}else{
		
		slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.opacity = 0.99;	// Can't use 1 and 0 because of screen flickering in FF
		slideshow2_imageDivs[divId][slideshow2_slideIndexNext[divId]].style.opacity = 0.01;
	}

	setTimeout('revealImage("' + divId + '")',slideshow2_timeBetweenSlides);
}

function revealImage(divId){
	if(slideshow2_noFading){
		slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.visibility = 'hidden';
		if(Opera)slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.display = 'none';
		showGallery(divId);
		return;
	}
	slideshow2_currentOpacity[divId]--;
	if(document.all){
		slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.filter = 'alpha(opacity='+slideshow2_currentOpacity[divId]+')';
		slideshow2_imageDivs[divId][slideshow2_slideIndexNext[divId]].style.filter = 'alpha(opacity='+(100-slideshow2_currentOpacity[divId])+')';
	}else{
		slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.opacity = Math.max(0.01,slideshow2_currentOpacity[divId]/100);	// Can't use 1 and 0 because of screen flickering in FF
		slideshow2_imageDivs[divId][slideshow2_slideIndexNext[divId]].style.opacity = Math.min(0.99,(1 - (slideshow2_currentOpacity[divId]/100)));
	}
	if(slideshow2_currentOpacity[divId]>0){
			setTimeout('revealImage("' + divId + '")',slideshow2_fadingSpeed);
	}else{
		slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.visibility = 'hidden';	
		if(Opera)slideshow2_imageDivs[divId][slideshow2_slideIndex[divId]].style.display = 'none';	
		showGallery(divId);
	}
}

function initImageGallery(divId){
	var slideshow2_galleryContainer = document.getElementById(divId);
	if (slideshow2_galleryContainer != null) {
		slideshow2_slideIndex[divId] = -1;
		slideshow2_slideIndexNext[divId] = false;

		var galleryImgArray = slideshow2_galleryContainer.getElementsByTagName('img');
		for(var no=0;no<galleryImgArray.length;no++)
			galleryImgArray[no].id = divId + '_' + no;

		slideshow2_imagesInGallery[divId] = galleryImgArray.length;
		createParentDivs(0,divId);
	}
}
function stopShow(divId){
	reverseShow = false;
	slideshow2_timeBetweenSlides = 1000000;
	slideshow2_noFading = true;
	clearTimeout( divId );
}
function showNext(divId){
	reverseShow = false;
	slideshow2_timeBetweenSlides = 1000000;
	slideshow2_noFading = true;
	revealImage(divId);
}
function showPrevious(divId){
	reverseShow = true;
	slideshow2_timeBetweenSlides = 1000000;
	slideshow2_noFading = true;
	revealImage(divId);
}

var xmlHttp
var xmlHttp2

function GetItineraryData(package_id, theDate,tour_id, isSoldOut){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	}
	str = "thisPackageID="+package_id+"&theDate="+theDate+"&tour_id="+tour_id+"&isSoldOut="+(isSoldOut ? "1" : "0");
	var url="/inc/ajax_itinerary.cfm";
	url += "?" + str;	
	xmlHttp.onreadystatechange=ChangeItinerary;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
	xmlHttp2=GetXmlHttpObject();
	url="/inc/ajax_personalized_itinerary.cfm";
	url += "?" + str;
	xmlHttp2.onreadystatechange=ChangeItinerary2;
	xmlHttp2.open("GET",url,true);
	xmlHttp2.send(null);
}

function ChangeItinerary(){
	if (xmlHttp.readyState == 4) {
		HideDiv("loading2");
		var myText = xmlHttp.responseText;
		document.getElementById('tourInfoItinerary').innerHTML = myText;
	} else if (xmlHttp.readyState == 1)
		ShowDiv("loading2");
}

function ChangeItinerary2(){
	if (xmlHttp2.readyState==4){
		var myText = xmlHttp2.responseText;
		document.getElementById('perItin').innerHTML = myText;
	}
}

function GetXmlHttpObject(){
	var xmlHttp = null;
	try {
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
	} catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}

function GetCount(){
	xmlHttp=GetXmlHttpObject();
	if (xmlHttp==null){
		alert ("Your browser does not support AJAX!");
		return;
	}
	str = "Destination="+document.Tours.Destination.value +"&Type="+document.Tours.TourType.value +"&ToDate="+document.Tours.ToDate.value +"&fromDate="+document.Tours.FromDate.value;
	var url="/inc/ajax_tour.cfm";
	url += "?" + str;
	xmlHttp.onreadystatechange=stateChanged;
	xmlHttp.open("GET",url,true);
	xmlHttp.send(null);
}

function stateChanged(){
	if (xmlHttp.readyState == 4){
		HideDiv("loading");
		var myText = xmlHttp.responseText;
		document.getElementById('Tour').innerHTML = myText;
	}
	if (xmlHttp.readyState==1)
		ShowDiv("loading");
}

function ShowDiv(div){
	target = document.getElementById(div);
	target.style.display="";
}

function HideDiv(div){
	target = document.getElementById(div);
	target.style.display="none";
}

function Goto(url){
	window.location = url;
}

var CurrentDiv='';
var CurrentCheckBox='';

function SaveTour(tour_id, thisCheckbox, thisDiv){
	SaveMe = eval("document.itineraryForm." + thisCheckbox + ".checked");
	CurrentDiv = thisDiv;
	CurrentCheckBox = SaveMe;
	xmlHttp=GetXmlHttpObject();

	if (xmlHttp == null){
		alert ("Your browser does not support AJAX!");
		return;
	}

	if(SaveMe == false){
		var answer = confirm("Are you sure you want to remove this tour?");
		if (answer){
			str = "Tour_ID=" + tour_id + "&Save=" + SaveMe;
			var url="/inc/ajax_SaveTour.cfm";
			url=url+"?"+str;
			xmlHttp.onreadystatechange=SaveThisTour;
			xmlHttp.open("GET",url,true);
			xmlHttp.send(null);
		} else
			SaveMe = true;
	} else {
		str = "Tour_ID="+tour_id+"&Save="+SaveMe;
		var url = "/inc/ajax_SaveTour.cfm";
		url += "?" + str;
		xmlHttp.onreadystatechange=SaveThisTour;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}	
}

function SaveThisTour(){
	if (xmlHttp.readyState == 4){
		var myText = xmlHttp.responseText;
		var el = document.getElementById(CurrentDiv);
		if (myText == 1){
			el.innerHTML = "<span class=red>Tour Removed</span>";
			CurrentCheckBox = false;
		} else if (myText == 2) {
			el.innerHTML = "<span class=red>Tour Saved</span>";
			CurrentCheckBox = true;
			ntptEventTag('ev=Saved_Tour');
		} else if (myText == 3) {
			el.innerHTML = "<span class=red>Can Only Save Three Tours</span>";
			CurrentCheckBox = false;
		} else
			el.innerHTML = myText;
	}
}

function SaveTourNotLoggedIn(thisPage, theString){
	var answer = confirm("To save a tour, login to your account or create a new one now.")
	if (answer)
		window.location = "login.cfm?thisPage=" + thisPage + "&" + theString;
}

function checkboxlimit(checkgroup, limit){
	if (checkgroup){
		var checkgroup = checkgroup;
		var limit = limit;
		for (var i=0; i<checkgroup.length; i++){
			checkgroup[i].onclick = function(){
				var checkedcount = 0;
				for (var i=0; i<checkgroup.length; i++)
					checkedcount += (checkgroup[i].checked) ? 1 : 0;
				if (checkedcount > limit){
					alert("You can only compare a maximum of " + limit + " tours");
					this.checked = false;
				}
			}
		}
	}
}
