//************************************************************
//  文件：通用函数程序集合
//  作者：唐鸣 (529Z.COM)
//  版权：部分函数转载于互联网，仅用作学习之用。开源授权。
//  创建：2009-11-01
//  修改：
//  记录：
//                                       Powered By 529Z.COM
//************************************************************

function correctPNG() {
	for(var i = 0; i < document.images.length; i++) {
		var img = document.images[i]
		var imgName = img.src.toUpperCase()
		if (imgName.substring(imgName.length-3, imgName.length) == "PNG") {
			var imgID = (img.id) ? "id='" + img.id + "' " : ""
			var imgClass = (img.className) ? "class='" + img.className + "' " : ""
			var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
			var imgStyle = "display:inline-block;" + img.style.cssText 
			if (img.align == "left") imgStyle = "float:left;" + imgStyle
			if (img.align == "right") imgStyle = "float:right;" + imgStyle
			if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle  
			var strNewHTML = "<span " + imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>" 
			img.outerHTML = strNewHTML
			i = i-1
		}
	}
}
window.attachEvent("onload", correctPNG);

window.onload=function() {
	for(var ii=0; ii<document.links.length; ii++)
	document.links[ii].onfocus = function() {
		this.blur()
	}
}

try {
	document.execCommand("BackgroundImageCache", false, true);
}
catch (e) {
}

function AddFavorite(sURL, sTitle) {
	try {
		window.external.addFavorite(sURL, sTitle);
	}
	catch (e) {
		try {
			window.sidebar.addPanel(sTitle, sURL, "");
		}
		catch (e) {
			alert("加入收藏失败，请使用Ctrl+D进行添加。");
		}
	}
}

function SetHome(obj,vrl) {
	try {
		obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
	}
	catch(e) {
		if(window.netscape) {
			try {
				netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");  
			}  
			catch (e) { 
				alert("此操作被浏览器拒绝！请在浏览器地址栏输入“about:config”并回车然后将[signed.applets.codebase_principal_support]设置为“true”。");  
			}
			var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
			prefs.setCharPref('browser.startup.homepage',vrl);
		}
	}
}

function totxt(str){    
	str = str.replace(/\&/g, "&amp;");
	str = str.replace(/\>/g, "&gt;");
	str = str.replace(/\</g, "&lt;");
	str = str.replace(/\"/g, "&quot;");
	str = str.replace(/\'/g, "&#39;");
	str = str.replace(/\n/g, "<br />");
	str = str.replace(/\0x13/g, "<br />");
	return str;    
}

function $(o) {
	return document.getElementById(o);
}

function webstyle(o) {
	var head = document.getElementsByTagName("head").item(0); 
	var style = document.createElement("link"); 
	style.href = o; 
	style.rel = "stylesheet";
	style.type = "text/css"; 
	head.appendChild(style); 
}

function search_button(i) {
	$("button").value = i;
	$("class").value = "0";
	$("search_button_1").className = "button_2";
	$("search_button_2").className = "button_2";
	$("search_button_3").className = "button_2";
	$("top_search_select").style.display = "none";
	$("top_search_selectarticle").style.display = "none";
	$("top_search_selectweb").style.display = "none";
	switch(i) {
		case 1:
			$("search_button_1").className = "button_1";
			$("top_search_select").style.display = "block";
			$("select").innerHTML = "全部";
			break;
		case 2:
			$("search_button_2").className = "button_1";
			$("top_search_selectarticle").style.display = "block";
			$("selectarticle").innerHTML = "综合";
			break;
		case 3:
			$("search_button_3").className = "button_1";
			$("top_search_selectweb").style.display = "block";
			$("selectweb").innerHTML = "百度";
			break;
	}
}

function shop_button(i) {
	$("shop_button_1").className = "button_2";
	$("shop_button_2").className = "button_2";
	$("shop_button_3").className = "button_2";
	$("shop_info_1").style.display = "none";
	$("shop_info_2").style.display = "none";
	$("shop_info_3").style.display = "none";
	switch(i) {
		case 1:
			$("shop_button_1").className = "button_1";
			$("shop_info_1").style.display = "block";
			break;
		case 2:
			$("shop_button_2").className = "button_1";
			$("shop_info_2").style.display = "block";
			break;
		case 3:
			$("shop_button_3").className = "button_1";
			$("shop_info_3").style.display = "block";
			break;
	}
}

function iKeyword(obj, type) {
	var init = "请输入搜索关键字..";
	switch(type) {
		case 1:
			if(obj.value == init) {
				obj.value = "";
			}
			obj.style.cssText = "color: black";
			break;
		case 2:
			if(obj.value == "") {
				obj.value = init;
				obj.style.cssText = "";
			}
			else {
				obj.style.cssText = "color: black";
			}
			break;
	}
}

function checkkeyword(f) {
	var k = f.elements["keyword"];
	if (k.value == "请输入搜索关键字.." || k.value == "") {
		alert("请您输入要搜索的信息，比如“手机”、“楼房”、“二手”等。");
		k.focus();
		return false;
	}
	return true;
}

function drop_mouseover() {
	try {
		window.clearTimeout(timer);
	}
	catch(e) {
	}
}
function drop_mouseout() {
	var o1 = $("district_list").style.display;
	var o2 = $("top_search_select_list").style.display;
	var o3 = $("top_search_selectarticle_list").style.display;
	var o4 = $("top_search_selectweb_list").style.display;
	if(o1 == "block" || o2 == "block" || o3 == "block" || o4 == "block") {
		timer = setTimeout("drop_hide()", 1000);
	}
}
function drop_hide() {
	$("district_list").style.display = "none";
	$("top_search_select_list").style.display = "none";
	$("top_search_selectarticle_list").style.display = "none";
	$("top_search_selectweb_list").style.display = "none";
}
function search_show(id, name) {
	if ($("button").value == 3) {
		$("selectweb").innerHTML = name;
	} else if ($("button").value == 2) {
		$("selectarticle").innerHTML = name;
	} else {
		$("select").innerHTML = name;
	}
	$("class").value = id;
	drop_hide();
}

function mybox(o, i, n) {
	if ($(i).value == "") {
		$(o).className = "mybox2";
		$(i).value = $(n).value;
	} else {
		$(o).className = "mybox";
		$(i).value = "";
	}
}

function radio(o, i, n, m, x) {
	for (var a=0; a<i; a++) {
		$(n+(a+1)).className = "radio";
	}
	$(n+o).className = "radio2";
	$(m).value = x;
}

function select_active(o) {
	if ($(o).style.display=="none") {
		$(o).style.display="block";
	} else {
		$(o).style.display="none";
	}
}
function select_mouseover() {
	try {
		window.clearTimeout(timer);
	}
	catch(e) {
	}
}
function select_mouseout(o) {
	var possel = $(o).style.display;
	if(possel == "block") {
		timer = setTimeout("select_hide('" + o + "')", 100);
	}
}
function select_hide(o) {
	$(o).style.display = "none";
}
function select_show(o, i, name, s) {
	$(o).innerHTML = name;
	$(i).value = name;
	select_hide(s);
}

function imgresize(o, n){
	if (n==2 || o.onmousewheel) {
		if(o.width > 620 ){
			o.style.width='620px';
		}
		if(o.height > 465){
			o.style.height='465px';
		}
	}
	else{
		var parentNode=o.parentNode.parentNode
		if (parentNode){
			if (o.offsetWidth>=parentNode.offsetWidth) o.style.width='100%';
		}
		else{
			var parentNode=o.parentNode
			if (parentNode){
				if (o.offsetWidth>=parentNode.offsetWidth) o.style.width='100%';
			}
		}
	}
}