	/*
	This is the JavaScript file for the AJAX Suggest Tutorial

	You may use this code in your own projects as long as this 
	copyright is left	in place.  All code is provided AS-IS.
	This code is distributed in the hope that it will be useful,
 	but WITHOUT ANY WARRANTY; without even the implied warranty of
 	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
	
	For the rest of the code visit http://www.DynamicAJAX.com
	
	Copyright 2006 Ryan Smith / 345 Technical / 345 Group.	

*/
//colorbox
//This hides the inline content if JavaScript is supported.
			document.write("<style type='text/css'>.hidden{display:none;}<\/style>");
			
	$(document).ready(function() {


		$("#origin").autocomplete("proxy.asp", {
			width: 260,
			selectFirst: false,
			maxItemsToShow: 100
		});
		
		
		
		$("#origin").result(function(event, data, formatted) {
			if (data)
			{
				
				$("#origin_id").val(data[1]);
				var splitArray = data[0].split(",");
				//alert("name = " + splitArray[0]);
				$("#origin").val(splitArray[0]);
			}
		});


});


function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}

var txtField = '';
var idField = '';
var divSuggest = '';

var language = 'pl';

	
	
	function runSearch() {
		closeInfoWindow();
		var form = document.route;
		form.submit();	
	}

	
	
	
	
	function clearDefaultValue(textElement, idElement, defaultTextValue, checkIdBool) {
		//alert("clear");
		var currentVal = document.getElementById(textElement).value;
		if (true == checkIdBool) { 
			var currentIdVal = document.getElementById(idElement).value;
		}
		if (currentVal == defaultTextValue) {
			document.getElementById(textElement).value = "";
			document.getElementById(idElement).value = "";
		}
		else if (true == checkIdBool && /^\d+$/.test(currentIdVal)) {
			document.getElementById(textElement).value = "";
			document.getElementById(idElement).value = "";
		}
		else if (false == checkIdBool) {
			document.getElementById(textElement).value = "";
			document.getElementById(idElement).value = "";
		}
	}
	
	function validate()
	{
		if(document.getElementById("origin_id").value == '')
		{
			alert("Ustal poczatek podrózy");
			//document.getElementById("origin_id").focus();
			return false;
		}
		else if(document.getElementById("dep_date").value == '' || document.getElementById("dep_date").value== 'dd/mm/rrrr')
		{
			alert("Wprowadz date w formacie dd/mm/rrrr");
			document.getElementById("dep_date").focus();
			document.getElementById("dep_date").value = 'dd/mm/rrrr';
			return false;
		}
		/*else if(validateDate("dep_date")==false)
		{
			alert("Wprowadz date w formacie dd/mm/rrrr");
			document.getElementById("dep_date").focus();
			document.getElementById("dep_date").value = 'dd/mm/rrrr';
			return false;
		}*/
		//alert("validateDate =  " +validateDate("dep_date"));
		return true;
		
	}
	
	function searchRoute()
	{
		if(validate())
		{
			var depDate = document.getElementById("dep_date").value;
			var day = depDate.substring(0, 2);
			var month = depDate.substring(3, 5);
			var year = depDate.substring(6, 10);
			
			//alert("dep " + dep_date);
			var hours = document.getElementById("hours").value;
			var minutes = document.getElementById("minutes").value;
			var origin_id = document.getElementById("origin_id").value;
			var destination_id = document.getElementById("destination_id").value;
			var origin = document.getElementById("origin").value;
			var destination = document.getElementById("destination").value;
			var url = "http://poznan.i-euro.eu/mpk/map.jsp?dep_date=" + depDate + "&day=" + day + "&month=" + month + "&year=" + year +  "&hours=" + hours + "&minutes=" + minutes + "&origin_id=" + origin_id + "&destination_id=" + destination_id + "&origin=" + origin + "&destination=" + destination + "&route_type=1&route_type=2&route_type=5";
			//window.open(,"width=400,height=200,toolbar=yes, location=yes,directories=yes,status=yes menubar=yes,scrollbars=yes,copyhistory=yes,resizable=yes");
			// $("<a></a>").colorbox({open: true, href: url, iframe:true, fixedHeight:570, fixedWidth:800}); 
			//$('boxen_map').boxen('http://www.google.com/');
			$.Boxen.open(url, {
             		width: 800,
					height: 570,
					url: url

                });

		}		
	}

