/*-- ------ #Message ------ --*/
function Message(){}

Message.prototype.sAjax_0=new netsSingleAjax();
Message.prototype.sAjax_1=new netsSingleAjax();
Message.prototype.sAjax_MessageCount=new netsSingleAjax();
//-- #Parameters --
//#Name
Message.prototype.sMessageTab="messageTab";
Message.prototype.sMessageTab_Head="messageTab_";
Message.prototype.sMessageTab_Count_Head="messageTab_Count_";
Message.prototype.sMessageOption="messageOption";
Message.prototype.sMessageContent="messageContent";
Message.prototype.sInputTab="inputTab";
Message.prototype.sInputContent="inputContent";
//#TEMPLATE
Message.prototype.sTemplate_MessageBut="";
Message.prototype.sTemplate_Loading="资料载入中...";
//#URL
Message.prototype.sURL_Frame="Plus/Common/Message/mess_frame.php";
Message.prototype.sURL_Message="Plus/Common/Message/child_message.php";
Message.prototype.sURL_SysMessage="Plus/Common/Message/child_sysmessage.php";
Message.prototype.sURL_Contact="Plus/Common/Message/child_contact.php";
//#FLAG
Message.prototype.sMessageCount=0;
Message.prototype.sMessageID=0;

Message.prototype.sID=0;
Message.prototype.sUserid=0;
//-- #Methods --
//-- #MessageMenu --
Message.prototype.messageOpen=function(pID,pUserid,pName){
	//#Initial
	var Coun0=0;
	var tmpINT=-1;
	var tmpTabBox=document.getElementById(this.sMessageTab);
	var tmpContentBox=document.getElementById(this.sMessageContent);
	//#Check
	Coun0=0;
	while(tmpTabBox.childNodes.length>Coun0){
		if(tmpTabBox.childNodes[Coun0].id==this.sMessageTab_Head+pUserid){
			tmpINT=Coun0;
		}
		if(tmpTabBox.childNodes[Coun0].id==this.sMessageTab_Head+"End"){
			tmpTabBox.childNodes[Coun0].className="DClear";
		}else{
			tmpTabBox.childNodes[Coun0].className="Frame_1_1";
		}
		Coun0++;
	}
	
	//-- #REQUEST --
	tmpURL=tmpCommon.sysRoot+this.sURL_Message+"?ActionType=DOpen&DOpen="+pID+tmpCommon.sysSPLIT1+pUserid;
	this.sAjax_0.sFlag="";
	this.sAjax_0.sPanel="";
	this.sAjax_0.sURL=tmpURL;
	this.sAjax_0.sendRequestSp(tmpURL,"Message_messageOpen_Callback()");
	//window.open(tmpURL,"_blank");
	
	if(tmpINT>=0){
		tmpTabBox.childNodes[tmpINT].className="Frame_1_0";
		tmpContentBox.src=tmpCommon.sysRoot+this.sURL_Message+"?ActionType=DMessage&DMessage=1,"+pID+tmpCommon.sysSPLIT1+pUserid;
		return 0;
	}
	//#Append
	tmpSTR=this.sTemplate_MessageBut;
	tmpSTR=tmpSTR.replace(/\{Nets.ID}/g,pID);
	tmpSTR=tmpSTR.replace(/\{Nets.Userid}/g,pUserid);
	tmpSTR=tmpSTR.replace(/\{Nets.Name}/g,pName);
	tmpTabBox.innerHTML=tmpSTR+tmpTabBox.innerHTML;
	//#Complete
	Coun0=0;
	while(tmpTabBox.childNodes.length>Coun0){
		tmpTabBox.childNodes[Coun0].className="Frame_1_1";
		Coun0++;
	}
	tmpElement_0=document.getElementById(this.sMessageTab_Head+pUserid);
	tmpElement_0.className="Frame_1_0";
	tmpContentBox.src=tmpCommon.sysRoot+this.sURL_Message+"?ActionType=DMessage&DMessage=1,"+pID+tmpCommon.sysSPLIT1+pUserid;
	//-- #Remeber window --
	tmpURL=tmpCommon.sysRoot+this.sURL_Frame+"?ActionType=DWindow&DWindow=0"+tmpCommon.sysSPLIT1+pID+tmpCommon.sysSPLIT1+pUserid+tmpCommon.sysSPLIT1+tmpCommon.encodeURL(pName,0);
	this.sAjax_1.sFlag="";
	this.sAjax_1.sPanel="";
	this.sAjax_1.sURL=tmpURL;
	this.sAjax_1.sendRequestSp(tmpURL,"Message_messageOpen_RemeberWindow_Callback()");
	//window.open(tmpURL,"_blank");
	
	return 0;
}
function Message_messageOpen_Callback(){
	var tmpFlag=tmpMessage.sAjax_0.sFlag;
	var tmpPanel=document.getElementById(tmpMessage.sAjax_0.sPanel);
	var tmpURL=tmpMessage.sAjax_0.sURL;
	var tmpHttpRequests=tmpMessage.sAjax_0.sHttpRequests;
	//alert(tmpHttpRequests.responseText);
	if(tmpHttpRequests.readyState==4){
		//alert(tmpHttpRequests.responseText);
		var tmpData=getDataByFlag(tmpHttpRequests.responseText,"messageOption");
		//alert(tmpData);
		if(tmpData.indexOf("sendRequest")>=0 && tmpData!="<!--sendRequest-->"){
			document.getElementById("messageOption").innerHTML=tmpData;
	    }else{
	    	document.getElementById("messageOption").innerHTML=tmpCommon.sysError_Ajax.replace(/\{Nets.Response}/g,tmpURL);
	    }
	}else{
		document.getElementById("messageOption").innerHTML=tmpMessage.sTemplate_Loading;
	}
}
function Message_messageOpen_RemeberWindow_Callback(){}

Message.prototype.messageOpenSpical=function(pType){
	//#Initial
	var Coun0=0;
	var tmpINT=-1;
	var tmpTabBox=document.getElementById(this.sMessageTab);
	var tmpContentBox=document.getElementById(this.sMessageContent);
	var tmpSTR="";
	var tmpURL=this.sURL_SysMessage;
	if(pType=="Contact"){
		tmpURL=this.sURL_Contact;
	}else if(pType=="SysMessage"){
		tmpURL=this.sURL_SysMessage;
	}
	//#Check
	Coun0=0;
	while(tmpTabBox.childNodes.length>Coun0){
		if(tmpTabBox.childNodes[Coun0].id==this.sMessageTab_Head+pType){
			tmpINT=1;
		}
		if(tmpTabBox.childNodes[Coun0].id==this.sMessageTab_Head+"End"){
			tmpTabBox.childNodes[Coun0].className="DClear";
		}else{
			tmpTabBox.childNodes[Coun0].className="Frame_1_1";
		}
		Coun0++;
	}
	if(tmpINT>=0){
		tmpElement_0=document.getElementById(this.sMessageTab_Head+pType);
		tmpElement_0.className="Frame_1_0"
		if(pType=="SysMessage"){
			tmpContentBox.src=tmpCommon.sysRoot+tmpURL+"?ActionType=DMessage"
		}else{
			tmpContentBox.src=tmpCommon.sysRoot+tmpURL;
		}

	}
	//-- #REQUEST --
	tmpURL=tmpCommon.sysRoot+tmpURL+"?ActionType=DOpen&DOpen=";
	this.sAjax_0.sFlag="";
	this.sAjax_0.sPanel="";
	this.sAjax_0.sURL=tmpURL;
	this.sAjax_0.sendRequestSp(tmpURL,"Message_messageOpenSpical_Callback()");
	//window.open(tmpURL,"_blank");
	
	return 0;
}
function Message_messageOpenSpical_Callback(){
	var tmpFlag=tmpMessage.sAjax_0.sFlag;
	var tmpPanel=document.getElementById(tmpMessage.sAjax_0.sPanel);
	var tmpURL=tmpMessage.sAjax_0.sURL;
	var tmpHttpRequests=tmpMessage.sAjax_0.sHttpRequests;
	//alert(tmpHttpRequests.responseText);
	if(tmpHttpRequests.readyState==4){
		//alert(tmpHttpRequests.responseText);
		var tmpData=getDataByFlag(tmpHttpRequests.responseText,"messageOption");
		//alert(tmpData);
		if(tmpData.indexOf("sendRequest")>=0 && tmpData!="<!--sendRequest-->"){
			document.getElementById("messageOption").innerHTML=tmpData;
	    }else{
	    	document.getElementById("messageOption").innerHTML=tmpCommon.sysError_Ajax.replace(/\{Nets.Response}/g,tmpURL);
	    }
	}else{
		document.getElementById("messageOption").innerHTML=tmpMessage.sTemplate_Loading;
	}
}
Message.prototype.messageSetOpen=function(pID,pUserid,pName){
	parent.tmpMessage.messageOpen(pID,pUserid,pName);
	
	return 0;
}
Message.prototype.messageClose=function(pID,pUserid){
	//-- #Delete --
	var tmpTabBox=document.getElementById(this.sMessageTab);
	Coun0=0;
	while(tmpTabBox.childNodes.length>Coun0){
		if(tmpTabBox.childNodes[Coun0].id==this.sMessageTab_Head+pUserid){
			tmpINT=Coun0;
		}
		Coun0++;
	}
	tmpTabBox.removeChild(tmpTabBox.childNodes[tmpINT]);
	this.messageOpenSpical('SysMessage');
	//-- #Remeber window --
	tmpURL=tmpCommon.sysRoot+this.sURL_Frame+"?ActionType=DWindow&DWindow=1"+tmpCommon.sysSPLIT1+pID+tmpCommon.sysSPLIT1+pUserid+tmpCommon.sysSPLIT1;
	this.sAjax_1.sFlag="";
	this.sAjax_1.sPanel="";
	this.sAjax_1.sURL=tmpURL;
	this.sAjax_1.sendRequestSp(tmpURL,"Message_messageOpen_RemeberWindow_Callback()");
	//window.open(tmpURL,"_blank");
	
}
//-- #MessageRefresh --
Message.prototype.messageRefresh=function(pID,pUserid,pIDS,pURL){
	this.sID=pID;
	this.sUserid=pUserid;
	//-- #REQUEST --
	var tmpURL=pURL+"?CODE="+Math.random();
	this.sAjax_0.sFlag="";
	this.sAjax_0.sPanel="";
	this.sAjax_0.sURL=tmpURL;
	this.sAjax_0.sendRequestSp(tmpURL,"Message_messageDATA_Callback()");
	//window.open(tmpURL,"_blank");
	
	return 0;
}
function Message_messageDATA_Callback(){
	var tmpFlag=tmpMessage.sAjax_0.sFlag;
	var tmpPanel=document.getElementById(tmpMessage.sAjax_0.sPanel);
	var tmpURL=tmpMessage.sAjax_0.sURL;
	var tmpHttpRequests=tmpMessage.sAjax_0.sHttpRequests;
	//alert(tmpHttpRequests.responseText);
	if(tmpHttpRequests.readyState==4){
		//-- #REQUEST --
		var tmpXML=tmpCommon.analyzeXML(tmpHttpRequests.responseText);
		if(tmpXML.getElementsByTagName("Value")[0]==null){
			return 1;
		}
		var tmpSTR=tmpXML.getElementsByTagName("Value")[0].childNodes[0].nodeValue;
		if(tmpSTR=="NonMessage"){
			return 1;
		}
		//-- ### --
		tmpURL=tmpCommon.sysPage+"?ActionType=DMessage&DMessage=0,"+tmpMessage.sID+tmpCommon.sysSPLIT1+tmpMessage.sUserid;
		tmpMessage.sAjax_0.sFlag="";
		tmpMessage.sAjax_0.sPanel="";
		tmpMessage.sAjax_0.sURL=tmpURL;
		tmpMessage.sAjax_0.sendRequestSp(tmpURL,"Message_messageLIST_Callback()");
		//window.open(tmpURL,"_blank");
		//document.getElementById("Report").innerHTML=tmpURL;
		//http://127.0.0.1:8080/_PROGRAM/MYPROJECT/Project0/unionNets/Program/version_0.042/unionNets/User/project/_DemoCore/webSite/Plus/Common/Message/child_message.php?ActionType=DMessage&DMessage=0,0,2
	
	}else{}
	
}
function Message_messageLIST_Callback(){
	var tmpFlag=tmpMessage.sAjax_0.sFlag;
	var tmpPanel=document.getElementById(tmpMessage.sAjax_0.sPanel);
	var tmpURL=tmpMessage.sAjax_0.sURL;
	var tmpHttpRequests=tmpMessage.sAjax_0.sHttpRequests;
	//alert(tmpHttpRequests.responseText);
	if(tmpHttpRequests.readyState==4){
		//alert(tmpHttpRequests.responseText);
		var tmpData=getDataByFlag(tmpHttpRequests.responseText,"messageContent");
		//alert(tmpData);
		if(tmpData.indexOf("sendRequest")>=0 && tmpData!="<!--sendRequest-->"){
			document.getElementById("messageContent").innerHTML+=tmpData;
			
			window.scroll(0,document.body.scrollHeight);
			//document.getElementById("Report").innerHTML+="DONE+. ";
	    	//tmpFrames.showLoading(1);
	    }else{
	    	//tmpFrames.showLoading(1);
	    }
	}else{
		//tmpFrames.showLoading(0);
	}
}
//-- #MessageCountRefresh --
Message.prototype.messageCountRefresh=function(pURL){
	//-- #REQUEST --
	var tmpURL=pURL+"?CODE="+Math.random();
	this.sAjax_MessageCount.sFlag="";
	this.sAjax_MessageCount.sPanel="";
	this.sAjax_MessageCount.sURL=tmpURL;
	this.sAjax_MessageCount.sendRequestSp(tmpURL,"Message_messageCountDATA_Callback()");
	//window.open(tmpURL,"_blank");
	
	return 0;
}
function Message_messageCountDATA_Callback(){
	var tmpFlag=tmpMessage.sAjax_MessageCount.sFlag;
	var tmpPanel=document.getElementById(tmpMessage.sAjax_MessageCount.sPanel);
	var tmpURL=tmpMessage.sAjax_MessageCount.sURL;
	var tmpHttpRequests=tmpMessage.sAjax_MessageCount.sHttpRequests;
	//alert(tmpHttpRequests.responseText);
	if(tmpHttpRequests.readyState==4){
		//-- #REQUEST --
		var tmpTabBox=document.getElementById(tmpMessage.sMessageTab);
		var tmpXML=tmpCommon.analyzeXML(tmpHttpRequests.responseText);
		if(tmpXML.getElementsByTagName("Value")[0]==null){
			return 1;
		}
		var tmpSTR=tmpXML.getElementsByTagName("Value")[0].childNodes[0].nodeValue;
		if(tmpSTR=="NonMessage"){
			return 1;
		}
		
		Coun0=0;
		while(tmpXML.getElementsByTagName("dataRow").length>Coun0){
			Coun1=0;
			while(tmpTabBox.childNodes.length>Coun1){
				tmpElement0=tmpXML.getElementsByTagName("dataRow")[Coun0];
				if(tmpTabBox.childNodes[Coun0].id==(tmpMessage.sMessageTab_Head+tmpElement0.childNodes[2].childNodes[0].nodeValue)){
					if(parseInt(tmpElement0.childNodes[4].childNodes[0].nodeValue)>0){
						document.getElementById(tmpMessage.sMessageTab_Count_Head+tmpElement0.childNodes[2].childNodes[0].nodeValue).innerHTML="("+tmpElement0.childNodes[4].childNodes[0].nodeValue+")";
					}else{
						document.getElementById(tmpMessage.sMessageTab_Count_Head+tmpElement0.childNodes[2].childNodes[0].nodeValue).innerHTML="";
					}
				}
				Coun1++;
			}
			Coun0++;
		}
		
	}else{}
	
}

//-- #Submit --
Message.prototype.messageSetContact=function(pID,pUserid){
	parent.document.getElementById("metContactByTxt").value=pID;
	parent.document.getElementById("metRecieveByTxt").value=pUserid;
	window.scroll(0,document.body.scrollHeight);

}
Message.prototype.messageSubmit=function(){
	if(parent.document.getElementById("metRecieveByTxt").value<=0){
		//ERROR:User is NON
		parent.tmpFrames.showMessage("系统消息","请选择联系人","",0);
		return 1;
	}
	if(document.getElementById("mectContentTxt").value==""){
		//ERROR:Content is EMPTY
		parent.tmpFrames.showMessage("系统消息","消息内容不能为空","",0);
		return 1;
	}
	document.getElementById("messageSubmitFrame").src=tmpCommon.sysPage+"?ActionType=SUBMIT";

}
Message.prototype.messageOnSubmit=function(){
	var tmpAR0=new Array(
		"metCreateByTxt",
		"metContactByTxt",
		"metRecieveByTxt",
		"mectContentTxt");
	var Coun0=0;
	while(tmpAR0.length>Coun0){
		if(tmpAR0[Coun0]=="mectContentTxt"){
			document.getElementById(tmpAR0[Coun0]).value=parent.document.getElementById(tmpAR0[Coun0]).value;
		}else {
			document.getElementById(tmpAR0[Coun0]).value=parent.parent.document.getElementById(tmpAR0[Coun0]).value;
		}
		Coun0++;
	}
	
	parent.document.getElementById("mectContentTxt").value="";
	document.getElementById("phpForm1").submit();
	return 0;
}
 
 