// Bus Application JavaScript Document


<!--	
	var action;
			
		//Use to set iPhone to fullscreen mode
	function init_iPhoneScrn() {
		window.scrollTo(0, 1);
	}
	
		//Utility Function: Use to add EventListers
	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; 
		 } 
	}
	
		//Utility Function: Check if string is Numeric
	function IsNumeric(sText){
	   var ValidChars = "0123456789.";
	   var IsNumber=true;
	   var Char;
	
	 
	   for (i = 0; i < sText.length && IsNumber == true; i++) 
		  { 
		  Char = sText.charAt(i); 
		  if (ValidChars.indexOf(Char) == -1) 
			 {
			 return false;
			 }
		  }
	   return true;
	   
	}

	function showmore(e, ab) {
		var obj = eval("'"+ e +"'");
		var evtObj = eval("'#"+ ab +"'"); 
		//alert(obj);
		
		//$(obj).toggleSlide("fast");
		var objDisplay = $(obj).css("display");
		if(objDisplay == "none") {
			$(obj).fadeTo("fast", 100); 
		} else if (objDisplay == "block"){
			$(obj).fadeTo("fast", 0); 
		}
		
		$(obj).slideToggle(300, function (){
			if(objDisplay == "none") {
				$(evtObj).html("Less buses");
				$(evtObj).removeClass();
				$(evtObj).addClass("button-more-down");
				
			} else if (objDisplay == "block"){
				$(evtObj).html("More buses");
				$(evtObj).removeClass();
				$(evtObj).addClass("button-more");
				
			}				  
		});
		
	}

	function keyup(e, value){

		var speed = 500;
		switch(e) {
			
			case "routelookup":
				clearTimeout(action);
				action = setTimeout("routelookup('"+ value +"')", speed);
				//alert(e);
			break;
			
			case "keywordsearch":
				clearTimeout(action);
				action = setTimeout("lookup('"+ value +"')", speed);
				//alert(e);
			
			break;
			
		}
		
	}

		//Use to empty form field
	function emptyfirstfocus(e) {
		var obj = document.getElementById(e);
		obj.value = "";
		obj.style.color = "#000000";
		obj.setAttribute("onfocus", "this.select();");
	}
	
		//Use to close boxes left open
	function closeboxes(e){
			$('#suggestions').slideUp();
			$('#routeBox').slideUp();
	}
	
	
	function goToStop(thisValue, route){
		
		var qrystr = "viewstop.php?busstop="+ thisValue;
		if(route != null && route != undefined){
			qrystr +="&route="+ route;
			}
		window.location = qrystr;
	}
			
		//Function to fill results into search field
	function fill(thisValue, thisName) {
		$('#inputString').val(thisName);			//Place string (thisName) into the streetname field
		$('#inputString').css("color","#000000");	//Change the style color of streetname field
		$('#busstop').val(thisValue);				//add value (thisValue) to busstop form field
		$('#routenum').val("");						//clear route number field
		$('#suggestions').slideUp();					//hide the streetname suggestion box
		$('#routeBox').slideUp();						//hide the route list box
		
		//setTimeout("$('#suggestions').hide();", 200);
		 $('#getstop').fadeIn(500, function () {
        	$("#busstopsubmit").fadeIn(700);
      	});

		//$('#getstop').show();						//show Get bus times div
		$('#busstopsubmit').focus();				//set focus to submit button
	}
	
	
	
		//lookup function to call AJAX search
	function lookup(inputString) {
		closeboxes();


		if(inputString.length == 0) {
			// Hide the suggestion box.
			$('#suggestions').slideUp();
			
		} else {
		$('#loadingsearch').show();
			$.post("busapp.php", {mode: "search", q:""+inputString+""}, function(data){
				if(data.length >=0) {
					$('#autoSuggestionsList').html(data);
						$('#suggestions').slideDown("slow");
					$('#loadingsearch').hide();
				}
			});
		}
	} // lookup
	

	
		//function to call AJAX route lookup
	function routelookup(inputString) {
		closeboxes();
		if(inputString.length == 0 ) {
			// Hide the suggestion box.
			$('#routeBox').slideUp();
		} else {
			
			$('#loadingroute').show();
			document.getElementById("err_route").innerHTML = "";
			if(IsNumeric(inputString)) {
			
				var path = 'metrokc/route.jsp?route='+ inputString;
				$.get("busapp.php", {mode: "getroute", ws_path: ""+path+""}, function(data) { 
					if(data.length >0) {
						$('#lookupname').html("Major stops for Route #"+ inputString);
						$('#autoRouteList').html(data);
							$('#routeBox').slideDown("slow");
						$('#loadingroute').hide();
					}
				});
			} else {
				$('#loadingroute').hide();
				document.getElementById("err_route").innerHTML = "Numbers only";
				document.getElementById("routenum").setAttribute("onfocus", "emptyfirstfocus(this.id);");
			}
		}
	} // lookup
	
	
	function hideloadicon() {
		$('#loadingroute').hide();
		$('#loadingsearch').hide();
	}
	
	
	function disableEnterKey(e){
     var key;     
     if(window.event)
          key = window.event.keyCode; //IE
     else
          key = e.which; //firefox     

     return (key != 13);
	}

	
	function loadingBackground(status){
		switch(status){
			case "on":
				$('#overlayBackground').css({'display' : 'block', 'width' : $(document).width(),'height' : $(document).height()});
				$('#overlayBackground').animate({'opacity':'.8'}, 500);
				
			break;
			
			case "off":
			$('#overlayBackground').fadeOut(500, function(){
			  $('#overlayBackground').css("display","none");
			  });
			break;
		}
	 
	}
	
		//used to display targeted tab container
	function showtab(name){
		//var container = eval("'#"+ name +"'");
		switch(name){
			case "routecontainer":
				$('#routecontainer').show();
				$('#streetcontainer').hide();
				highlightTab("routetab", "route");
				highlightTab("streettab", "");
			break;
			
			case "streetcontainer":
				$('#streetcontainer').show();
				$('#routecontainer').hide();
				highlightTab("routetab", "");
				highlightTab("streettab", "street");
			break;
				
		}	
	}
	
	function highlightTab(trgt, className){
		var tabname = eval("'#"+ trgt +"'");
		$(tabname).removeClass();
		$(tabname).addClass(className);
	}
	

-->