document.domain = 'fzpinke.cn';

var $ = {
	get : function(_id){
		if(typeof _id != 'string')return _id
		var _e = document.getElementById(_id);
		if(_e)return _e;
		_e = document.getElementsByName(_id);
		if(_e.length == 1)return _e[0];
		return _e;
	},
	
	create : function(_tagName){
		return document.createElement(_tagName);
	},
	
	tag : function(_tagName){
		return document.getElementsByTagName(_tagName);
	}
}

var $Form = {
	theForm : null,
	
	load : function($o){
		if(typeof $o == "string"){
			this.theForm = document.forms[$o] || document.getElementById($o);
		}
		else{
			this.theForm = $o;
		}
	},
	
	_get_attribute : function(_e, _attrib){
		var _d = _e.attributes.getNamedItem(_attrib);
		if(_d){
			return _d.value;
		}
		else{
			return "";
		}
	},
	
	_get_elements_name : function(_e){
		return this._get_attribute(_e, "name") || this._get_attribute(_e, "id");
	},
	
	_get_elements : function(){
		var _el = null, _eln;
		var _els = new Array();
		var _elc = this.theForm.elements.length;
		for(var _i = 0; _i < _elc; _i++){
			_el = this.theForm.elements[_i];
			_eln = this._get_elements_name(_el);
			if(!_eln)continue;
			if(this._get_attribute(_el, "type").toLowerCase == "checkbox" || this._get_attribute(_el, "type").toLowerCase() == "radio"){
				if(_el.checked == false)continue;
			}
			_els.push(new Array(_eln, _el.value));
		}
		return _els;
	},
	
	_check : function(_e){
		var _ns = this._get_attribute(_e, "desc");
		if(!_ns)return true;
		
		var _nss = _ns.split("|||");
		var _val = _e.value;
		
		switch(_nss[0]){
			case "1":
				if(!_val){
					alert(_nss[1]);
					_e.focus();
					return false;
				}
				break;
			case "2" :
				if(_val == "" || isNaN(_val)){
					alert(_nss[1]);
					_e.focus();
					return false;
				}
				break;
			case "8" :
				var _com = $.get(_nss[1]).value;
				if(_com != _val){
					alert(_nss[2]);
					_e.focus();
					return false;
				}
				break;
			case "0" :
			default :
				if((new RegExp(_nss[1], "gi")).test(_val) == false){
					alert(_nss[2]);
					_e.focus();
					return false;
				}
				break;
		}
		return true;
	},
	
	check : function(){
		var _theForm = this.theForm;
		var _len = _theForm.elements.length;
		
		for(var _i = 0; _i < _len; _i++){
			if(!this._check(_theForm.elements[_i]))return false;
		}
		return true;
	},
	
	chkValue : function(_o){
		_o = $.get(_o);
		var _r = "";
		
		var _l = _o.length;
		for(var _i = 0; _i < _l; _i++){
			if(_o[_i].checked)_r += "," + _o[_i].value;
		}
		return _r.substring(1);
	},
	
	submit : function(_xr, _fun, _text){
		var _theForm = this.theForm;
		if(_xr){
			var _args = this._get_elements();
			//var _req = $Ajax;
			var _req = new $Ajax;
			_req.fun = _fun;
			_req.args = _args;
			_req.text = _text;
			_req.url = this._get_attribute(_theForm, "action");
			_req.method = this._get_attribute(_theForm, "method");
			_req.send();
		}
		else{
			_theForm.submit();
		}
	}
}

var $Ajax = function(){
	var _state = 0;
	var _request = null;
	this.fun = alert;
	this.args = new Array();
	this.text = "text";
	this.url = "";
	this.charset = "utf8";
	this.method = "get";
	
	this.send = function(){
		var _This = this;
		var _req = _create();
		if(!_req)return;
		var _fun = _This.fun;
		
		_req.onreadystatechange = function(){
			if (_req.readyState == 4) {
				if (_req.status == 200) {
					if('text' == String(_This.text).toLowerCase() || "json" == String(_This.text).toLowerCase()){
						_fun(_req.responseText);
					}
					else{
						_fun(_req.responseXML.documentElement);
					}
				}
			}
			_This._state = 0;
		}
		
		var _argstr = _This._args();
		
		if("GET" == String(_This.method).toUpperCase() && _argstr){
			this.url += "?" + _argstr;
		}
		//alert(this.url);

		_req.open(_This.method, _This.url, true);
		
		var headers = new Array(
			new Array("Content-Type", "application/x-www-form-urlencoded"), //multipart/form-data 
			new Array("Connection", "Keep-Alive"),
			new Array("Pragma", "no-cache"),
			new Array("Cache-Control", "no-cache"),
			new Array("Charset", _This.charset)
		);

		if(headers != null && typeof(headers) == 'object' && (headers instanceof Array))
		{
			for(var i = 0; i < headers.length; i++)
			{
				var tmp = headers[i];
				if(typeof(tmp) == 'object' && (tmp instanceof Array) && tmp.length >= 2)
				{
					_req.setRequestHeader(tmp[0], tmp[1]);
				}
			}
		}
		if("GET" == String(_This.method).toUpperCase()){
			_req.send(null);
		}
		else{
			_req.setRequestHeader("Content-length", argstr.length);
			_req.send(argstr);
		}
	};
	
	this._args = function(){
		var _argstr = "";
		var _as = this.args;
		var _al = _as.length;
		for(var _i = 0; _i < _al; _i++){
			_argstr += "&" + _as[_i][0] + "=" + _as[_i][1];
		}
		return _argstr.substring(1);
	};
	
	var _header = function(){
		
	};
	
	var _create = function(){
		var _req = null;
		if(_request){
			_req = _request;
		}
		else if(typeof ActiveXObject != "undefined"){
			var _xmlHttp_ver = false;
			var _xmlHttp_vers = [
				"MSXML2.XmlHttp.5.0",
				"MSXML2.XmlHttp.4.0",
				"MSXML2.XmlHttp.3.0",
				"MSXML2.XmlHttp",
				"Microsoft.XmlHttp"
			];
			for(var _i = 0 ; _i < _xmlHttp_vers.length ; _i++){
				try{
					new ActiveXObject(_xmlHttp_vers[_i]);
					_xmlHttp_ver = _xmlHttp_vers[_i];
					break;
				}
				catch(oError){;}
			}
			if(_xmlHttp_ver){
				_req = new ActiveXObject(_xmlHttp_ver);
			}
		}
		else if(typeof XMLHttpRequest != "undefined"){
			_req = new XMLHttpRequest();
		}
		else{
			_req = null;
		}
		_request = _req;
		return _req;
	};
}

function $Trans(show){
	var $box = null;
	var $len = 0;
	var $arr = new Array();
	var $delay = 4000;
	var $number = null;
	var $oThis = this;
	var $key = 0;
	var $timeout = null;
	var $showNumber = show && true;
	var $last = 0;
	
	this.loadFromElement = function(id){
		var t = $.get(id);
		var l = t.childNodes.length;
		for(var i = 0; i < l; i++){
			if(t.childNodes[i].tagName){
				$arr[$len++] = t.childNodes[i];
			}
		}
		return;
	}
	
	this.loadFromArray = function(arr, image){
		for(var i = 0; i < arr.length; i++){
			if(!arr[i] || arr[i].length == 0)continue;
			var obj = $.create('a');
			obj.href = arr[i][1];
			obj.target = '_blank';
			if(image == 'image'){
				obj.innerHTML = '<img src="' + arr[i][0] + '" />';
			}
			else{
				obj.innerHTML = arr[i][0];
			}
			$arr[$len++] = obj;
		}
	}
	
	this.setBox = function(id){
		$box = $.get(id);
	}
	
	this.setDelay = function(delay){
		$delay = delay;
	}
	
	this.display = function(){
		if(!$box)return;
		$box.innerHTML = '<p></p>';
		if($showNumber){
			_showNumber();
		}
		_play(0);
		
	}
	
	function _showNumber(){
		var str = '';
		var id = $box.id + '_box';
		for(var i = 1; i <= $len; i++){
			str += '<u title="' + (i - 1) + '">' + i + '</u>';
		}
		$box.innerHTML = '<div id="' + id + '"><span>' + str + '</span></div>' + $box.innerHTML;
		$number = ($.get(id)).getElementsByTagName('u');
		for(var i = 0; i < $len; i++){
			$number[i].onclick = function(){_play(this.title);}
		}
		$last = 1;
	}
	
	function _change(){
		if(document.all 
			&& $box.filters 
			&& $box.filters.revealTrans){
			$box.filters.revealTrans.Transition = Math.floor(Math.random() * 23);
				$box.filters.revealTrans.apply();
		}
		$box.replaceChild($arr[$key], $box.childNodes[$last]);
		if(document.all 
			&& $box.filters 
			&& $box.filters.revealTrans){
			$box.filters.revealTrans.Transition = Math.floor(Math.random() * 23);
				$box.filters.revealTrans.play();
		}
	}
	
	function _play(key){
		window.clearTimeout($timeout);
		_newKey(key);
		_change();
		if($len > 1)$timeout = window.setTimeout(function(){_play()}, $delay);
	}
	
	function _stop(){
		window.clearTimeout($timeout);
	}
	
	function _newKey(key){
		if($showNumber)$number[$key].className = '';
		if(key || key === 0){
			$key = key;
		}
		else{
			$key ++;
		}
		$key = $key % $len;
		if($showNumber)$number[$key].className = 'a';
	}
}
function $Scroll(_director){
	var $box = null;
	var $speed = 1;
	var $lines = 1;
	var $lineHeight = 20;
	var $timeout = null;
	var $scrollHeight = 0;
	var $scrollBox = null;
	var $director = _director;
	
	var $delay = 2000;
	var $dtime = 20;
	
	var $height = 0;
	var $pheight = 0;
	
	var $timeout = null;
	
	var $oThis = this;
	
	this.setBox = function(id){
		var _box = $.get(id);
		if(_box && _box.id)$box = _box;
	}
	
	this.setDelay = function(delay){
		$delay = delay;
	}
	
	this.loadFromArray = function(arr){
		if(!$box)return;
		var str = '';
		for(var i = 0; i < arr.length; i++){
			if(!arr[i] || arr[i].length == 0)continue;
			str += '<li><a href="' + arr[i][1] + '" style="' + arr[i][2] + '">' + arr[i][0] + '</a></li>'
		}
		var id = $box.id + '_list';
		if($director)str += str;
		$box.innerHTML = '<ul id="' + id + '">' + str + '</ul>';
		
		$scrollBox = $.get(id);
	}
	
	this.display = function(){
		if(!$box)return;
		//alert($box.innerHTML);
		$pheight = $lines * $lineHeight;
		$height = _height($box) / 2;
		$box.onmouseover = function(){_stop();}
		$box.onmouseout = function(){_play();}
		_play();
	}
	
	function _play(){
		_scroll();
	}
	
	function _stop(){
		window.clearTimeout($timeout);
	}
	
	function _scroll(){
		window.clearTimeout($timeout);
		$scrollHeight = ($speed + $scrollHeight) % $height;
		$scrollBox.style.top = ((-1) * $scrollHeight) + 'px';
		if($scrollHeight % $pheight == 0){
			$timeout = window.setTimeout(function(){_scroll();}, $delay);
		}
		else{
			$timeout = window.setTimeout(function(){_scroll();}, $dtime);
		}
	}
	
	function _height(obj){
		var cld = obj.childNodes;
		var height = 0;
		for(var i = 0; i < cld.length; i++){
			if(cld[i].tagName)height += cld[i].offsetHeight;
		}
		return height;
	}
	
}

function loadSingleImage(arr, id){
	var box = $.get(id);
	if(!arr[0] || !box)return;
	arr = arr[0];
	var html = '<a href="' + arr[1] + '" class="cltThrough" target="_blank"><img src="' + arr[0] + '" /></a>';
	box.innerHTML = html;
}

function loadSingleText(arr, id){
	var box = $.get(id);
	if(!arr || !box)return;
	var str = '';
	for(var i = 0; i < arr.length; i++){
		if(arr[i] && arr[i].length == 3)str += '<li><a href="' + arr[i][1] + '" style="' + arr[i][2] + '">' + arr[i][0] + '</a></li>'
	}
	box.innerHTML = '<ul>' + str + '</ul><div class="blk"></div>';
}

var Form = $Form;