/** 
 * @author idealbigpig
 */
 function stopBubble(e) 
	{
		//如果提供了事件对象，则这是一个非IE浏览器
		if ( e && e.stopPropagation)
		{
			//因此它支持W3C的stopPropagation()方法
			e.stopPropagation();
		}
		else
		{
			window.event.cancelBubble= true;
		}
			//否则使用IE的方式来取消事件冒泡
			
	}

var Site={};
/**
 * 返回随机数字
 */
Site.ReturnRandNum=function()
{
		var now = new Date();
		var year = now.getYear();
		var month = now.getMonth() + 1;
		var day = now.getDate();
		var hour = now.getHours();
		var minute = now.getMinutes();
		var second = now.getSeconds();
		Num = year+month+day+hour+minute+second+Math.random()*(200-50);
		return Num;
}
Site.playSound=function(soundname)
 {
	 var oDiv = $("#divSound")[0];
	 if (!oDiv)
	 return;
	 oDiv.innerHTML="<embed id=\"sound\" name=\"sound\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" src=\"" + soundname + ".swf\" width=\"1\" height=\"1\" type=\"application/x-shockwave-flash\" autoplay=\"true\" quality=\"high\" loop=\"False\"></embed>";
	 return;
 } 
 Site.StopPlaySound=function()
 {
	 var oDiv = $("#divSound")[0];
	 if (!oDiv)
	 return;
	 oDiv.innerHTML="";
	 return;
 }
 Site.ChanageSoundStatus=function(soundname)
 {

	 var oDiv = $("#divSound")[0];
	 if (!oDiv)
	 return;
	 if (oDiv.innerHTML=="")
	 {
	 	oDiv.innerHTML="<embed id=\"sound\" name=\"sound\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" src=\"" + soundname + ".swf\" width=\"1\" height=\"1\" type=\"application/x-shockwave-flash\" autoplay=\"true\" quality=\"high\" loop=\"False\"></embed>";
		return;
	 }
	 if (oDiv.innerHTML!="")
	 {
	 	oDiv.innerHTML="";
		return;
	 }
	 return;
 }
/**
 * 缩放图片宽度
 * @param {Object} Images
 */
Site.resizeImg=function(Images)
{
	if(Images.width>=600)
	{
		Images.style.width="600px";
	}
	else
	{
		Images.style.width="auto";
	}
}
/**
 * 取得Cookie
 * @param {String} key
 */
Site.GetCookie=function(key)
	{
		var search=key+"=";
		if(document.cookie.length>0)
		{
			var offset=document.cookie.indexOf(search);
			if(offset!=-1)
			{
				offset+=search.length;
				var end=document.cookie.indexOf(";",offset);
				if(end==-1)end=document.cookie.length;
				return unescape(document.cookie.substring(offset,end));
			}
			return "";
		}
		return "";
	},
Site.playSound=function(soundname)
	{
            var oDiv = $("#divSound")[0];
            if (!oDiv) 
                return;
				oDiv.innerHTML="<embed id=\"sound\" name=\"sound\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\" src=\"" + soundname + ".swf\" width=\"1\" height=\"1\" type=\"application/x-shockwave-flash\" autoplay=\"true\" quality=\"high\" loop=\"true\"></embed>";
				return;
    }
Site.SetCookie=function(key,value,expdate)
	{
		if (expdate == ""||typeof(expdate)=="undefined"||expdate=="undefined") {
			var today = new Date();
			var expires = new Date();
			value = value.toString();
			expires.setTime(today.getTime() + 86400 * 1000 * 60);
			document.cookie = key + "=" + value + ";path=/; expires=" + expires.toGMTString();
		}
		else
		{
			document.cookie = key + "=" + value + ";path=/; expires=" + expires;
		}
	},
Site.TestCookie=function()
	{
		Site.SetCookie("test","");
		var t = "test";
		Site.SetCookie("test",t);
		return Site.GetCookie("test")==t;
	}
Site.deleteCookie=function (name)
{
	var expdate = new Date();
	expdate.setTime(expdate.getTime() - (86400 * 1000 * 1));
	Site.SetCookie(name, "", expdate);
}
Site.OpenDiv=function(e,value)
{
		ei.style.display = "block";
		ei.innerHTML = value;
		ei.style.top  = document.body.scrollTop + event.clientY + 10 + "px";
		ei.style.left = document.body.scrollLeft + event.clientX + 10 + "px";
}
Site.GetWidth=function()//屏幕可视范围宽
{
		if(document.compatMode!='undefined'&&document.compatMode!='BackCompat')
		{
			return document.documentElement.clientWidth;
		}
		else if(typeof(document.body)!='undefined')
		{
			return document.body.clientWidth;
		}
}
Site.Height=function()//屏幕可视范围高
{
		if(typeof(document.compatMode)!='undefined'&&document.compatMode!='BackCompat')
		{
			return document.documentElement.clientHeight;
		}
		else if(typeof(document.body)!='undefined')
		{
			return document.body.clientHeight;
		}
}
/**
 * String 扩展
 */ 
String.prototype.trim = function()
{
	var str = this;
	var m = str.match(/^\s*(\S+(\s+\S+)*)\s*$/);
	return (m == null) ? "" : m[1];
}
String.prototype.strip = function()
{
	return this.replace(/<\/?[^>]+>/gi, '').trim();
}
String.prototype.escapeHTML = function()
{
	var div = document.createElement('div');
	var text = document.createTextNode(this);
	div.appendChild(text);
	return div.innerHTML;
}
String.prototype.unescapeHTML = function()
{
	var div = document.createElement('div');
	div.innerHTML = this.stripTags();
	return div.childNodes[0].nodeValue;
}
String.prototype.escapeEx = function()
{
	return escape(this).replace(/\+/g,"%2b");
}
String.prototype.replaceAll = function(a,b)
{
	return this.replace(new RegExp(a.replace(/([\(\)\[\]\{\}\^\$\+\-\*\?\.\"\'\|\/\\])/g,"\\$1"),"g"),b);
}
String.prototype.indexOfEx = function()
{
	var bi = arguments[arguments.length - 1];
	var thisObj = this;
	var idx = 0;
	if(typeof(arguments[arguments.length - 2]) == 'number')
	{
		idx = arguments[arguments.length - 2];
		thisObj = this.substr(idx);
	}
	var re = new RegExp(arguments[0],bi?'i':'');
	var r = thisObj.match(re);
	return r==null?-1:r.index + idx;
}
String.prototype.padLeft = function(str,n)
{
	var result = this;
	if(this.length<n)
	for(var i=0;i<n-this.length;i++)
		result = str+result;
	return result;
}
String.prototype.GetCount = function(str,mode)
{
	return eval("this.match(/("+str+")/g"+(mode?"i":"")+").length");
} 
String.prototype.CountFormStr=function()
{  
 var len;  
 var i;  
 len = 0;  
 var str=this;
 for (i=0;i<str.length;i++)  
  {  
   if (str.charCodeAt(i)>255)   
	{  
	 len+=2;   
	}  
   else   
	{  
	 len++;  
	}  
  }  
 return len;  
}
String.prototype.trim = function()
{
 return this.replace(/(^\s*)|(\s*$)/g, "");
}
String.prototype.left = function(num,mode)
{
	if(!/\d+/.test(num))return(this);
	var str = this.substr(0,num);
	if(!mode) return str;
	var n = str.Tlength() - str.length;num = num - parseInt(n/2);
	return this.substr(0,num);
}
String.prototype.right = function(num,mode)
{
	if(!/\d+/.test(num))return(this);
	var str = this.substr(this.length-num);
	if(!mode) return str;
	var n = str.Tlength() - str.length;num = num - parseInt(n/2);
	return this.substr(this.length-num);
}
String.prototype.getLen=function()
{
	var len = 0;   
	for (var i=0; i<this.length; i++)
	{   
		if (this.charCodeAt(i)>127 || this.charCodeAt(i)==94) 
		{   
			len += 2;   
		} else 
		{   
			len ++;   
		}   
	}   
	return len;
}
//******************************************
//Array扩展
//******************************************
Array.prototype.indexOf = function(obj)//返回一个对象在Array中的位置
{
	var result = -1;
	for(var i = 0; i < this.length; i++)
	{
		if(this[i] == obj)
		{
			result = i;
			break;
		}
	}
	return result;
}
Array.prototype.contains = function(obj)//检查一个对象是否包含在Array中
{
	return this.indexOf(obj) > -1;
}
Array.prototype.add = function(obj)//添加一个对象
{
	if(!(this.contains(obj)))
	{
		this[this.length] = obj;
	}
}
Array.prototype.remove = function(obj)//删除一个对象
{
	if(this.contains(obj))
	{
		var index = this.indexOf(obj);
		for(var i = index; i < this.length - 1; i++)
		{
			this[i] = this[i + 1];
		}
		this.length--;
	}
}
Array.prototype.clear = function()//清空数组
{
	this.splice(0,this.length);
}
Array.prototype.value = function(s,l)//设置默认值
{
	if(l)this.length=l;
	for(var i = 0; i < this.length; i++)
	{
		this[i] = s;
	}
}
/**
 * 模拟get取
 * @param {Object} key
*/
var $GETVALUES=new Array();
var $GET=function(key)
{
		$GETVALUES=new Array();
		var Location=document.location;
		Location=Location.toString();
		if (Location == "") 
		{
			return "";
		}
		if (Location.indexOf("?")==-1)
		{
			return "";
		}
		Values=Location.split("?")[1];
		ValueArray=Values.split("&");
		for (var i=0;i<ValueArray.length;i++)
		{
			if (typeof(ValueArray[i].split("=")[1])=="undefined") return "";
			if (typeof(ValueArray[i].split("=")[0])=="undefined") return "";
			$GETVALUES[ValueArray[i].split("=")[0]]=ValueArray[i].split("=")[1]
		}
		if (typeof($GETVALUES[key])=="undefined"||$GETVALUES[key]=="NaN"||$GETVALUES[key]=="undefined") return "";
		return $GETVALUES[key];
}
Site.obj2str=function(o)
{
    var r = [];
    if(typeof o =="string") return "\""+o.replace(/([\'\"\\])/g,"\\$1").replace(/(\n)/g,"\\n").replace(/(\r)/g,"\\r").replace(/(\t)/g,"\\t")+"\"";
    if(typeof o =="undefined") return "undefined";
    if(typeof o == "object"){
        if(o===null) return "null";
        else if(!o.sort){
            for(var i in o)
                r.push(i+":"+Site.obj2str(o[i]))
            r="{"+r.join()+"}"
        }else{
            for(var i =0;i<o.length;i++)
                r.push(Site.obj2str(o[i]))
            r="["+r.join()+"]"
        }
        return r;
    }
    return o.toString();
}
function isMouseLeaveOrEnter(e, handler) {  
    if (e.type != 'mouseout' && e.type != 'mouseover') return false;  
    var reltg = e.relatedTarget ? e.relatedTarget : e.type == 'mouseout' ? e.toElement : e.fromElement;  
    while (reltg && reltg != handler)  
        reltg = reltg.parentNode;  
    return (reltg != handler);  
} 
var Elem = {
	New:function(a,d,c,i)//新建element,a:类型,d:id,c:,className,i:innerHTML
	{
		var o = document.createElement(a);
		if(d)o.id = d;
		if(c)o.className = c;
		if(i)o.innerHTML = i;
		return o;
	},
	Add:function(o)//为o元素追加子元素,可一个传进多个子元素
	{
		if(arguments.length==1)
		{
			Elem.Add(document.body,o);
			return;
		}
		var o = $(o);
		if(!o)return;
		for (var i = 1; i < arguments.length; i++)
		{
			o.appendChild($(arguments[i]));
		}
		return o;
	},
	Del:function()//删除元素
	{
		for (var i = 0; i < arguments.length; i++)
		{
			if ($("#"+arguments[i])[0]) 
				if ($("#"+arguments[i])[0].parentNode) {
					$("#"+arguments[i])[0].parentNode.removeChild($("#"+arguments[i])[0]);
				}
		}
	},
	Hid:function()//隐藏
	{
		for (var i = 0; i < arguments.length; i++)
		{
			if($(arguments[i]))
				$(arguments[i]).style.display="none";
		}
	},
	Show:function()//显示
	{
		for (var i = 0; i < arguments.length; i++)
		{
			if($(arguments[i]))
				$(arguments[i]).style.display="block";
		}
	},
	Value:function(o,s)//赋值
	{
		s=s?s:"";
		if(!$(o))return;
		var tag = $(o).tagName.toUpperCase();
		if(tag=="INPUT"||tag=="TEXTAREA"||tag=="SELECT")
		{
			$(o).value = s;
		}
		else
		{
			$(o).innerHTML = s;
		}
	},
	Append:function(o,s)//追加内容
	{
		var tag = $(o).tagName.toUpperCase();
		if(tag=="INPUT"||tag=="TEXTAREA")
		{
			$(o).value += s;
		}
		else
		{
			$(o).innerHTML += s;
		}
	},
	Toggle:function()//原本显示则隐藏，反正也如此
	{
		for (var i = 0; i < arguments.length; i++)
		{
			if($(arguments[i]))
				$(arguments[i]).style.display=$(arguments[i]).style.display=="none"?"block":"none";
		}
	},
	Enable:function()//可用
	{
		for (var i = 0; i < arguments.length; i++)
		{
			$(arguments[i]).disabled="";
		}
	},
	Disable:function()//不可用
	{
		for (var i = 0; i < arguments.length; i++)
		{
			$(arguments[i]).disabled="disabled";
		}
	},
	Child:function(o)
	{
		return $(o).childNodes;
	},
	GetX:function(o,po)
	{
		for (var lx=0;o!=po;lx+=o.offsetLeft,o=o.offsetParent);
		return lx;
	},
	GetY:function(o,po)
	{
		for (var ly=0;o!=po;ly+=o.offsetTop,o=o.offsetParent);
		return ly;
	},
	Top:function()//屏幕可视范围离页面顶距离,放在这里是为了好管理
	{
		if(typeof(window.pageYOffset)!='undefined')
		{
			return window.pageYOffset;
		}
		else if(typeof(document.compatMode)!='undefined'&&document.compatMode!='BackCompat')
		{
			return document.documentElement.scrollTop;
		}
		else if(typeof(document.body)!='undefined')
		{
			return document.body.scrollTop;
		}
	},
	Left:function()//屏幕可视范围离左边距离
	{
		if(typeof(window.pageXOffset)!='undefined')
		{
			return window.pageXOffset;
		}
		else if(typeof(document.compatMode)!='undefined'&&document.compatMode!='BackCompat')
		{
			return document.documentElement.scrollLeft;
		}
		else if(typeof(document.body)!='undefined')
		{
			return document.body.scrollLeft;
		}
	},
	Width:function()//屏幕可视范围宽
	{
		if(document.compatMode!='undefined'&&document.compatMode!='BackCompat')
		{
			return document.documentElement.clientWidth;
		}
		else if(typeof(document.body)!='undefined')
		{
			return document.body.clientWidth;
		}
	},
	Height:function()//屏幕可视范围高
	{
		if(typeof(document.compatMode)!='undefined'&&document.compatMode!='BackCompat')
		{
			return document.documentElement.clientHeight;
		}
		else if(typeof(document.body)!='undefined')
		{
			return document.body.clientHeight;
		}
	}
}