// JavaScript Document
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  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_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function addToFavorites() { 
	var url= "http://www.aagetawaycoaches.com/"; 
	var title = "Buses, Limousines - aagetawaycoaches.com"; 
	if (window.sidebar) { // firefox
    	window.sidebar.addPanel(title, url, ""); return;
	} 
	if(window.opera && window.print){ // opera
    		var elem = document.createElement('a');
			elem.setAttribute('href',url);
			elem.setAttribute('title',title);
			elem.setAttribute('rel','sidebar');
			elem.click();
			return;
	}
	if(document.all){ window.external.AddFavorite(url, title); return;}
	
}
function getAnchorPosition(anchorname) {
	// This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	// Browser capability sniffing
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
 	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
		}
 	else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
			}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// getAnchorWindowPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the window
function getAnchorWindowPosition(anchorname) {
	var coordinates=getAnchorPosition(anchorname);
	var x=0;
	var y=0;
	if (document.getElementById) {
		if (isNaN(window.screenX)) {
			x=coordinates.x-document.body.scrollLeft+window.screenLeft;
			y=coordinates.y-document.body.scrollTop+window.screenTop;
			}
		else {
			x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
			y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
			}
		}
	else if (document.all) {
		x=coordinates.x-document.body.scrollLeft+window.screenLeft;
		y=coordinates.y-document.body.scrollTop+window.screenTop;
		}
	else if (document.layers) {
		x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
		y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
	}
function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
	}
function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
	}
function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
	}
function MM_effectAppearFade(targetElement, duration, from, to, toggle){
	Spry.Effect.DoFade(targetElement, {duration: duration, from: from, to: to, toggle: toggle});
}
function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}
	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}
	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}
function openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
function getViewPort(){
	 var viewportwidth;
 var viewportheight;
 
 // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight
 
 if (typeof window.innerWidth != 'undefined')
 {
      viewportwidth = window.innerWidth,
      viewportheight = window.innerHeight
 }
 
// IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

 else if (typeof document.documentElement != 'undefined'
     && typeof document.documentElement.clientWidth !=
     'undefined' && document.documentElement.clientWidth != 0)
 {
       viewportwidth = document.documentElement.clientWidth,
       viewportheight = document.documentElement.clientHeight
 }
 
 // older versions of IE
 
 else
 {
       viewportwidth = document.getElementsByTagName('body')[0].clientWidth,
       viewportheight = document.getElementsByTagName('body')[0].clientHeight
 }
 	pageSize = new Array(viewportwidth,viewportheight) 
	return pageSize;
}
function show_hide_Overlay( action, showBg ){
	var arrayPageSize = getPageSize();
	var h = arrayPageSize[1];
	var w = arrayPageSize[0];

	document.getElementById('overlayDiv').style.height = h + 'px';
	//document.getElementById('overlayDiv').style.width = w + 'px';
	document.getElementById('overlayDiv').innerHTML = '';selects = document.getElementsByTagName("select");
	if( action == '1' ) {
		var cl = 'overlay';
		if( showBg == '0' ) { 
			cl = 'overlayNoBg';
		}
		if (navigator.appVersion.indexOf("MSIE")!=-1){
	        for (i = 0; i != selects.length; i++) {
                selects[i].style.visibility = "hidden";
    	    }
		}
		document.getElementById('overlayDiv').className=cl;
		document.getElementById('overlayDiv').style.display = 'block';
	} else {
		if (navigator.appVersion.indexOf("MSIE")!=-1){
	        for (i = 0; i != selects.length; i++) {
                selects[i].style.visibility = "visible";
    	    }
		}
		document.getElementById('overlayDiv').style.display = 'none';
	}
}
function resizeOverlay(){
	if( document.getElementById('overlayDiv').style.display!='none' ){
		var h = getPageSize();
		document.getElementById('overlayDiv').style.height = h[1] + 'px';
		document.getElementById('overlayDiv').style.width = h[0] + 'px';
	}
}
function showAlert( titleStr, bodyStr, showOverlay  ){
	show_hide_Overlay( 1, showOverlay );
	var x = '<div id="shadow"><div id="alertDiv" class="alertDialog"><div id="dialogTitle">' + titleStr +'</div><div id="dialogBody">' + bodyStr + '</div><div id="alertFooter"><a href="javascript:;" onclick="show_hide_Overlay(0)">Close</a></div></div></div>';
	arrayPageScroll = getPageScroll();
	arrayPageSize = getPageSize();
	 var vtop = arrayPageScroll[1] + 100;
	var vleft = ((arrayPageSize[0] - 10 - 350 ) / 2);

	
	document.getElementById('overlayDiv').innerHTML = x;
	document.getElementById('alertDiv').style.left = vleft + 'px';
	document.getElementById('alertDiv').style.top = vtop + 'px';
	return;
}
function setCookie(c_name,value,expiredays){
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function getCookie(c_name){
if (document.cookie.length>0){
  var c_start=document.cookie.indexOf(c_name + "=");
  	if (c_start!=-1){
    	c_start=c_start + c_name.length+1;
    	var c_end=document.cookie.indexOf(";",c_start);
    	if (c_end==-1) c_end=document.cookie.length;
    		return unescape(document.cookie.substring(c_start,c_end));
    	}
  	}
	return "";
}
var count = 0;
function isInArray( arr, val ){
	var col = arr.split(",");
	var ret = false;
	for(i = 0; i < col.length; i++){
		if( parseInt( col[i] ) == parseInt( val ) ) { ret = true; break; }
		count = count + 1;
	}
	return ret;
}
function addVehicleToCompare( id ){
	var c = getCookie( 'cVehicles');
	var s = c.split(',');

	if( s == 5 ) { return; }
	if ( c != '' ){
		if( isInArray( c, parseInt(id) ) ) { return; }
		c = c + ',' + id;
	} else { 
		c = id; 
	}
	setCookie( 'cVehicles', c, 365 );
	loadComparison();
}
function hideImageGallery(){
	//document.getElementById('vImg').style.display='none';
	show_hide_Overlay( 0, 0 );
		
}
function deleteVehicleFromCompare( id ){
	var c = getCookie( 'cVehicles');
	var col = c.split(",");
	var v = '';

	for(i = 0; i < col.length; i++){
		if( col[i] == id ){ continue; }
		if(i == 1 ){ v = col[i]; } else { v = v + ',' + col[i]; }
	}
	setCookie( 'cVehicles', v, 365 );
	loadComparison();
}
function deleteCookie( name ){
   document.cookie = name + '=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
}
function clearComparison( ) {
	deleteCookie( 'cVehicles' );
	loadComparison();
}
function loadComparison_cb( x ){
	document.getElementById('compareDetail').innerHTML = x;
}
function loadComparison( ){
	document.getElementById('compareDetail').innerHTML = '<div align="center">Loading Comparisons</div>';
	x_compareVehicles( loadComparison_cb, 'lib/compareVehicles.php');
}
function showImageGallery_cb( x ){
	document.getElementById('overlayDiv').innerHTML =  '<div align="center" id="vImg">' + x + '</div>';
	var arrayPageScroll = '';
	var arrayPageSize = '';
	var vtop = '';
	var vleft = '';
	var f = '';
	arrayPageScroll = getPageScroll();
	arrayPageSize = getPageSize();
	 vtop = arrayPageScroll[1] + 15;
	vleft = ((arrayPageSize[0] - 10 - 400 ) / 2);

	//document.getElementById('vImg').style.left = vleft + 'px';
	document.getElementById('vImg').style.top = vtop + 'px';
}
function clearTextField( el ) {
	document.getElementById( el ).value = '';	
	
}
function showImageGallery( vehicleID, imageID ){
	show_hide_Overlay( 1, 1 );
	
	arrayPageScroll = getPageScroll();
	 arrayPageSize = getPageSize();
	var vtop = ( arrayPageSize[3] /2) + arrayPageScroll[1] - 125 ;
	var	vleft = ((arrayPageSize[0] - 450 ) / 2);
	var str = '?vehicleID=' + vehicleID;
	if( imageID!=''){ str = '?imageID=' + imageID; }
	//document.getElementById('vImg').style.left = vleft + 'px';

	document.getElementById('overlayDiv').innerHTML =  '<div align="center" id="vImg"><img src="images/loading_bar.gif"><br/>Loading Images</div>';
	document.getElementById('vImg').style.display='inline';	document.getElementById('vImg').style.top = vtop + 'px';
	x_showImageGallery( showImageGallery_cb, 'lib/imageGallery.php' + str );
}
function getPageScroll(){
	var yScroll;
	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}
	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}
function goToVehicleGallery( vType ){
	document.location = 'vehicle_gallery.php?vtype=' + vType;	
}
function moveRs( x ){
	x_showImageGallery( showImageGallery_cb, 'lib/imageGallery.php' + x );
}
function loadPoll(){
		document.getElementById('vehiclePoll').innerHTML = "<div align='center'><img src='images/loading.gif'/><br/>Loading Poll</div>";
		x_loadPoll( loadPoll_cb, 'lib/ajaxPoll.php');	
	
}
function loadPoll_cb( x ){
	document.getElementById('vehiclePoll').innerHTML = x;	
}
function viewPollResults(){
	//show_hide_Overlay( 1, 0 );	
	//document.getElementById('pollDiv').
	document.getElementById('vehiclePoll').innerHTML = "<div align='center'><img src='images/loading.gif'/><br/>Loading Poll</div>";
	x_loadPoll( loadPoll_cb, 'lib/ajaxPoll.php?viewOnly=1');	
	
}
function viewPoll_cb( x ){
	document.getElementById('pollDiv').innerHTML = x;	
}
function submitVote(){
		var foundIt = '';
		for (var i=0; i<document.pollForm.itemID.length; i++)  {
			if (document.pollForm.itemID[i].checked)  {
			foundIt = document.pollForm.itemID[i].value;
			}
		}
	
		if( foundIt == '' ){
			document.getElementById('errorDiv').innerHTML = "Select A Poll Item";
			return false;
		}
		document.getElementById('vehiclePoll').innerHTML = "<div align='center'><img src='images/loading.gif'/><br/>Loading Poll</div>";
		x_loadPoll( loadPoll_cb, 'lib/ajaxPoll.php?vote=1&itemID=' + foundIt );
}
function showVehicleGallery_cb( x ){
	document.getElementById('vehicleGallery').innerHTML = x;
}
function loadVehicleGallery( type ){
	document.getElementById('vehicleGallery').innerHTML = "<div align='center' ><img src='images/loading.gif'><br/>Loading Images .... Please Wait</div>";
	x_showVehicleGallery( showVehicleGallery_cb, 'lib/vehicleGallery.php?vtype=' + type );
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
function clearText(el){
	document.getElementById( el ).value = '';	
	
}
function setSearchText(){
	if( document.getElementById('searchText').value == '' ){
		document.getElementById('searchText').value = "Search The Web";
		return;
	}
	
}
function showDialog(){
	document.getElementById('dcontainer').style.visibility = 'visible';
}
function hideDialog(){
	document.getElementById('dcontainer').style.visibility = 'hidden';
}
function searchGoogle(){
	document.gSearch.submit();
}
function showErrorBox( w, str ){
	var z = getAnchorPosition( w );
	var x,y;
	var ebox = document.getElementById('errorBox');
	var ebody = document.getElementById('eboxText');
	x = z.x;
	y = z.y + 15;
	ebox.style.top = y + 'px';
	ebox.style.left = x + 'px';
	ebody.innerHTML = str;
	ebox.style.visibility = 'visible';
}
function hideErrorBox(){
	var ebox = document.getElementById('errorBox');
	if( ebox.style.visibility == 'visible' ){
		ebox.style.visibility = 'hidden';
	}
}
function showLoginDialog(){
	var el = document.getElementById('loginDialog');
	arrayPageScroll = getPageScroll();
	var vtop = arrayPageScroll[1] + 15;
	document.getElementById('ldialog').style.top = vtop + 'px';
	el.style.visibility = 'visible';
	loadLogin();
}
function loadLogin(){
	x_loadLogin( loadLogin_cb, 'lib/clientLogin.php');
}
function loadLogin_cb( x ){
	document.getElementById('loginContent').innerHTML = x;
}
function hideLoginDialog(){
	document.getElementById('progressIcon').style.visibility = 'hidden';
	document.getElementById('loginDialog').style.visibility = 'hidden';
}
function doLogin(){
	document.getElementById('status').innerHTML = "";
	var b = document.getElementById('loginButton');
	var pr = document.getElementById('progressIcon');
	var cl = document.getElementById('closeLink');
	var userID = document.getElementById('username');
	var password = document.getElementById('password');
	
	if( password.value == '' && userID.value == '' ){
		document.getElementById('status').innerHTML = "Enter a username and password";
		return false;
	}
	b.disabled = true;
	cl.disabled = true;
	pr.style.visibility = 'visible';
	x_doLogin( checkPassword, 'lib/loginClient.php?userID=' + userID.value + '&password=' + password.value );
}
function checkPassword( x ){
	var err = '';
	if( x == 0 ){
		document.getElementById('status').innerHTML = "Login Error";
		return false;
	} else {
		document.location="webApp/clientCenter.php";
	}	
}