var check_commentvoteAjax;
var check_key;
var check_flag;
var check_allNotify;
//Ôìº¯µ
var checkvalues=function(url,method){	
    check_flag=true;
    this.url=url;
	  this.method=method;
	  this.queuesVars=[];
	  this.queuesKeys=[];
	  this.queuesFlag=false;
	  this.retrydelay=10;
};

checkvalues.prototype={
	//Ê¹ÓÃajaxÏò·þÕÆ÷°lËÍÏûÏ¢
	createAjax:function(PostVars,key){	
	
	//for(var i=0;i<this.queuesVars.length&&check_flag;i++)
	//{
	// check_key=this.queuesKeys[i];
	 check_key=key;
     check_commentvoteAjax = new sack();
	 check_commentvoteAjax.requestFile = this.url;
	 check_commentvoteAjax.method = this.method;
	 check_commentvoteAjax.setVar(key,PostVars);
	 check_commentvoteAjax.element = null;
    //commentvoteAjax.onLoading = checkName_loading;
     check_commentvoteAjax.onInteractive = this.loading_checkvalue;
	 check_commentvoteAjax.onCompletion = this.completion_checkvalue;
	 check_commentvoteAjax.onFail = this.onFail_checkvalue;
	 check_commentvoteAjax.runAJAX();
	 //ÔOÖÃê ÁÐ°lËÍ
	 if(check_flag)
	 {
		 
		 if(this.queuesVars.length==0&&this.queuesKeys.length==0){
		    this.queuesFlag=false;
			return;
		 }
		 
		 var reqVar=this.queuesVars.shift();
		 var reqKey=this.queuesKeys.shift();
		 this.createAjax(reqVar.reqKey);
		
 
	 }
	 else{
		 
		 that=this;
		 setTimeout(that.createAjax(PostVars,key),this.retrydelay*1000);
	 }	
		
	},
	
	sendrecommand:function(){
		check_key="recommand";
     check_commentvoteAjax = new sack();
	 check_commentvoteAjax.requestFile = this.url;
	 check_commentvoteAjax.method = this.method;
	 var recommandaccount=document.getElementById("recommandstudent_account").value;
	 var recommandname = document.getElementById("recommandstudent_name").value;
     check_commentvoteAjax.setVar("recommandaccount",recommandaccount);
	 check_commentvoteAjax.setVar("recommandname",recommandname);
	 check_commentvoteAjax.element = null;
        //commentvoteAjax.onLoading = checkName_loading;
     check_commentvoteAjax.onInteractive = this.loading_checkvalue;
	 check_commentvoteAjax.onCompletion = this.completion_checkvalue;
	 check_commentvoteAjax.onFail = this.onFail_checkvalue;
	 check_commentvoteAjax.runAJAX();
	
		
		
	},
	comment_checksomevalue:function(PostVars,key){	
	   if(this.queuesFlag){
	    this.queuesVars.push(PostVars);
		this.queuesKeys.push(key);
	   }else
	   {
		this.queuesFlag=true;
		this.createAjax(PostVars,key);
	   }
		
	},
	loading_checkvalue:function(){
		
		var obj=document.getElementById(check_key+"Notify");
		 obj.className="Show_LoadingResult";
		 obj.innerText=Languages['loading'];
		
	},
	completion_checkvalue:function(){
		var response = check_commentvoteAjax.response;
		
		var classtype = response.split(":");
		var obj=document.getElementById(check_key+"Notify");
		
		if(classtype[0]=="OK")
		{
			obj.className="Show_RightResult";
		}else{
			obj.className="Show_ErrorResult";
			
		}
		
		obj.innerText=Languages[classtype[1]];
		
	    check_flag=true;
	    
	},
	
	onFail_checkvalue:function(){
		check_flag=false;
	}
	
	
	
	
};

//ÔìzyåeÕ`µÄî
var checkobj_class=function(postvalues,ajaxsend){
	 this.postvalues=postvalues;//classépostvaluesµÄinputÔªËØï@Ê¾ÌáÊ¾ÐÅÏ¢µÄÔªËØ
	 this.ajaxsend=ajaxsend;//classéajaxsendµÄinputÔªËØï@Ê¾é°lËÍajaxÐÅÏ¢µÄÔªËØ
	 
	 var pvRE="\\w*"+this.postvalues+"\\s?\\w*";
	 this.postvaluesRE=new RegExp(pvRE);//²éÕÒclassépostvaluesµÄËùÓÐÔªËØ
	 var asRE="\\w*\\s?"+this.ajaxsend;
	 this.ajaxsendRE=new RegExp(asRE);//²éÕÒclasséajaxsendµÄËùÓÐÔªËØ
};

checkobj_class.prototype={
	 //µÃµ½¸÷ÌáÊ¾µÄºÍ°lËÍajaxµÄÔªËØKÇÒ·Ö°lÏûÏ¢
	 _notifyResult:function(){
		 this.NotifyArray=[];
		 this.AjaxArray=[];
		 var inputobj=$(":input");
		 var inputobjlength=inputobj.length;
		 for(i=0;i<inputobjlength;i++){
			 var matchobj=inputobj[i];
			 if(this.postvaluesRE.test(matchobj.className)){
				
			    this.NotifyArray.push(matchobj);
			 }
			 if(this.ajaxsendRE.test(matchobj.className)){
				
			    this.AjaxArray.push(matchobj);
			 }
		 }
		 this._clickNotify();
		 this._sendAjax();
		 
 	 },
	 //ÌáÊ¾ÐÅÏ¢
	 _clickNotify:function(){
		 if(this.NotifyArray){
			 var NotifyArraylength=this.NotifyArray.length;
			 
			 for(i=0;i<NotifyArraylength;i++){
				 var currentobj=this.NotifyArray[i];
				
				 currentobj.thisobj=this;
				 currentobj.onclick=this.inputonclick;
			 }
		 }
		 if(window.externclickNotify!=null)//Ìá¹©î~ÍâµÄÌáÊ¾ÐÅÏ¢µÄº¯µ
		     externclickNotify(this);
	 },
	 
	 inputonclick:function(){
		
		var that=this.thisobj;
		var name=this.name;
		var NotifyKey="Notify_"+name;
		var textid=name+"Notify";
		var textvalue=Notify[NotifyKey];
		document.getElementById(textid).className="Show_NotifyResult";
	    $("#"+textid).text(textvalue);
		var NotifyArray=that.NotifyArray;
		var NotifyArraylength=NotifyArray.length; 
		
		for(i=0;i<NotifyArraylength;i++){
			var currentitem=NotifyArray[i];
			var notifyobjid=currentitem.name+"Notify";
			var notifyobj=document.getElementById(notifyobjid);
			
			if(currentitem.name!=this.name&&notifyobj.className=="Show_NotifyResult"){
				
			    notifyobj.innerText="";
			}
		}

	 },
	   //°lËÍajaxÏûÏ¢
	 	_sendAjax:function(){
			if(this.AjaxArray){
				var AjaxArraylength=this.AjaxArray.length;
				for(i=0;i<AjaxArraylength;i++)
				{
					var currentitem=this.AjaxArray[i];
					currentitem.thisobj=this;
					currentitem.onblur=this.inputonblur;
				}
				
				
			}
			if(window.externsendAjax!=null)
			    externsendAjax(this);
			
		},
		
		inputonblur:function(){
			var inputid=this.id;
			var inputvalue=document.getElementById(inputid).value;
		    m_checkvalues.comment_checksomevalue(inputvalue,inputid);
		},
		//×îáá°´ÏÂ°´âorzyËùÓÐµÄÔªËØÊÇ·ñé¿ÕKï@Ê¾ËùÓÐµÄåeÕ`ÐÅÏ¢
		_oncheckvalues:function(){
			
			this.postflags=false;
		    this.check_allNotify=Languages["notifymessage"];
			if(this.AjaxArray){
				var AjaxArraylength=this.AjaxArray.length;
				for(i=0;i<AjaxArraylength;i++)
				{
					var currentitem=this.AjaxArray[i];
					var spanid=currentitem.name+"Notify";
					if(document.getElementById(spanid).className=="Show_ErrorResult"){
						this.check_allNotify+="   "+document.getElementById(spanid).innerText;
			            this.postflags=true;
					}
					else{
					
					  if(currentitem.value==""){
						var NotifyId=currentitem.name+"Notify";
						
						var NotifyText="empty_"+currentitem.name;
						
						document.getElementById(NotifyId).className="Show_ErrorResult";
		            document.getElementById(NotifyId).innerText=Languages[NotifyText];
				        this.check_allNotify+=" "+Languages[NotifyText];
				        
				        this.postflags=true;
					 }
					}
				}
				if(window.externcheckvalues!=null)//Ìá¹©î~ÍâÍâ²¿µÄº¯µ
				   externcheckvalues(this);
				
				
				if(this.postflags){
		           document.getElementById("showallNotify").innerText=this.check_allNotify;
		           document.getElementById("showallNotify").style.display="block";
			         return false;
			    }
			    else
			        return true;
			}
			
			
		}
	
};





