// JavaScript Document

var ss;
var searchresultCount = 9 ;
var resultIndex = -1;

// 鼠标键盘事件经过的背景颜色
var xbgColor = '#DFDFDF';

//返回文本输入框的坐标函数，参数element为要返回的对象,参数offset可选为offsetLeft|offsetTop 分别表示为该对象距离左窗口上角的绝对位置
//利用这个函数可以定位我们要显示的提示层位置，使提示层正确的显示在文本输入框下面
function getposition(element,offset)
{
	var c=0;
	while(element)
	{
		c+=element[offset];
		element=element.offsetParent;
	}
	return c;
}


// 打开提示框
function opensearchlist()
{
	$('searchlist').style.display = "block";
}


// 启动搜索提示框
function showsearchlist()
{
	var SearchKeyWord = $('keyword')
	var LastKeyWord = $('lastkeyword');
	var slist = $('searchlist');
	
	if(SearchKeyWord.value=='想去哪儿？请输入旅游线路试试！'){SearchKeyWord.value='';}
	SearchKeyWord.style.color='#666666'; SearchKeyWord.style.fontSize='14'; SearchKeyWord.style.fontWeight='bold';
	
	// 有搜索内容才运行检索
	if(SearchKeyWord.value.length>0)
	{
		slist.style.left=getposition(SearchKeyWord,'offsetLeft') - 6 +"px";
		slist.style.top =(getposition(SearchKeyWord,'offsetTop')+SearchKeyWord.clientHeight +3)+"px";
		
		// 内容变化就重新检索
		if(SearchKeyWord.value!=LastKeyWord.value)
		{
			// AJAX载入数据
			var myAjax = new Ajax.Request(
			'/line/SearchListAJAX.asp?keyword='+ escape(SearchKeyWord.value),
			{
			method: 'get',
			parameters: '',
			onComplete: getResponse
			});
			document.onkeydown = xonkey;
		}
		else
		{
			// 提示框有内容在已隐藏的状态改为显示
			if($('searchlist').innerHTML.length>1)
			{opensearchlist();}
		}
	}
	else
	{
		displaysearchlist();
		$('keyword').value='';
	}
	
	// 设置最后搜索关键词
	LastKeyWord.value = SearchKeyWord.value;
}




// 关闭搜索提示框
function closesearchlist()
{
	window.clearInterval(ss);
	ss = window.setInterval("displaysearchlist()",200);
}


// 真正关闭提示框
function displaysearchlist()
{
	SearchKeyWord = $('keyword');
	window.clearInterval(ss);
	$('searchlist').style.display = "none";
	if(SearchKeyWord.value==''){SearchKeyWord.value='想去哪儿？请输入旅游线路试试！'; SearchKeyWord.style.color='#999999'; SearchKeyWord.style.fontSize='12'; SearchKeyWord.style.fontWeight='normal';}
	
}


// AJAX 返回信息处理
function getResponse(originalRequest)
{
	//put returned XML in the textarea
	var searchresult = originalRequest.responseText;
	var resultHTML;
	var resultarray = searchresult.split('#');
	
	if(searchresult.length>0)
	{
		
		searchresultCount = resultarray.length - 1;
		resultHTML = "<ul>";

		for(i=0; i<resultarray.length; i++)
		{
			resultHTML = resultHTML + '<li id=\"list'+ i +'\" onmousemove=\"ClearBgColor(); this.style.background=\''+ xbgColor +'\'; resultIndex='+ i +'\" onmouseout=\"this.style.background=\'\'\"><a href="\/line/line_'+ resultarray[i].split('|')[0] +'.asp"\><h5 title=\"'+ resultarray[i].split('|')[1] +'\">'+ resultarray[i].split('|')[1] +'</h5><p>'+ resultarray[i].split('|')[2] +'</p></a></li>';
		}

		if(resultarray.length>0){resultHTML = resultHTML + '<ul><div class=\"searchlistfunction\"><span class=\"searchmore\"><a href=\"/line/list.asp?keyword='+ $('keyword').value +'\"><img src=\"/images/Default/more.gif\" />更多'+ $('keyword').value +'线路</span><span class=\"searchclose\"><a href=\"javascript:displaysearchlist();\"><img src=\"/images/Default/close.gif\" />关闭</a></span></div>';}

		$('searchlist').innerHTML = resultHTML;
		opensearchlist();
	}
	else
	{
		$('searchlist').innerHTML = '';
		displaysearchlist()
		searchresultCount = 9;
	}

}




// 键盘事件
function xonkey(e)
{
		var lastresultIndex = resultIndex;
		var key;
		var e=e||event;
		key=e.keyCode||e.which||e.charCode;
		
		
		if(key=='38')
		{ if(lastresultIndex<=0){lastresultIndex=searchresultCount;}else{lastresultIndex--;} }
		
		if(key=='40')
		{ if(lastresultIndex==searchresultCount){lastresultIndex=0;}else{lastresultIndex++;} }
		
		
		if(lastresultIndex!=resultIndex)
		{
			resultIndex = lastresultIndex;
			// 清除所有的背景颜色
			ClearBgColor();
			// 设置当前索引结果背景颜色
			document.getElementById('list'+lastresultIndex).style.background = xbgColor;
		}
}

function ClearBgColor()
{
	for(i=0; i<=searchresultCount; i++)
	{
		document.getElementById('list'+i).style.background = '';
	}
}


var domainheight = 1 ;


// 显示域名更改公告
function showdomain()
{
	$('domain').style.display="block";
	$('domain').style.height='1px' ;
	adddomain(3) ;
}


// 收起域名更改公告
function hidedomain()
{
	adddomain(-5) ;
}


// 倒数
function adddomain(addvalue)
{
	if(domainheight<100&&domainheight>0)
	{
		domainheight+=addvalue ;
		if(domainheight<0){domainheight=0}
		$('domain').style.height = domainheight + 'px';
		setTimeout("adddomain("+ addvalue +")",1) ;
	}
	else
	{
		// 启动定时关闭
		if(domainheight>=100)
		{
			domainheight = 99 ;
			setTimeout("hidedomain()",20000) ;
		}
		else
		{
			$('domain').style.display="none";
		}
	}
}






// 更换验证码图片
function ChangeCodeImage()
{
	document.getElementById("CodeImages").style.display = "block" ;
	document.getElementById("CodeImages").src='/include/code/GetCode.asp?t='+Math.random();
}






/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////// 弹出层的控制 //////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function OpenLayer(objId)
{
	
	// 设置灰色背景
	var bodybgdiv = document.getElementById("bodybg") ;
	bodybgdiv.style.display = "block";
	bodybgdiv.style.position = "absolute" ;
	bodybgdiv.style.background = "#666666" ;
	bodybgdiv.style.zIndex = 10 ;
	bodybgdiv.style.width = "100%" ;
	bodybgdiv.style.height = document.body.offsetHeight + "px" ;
	bodybgdiv.style.top = 0;
	bodybgdiv.style.left = 0;
	bodybgdiv.style.filter = "alpha(opacity=50)";
	bodybgdiv.style.opacity = 0.8;
	// 设置弹出内容层
	var layer = document.getElementById(objId) ;
	layer.style.position = "absolute" ;
	layer.style.zIndex = 11 ;
	layer.style.display = "block" ;
	layer.style.left = ((window.screen.availWidth - parseInt(layer.offsetWidth)) / 2) + "px";
	layer.style.top = ((window.screen.availHeight - parseInt(layer.offsetHeight)) / 2 -100) + "px";
}



function CloseLayer(objId)
{
	var bodybgdiv = document.getElementById("bodybg") ;
	bodybgdiv.style.display = "none";
	// 设置弹出内容层
	var layer = document.getElementById(objId) ;
	layer.style.display = "none" ;
}


function g(groupid)
{ groupLink=groupid; }

function alipaylink()
{
	document.location.href = '/line/alipay_'+ groupLink +'.asp'
}

function linebuylink()
{
	document.location.href = '/line/linebuy_'+ groupLink +'.asp'
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////// 弹出层的控制结束 //////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////







