/**
 * @author idealbigpig
 */

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;
}
/**
 * 缩放图片宽度
 * @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.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() + 1000 * 60 * 60);
			document.cookie = key + "=" + value.escapeEx() + ";path=/; expires=" + expires.toGMTString();
		}
		else
		{
			document.cookie = key + "=" + value.escapeEx() + ";path=/; expires=" + expdate.toGMTString();
		}
	},
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];
}