// JavaScript Document
var selectedID = 0;
selectedThumbID = 'thumb1';
destinationID = '';

function open_win(theURL,winName,features) { 
   
  var mainWin = self;
		if( window.winName == null )      // If the window has never been opened
			winName=window.open(theURL, winName, features);
		else {
		if( window.winName.closed )    // 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 SwapImageJPG(img,state) {
	eval("document." +img+ ".src='images/" +img+ "_" +state+ ".jpg'");
}

function SwapImagePage(img,state) {
	//eval("document." +img+ ".src='images/" +img+ "_" +state+ ".jpg'");
	//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){
		if (b == 1 ){
			document.getElementById(a).style.backgroundImage = 'URL(images/tab_background_on.jpg)'; 
		}
		else{
			document.getElementById(a).style.backgroundImage = ''; 
		}
	 }
}

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){
		if(document.getElementById(id).style.backgroundColor == '') { 
		   document.getElementById(id).style.backgroundColor = '#dfe7ea';
		 } 
		 else { 
		  document.getElementById(id).style.backgroundColor = '';
		 } 
	}
}


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){
	 
	 if(selectedID != 0){
		 	document.getElementById(selectedID).style.backgroundColor = '';
	 }
		 document.getElementById(id).style.backgroundColor = '#ffffff';
		 selectedID = id;
		 
	GetItineraryData(package_id, theDate,tour_id);		 
	
}

function highliteThumb(a,b){
	//var obj = document.getElementById(a).style;
	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-back1.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 = 3000;	// 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);
	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

function GetItineraryData(package_id, theDate,tour_id)
{ 
			
xmlHttp=GetXmlHttpObject();

if (xmlHttp==null)
  {
  alert ("Your browser does not support AJAX!");
  return;
  } 

 
 str = "thisPackageID="+package_id+"&theDate="+theDate+"&tour_id="+tour_id; 
var url="inc/ajax_itinerary.cfm";
url=url+"?"+str;	
xmlHttp.onreadystatechange=ChangeItinerary;			
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}

function ChangeItinerary() 
{ 
	if (xmlHttp.readyState==4)
	{ 
		HideDiv("loading2");
		var myText = xmlHttp.responseText;					
		document.getElementById('tourInfoItinerary').innerHTML = myText;
		
	}
	
	if (xmlHttp.readyState==1)
	{
		ShowDiv("loading2");
	}
}

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()
{ 
	//alert("HERE");
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null)
	  {
	  alert ("Your browser does not support AJAX!");
	  return;
	  } 
	
	 //alert(document.Tours.Action.value)
	 str = "Destination="+document.Tours.Destination.value +"&Type="+document.Tours.TourType.value +"&ToDate="+document.Tours.ToDate.value +"&fromDate="+document.Tours.FromDate.value ;
	
	 
	 // alert(str);
	  
	var url="inc/ajax_tour.cfm";
	url=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)
{
	//alert(thisCheckbox);
	SaveMe = eval("document.itineraryForm."+thisCheckbox+".checked");
	CurrentDiv = thisDiv;
	CurrentCheckBox=SaveMe;
	//alert(eval("document.itineraryForm."+thisCheckbox+".checked"));
	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;		  
		 // alert(str);		  
		var url="inc/ajax_SaveTour.cfm";
		url=url+"?"+str;			
		xmlHttp.onreadystatechange=SaveThisTour;			
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}
	
}

function SaveThisTour()
{
	if (xmlHttp.readyState==4)
	{ 
		var myText = xmlHttp.responseText;					
		document.getElementById(CurrentDiv).innerHTML = myText;
		
		if(myText==1)
		{
			document.getElementById(CurrentDiv).innerHTML = "<span class=red>Tour Removed</span>";
			CurrentCheckBox = false;
		}
		else if (myText==2)
		{
			document.getElementById(CurrentDiv).innerHTML = "<span class=red>Tour Saved</span>";
			CurrentCheckBox = true;
		}
			 
		else if (myText==3)
		{	
			document.getElementById(CurrentDiv).innerHTML = "<span class=red>Can Only Save Three Tours</span>";
			CurrentCheckBox = false;
		}
			
	
		
	}
	if (xmlHttp.readyState==1)
	{
		//ShowDiv("SavedTour");
	}
}

function SaveTourNotLoggedIn(thisPage,theString)
{
	var answer = confirm("You Are Not Logged in, would you like to proceed to login?")
	if (answer)	
	{
		window.location = "login.cfm?thisPage="+thisPage+"&"+theString;	
	}
}

function checkboxlimit(checkgroup, limit){
                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
                                                }
                                }
                }
}

