String.prototype.Trim  = function(){return this.replace(/^\s+|\s+$/g,"");}
function checkVerify(){
	var _format = {
		"email":"^\\w+([-+.]\\w+)*@\\w+([-.]\w+)*\\.\\w+([-.]\\w+)*",
		"number":"[^\\d]",
		"char":"[^A-Z,a-z]",
		"phone":"[\\d,\\-]",
		"money":"[\\d\\.]"
	};
	var _name = ["type","required","format","min"];
	var _obj = arguments[0];
	var _sets = {};
	_sets["tags"]=_obj.tagName.toLowerCase();
	for(_i=0;_i<_name.length;_i++){
		_sets[_name[_i]] = _obj.getAttribute(_name[_i]) || "";
	}
	if(_sets["tags"]==="input"&&_sets["type"].toLowerCase()==="text"){
		_obj.value = _obj.value.Trim();
	}
	_sets["text"]=_obj.value || _obj.checked || "";
	if(_sets["type"]!=="hidden"){
		if(_sets["required"]==="true"){
			if(_sets["text"].length==0)return [_obj,false,0];
		}
		if(_sets["text"].length>0){
			if(_sets["format"].length>0){
				var _re = new RegExp(_format[_sets["format"]],"gi");
				var _value = _sets["text"].replace(_re,"");
				if(_value.length>0)return [_obj,false,1];
			}
			if(_sets["min"].length>0){
				if(_sets["text"].length<_sets["min"])return [_obj,false,2,_sets["min"]];
			}
		}
		setErrtext(_obj,"");
	}
	return [_obj,true];
}
function setErrtext(){
	var _obj = arguments[0];
	var _objs = _obj.parentNode.getElementsByTagName("S");
	if(_objs.length>0){
		_objs[0].innerHTML = arguments[1];
		_objs[0].style.display=(arguments[1].length>0)?"inline":"none";
		return false;
	}
	return true;
}
function choosect(o){
	var _obj = $("cts");
	var __obj = _obj.getElementsByTagName("SELECT");
	for(i=0;i<__obj.length;i++){
		__obj[i].style.display="none";
		__obj[i].disabled=true;
	}
	var __obj = _obj.getElementsByTagName("INPUT");
	__obj[0].style.display="none";
	__obj[0].disabled=true;

	var _name = "ct"+o.options[o.selectedIndex].value;
	var _obj = $(_name);
	if(_obj){
		_obj.disabled=false;
		_obj.style.display="inline";
	} else {
		__obj[0].disabled=false;
		__obj[0].style.display="inline";
	}
}
function checkForm(){
	var _objs = arguments[0].elements;
	var _obj = null;
	for(i=0;i<_objs.length;i++){
		if(!_objs[i].disabled&&_objs[i].style.display!="none"){
			var _v = checkVerify(_objs[i]);
			if(!_v[1]){
				_obj = _v;
				break;
			}
		}
	}
	var _err = ["Required.","Format error.","Length error."];
	if(_obj){
		if(setErrtext(_obj[0],_err[_obj[2]]))alert(_err[_obj[2]]);
		_obj[0].focus();
		return false;
	}
	return true;
}
function startReg(obj,name){
	var _obj = $(name)
	_obj.style.display=(obj.checked)?'':'none';
	var _objs = $$(_obj,"INPUT");
	for(i=0;i<_objs.length;i++){
		_objs[i].disabled=!obj.checked;
	}
}
function $(name){
	return document.getElementById(name);
}
function $$(obj,name){
	return obj.getElementsByTagName(name);
}
function cb(obj,col){
	obj.style.backgroundColor=col;
}
if($("catalog")){
	$("catalog").getElementsByTagName("DT")[0].onclick=function(){
		var _objs = this.parentNode.getElementsByTagName("DD");
		this.className=(this.className=='c')?'':'c';
		_objs[_objs.length-1].style.display=(this.className=='c')?'none':'block';
	}
}
if($("brands")){
	$("brands").getElementsByTagName("DT")[0].onclick=function(){
		var _objs = this.parentNode.getElementsByTagName("DD");
		this.className=(this.className=='c')?'':'c';
		_objs[_objs.length-1].style.display=(this.className=='c')?'none':'block';
	}
}
/*	A link	*/
var _obj = document.getElementsByTagName("A");
for(i=0;i<_obj.length;i++){
	_obj[i].onfocus=function(){
		this.blur();
	}
}
/*	nav	*/
if($("nav")){
	var _obj = $("nav").getElementsByTagName("DD");
	for(i=0;i<_obj.length;i++){
		_obj[i].onmouseover=function(){
			this.className="sel";
			var _obj = $$(this,"UL")[0];
			_obj.style.display="block";
		}
		_obj[i].onmouseout=function(){
			this.className="";
			var _obj = $$(this,"UL")[0];
			_obj.style.display="none";
		}
	}
}
/*	pshow	*/
function mouseCoords(ev){
	if(ev.pageX || ev.pageY){
		return {x:ev.pageX, y:ev.pageY};
	}
	var _obj = document.documentElement || document.body;
	return {
		x:ev.clientX + _obj.scrollLeft - _obj.clientLeft,
		y:ev.clientY + _obj.scrollTop - _obj.clientTop
	};
}
function getAbsPoint(e){   
	var   x = e.offsetLeft, y = e.offsetTop;   
	while(e=e.offsetParent){
		x += e.offsetLeft;
		y += e.offsetTop;
	}
	return {x:x,y:y};
}
var _obj = $("pover");
if(_obj){
	_obj.onmouseover=function(){
		var _obj = $("loading");
		if(_obj&&_obj.style.display=="none"&&$("pview").getAttribute("w")>350){
			var _objs = document.getElementsByTagName("SELECT");
			for(i=0;i<_objs.length;i++)_objs[i].style.display="none";
			$("picbox").style.backgroundColor="#F9F9F9";
			var _obj = $("pview");
			if(_obj)_obj.style.display="block";
			var _obj = $("ppsit");
			if(_obj)_obj.style.display="block";
		}
	}
	_obj.onmouseout=function(){
		var _obj = $("pview");
		if(_obj)_obj.style.display="none";
		var _obj = $("ppsit");
		if(_obj)_obj.style.display="none";
		var _objs = document.getElementsByTagName("SELECT");
		for(i=0;i<_objs.length;i++)_objs[i].style.display="";
			$("picbox").style.backgroundColor="";
	}
	_obj.onmousemove=function(){
		var _obj = $("loading");
		if(_obj&&_obj.style.display=="none"&&$("pview").getAttribute("w")>350){
			var _obj = $("pview");
			if(_obj)_obj.style.display="block";
			var _obj = $("ppsit");
			if(_obj)_obj.style.display="block";
			var ev = arguments[0] || window.event;
			var mousePos = mouseCoords(ev);
			var pshowPos = getAbsPoint($("pover"));
			//document.title = mousePos.x + "," + mousePos.y + " | " + pshowPos.x + "," + pshowPos.y;
			var x = mousePos.x - pshowPos.x;
			var y = mousePos.y - pshowPos.y;
			var px = (x<350-170/2)?((x<170/2)?0:x-170/2):350-170;
			var py = (y<350-170/2)?((y<170/2)?0:y-170/2):350-170;
			var _obj = $("ppsit");
			_obj.style.top = (pshowPos.y+py)+"px";
			_obj.style.left = (pshowPos.x+px)+"px";
			var _obj = $("pview");
			_obj.scrollTop = parseInt(_obj.getAttribute("index")*800+py*800/350);
			_obj.scrollLeft = parseInt(px*800/350);
		}
	}
	//init
	$("pshow").scrollTop = 0;
	$("pview").scrollTop = 0;
	$("pview").scrollLeft = 0;
}
var _obj = $("ptask");
if(_obj){
	var _obj = $("ptask").getElementsByTagName("LI");
	for(i=0;i<_obj.length;i++){
		_obj[i].setAttribute("index",i);
		_obj[i].onclick=function(){
			$("pview").setAttribute("w",this.getElementsByTagName("IMG")[0].getAttribute("w"));
			$("pview").setAttribute("index",this.getAttribute("index"));
			$("ppos").style.marginLeft = ((this.getAttribute("index"))*44)+"px";
			$("pshow").scrollTop = (this.getAttribute("index"))*350;
			var _obj = $("ptask").getElementsByTagName("LI");
			for(i=0;i<_obj.length;i++){
				_obj[i].className=(this.getAttribute("index")==_obj[i].getAttribute("index"))?"sel":"";
			}
		}
	}
	var _obj = $("ptask").getElementsByTagName("IMG");
	for(i=0;i<_obj.length;i++){
		_obj[i].alt = 'Click it view larger images';
	}
}
