//网站一些公共JS
  

//设置class
function shover(o,className)
	{
	if(!o) return;
	o.className = className;		
	}
//添加class
function addClass(o,className)
	{
	if(!o) return;
	o.className = className+" " + o.className;		
	}
//删除class
function repalceClass(o,className)
	{
	if(!o) return;
	//o.className = className+" " + o.className;		
	SunRise.Dom.removeClass(o,className);
	}
 


	//干掉验证码
function hiddenVerify(isImme){
	if(!verifyCounter[0])
		return;
	if(!isImme)
		verifyCounter[0].timeout=setTimeout(function(){verifyCounter[0].killMe()},500);
	else
		verifyCounter[0].killMe();
}
	
VerifyImage.prototype.change=function(){
	 
	var o=document.getElementById(this.eleID);//$(this.eleID);
	this.seed=Math.random();
	o.src="/center/verify.jsp?sds="+this.seed;
	
}

var verifyCounter=[];
function VerifyImage(eleID,x,y){
	var c=verifyCounter.length;
	this.timeout=null;
	this.ipt = null;
	if(!eleID)
		this.eleID=eleID="verifyIMG_"+c;
	this.od=document.getElementById("_rndImageDIV");//document.createElement("div");
	with(this.od){
		style.position="absolute";
		style.backgroundColor="#E8FBFF";
		style.border="solid 1px #545454";
		style.padding="3px";
		id=eleID+"_anchor";
		style.zIndex = 3000;
	}
 
	this.templete=('<img id="'+eleID+'" onclick="getVerify(\''+eleID+'\','+c+')" style="cursor:pointer;margin-bottom:5px" src="/center/verify.jsp?sds={{_random_}}" alt="获取中..." title="点击更换" width="130" height="53" /><br /><span onclick="getVerify(\''+eleID+'\','+c+')" style="color:black;cursor:pointer;font-size: 12px;white-space:nowrap;">看不清楚?換一個</span>');
	this.seed=Math.random();
	this.appended=false;
 
	verifyCounter[c]=this;
}

VerifyImage.prototype.killMe=function(){
	this.od.style.display="none";
}


	//获取验证码
function getVerify(s,n){
	clearTimeout(verifyCounter[n].timeout);
	verifyCounter[n].change();
	//var i=$("verifycode");
	if(verifyCounter[n].ipt){
		verifyCounter[n].ipt.value="";
		verifyCounter[n].ipt.focus();
	}
}

	//input focus获取验证码
function focusGetVerify(o){
    if(o==undefined){
    return ;
    }
	var pos=getPosition(o);
	var e=(verifyCounter.length>0)?(verifyCounter[0]):(new VerifyImage());
	e.ipt = o;
	e.showMe(pos.left,pos.top);
	o.value="";
}

function   getPosition(obj)   {   
          var   top=105;   
          var   left=obj.offsetWidth;   
          var   width=obj.offsetWidth;   
          var   height=obj.offsetHeight;   
  while   (obj.offsetParent)   {   
          top   +=   obj.offsetTop;   
          left   +=   obj.offsetLeft;   
          obj   =   obj.offsetParent;   
          }   
          return   {"top":top,"left":left,"width":width,"height":height};   
    }
    
VerifyImage.prototype.showMe=function(x,y){
	with(this.od){
		style.top=(y-187)+"px";
		style.left=(x-123)+"px";
	}
   //  if(document.readyState){
	//if(!this.appended&&document.readyState=="complete"){
		//document.body.appendChild(this.od);
	if(!this.appended){
		 this.od.innerHTML=this.templete.replace(/\{\{_random_\}\}/g,this.seed); 
		 this.appended=true;
	}
	 //}else{
	 // document.body.appendChild(this.od);
		// this.od.innerHTML=this.templete.replace(/\{\{_random_\}\}/g,this.seed); 
		// this.appended=true;
	// }	
	this.od.style.display="";
}//end function
