var debug = false;
function errorHandler() {
	var errorMsg="出错了!\n";
	errorMsg+="信息: " + arguments[0];
	errorMsg+="\nURL: " + arguments[1];
	errorMsg+="\n行号: " + arguments[2];
	alert(errorMsg);
	return true;
}

if (debug) {
	window.onerror = errorHandler;
}

function getObj(obj) {
	return document.getElementById(obj);
}

function o(obj) {
	if (isStartsWith(obj, '+')) {
		return document.getElementsByName(obj.substring(1));
	}
	
	if (isStartsWith(obj, '*')) {
		return document.getElementsByTagName(obj.substring(1));
	}
	
	return document.getElementById(obj);
}

function ov(obj) {
	return document.getElementById(obj).value;
}

function isStartsWith(str, child) {
	return str.indexOf(child) == 0;
}

function addFavorite() {
	if (document.all) {
		window.external.addFavorite("http://www.haowan.cn", "\u597d\u73a9\u6e38\u620f");
	} else {
		if (window.sidebar) {
			window.sidebar.addPanel("好玩网", "http://www.haowan.cn", "");
		}
	}
}
function setHomepage() {
	if (document.all) {
		document.body.style.behavior = "url(#default#homepage)";
		document.body.setHomePage("http://www.haowan.cn");
	} else {
		if (window.sidebar) {
			if (window.netscape) {
				try {
					netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
				}
				catch (e) {
					alert("\u8be5\u64cd\u4f5c\u88ab\u6d4f\u89c8\u5668\u62d2\u7edd\uff0c\u5982\u679c\u60f3\u542f\u7528\u8be5\u529f\u80fd\uff0c\u8bf7\u5728\u5730\u5740\u680f\u5185\u8f93\u5165 about:config,\u7136\u540e\u5c06\u9879 signed.applets.codebase_principal_support \u503c\u8be5\u4e3atrue");
				}
			}
			var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
			prefs.setCharPref("browser.startup.homepage", "http://www.haowan.cn");
		}
	}
}
function getOs() {
	var agt = window.navigator.userAgent.toLowerCase();
	if (agt.indexOf("msie") >= 0) {
		return 0;
	}
	if (agt.indexOf("firefox") >= 0) {
		return 1;
	}
	if (agt.indexOf("opera") >= 0) {
		return 3;
	}
	if (agt.indexOf("camino") >= 0) {
		return 4;
	}
	if (agt.indexOf("gecko/") >= 0) {
		return 5;
	}
	return 0;
}
function s(a) {
	if (o(a)) {
		o(a).style.display = "block";
	}
}
function showHtml(a, v) {
	if (o(a)) {
		o(a).innerHTML = v;
		o(a).style.display = "block";
	}
}

function showError(a, v) {
	var obj = o(a.id + "_error");
	if (obj) {
		obj.innerHTML = v;
		obj.style.display = "block";
	}
}

function cleanError(a, v) {
	var obj = o(a.id + "_error");
	if (obj) {
		obj.style.display = "none";
	}
}

function h(a) {
	if (o(a)) {
		o(a).style.display = "none";
	}
}
function c(a) {
	if (o(a)) {
		o(a).value = "";
	}
}
function sh(a) {
	if (o(a)) {
		o(a).style.display = o(a).style.display == "none" ? "block" : "none";
	}
}
function hs(a) {
	if (o(a)) {
		o(a).style.display = o(a).style.display == "block" ? "none" : "block";
	}
}
function vv(a) {
	if (o(a)) {
		o(a).style.visibility = "visible";
	}
}
function vh(a) {
	if (o(a)) {
		o(a).style.visibility = "hidden";
	}
}
var flag = 0;
function hy() {
}
function xs(a) {
	hy();
	s("hn" + a + "_l");
	o("hn" + a + "_l").focus();
	h("hn_xx" + a);
	o("hn" + a).className = "hn_on";
}
function timeMills() {
	return new Date().getTime();
}

 //注册
function addEH(element, evtName, callback, useCapture) {
	callback.obj = element;
	//DOM标准
	if (element.addEventListener) {
		if (arguments.length == 4) {
			element.addEventListener(evtName, callback, useCapture);
		} else {
			element.addEventListener(evtName, callback, false);
		}
	} else {
//IE方式,忽略useCapture参数
		element.attachEvent("on" + evtName, callback);
	}
}
 
//移除
//注册
function removeEH(element, evtName, callback, useCapture) {
	callback.obj = element;
	//DOM标准
	if (element.removeEventListener) {
		// 判断参数
		if (arguments.length == 4) {
			element.removeEventListener(evtName, callback, useCapture);
		} else {
			element.removeEventListener(evtName, callback, false);
		}
	} else {
	//IE方式,忽略useCapture参数
		element.dettachEvent("on" + evtName, callback);
	}
}
  function stopBubble(event) {
	event = event || window.event;
	if(event.stopPropagation) {
		event.stopPropagation();
	} else { 
		event.cancelBubble = true;
	}
  }
  
  function stopProcess(event) {
	event = event || window.event;
	if(event.preventDefault) {
		event.preventDefault();
	} else {
		event.returnValue = false;
	}
  }
  
  function getEvent() {
 	   return arguments.callee.caller.arguments[0] || window.event;
  }
  
  function getTarget() {
  	var e = arguments.callee.caller.arguments[0] || window.event;
  	return e.target ||  e.srcElement;
  }
  
  function pe(obj) {
  	var str = '';
	for (var m in obj) {
		str += m + "<br/>";
	}
	document.write(str);
  }
  
  function me() {
  	return arguments.callee.caller;
  }
  function p(obj) {
  	document.write(obj);
  }
  
  function pl(obj) {
  	document.write(obj + "<br/>");
  }
  
  function attr(obj, name) {
  	return obj.getAttribute(name);
  }
  
  function ps(objs) {
	var str = '';
	var len = objs.length;
	for (var i = 0; i < len; i++) {
		str += objs[i] + "<br/>";
	}
	document.write(str);
  }

  function invoker() {
	return arguments.callee.caller.arguments.callee.caller;
  }
  
function subPx(src, num) {
	var tmp = (src.substring(0, src.length - 2) - num) + "px";
	return tmp;
}
 
function addPx(src, num) {
	return (src.substring(0, src.length - 2) + num) + "px";
}
 
function pxNum(src) {
	return src.substring(0, src.length - 2);
}

function confirmJump(href, msg) {
	if (confirm(msg)) {
		document.location.href=href;
	}
}

function showDialog(url,width, height) {
	if(document.all) {
		 //IE  
		feature="dialogWidth:" +width+ ";dialogHeight:" +height+ ";status:no;help:no";
		window.showModalDialog(url,null,feature);
		window.location.reload();
	} else {
		//modelessDialog可以将modal换成dialog=yes
		var top = (window.screen.availHeight-30-pxNum(height))/2;       //获得窗口的垂直位置;
		var left = (window.screen.availWidth-10-pxNum(width))/2;           //获得窗口的水平位置;
		//modelessDialog可以将modal换成dialog=yes
		feature ="width=" +width+ ",height=" + height + ",top=" +top+ ",left=" +left+ ",menubar=no,toolbar=no,location=no,";
		feature += "scrollbars=no,status=no,modal=yes";
		window.open(url,null,feature);
	}
	
	/*if(document.all) {
		 //IE  
		feature="dialogWidth:300px;dialogHeight:200px;status:no;help:no";
		window.showModalDialog(url,null,feature);
	} else {
		//modelessDialog可以将modal换成dialog=yes
		feature ="width=300,height=200,menubar=no,toolbar=no,location=no,";
		feature += "scrollbars=no,status=no,modal=yes";
		window.open(url,null,feature);
	}*/
}

function showModallessDialog(url,width, height) {
	if(document.all) {
		 //IE  
		feature="dialogWidth:" +width+ ";dialogHeight:" +height+ ";status:no;help:no";
		window.showModelessDialog(url,null,feature);
	} else {
		var top = (window.screen.availHeight-30-pxNum(height))/2;       //获得窗口的垂直位置;
		var left = (window.screen.availWidth-10-pxNum(width))/2;           //获得窗口的水平位置;
		//modelessDialog可以将modal换成dialog=yes
		feature ="width=" +width+ ",height=" + height + ",top=" +top+ ",left=" +left+ ",menubar=no,toolbar=no,location=no,";
		feature += "scrollbars=no,status=no,dialog=yes";
		window.open(url,null,feature);
	}
}

function hasClass(ele,cls) {
  return ele.className.match(new RegExp('(\\s|^)'+cls+'(\\s|$)'));
}

function addClass(ele,cls) {
  if (!this.hasClass(ele,cls)) ele.className += " "+cls;
}

function removeClass(ele,cls) {
  if (hasClass(ele,cls)) {
          var reg = new RegExp('(\\s|^)'+cls+'(\\s|$)');
    ele.className=ele.className.replace(reg,' ');
  }
}

function trim(str) {
	str = str.replace(/^\s+/, ''); 
	for (var i = str.length - 1; i >= 0; i--) { 
		if (/\S/.test(str.charAt(i))) { 
		str = str.substring(0, i + 1); 
		break ; 
	} 
	}
	return str; 
}

String.prototype.trim = function(){  
	alert(331);
	var str = this ,str = str.replace(/^\s+/, '' ); 
	for ( var i = str.length - 1; i >= 0; i--) { 
	if (/\S/.test(str.charAt(i))) { 
	str = str.substring(0, i + 1); 
	break ; 
	} 
	} 
	return str; 
};

function zoom(obj, width, height){
    var img = new Image();
    img.src = obj.src;
    var scale = Math.max(width / img.width, height / img.height);
    var newWidth = img.width * scale;
    var newHeight = img.height * scale;
    var div = obj.parentNode;

    obj.width = newWidth;
    obj.height = newHeight;
    div.style.width = width + "px";
    div.style.height = height + "px";
    div.style.overflow = "hidden";
    obj.style.marginLeft = (width - newWidth) / 2 + "px";
    obj.style.marginTop = (height - newHeight) / 2 + "px";
}

