var Tickets = {};

Tickets.lastOpen = null;

Tickets.open_content = null;

Tickets.onCityClick = function(obj){
	var content = null;
	if(Tickets.open_content != null && obj.id != Tickets.open_content.id){
		content = document.getElementById(Tickets.open_content.id + "content");
		if(content && typeof(content.tagName) != "undefined"){
			content.style.display = "none";
		}
	}
	Tickets.open_content = obj;
	content = document.getElementById(obj.id + "content");
	if(content.style.display == "none"){
		content.style.display = "";
	}else{
		content.style.display = "none";
	}
//	var container = obj.nextSibling;
//	container.style.display = "";
//	
//	if(container.innerHTML == ""){
//		//container.innerHTML = loadingText;
//		var ajax = new AjaxRequest();
//		ajax.FilePath = "frontend/temp.tickets.php";
//		ajax.ClassName = "TicketsTemplate";
//		ajax.MethodName = "Render";
//		ajax.CallBack = "Tickets.CallBack";
//		ajax.Attributes = obj.nextSibling;
//		ajax.CustomURL = url;
//		ajax.Send();
//	}else{
//		if(Tickets.lastOpen != null){
//			Tickets.lastOpen.style.display = "none";
//		}
//		Tickets.lastOpen = container;
//	}
}

Tickets.CallBack = function(xmlHttp, Attributes){
	Attributes.innerHTML = xmlHttp.responseText;
	if(Tickets.lastOpen != null && Tickets.lastOpen.tagName){
		Tickets.lastOpen.style.display = "none";
	}
	Tickets.lastOpen = Attributes;
}

Tickets.change_start_sity = function(obj){
	var cityObj = document.getElementById("start_destination");
//	for(var z = 0; z < cityObj.childNodes.length; z++){
//		if(cityObj.childNodes[z].getAttribute("name") != obj.value && obj.value != ""){
//			cityObj.childNodes[z].style.display = "none";
//		}else{
//			cityObj.childNodes[z].style.display = "";
//		}
//	}
	
	var ajax = new AjaxRequest();
	ajax.FilePath = "frontend/temp.tickets.php";
	ajax.ClassName = "TicketsTemplate";
	ajax.MethodName = "ChangeContent";
	ajax.CallBack = "Tickets.ChangeCountryBack";
	ajax.RegisterArgument("start_sity_id", obj.value);
	ajax.Attributes = "";
	ajax.Send();
}

Tickets.ChangeCountry = function(obj){
	var cityObj = document.getElementById("chooseCity");
	for(var z = 0; z < cityObj.childNodes.length; z++){
		if(cityObj.childNodes[z].getAttribute("name") != obj.value && obj.value != ""){
			cityObj.childNodes[z].style.display = "none";
		}else{
			cityObj.childNodes[z].style.display = "";
		}
	}
	
	var ajax = new AjaxRequest();
	ajax.FilePath = "frontend/temp.tickets.php";
	ajax.ClassName = "TicketsTemplate";
	ajax.MethodName = "ChangeContent";
	ajax.CallBack = "Tickets.ChangeCountryBack";
	ajax.RegisterArgument("CountryID", obj.value);
	ajax.Attributes = "";
	ajax.Send();
}

Tickets.ChangeCity = function(obj){
	var ajax = new AjaxRequest();
	ajax.FilePath = "frontend/temp.tickets.php";
	ajax.ClassName = "TicketsTemplate";
	ajax.MethodName = "ChangeContent";
	ajax.CallBack = "Tickets.ChangeCountryBack";
	ajax.RegisterArgument("CityID", obj.value);
	ajax.Attributes = "";
	ajax.Send();
}

Tickets.ChangeCountryBack = function(req, attr){
	//return false;
	var content = document.getElementById("flashcontent");
	if(!content){
		var content = document.getElementById("Countries");
	}
	var parent = content.parentNode;
	parent.removeChild(content);
	parent.innerHTML = parent.innerHTML + req.responseText;
}

Tickets.showInfo = function(containerID){
	document.getElementById("payOption1").style.display = "none";
	document.getElementById("payOption2").style.display = "none";
	document.getElementById("payOption3").style.display = "none";
	document.getElementById(containerID).style.display = "";
}

Tickets.changeDirection = function(obj, unique){
	obj1 = document.getElementById(unique + "direction1");
	obj2 = document.getElementById(unique + "direction2");
	obj1t = document.getElementById(unique + "direction1table");
	obj2t = document.getElementById(unique + "direction2table");
	obj1.style.backgroundColor = "#cccccc";
	obj1.style.borderBottom = "solid 1px #000000";
	obj2.style.backgroundColor = "#cccccc";
	obj2.style.borderBottom = "solid 1px #000000";
	obj1t.style.display = "none";
	obj2t.style.display = "none";
	
	obj.style.backgroundColor = "#FFE550";
	obj.style.borderBottom = "solid 1px #FFE550";
	document.getElementById(obj.id + "table").style.display = "";
}

Tickets.discount = function(obj, textID){
	var coordinates = DocumentDOM.GetCoordinates(obj);
	layer = document.createElement("DIV");
	layer.style.position = "absolute";
	layer.style.top = coordinates[1] + "px";
	layer.style.left = (coordinates[0] - 200) + "px";
	layer.style.backgroundColor = "#FFE550";
	layer.style.border = "solid 1px #000000";
	layer.style.padding = "4px";
	layer.style.zIndex = "100";
	layer.style.width = "200px";
	//Event.RegisterEventHandler(layer, "onclick", Tickets.discountHideLayer);
	var body = document.getElementsByTagName("BODY")[0];
	
	var ajax = new AjaxRequest();
	ajax.Async = false;
	ajax.FilePath = "frontend/temp.tickets.php";
	ajax.ClassName = "TicketsTemplate";
	ajax.MethodName = "getInfoText";
	ajax.CallBack = "";
	ajax.RegisterArgument("ID", textID);
	ajax.Attributes = "";
	var httprequest = ajax.Send();
	layer.innerHTML = '<div style="text-align: right;"><img onclick="Tickets.discountHideLayer(this);" style="cursor: pointer;" src="images/ticket_layer_close.gif" alt=""></div>' + httprequest.responseText;
	body.appendChild(layer);
}

Tickets.discountHideLayer = function(obj){
//	obj = this;
//	
//	if(typeof(this.tagName) == "undefined"){
//		obj = e.srcElement;
//	}
	
	var body = document.getElementsByTagName("BODY")[0];
	body.removeChild(obj.parentNode.parentNode);
}