﻿// BEGIN: URLParams holds all URL passed parameters (like ?Param1=Value1&Param2=Value2)
var URLParams = new Object() ;
var aParams = document.location.search.substr(1).split('&');
for (i=0 ; i < aParams.length ; i++)
{
	var aParam = aParams[i].split('=') ;
	URLParams[aParam[0]] = aParam[1] ;
}
// END: URLParams

function GetCookieVal(offset)
//获得Cookie解码後的值
{
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}
function SetCookie(name, value)
//设定Cookie值
{
	var expdate = new Date();
	var argv = SetCookie.arguments;
	var argc = SetCookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	//var path = (argc > 3) ? argv[3] : null;
	var path="/";
	var domain = (argc > 4) ? argv[4] : null;
	var secure = (argc > 5) ? argv[5] : false;
	if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
	document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
	+((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
	+((secure == true) ? "; secure" : "");
}
function DelCookie(name)
//刪除Cookie
{
	var exp = new Date();
	exp.setTime (exp.getTime() - 1);
	var cval = GetCookie (name);
	document.cookie = name + "=" + cval + "; path=/; expires="+ exp.toGMTString();
}
function GetCookie(name)
//获得Cookie的原始值
{
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen)
	{
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
			return GetCookieVal (j);
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break;
	}
	return null;
}
//新增窗體
var win=this;
function openWindow(url, name, width, height, features)
{
	var winname="_self";
	if(typeof(name)!= "undefined"&&name!="")winname=name;
	var winfeatures="";
	if(typeof(width)!= "undefined"&&width!="")
	{
		var left=0;
		if(screen.width>width)left=(screen.width-width)/2;
		winfeatures+="left="+left+",screenX="+left+",width="+width+",";
	}
	if(typeof(height)!= "undefined"&&height!="")
	{
		var top=0;
		if(screen.height>height)top=(screen.height-height)/2;
		winfeatures+="top="+top+",screenY="+top+",height="+height+",";
	}
	if(typeof(features)!= "undefined"&&features!="")
	{
		var top=0;
		if(screen.height>height)top=(screen.height-height)/2;
		winfeatures+=features+",";
	}
	winfeatures=winfeatures.substring(0,winfeatures.length-1);
	win=window.open(url,winname,winfeatures);
	if(navigator.appName!= 'Microsoft Internet Explorer'){if(window.focus)win.focus()};
}
//包含
function IsConsistent(Str1,Str2)
{
	//例子:"-2-3-5-","-1-4-5-"==>true
	var j = 0;
	for(var i=0;i<Str1.length;i++)
	{
		if (Str1.substring(i, i + 1)=="-")
		{
			if (i != 0)
				if (Str2.indexOf(Str1.substring(j, i + 1)) != -1)
					return true;
			j = i;
		}
	}
	return false;
}
//定义路径警示
function _DefUrl(url,message)
{
	if(url==null)
	{
		url="|";
	}
	{
		var nowurl=document.location;
		nowurl=(nowurl+"").split("http://"+document.location.host)[1];
		url=((url.split("\|")[0]=="")?nowurl:url.split("\|")[0])+"|"+((url.split("\|")[1]=="")?nowurl:url.split("\|")[1]);
	}
	if(message==null)
	{
		message="|";
	}
	SetCookie("NewNowPage",url);
	SetCookie("NewAlertMessage",message);
}
//临时定义路径警示
function _DefTMPUrl()
{
	SetCookie("NewTMPNowPage",GetCookie("NewNowPage"));
	SetCookie("NewTMPAlertMessage",GetCookie("NewAlertMessage"));
	SetCookie("NewNowPage","/css/close.html|/css/close.html");
	SetCookie("NewAlertMessage","|");
}
function clickep(_control,_index)
{
	if(_control.innerHTML=="+")
	{
		_control.innerHTML="-";
		_control.parentNode.childNodes[_index].style.display="block";
	}
	else
	{
		_control.innerHTML="+";
		_control.parentNode.childNodes[_index].style.display="none";
	}
}
//头尾除空格
String.prototype.trim=function(){return this.replace(/(^\s*)|(\s*$)/g,"");}
//Date格式定義
Date.prototype.doMask = function(mask)
{
	var str = [];
	var re = this.base.reg;
	var _Y = re[0].exec(mask);
	var _M = re[1].exec(mask);
	var _D = re[2].exec(mask);
	var _h = re[3].exec(mask);
	var _m = re[4].exec(mask);
	var _s = re[5].exec(mask);
	var _wcn = re[6].exec(mask);
	var _wen = re[7].exec(mask);
	if(_Y)str[0] = this.getFullYear().toString().substr(4 - _Y.toString().length);
	if(_M)
	{
		var monStr =(this.getMonth() + 1).toString();
		str[1] = monStr.length < _M.toString().length ? "0"+ monStr:monStr;
	}
	if(_D)
	{
		var dayStr = this.getDate().toString();
		str[2] = dayStr.length < _D.toString().length ? "0"+ dayStr:dayStr;
	}
	if(_h)
	{
		var hourStr = this.getHours().toString();
		str[3] = hourStr.length < _h.toString().length ? "0"+ hourStr:hourStr;
	}
	if(_m)
	{
		var minStr = this.getMinutes().toString();
		str[4] = minStr.length < _m.toString().length ? "0"+ minStr:minStr;
	}
	if(_s)
	{
		var secStr = this.getSeconds().toString();
		str[5] = secStr.length < _s.toString().length ? "0"+ secStr:secStr;
	}
	if(_wcn)str[6] = this.base.weekCN[this.getDay()];
	if(_wen)str[7] = this.base.weekEN[this.getDay()];
	for(var i in re)
		mask = mask.replace(re[i], str[i]);
	return mask;
}
//時間分隔定義
Date.prototype.base={reg:[/Y+/,/M+/,/D+/,/h+/,/m+/,/s+/,/星期/,/week/],weekCN:["星期日","星期一","星期二","星期三","星期四","星期五","星期六"],weekEN:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]};
//時間格式定義
Date.prototype.format = function(mask) {
	var d = this;
	var zeroize = function (value, length) {
		if (!length) length = 2;
		value = String(value);
		for (var i = 0, zeros = ''; i < (length - value.length); i++) {
			zeros += '0';
		}
		return zeros + value;
	};
	return mask.replace(/"[^"]*"|'[^']*'|\b(?:d{1,4}|m{1,4}|M{1,4}|yy(?:yy)?|([hHstT])\1?|[lLZ])\b/g,function($0){
		switch($0) {
			case 'd':return d.getDate();
			case 'dd':return zeroize(d.getDate());
			case 'ddd':return ['Sun','Mon','Tue','Wed','Thr','Fri','Sat'][d.getDay()];
			case 'dddd':return ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'][d.getDay()];
			case 'M':return d.getMonth() + 1;
			case 'MM':return zeroize(d.getMonth() + 1);
			case 'MMM':return ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'][d.getMonth()];
			case 'MMMM':return ['January','February','March','April','May','June','July','August','September','October','November','December'][d.getMonth()];
			case 'yy':return String(d.getFullYear()).substr(2);
			case 'yyyy':return d.getFullYear();
			case 'h':return d.getHours() % 12 || 12;
			case 'hh':return zeroize(d.getHours() % 12 || 12);
			case 'H':return d.getHours();
			case 'HH':return zeroize(d.getHours());
			case 'm':return d.getMinutes();
			case 'mm':return zeroize(d.getMinutes());
			case 's':return d.getSeconds();
			case 'ss':return zeroize(d.getSeconds());
			case 'l':return zeroize(d.getMilliseconds(), 3);
			case 'L':var m = d.getMilliseconds();
				if (m > 99) m = Math.round(m / 10);
					return zeroize(m);
			case 'tt':return d.getHours() < 12 ? 'am' : 'pm';
			case 'TT':return d.getHours() < 12 ? 'AM' : 'PM';
			case 'Z':return d.toUTCString().match(/[A-Z]+$/);
			default:return $0.substr(1, $0.length - 2);
		}
	});
}; 
Date.prototype.add = function(part, value) {
	value *= 1;
	if(isNaN(value)) {
	value = 0;
	}
	switch(part){
		case "y":
			this.setUTCFullYear(this.getUTCFullYear() + value);
			break;
		case "m":
			this.setUTCMonth(this.getUTCMonth() + value);
			break;
		case "d":
			this.setUTCDate(this.getUTCDate() + value);
			break;
		case "h":
			this.setUTCHours(this.getUTCHours() + value);
			break;
		case "n":
			this.setUTCMinutes(this.getUTCMinutes() + value);
			break;
		case "s":
			this.setUTCSeconds(this.getUTCSeconds() + value);
			break;
		default:
	}
}
//數字格式定義
String.prototype.format=function(len){var tmpstr="";for(var i=0;i<len;i++)tmpstr+="0";tmpstr+=this;return tmpstr.substring(tmpstr.length-len);}
//连接
function linkform(_url,_target)
{
	document.LinkForm.action=_url;
	if(typeof _target=='undefined')
		document.LinkForm.target="_self";
	else
		document.LinkForm.target=_target;
	document.LinkForm.submit();
}

var _OnLoadStr="";
function _OnLoad()
{
	_OnLoadStr+="ShowFlash();\n";
	var nowurl=document.location;
	nowurl=(nowurl+"").split("http://"+document.location.host)[1];
	var url=nowurl+"|"+nowurl;
	SetCookie("NewNowPage",url);
	SetCookie("NewAlertMessage","|");
	eval(_OnLoadStr);
}
//显示flash
function ShowFlash()
{
	var _flashcontrol=document.getElementsByTagName("span");
	for(var i=0;i<_flashcontrol.length;i++)
	{
		if(_flashcontrol[i].getAttribute("type")=="flash")
		{
			/*
			var _flashshow=document.createElement("embed");
			_flashshow.setAttribute("pluginspage", "http://www.macromedia.com/go/getflashplayer");
			_flashshow.setAttribute("type", "application/x-shockwave-flash");
			_flashshow.setAttribute("quality", "high");
			if(_flashcontrol[i].getAttribute("wmode")!=null)
				_flashshow.setAttribute("wmode", _flashcontrol[i].getAttribute("wmode"));
			else
				_flashshow.setAttribute("wmode", "transparent");
			if(_flashcontrol[i].getAttribute("allowscriptaccess")!=null)
				_flashshow.setAttribute("allowscriptaccess", _flashcontrol[i].getAttribute("allowscriptaccess"));
			if(_flashcontrol[i].getAttribute("allowfullscreen")!=null)
				_flashshow.setAttribute("allowfullscreen", _flashcontrol[i].getAttribute("allowfullscreen"));
			_flashshow.src=_flashcontrol[i].getAttribute("src");
			_flashshow.setAttribute("width", _flashcontrol[i].getAttribute("width"));
			_flashshow.setAttribute("height", _flashcontrol[i].getAttribute("height"));
			_flashcontrol[i].appendChild(_flashshow);
			*/
			var _flashshow=document.createElement("iframe");
			_flashshow.setAttribute("width", _flashcontrol[i].getAttribute("width"));
			_flashshow.setAttribute("height", _flashcontrol[i].getAttribute("height"));
			_flashshow.src=_flashcontrol[i].getAttribute("src");
			_flashshow.setAttribute("frameborder", "0");
			_flashshow.setAttribute("allowfullscreen", "true");
			_flashcontrol[i].appendChild(_flashshow);
		}
	}
}
//图片处理
function ChangeSize(img,w,h)
{
	var image=new Image();
	image.src=img.src;
	try
	{
		if(image.width/image.height>w/h||h==0)
		{
			if(image.width>w)
			{
				img.width=w;
				img.height=image.height*w/image.width;
			}
			else
			{
				img.width=image.width;
				img.height=image.height;
			}
		}
		else
		{
			if(image.height>h)
			{
				img.width=image.width*h/image.height;
				img.height=h;
			}
			else
			{
				img.width=image.width;
				img.height=image.height;
			}
		}
	}
	catch(ex){}
}
function ChangeSizeCut(img,w,h)
{
	var image=new Image();
	image.src=img.src;
	try
	{
		if(image.width/image.height>w/h)
		{
			img.width=image.width*h/image.height;
			img.height=h;
		}
		else
		{
			img.width=w;
			img.height=image.height*w/image.width;
		}
	}
	catch(ex){}
}
//编辑隐藏内容
function clickedit(_control,_index)
{
	if(_control.innerHTML=="+")
	{
		_control.innerHTML="-";
		_control.parentNode.childNodes[_index].style.display="block";
	}
	else
	{
		_control.innerHTML="+";
		_control.parentNode.childNodes[_index].style.display="none";
	}
}
//颜色转换
String.prototype.hexColor = function(){
	if(this=="")return this;
	if(this.indexOf("#") >= 0) return this;//如果是一个hex值则直接返回
	var pattern = new RegExp("2[0-4]\\d|25[0-5]|[01]?\\d\\d?","ig");//这个正则是取 0 ~ 255的数字
	var va = this.match(pattern);
	if(va.length != 3) return "NaN";//取出的数组长度一定得为3
	var result = "#";
	for(var i = 0; i < 3; i++) {
			var num = parseInt(va[i]);
			result += num < 16 ? "0" + num.toString(16) : num.toString(16);//如果小于F在前面补0
	}
	return result;
}
