function GetCookieVal(offset)
//获得Cookie解码后的值
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function SetCookie(name, value)
//设定Cookie值
{
var expdate = new Date();
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ))
document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
+((secure == true) ? "; secure" : "");
}
function DelCookie(name)
//删除Cookie
{
var exp = new Date();
exp.setTime (exp.getTime() - 1);
var cval = GetCookie (name);
document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
}
function GetCookie(name)
//获得Cookie的原始值
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return GetCookieVal (j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
function clic(id,n,lc,ws) {
	wc=GetCookie('wc')
	if(wc!=id) {
		if(confirm('把该城市作为您的默认城市吗？\n设为默认城市后,该城市天气即在首页显示\n\n点确定定制该城市天气,点取消浏览该城市天气')) { 
var argc = clic.arguments.length;
if(argc>2) {
DelCookie('lc')
SetCookie('lc',lc,5184000,'/',top_domain())
DelCookie('wc_sf')
SetCookie('wc_sf',ws,5184000,'/',top_domain())
}
addc(id,n)
} else { return false}
	return true
	} else { whis(id)}

}
function addc(id,n,lc,ws) {
	whis(id)
var argc = addc.arguments.length;
var main = domain()
if(argc>2) {
	DelCookie('lc')
	SetCookie('lc',lc,5184000,'/',top_domain())
	DelCookie('wc_sf')
	SetCookie('wc_sf',ws,5184000,'/',top_domain())
}
	DelCookie('wc')
	SetCookie('wc',id,5184000,'/',top_domain())
	DelCookie('wc_n')
	SetCookie('wc_n',escape(n),5184000,'/',top_domain())
	var _dh=document.createElement('script')
	_dh.setAttribute('id','sifr')
	_dh.setAttribute('src','http://fav.'+main+'.com/myset.php?cmd=savewc&'+Math.random())
	document.getElementsByTagName('head')[0].appendChild(_dh)
	alert("您选择的城市已经定制成功!\n下次访问,该城市天气即在首页显示.")
}
function top_domain()
{
	var domain
	var tmp=location.host.split('.')
	var i = tmp.length;
	return tmp[(i-2)]+"."+tmp[(i-1)];
}
function domain() {
	var tmp=location.host.split('.')
	var len=tmp.length
	return tmp[len-2]
}
function show_city() {
	wsc=GetCookie('wc')
	wc_name=GetCookie('wc_n')
	if(wc_name) {
		document.write('<td><img src="img/right.gif" alt="">当前默认城市:<a href="dq.asp?id='+wsc+'.htm">'+unescape(wc_name)+'</a> <a href="index.asp" onclick="DelCookie(\'wc\')">更改</a></td>')
	}
}
function whis(id) {
	cook=GetCookie('wh')
	if(cook) {
		cook = cook.replace('@@', "@");    
		arr=cook.split('@')
		narr=new Array()
		for(i in arr) {
			if(arr[i]!='' && arr[i]!=id) narr[i]=arr[i]
		}
		if(narr.length>10) narr.length=10
		if(narr.length<1) str=id
		else str=id+'@'+narr.join('@')
		SetCookie('wh',str,5184000,'/')
	}
	else SetCookie('wh',id,5184000,'/')
}
function show_his(id) {
	htbl=document.getElementById("histbl")
	hcook=GetCookie('wh')
	if(hcook) {
		var arys=hcook.split('@')
		if(arys.length>1) {
		phis=document.getElementById("his")
		var result = "<table border=0 cellpadding=0 cellspacing=0><tr align=center>"
		for (var i in arys) {
			if(arys[i]!='')
			result += '<td width="140"><iframe height="50" frameborder=0 width="115" scrolling="no" src="../his/'+arys[i]+'.htm"></iframe></td>'
			if( i > 4 ) break;
		}
		result+='</tr></table>'
		phis.innerHTML=result
		htbl.style.display=''
		}
	}
}