// $Id: default.js,v 1.1 2010/11/02 07:21:53 lij Exp $

var userAgent = navigator.userAgent.toLowerCase();
var isIE = userAgent.indexOf('msie') > 0;

function h(obj){if(isIE){var url=window.location.toString();var loc = url.toString().substr(0,url.toString().lastIndexOf('/')+1);obj.style.behavior='url(#default#homepage)';obj.setHomePage(loc);}else{window.status='该操作仅支持IE浏览器';}}
function af(){if(isIE){var url=window.location;window.external.addFavorite(url,document.title);}else{window.status='该操作仅支持IE浏览器';}}
function ss(w){window.status='当前搜索:'+w;return true;}
function cs(){window.status='';return true;}
function rs(form){
	if (isNull(form.q.value))
	{
	    alert("请输入搜索关键词！");
		form.q.value = "";
		form.q.focus();
		return false;
	}
	else
	{
		//form.ads.value = "1"; 
		//form.q.value = form.last_q.value + " " + form.q.value;
		form.qq.value = form.q.value;
		form.submit();
	}
}

//left trim
function ltrim( s ){return s.replace( /^\s*/, "" );}

//right trim
function rtrim( s ){return s.replace( /\s*$/, "" );}

//trim left & right
function trim( s ){return rtrim(ltrim(s));}

//is null or not
function isNull( s ){return (trim(s).length<1);}

//check Form
function checkForm(obj)
{
	if (isNull(obj.q.value))
	{
	    alert("请输入搜索关键词！");
		obj.q.value = "";
		obj.q.focus();
		return false;
	}
	else
	{
		var q = trim(obj.q.value);
		obj.q.value = q;
	}
}

//show help
function showHelp()
{
	cs();

	var theURL = "./help.html";

	if(window.screen){
		var aw = screen.availWidth*3/4;
		var ah = screen.availHeight;
		window.moveTo(1,1);
		window.resizeTo(aw,ah);
		
		var w = screen.availWidth*1/4;
		var features="toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width=" + w + ",height=" + ah + ",left=" + aw + ",top=1";
		var p = window.open(theURL,'help',features);
		p.focus();
	}
	else
	{
		window.open(theURL,'help','');
	}
}

//还原搜索窗口大小
function restore()
{
	cs();

	var obj = window.opener;
	if (obj)
	{
		var aw = screen.availWidth;
		var ah = screen.availHeight;
		obj.moveTo(1,1);
		obj.resizeTo(aw,ah);
	}
	if(window)
		window.close();
}
