function killErrors() { 
return true; 
} 
window.onerror = killErrors; 

var $ = document.all || document.getElementById;

var $A = function(iterable) {
  if (!iterable) return [];
  if (iterable.toArray) {
    return iterable.toArray();
  } else {
    var results = [];
    for (var i = 0; i < iterable.length; i++)
      results.push(iterable[i]);
    return results;
  }
}

String.prototype.EndsWith = function(str){
	var len = str.length;
	var start = this.length - len;
	var end = this.length;
	var subStr = this.substring(start,end);
	return subStr == str;
}


function String.prototype.Trim() {return this.replace(/(^\s*)|(\s*$)/g,"");} 
function String.prototype.Ltrim(){return this.replace(/(^\s*)/g, "");} 
function String.prototype.Rtrim(){return this.replace(/(\s*$)/g, "");}

String.prototype.isUpper = function(){
	if(this.length>1) return false;
	var upper = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];
	for(var s in upper){
		if(upper[s] == this){
			return true;
		}
	}
	return false;
}
String.prototype.isLower = function(){
	if(this.length>1) return false;
	var upper = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'];
	for(var s in upper){
		if(upper[s] == this){
			return true;
		}
	}
	return false;
}
String.prototype.parseCodeUpper = function(){
	var returnStr = this;
	var replaceStr = {};
	for(var i = 0;i<this.length;i++){
		var a = this.charAt(i);
		if(a=="-"){
			replaceStr[a+this.charAt(i+1)] = this.charAt(i+1).toUpperCase();
			i++;
		}
	}
	for(var p in replaceStr){
		returnStr = this.replace(p,replaceStr[p]);
	}
	return returnStr;
}

String.prototype.parseCodeLower = function(){
	var returnStr = this;
	var replaceStr = {};
	for(var i = 0;i<this.length;i++){
		var a = this.charAt(i);
		if(a.isUpper()){
			replaceStr[a] = "-"+a.toLowerCase();
		}
	}
	for(var p in replaceStr){
		returnStr = this.replace(p,replaceStr[p]);
	}
	return returnStr;
}

/*用法
 *var ddd = new Date();
 *document.write (ddd.format('MM-dd-yyyy hh:mm:ss'));
 */
Date.prototype.format = function(format)
{
    var o = 
    {
        "M+" : this.getMonth()+1, //month
        "d+" : this.getDate(),    //day
        "h+" : this.getHours(),   //hour
        "m+" : this.getMinutes(), //minute
        "s+" : this.getSeconds(), //second
        "q+" : Math.floor((this.getMonth()+3)/3),  //quarter
        "S" : this.getMilliseconds() //millisecond
    }
    if(/(y+)/.test(format)) 
    format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4 - RegExp.$1.length));
    for(var k in o)
    if(new RegExp("("+ k +")").test(format))
    format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
    return format;
}

function setStyle(o,style){
	for(property in style){
		o.style[property] = style[property];
	}
}

function getUrlType(o,url,width,height){
	if(url.EndsWith(".swf")){
		try{
			var so = new SWFObject(ob.src, o, width, height, "7", "#FFFFFF");
			so.addParam("wmode","transparent");
			so.write(o);
		}catch (e){}
	}else{
		var content = "<img src=\""+url+"\" border=\"0\"/>";
		o.innerHTML = content;
	}
}

function getObj(o){
	o = typeof(o) == "string"?$(o):o;
	return o;
}

function getInt(o){
	o = typeof(o)=="string"?parseInt(o):o;
	return o;
}

var loadComplete=function(element,func){
	if(element.addEventListener){
		element.addEventListener("load",func,true);
	}else{
		element.attachEvent("onload",func,true);
	}
	
}

var Class = {
  create: function() {
    return function() {
      this.initialize.apply(this, arguments);
    }
  }
}

Object.extend = function(destination, source) {
  for (property in source) {
    destination[property] = source[property];
  }
  return destination;
}

//
Function.prototype.bind = function() {
  var __method = this, args = $A(arguments), object = args.shift();
  return function() {
    return __method.apply(object, args.concat($A(arguments)));
  }
}

Function.prototype.bindAsEventListener = function(object) {
  var __method = this;
  return function(event) {
    return __method.call(object, event || window.event);
  }
}

var Try = {
  these: function() {
    var returnValue;
    for (var i = 0; i < arguments.length; i++) {
      var lambda = arguments[i];
      try {
        returnValue = lambda();
        break;
      } catch (e) {}
    }
    return returnValue;
  }
}

//Cookie相关
var Cookie = {
	addCookie:function(name,value,expireHours){
		var cookieString=name+"="+escape(value);
		//判断是否设置过期时间
		if(expireHours>0){
			var date=new Date();
			date.setTime(date.getTime()+expireHours*3600*1000);
			cookieString=cookieString+"; expire="+date.toGMTString();
		}
		document.cookie=cookieString;
	},
	getCookie:function(name){
		var strCookie=document.cookie;
		var arrCookie=strCookie.split("; ");
		var value = "";
		for(var i=0;i<arrCookie.length;i++){
			var arr=arrCookie[i].split("=");
			if(arr[0]==name)value = unescape(arr[1]);
		}
		return value;
	},
	deleteCookie:function(name){
		var date=new Date();
		date.setTime(date.getTime()-10000);
		document.cookie=name+"=v; expire="+date.toGMTString();
	}
}


//Ajax相关
var Ajax = {
  getTransport: function() {
    return Try.these(
      function() {return new ActiveXObject('Msxml2.XMLHTTP')},
      function() {return new ActiveXObject('Microsoft.XMLHTTP')},
      function() {return new XMLHttpRequest()}
    ) || false;
  },

  activeRequestCount: 0
}

Ajax.Request = Class.create();

Ajax.Request.prototype = {
	initialize: function(url, options) {
		this.transport = Ajax.getTransport();
		this.setOptions(options);
		this.request(url);
	},
	setOptions:function(options){
	  	this.method = options.method || 'post';
		this.parameters = options.parameters || '';
		this.asynchronous = options.asynchronous || true;
		this.onComplete = options.onComplete || new Function();
		this.onFailure = options.onFailure || new Function();
	},
	request:function(url){
		this.url = url;
		if (this.method == 'get' && this.parameters.length > 0)
			 this.url += (this.url.match(/\?/) ? '&' : '?') + this.parameters;
		
		this.transport.open(this.method, this.url, this.asynchronous);
		if(this.asynchronous){
			this.transport.onreadystatechange = this.onStateChange.bind(this);
		}
		this.setRequestHeaders();
		this.transport.send(this.parameters);
	},
	setRequestHeaders:function(){
		var requestHeaders = new Array();
		if (this.method == 'post')
     		requestHeaders.push('Content-type','application/x-www-form-urlencoded');
		for (var i = 0; i < requestHeaders.length; i += 2)
		   this.transport.setRequestHeader(requestHeaders[i], requestHeaders[i+1]);
	},
	onStateChange:function(){
		var transport = this.transport;
		if(transport.readyState==4){
			if(transport.status==200||transport.status==0){
				this.onComplete(transport);
			}else{
				this.onFailure();
			}
		}
	}
	
}
/*用法
 *function sss(){
 *var ajax = new Ajax.Request(
 *					"a.html",
 *					{method: 'post', parameters: "",asynchronous:true, onComplete:a.bind(sss), onFailure:new Function()}
 *					);
 *}
 *sss.dd = "dsfsf";
 *sss();
 *function a(h){
 *	alert(this.dd);
 *}
 */

//删除空白的文本节点
function cleanWhitespace(element) {
	//遍历element的子结点
	for (var i = 0; i < element.childNodes.length; i++) {
		var node = element.childNodes[i];
		//判断是否是空白文本结点，如果是，则删除该结点
		if (node.nodeType == 3 && !/\S/.test(node.nodeValue)) 
		node.parentNode.removeChild(node);
	}
}
//取父节点下的所有子节点
function getObjectAllChildNode(parentNode){
	parentNode = getObj(parentNode);
	var returnArray = [];
	cleanWhitespace(parentNode);
	var array = parentNode.childNodes;
	for(p in array) returnArray.push(array[p]);
	for(var i = 0;i<array.length;i++){
		var childArray = array[i].childNodes;
		if(childArray.length>0){
			returnArray = returnArray.concat(getObjectAllChildNode(array[i]));
		}
	}
	return returnArray;
}
//取父节点下具有相同class属性的子节点
function getObjectByClassName(parentNode,className,hasClassName){
	parentNode = getObj(parentNode);
	className = className.Trim();
	var returnArray = [];
	var childArray = getObjectAllChildNode(parentNode);
	for(p in childArray){
		var isPush = false;
		if(hasClassName){
			var classArray = childArray[p].className?childArray[p].className.split(" "):childArray[p].className;
			for(i in classArray){
				if(classArray[i].Trim()==className){
					isPush = true;
					break;
				}
			}
		}else if(childArray[p].className == className){
			isPush = true;
		}
		if(isPush)
			returnArray.push(childArray[p]);
	}
	return returnArray;
}
//取父节点下具有相同id属性的子节点
function getObjectById(parentNode,idName){
	parentNode = getObj(parentNode);
	idName = idName.Trim();
	var returnArray = [];
	var childArray = getObjectAllChildNode(parentNode);
	for(p in childArray){
		if(childArray[p].id == idName){
			returnArray.push(childArray[p]);
		}
	}
	return returnArray;
}

function opwin(catid,id,href){
	var left = (screen.width - 800) / 2;
	var top = (screen.height - 600) / 2;
	var link ="";
	link=href+"?catid=" + catid + "&id="+id;
	link = unescape(link);
	var news = window.open(link, "news", "width = 816, height = 620, scrollbars = 2, left = " + left + ", top = " + top + ", resizable = 1");
	news.focus();
}
 
//opwin(&quot;2402|2428&quot;,&quot;/2007/share/weather_detail.jsp&quot;)
