addEvent(window, "load", preparePage);

function preparePage() {
    // We don't actually need createElement, but we do
    // need good DOM support, so this is a good check.
    if (!document.createElement) return;
	uls = document.getElementsByTagName("a");
    for (uli=0;uli<uls.length;uli++) {
        theA = uls[uli];
        if (theA.nodeName == "A") {
        	if(theA.className == "tab"){
        		prepareTabs(theA);
	        }else if(theA.parentNode.parentNode.parentNode.id == "nav"){
	        	prepareNav(theA);
	        }
        }
    }

    if(getPageName() == "index.asp" || getPageName().length == 0){
    	t = location.search.substring(1,location.search.length);
    	var p;
	    if(t.indexOf("t=2") > -1){
		    p = "specialoffers";
		}else if(t.indexOf("t=3") > -1){
			p = "packages";
		}else if(t.indexOf("t=4") > -1){
			p = "venues";
		}else if(t.indexOf("t=5") > -1){
			p = "aboutus";
		}else if(t.indexOf("t=6") > -1){
			p = "help";
		}else{
			p = "homeevents";
		}
		if(p == "homeevents"){
}else{
		document.getElementById(p).className = "theone";
		document.getElementById(p).firstChild.firstChild.src = document.getElementById(p).firstChild.firstChild.src.replace('.gif','-on.gif');
		document.getElementById(p).parentNode.className = "on";
		if(p == "help"){
	        document.getElementById("ic").style.backgroundImage = 'url(/images/blank.gif)';
	    }
}
    }
    PrepareDates();
    PreloadImages();
    populateDates();
    SetHeights();
}

function PreloadImages(){
	img1 = new Image();img1.src = "images/bullet-hit.gif";
	img2 = new Image();img2.src = "images/homeevents-on.gif";
	img3 = new Image();img3.src = "images/packages-on.gif";
	img4 = new Image();img4.src = "images/specialoffers-on.gif";
	img5 = new Image();img5.src = "images/venues-on.gif";
	img6 = new Image();img6.src = "images/aboutus-on.gif";
	img7 = new Image();img7.src = "images/help-on.gif";
}

function SetHeights(){
	if(document.getElementById("leftpane") && document.getElementById("content")){
		theLeft = document.getElementById("leftpane");
		theRight = document.getElementById("content");
		theLeft.style.height="auto";
		theRight.style.height="auto";
		if(theLeft.offsetHeight){
	        tallA = theLeft.offsetHeight;
	        tallB = theRight.offsetHeight;
	    }else if(theLeft.style.pixelHeight){
	        tallA = theLeft.style.pixelHeight;
	        tallB = theRight.style.pixelHeight;
	    }
	    tallest = Math.max(tallA,tallB);
		theLeft.firstChild.style.height = (tallest - 18) +"px";
		if(document.getElementById("ic")){
			if(navigator.appName == "Microsoft Internet Explorer"){
				document.getElementById("ic").style.height = (tallest - 29) +"px";
			}else{
				document.getElementById("ic").style.height = (tallest - 39) +"px";
			}
		}
		return true;
	}
}

function prepareNav(theA){
	theA.onmouseover = function(){
       	theA.parentNode.className = "on";
		return true;
    }
    theA.onmouseout = function() {
    	theA.parentNode.className = "";
		return true;
    }
}

// Reads the quantity and price columns in the form and computes the
// totals and grand total, filling these in.
function UpdateTotals(table_id)
{
  var numrows = document.getElementById(table_id).rows.length - 2;  // don't count the header row!
  var i, totalcost = 0.00, totalq = 0;
  for (i = 1; i <= numrows; i++) {
  
     // Compute total for each row
  	
    var q = parseInt(document.getElementById('quantity_' + i).value);
    var price = parseFloat(document.getElementById('price_' + i).value);
    var cost;
    totalq = totalq + q;
    if (!q || !price)
      cost = 0.00;
    else
      cost = q * price;
    var total = document.getElementById('total_' + i);
    total.value = '$' + cost.toFixed(2);
    totalcost = totalcost + cost;  // Keep running grand total

 	
 }
  var totalprice = document.getElementById('totalprice');
  totalprice.value = '$' + totalcost.toFixed(2);
  var totalquantity = document.getElementById('totalquantity');
  totalquantity.value = totalq

}


   
function prepareTabs(theA){

	if(getPageName() == "index.asp"){
		theA.setAttribute('href', '#');
		theA.onclick = function() {
			ajaxRead("tabs.asp",theA.parentNode.id,"ic");
			uls = document.getElementsByTagName("li");
		    for (uli=0;uli<uls.length;uli++) {
		    	theLi = uls[uli];
		        if(theLi.parentNode.parentNode.id == "tabs"){
					theLi.className = "";
					theLi.firstChild.className = "";
					theLi.firstChild.firstChild.firstChild.src = theLi.firstChild.firstChild.firstChild.src.replace('-on','');
					if(uli + 1 == uls.length){
						theLi.className = "end";
					}
		        }
		    }
		    theA.parentNode.className = "theone";
		    theA.firstChild.src = theA.firstChild.src.replace('.gif','-on.gif');
		    theA.parentNode.parentNode.className = "on";
		    SetHeights();
			return true;
	    }
	}
	
    theA.onmouseover = function(){
    	if(theA.parentNode.parentNode.className == "end"){
        	theA.parentNode.parentNode.className = "end on";
        	document.getElementById("ic").style.backgroundImage = 'url()';
        }else{
        	theA.parentNode.parentNode.className = "on";
        }
        if(theA.firstChild.src.split("-on").length < 2){
	        newFileArray = theA.firstChild.src.split(".");
	        newFileName = "";
	        if(newFileArray.length > 1){
	        	j = newFileArray.length - 2;
	        	for (i=0;i<newFileArray.length;i++){
	        		if(newFileName.length < 1){
	        			newFileName = newFileArray[i];
	        		}else{
	        			newFileName = newFileName + "." + newFileArray[i];
	        		}
	        		if(i == j){
	        			newFileName = newFileName + "-on";
	        		}
	        	}
	        	theA.firstChild.src = newFileName;
	       	}
        	
        }
		return true;
    }
    theA.onmouseout = function() {
    	if(theA.parentNode.className != "theone"){
	        if(theA.parentNode.parentNode.className == "end on"){
	        	theA.parentNode.parentNode.className = "end";
	        	document.getElementById("ic").style.backgroundImage = 'url(/images/tcw.gif)';
	        }else{
	        	theA.parentNode.parentNode.className = "";
	        }
        	theA.firstChild.src = theA.firstChild.src.replace('-on','');
        }
		return true;
    }
}

function reNameFile(newFileArray){
    newFileName = "";
    if(newFileArray.length > 1){
    	j = newFileArray.length - 2;
    	for (i=0;i<newFileArray.length;i++){
    		if(newFileName.length < 1){
    			newFileName = newFileArray[i];
    		}else{
    			newFileName = newFileName + "." + newFileArray[i];
    		}
    		if(i == j){
    			newFileName = newFileName + "-on";
    		}
    	}
    	return newFileName;
   	}
   	return "";
}


// adds an eventListener for browsers which support it.

function addEvent(obj, evType, fn){
  if (obj.addEventListener){
    obj.addEventListener(evType, fn, false);
    return true;
  } else if (obj.attachEvent){
	var r = obj.attachEvent("on"+evType, fn);
    return r;
  } else {
	return false;
  }
}

function ajaxRead(file,tabName,output){
	var xmlObj = null;
	if(window.XMLHttpRequest){
		xmlObj = new XMLHttpRequest();
	} else if(window.ActiveXObject){
		xmlObj = new ActiveXObject("Microsoft.XMLHTTP");
	} else {
		return;
	}
	xmlObj.onreadystatechange = function(){
    	if(xmlObj.readyState == 4){
			updateObj(output, xmlObj.responseXML.getElementsByTagName(tabName)[0].firstChild.data);
		}
    }
    xmlObj.open ('GET', file, true);
    xmlObj.send ('');
}
function updateObj(output, data){
	document.getElementById(output).innerHTML = data;
}

function findPosX(obj){
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent){
		curtop += obj.offsetHeight;
		while (obj.offsetParent){
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else if (obj.y){
		curtop += obj.y;
		curtop += obj.height;
	}
	return curtop;
}

function changeOpac(opacity, id) {
    var object = document.getElementById(id).style;
    object.opacity = (opacity / 100);
    object.MozOpacity = (opacity / 100);
    object.KhtmlOpacity = (opacity / 100);
    object.filter = "alpha(opacity=" + opacity + ")";
}

function getPageName(){
	var sPath = window.location.pathname;
	var sPage = sPath.substring(sPath.lastIndexOf('/') + 1);
	return sPage;
}






		function PrepareDates(){
			if(document.getElementById("dayend")){
				document.getElementById("dayend").onchange = function() {
					validateReturnDate();
		    	}
				document.getElementById("monthend").onchange = function() {
					validateReturnDate();
		    	}
		    	document.getElementById("monthstart").onchange = function() {
					fillReturnDate();
		    	}
		    	document.getElementById("daystart").onchange = function() {
					fillReturnDate();
		    	}
			}
		}
		var monthOffset = 0;
		var Saf = ( navigator.userAgent.indexOf("Safari") > -1 ? true : false ); 
		var Mac = ( navigator.userAgent.indexOf("Mac") > -1 ? true : false );
		var monthValueArray = new Array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12');
		var monthTextArray = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
		
		function openCalendar(theType) {
			var width = 181;
			var height = 140;
			if(Saf) {
				width=200;
				height=130;
			}
			if (IsIE()) {
				var Xpos = event.screenX; 
				var Ypos = event.screenY; 
			}
			else {
				var Xpos = 200;
				var Ypos = 300;
			}
			popWindow('calendar.asp?w=' + theType,'termsWindow','scrollbars=no,resizable=no,width=' + width + ',height=' + height + ',left=' + Xpos + ',top=' + Ypos); //width=175, height=125
		}
	
		
		var prev_return_day = 0;
		var prev_return_month = 0;
		var prev_return_time = 0;

		function populateDates() {
			if (document.frmVisible){
				if (document.frmVisible)
				{
					var deptMonthDropdown = document.frmVisible.elements["monthstart"];
				}
				if (document.frmVisible)
				{
					var arrivalMonthDropdown = document.frmVisible.elements["monthend"];
				}
				var dDate = new Date();
				monthOffset = (dDate.getMonth());
				if (document.frmCalendar)
				{
					document.frmCalendar.elements["monthOffset"].value = monthOffset; 
				}
				
				//repopulate the month dropdown with months starting from today
				for(i=0; i<12; i++){
					j = i + monthOffset;
					if (deptMonthDropdown)
					{
						if (j > 11)j = j - 12;
						deptMonthDropdown.options[i].value = monthValueArray[j];
						deptMonthDropdown.options[i].text = monthTextArray[j];
						if(arrivalMonthDropdown.options[i+1]){
							arrivalMonthDropdown.options[i+1].value = monthValueArray[j];
							arrivalMonthDropdown.options[i+1].text = monthTextArray[j];
						}
					}
				}
				dDate.setDate(dDate.getDate() + 1);
				doPopulate(dDate,dDate);
				
			}
		}	
		
		function getDayName(iDay) {
			switch(iDay)
			{
				case 0 :
					sOutputDay = "Sun";
					break;
				case 1 :
					sOutputDay = "Mon";
					break;
				case 2 :
					sOutputDay = "Tue";
					break;
				case 3 :
					sOutputDay = "Wed";
					break;
				case 4 :
					sOutputDay = "Thu";
					break;
				case 5 :
					sOutputDay = "Fri";
					break;
				case 6 :
					sOutputDay = "Sat";
					break;
			}
			return sOutputDay;
		}
		
		function fillReturnDate() {
			var startDate = document.frmVisible.elements["daystart"].selectedIndex;
			var deptMonth = getMonthFromSelected(document.frmVisible.elements["monthstart"].selectedIndex);
			var dDate = new Date();
			var dStartDay;
			var dDateDept = new Date(dDate.getFullYear(), deptMonth, startDate+2);
			dStartDay = dDateDept;
			if(dDateDept < dDate){
				if(deptMonth+1 != dDate.getMonth()){
					dDateDept = new Date(dDate.getFullYear()+1, deptMonth, startDate+2);
				}
			}
			
			if (dStartDay < new Date(dDate.getFullYear(), dDate.getMonth(), 1)){
				dStartDay = new Date(dDateDept.getFullYear(), dDateDept.getMonth(), dDateDept.getDate());
			}

			doPopulate(dDateDept, dStartDay);
		}
		
		function doPopulate(dDateDept, dDeptDay) {
			if (document.frmVisible)
			{
				tF = document.frmVisible.elements;
				tF["daystart"].selectedIndex = dDateDept.getDate()-2;
				tF["monthstart"].selectedIndex = setSelectedIndexFromMonth(dDateDept.getMonth());	


					if (dDeptDay > ""){
						var dArrivalDay = new Date(dDeptDay.getFullYear(), dDeptDay.getMonth(), dDeptDay.getDate()+1);
						return_day = tF["dayend"].selectedIndex;
						return_month = getMonthFromSelected(tF["monthend"].selectedIndex-1);
						
						var dDate = new Date();
						tempreturndate = new Date(dDate.getFullYear() , return_month,  return_day);
						if(tempreturndate < dDate){
										tempreturndate = new Date(dDate.getFullYear()+1, return_month, return_day);
						}
						dDateDept.setDate(dDateDept.getDate() + 1);
						if(tempreturndate<dDateDept){
							tF["dayend"].selectedIndex = dDateDept.getDate();
							tF["monthend"].selectedIndex = setSelectedIndexFromMonth(dDateDept.getMonth())+1;
						}
						else{
							tF["monthend"].selectedIndex = setSelectedIndexFromMonth(dDateDept.getMonth())+1;
						}
					}else{
						dDateDept.setDate(dDateDept.getDate() + 1);		
						tF["dayend"].selectedIndex = dDateDept.getDate();
						tF["monthend"].selectedIndex = setSelectedIndexFromMonth(dDateDept.getMonth())+1;
					}
					rememberReturnDate();
	
			}
		}
		
		function validateReturnDate() {
			var retnDay = document.frmVisible.elements["dayend"].selectedIndex;
			var retnMonth = getMonthFromSelected(document.frmVisible.elements["monthend"].selectedIndex);
			var dDate = new Date();
			var dArivDay;
			var dDateRetn = new Date(dDate.getFullYear(), retnMonth-1, retnDay);
            dArivDay = new Date(dDateRetn.getFullYear(), dDateRetn.getMonth(), dDateRetn.getDate());
			if(dDateRetn < dDate){
				var dDateRetn = new Date(dDate.getFullYear()+1, retnMonth-1, retnDay);
			}
			
			if (dArivDay < new Date(dDate.getFullYear(), dDate.getMonth(), 1)){
				dArivDay = new Date(dDateRetn.getFullYear(), dDateRetn.getMonth(), dDateRetn.getDate());
			}
			
			document.frmVisible.elements["dayend"].selectedIndex = dDateRetn.getDate();
			document.frmVisible.elements["monthend"].selectedIndex = setSelectedIndexFromMonth(dDateRetn.getMonth())+1;
			rememberReturnDate();	
		}	
		
		function rememberReturnDate() {
		    tF = document.frmVisible.elements;
			prev_return_day = tF["dayend"].selectedIndex;
			prev_return_month = tF["monthend"].selectedIndex;
		}

		function getMonthFromSelected(sindex){
			if(typeof(document.frmCalendar) == "undefined") monthOffset = 0;
			rtnValue = sindex + monthOffset; 
			if (rtnValue > 11) rtnValue = rtnValue - 12;
			return rtnValue;
		}
		
		function setSelectedIndexFromMonth(smonth){
			if(typeof(document.frmCalendar) == "undefined") monthOffset = 0;
			rtnValue = smonth - monthOffset; 
			if (rtnValue < 0) rtnValue = rtnValue + 12;
			return rtnValue;	
		}

		
		function popWindow(theURL,winName,features) {
		  var newWin
		  newWin = window.open(theURL,winName,features);
		  newWin.focus();
		}
		function IsIE() {
			return (navigator.appName == "Microsoft Internet Explorer")
		}

