var Request = new Object();

Request.send = function(url, method, callback, data, urlencoded) {
	var req;	
	if (window.XMLHttpRequest) {
		req = new XMLHttpRequest();
	} else if (window.ActiveXObject) {
		req = new ActiveXObject("Microsoft.XMLHTTP");
	}	
	req.onreadystatechange = function() {
		if (req.readyState == 4) {
			if (req.status < 400) {				
				(method=="POST") ? callback(req) : callback(req,data);
			} else {
				alert("There was a problem loading data :\n" + req.status+ "/" + req.statusText);
			}
		}
	}
	
	if (method=="POST") {
		req.open("POST", url, true);
		if (urlencoded) req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');		
		req.send(data);
	} else {	
		req.open("GET", url, true);
		req.send(null);
	}
	
	return req;
}

Request.sendRawPOST = function(url, data, callback) {
	Request.send(url, "POST", callback, data, false);
}
Request.sendPOST = function(url, data, callback) {
	Request.send(url, "POST", callback, data, true);
}
Request.sendGET = function(url, callback, args) {
	return Request.send(url, "GET", callback, args);
}
function get_user_index(){
	var pars = "do=special_get_inc_top&cache="+Math.random();
	Request.sendPOST("/main.php", pars, get_user_index_result);
}
function get_user_index_result(ajax){
	var result = ajax.responseText;
	if(result != ""){
		document.getElementById("hnav").innerHTML = result;
	}else{
		document.getElementById("hnav").innerHTML = '<span class="rf" style="margin-top: 4px;"><a href="/u/login">登录会员中心</a>. 第一次访问途牛? <a href="/u/register">从这里开始</a></span><a href="http://www.tuniu.com/" target="_blank"><img src="/icons/logo.gif" alt="途牛旅游网:要旅游,找途牛!" border="0" id="logo" /></a><img src="/icons/800400.gif" alt="旅游预定电话" />';
	}
}
function   myAddPanel(title,url,desc){  
	if((typeof window.sidebar == 'object')&&(typeof window.sidebar.addPanel == 'function'))//Gecko  
	{  
		window.sidebar.addPanel(title,url,desc);  
	}  
	else//IE  
	{  
		window.external.AddFavorite(url,title);  
	}  
}
function changeDeparture(){
	var departure_code = document.getElementById("departure_code").value;
	window.location.href = '../'+departure_code;
}
