/*
美化选中框 Version 2.0
作者:456Vv
Email:123@456Vv.com
网址:www.456Vv.com
*/

function select_element(obj,lab,type,el){
	if(type=="checkbox"){
		if(el==-1){lab.className="checkbox_x";
		}else if(el==1){lab.className="checkbox_on";
		}else{lab.className="checkbox_off";}
	}
	if(type=="radio"){
		if(el==-1){
			if(obj.getAttribute("operator_")==-1){return;}
			lab.className="radio_x";
			obj.setAttribute("operator_",-1);
		}else if(el==1){
			if(obj.getAttribute("operator_")==1){return;}
			lab.className="radio_on";
			obj.setAttribute("operator_",1);
		}else{
			if(obj.getAttribute("operator_")==0){return;}
			lab.className="radio_off";
			obj.setAttribute("operator_",0);
		}
	}
}
var iover0808097979=true;
function radio_style(){

	var label,
		type,
		TagName,
		sel,
		re,
		Cinput,
		Cdiv,
		Atts,
		Att,
		Val,
		rnd;

	label	= Vv.T("label");
	re		= /\s+([\w\-:]+)/g;

	for(var i=0,len=label.length;i<len;i++){//>
		type	= label[i].getAttribute("type");
		if(!type){continue;}
		type	= type.toLowerCase();

		if(type=="radio" || type=="checkbox"){

			//第一次刷新
			if(iover0808097979){
				//转换赋值
				TagName = ("8.0">Vv.BVersion("ie")&&Vv.isIE)?"<input name=\""+ label[i].getAttribute("name$") +"\"/>":"input";

				var	Cinput	= document.createElement(TagName);
				Cinput.type=type;
				label[i].parentNode.appendChild(Cinput);

				Atts=Vv.RegExpTest(re,label[i].outerHTML,true,true,true,0,0,"$1",",").split(",");

				for(var j=0,leng=Atts.length;j<leng;j++){//>
					Val		= label[i].getAttribute(Atts[j]+"$");
					Att		= Atts[j].toLowerCase();

					if(Val==null||Val=="undefined"){continue;}

					if(Att.substr(0,2)=="on"){
						Cinput[Att]=(typeof Val=="string")?new Function(Val):Val;
					}else if(Att=="checked"){
						if(Val=="checked"||Val=="true"){Cinput.checked=true;}
						else{Cinput.checked=false;}
					}else{
						Cinput.setAttribute(Att,Val);
					}
					label[i].removeAttribute(Atts[j]+"$")
				}
				//生出
				rnd=(!Cinput.id)?Vv.random("随机",6):Cinput.id;
				Cinput.id=rnd;
				label[i].htmlFor=rnd;
			}else{
				//第二次刷新
				Cinput=Vv.G(label[i].htmlFor);
			}
			//选择处理
			if(!!Cinput.checked || Cinput.getAttribute("sel")===Cinput.value){
				select_element(Cinput,label[i],type,1);
				Cinput.checked=true;
				Cinput.removeAttribute("sel");
			}else if(Cinput.disabled){
				select_element(Cinput,label[i],type,-1);
			}else{
				select_element(Cinput,label[i],type,0);
			}

			//CSS处理
			if(iover0808097979){
				if(type=="radio" && label[i].innerText!=""){
					label[i].style.padding="0 0 0 18px";
				}else if(type=="radio"){
					label[i].style.display="inline-block";
					label[i].style.height=label[i].style.width="14px";
				}
				if(type=="checkbox"&&label[i].innerText!=""){
					label[i].style.padding="0 0 0 13px";
				}else if(type=="checkbox"){
					label[i].style.display="inline-block";
					label[i].style.height=label[i].style.width="11px";
				}
				Cinput.style.position="absolute";
				Cinput.style.left="-99999px";
				Vv.addEvent_(label[i],"mouseup",function(){setTimeout("radio_style()",100);});
			}
		};
	}
	iover0808097979=false;
};
Vv.addLoadEvent(function(){radio_style();});
