// JavaScript Document
var filepagecut="module/ajax_pagecutrpl.php";
//Page Cut
function $(id){return document.getElementById(id);}
function $name(name){return document.getElementsByName(name);};
function $value(node,name){try{return node.getElementsByTagName(name)[0].firstChild.nodeValue;}catch(e){return "";}}
function numberFormat(number){
	number += '';
	x = number.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}
function spacialChar(txt){
	txt = txt.replace(/\\u000a/g,"<br>");
	txt = txt.replace(/\\u003c/g,"<");
	txt = txt.replace(/\\u003e/g,">");
	txt = txt.replace(/\\u0026/g,"&");
	txt = txt.replace(/\\/g,"");
	return txt;
}
function thispagerpl(tvID,thispage,rowPerPage,allPage,nextPage,pagePerGroup,allRpl1,rplTo){
	cp.call(filepagecut,'getNextGroup',resThispagerpl,tvID,thispage,rowPerPage,allPage,nextPage,pagePerGroup,rplTo);
	
	var thisGroup=Math.ceil(thispage/pagePerGroup);
	var allGroup=Math.ceil(allPage/pagePerGroup);
	var numberGroupHTML="";
	if(thisGroup>1&&allGroup>1){
		var limit=((((thisGroup-2)*pagePerGroup+1)-1)*rowPerPage)+","+rowPerPage;
		numberGroupHTML+="<img src=\"images/icon/btn_first.gif\" title=\""+lgFirstPage+"\" id=\"pageFitst\" onclick=\"thispagerpl("+tvID+",1,"+rowPerPage+","+allPage+",'0,"+rowPerPage+"',"+pagePerGroup+","+allRpl1+",'"+rplTo+"');\" style=\"cursor:pointer;\" />&nbsp;";
		numberGroupHTML+="<img src=\"images/icon/btn_previous.gif\" title=\""+lgPrevious+"\" id=\"pagePrevious\" onclick=\"thispagerpl("+tvID+","+((thisGroup-2)*pagePerGroup+1)+","+rowPerPage+","+allPage+",'"+limit+"',"+pagePerGroup+","+allRpl1+",'"+rplTo+"');\" style=\"cursor:pointer;\" />&nbsp;";
	}else{
		numberGroupHTML+="<img src=\"images/icon/btn_first.gif\" title=\""+lgFirstPage+"\" id=\"pageFitst\" />&nbsp;";
		numberGroupHTML+="<img src=\"images/icon/btn_previous.gif\" title=\""+lgPrevious+"\" id=\"pagePrevious\" />&nbsp;";
	}
	for(i=1;(i<=pagePerGroup)&&(i+pagePerGroup*(thisGroup-1)<=allPage);i++){
		if(i+pagePerGroup*(thisGroup-1)==thispage){
			numberGroupHTML+="<font id=\"pageNum"+(i+pagePerGroup*(thisGroup-1))+"\" style=\"font-weight:bold; color:#FF0000;\">"+(i+pagePerGroup*(thisGroup-1))+"</font>&nbsp;";
		}else{
			var limit=(((i+pagePerGroup*(thisGroup-1))-1)*rowPerPage)+","+rowPerPage;
			numberGroupHTML+="<a href=\"javascript:void(0);\" id=\"pageNum"+(i+pagePerGroup*(thisGroup-1))+"\" onclick=\"thispagerpl("+tvID+","+(i+pagePerGroup*(thisGroup-1))+","+rowPerPage+","+allPage+",'"+limit+"',"+pagePerGroup+","+allRpl1+",'"+rplTo+"');\">"+(i+pagePerGroup*(thisGroup-1))+"</a>&nbsp;";
		}
	}
	if(thisGroup<allGroup&&allGroup>1){
		var limit=(((thisGroup*pagePerGroup+1)-1)*rowPerPage)+","+rowPerPage;
		var lastLimit=((allRpl1-rowPerPage)-1)+","+rowPerPage;
		numberGroupHTML+="<img src=\"images/icon/btn_next.gif\" title=\""+lgNext+"\" id=\"pageNext\" style=\"cursor:pointer;\"";
		numberGroupHTML+="onclick=\"thispagerpl("+tvID+","+(thisGroup*pagePerGroup+1)+","+rowPerPage+","+allPage+",'"+limit+"',"+pagePerGroup+","+allRpl1+",'"+rplTo+"');\" />&nbsp;";
		numberGroupHTML+="<img src=\"images/icon/btn_last.gif\" title=\""+lgLastPage+"\" id=\"pageLast\" style=\"cursor:pointer;\"";
		numberGroupHTML+="onclick=\"thispagerpl("+tvID+","+((allPage-pagePerGroup)+1)+","+rowPerPage+","+allPage+",'"+lastLimit+"',"+pagePerGroup+","+allRpl1+",'"+rplTo+"');\" />&nbsp;";
	}else{
		numberGroupHTML+="<img src=\"images/icon/btn_next.gif\" title=\""+lgNext+"\" id=\"pageNext\" />&nbsp;";
		numberGroupHTML+="<img src=\"images/icon/btn_last.gif\" title=\""+lgLastPage+"\" id=\"pageLast\" />";
	}
	$('pageNumberGroup').innerHTML=numberGroupHTML;
}
function resThispagerpl(result){
	//Check User login
	var sessuserID=$('sessionID').value;
	var sessuserDis=$('sessionDIS').value;
	//All Comment Group
	var comment=result.getElementsByTagName('comment')[0];
	var pageNumber=comment.getAttribute('id');
	var tvID=comment.getAttribute('tvID');
	var allPage=comment.getAttribute('allPage');
	var pagePerGroup=comment.getAttribute('pagePerGroup');
	//Set Font Number
//	$('pageNum'+pageNumber).style.cssText="font-weight:bold; color:#FF0000;";
	//Finish Set Font Number
	var rpl1items=comment.getElementsByTagName('rpl1items');
	for(var i1=0;i1<rpl1items.length;i1++){
		//Clear Box Comment
		if(i1==0){
			$('boxAllCM').innerHTML="<center><img src=\"images/icon/loading2.gif\" /></center>";
		}
		var rpl1itemsID=rpl1items[i1].getAttribute('id');
		var fmbID1=$value(rpl1items[i1],'fmbID1');
		var name1=spacialChar($value(rpl1items[i1],'name1'));
		var homepage1=spacialChar($value(rpl1items[i1],'homepage1'));
		var date1=$value(rpl1items[i1],'date1');
		var detail1=spacialChar($value(rpl1items[i1],'detail1'));
//		alert("rpl1itemsID = "+rpl1itemsID+"\n fmbID1 = "+fmbID1+"\n name1 = "+name1+"\n homepage1 = "+homepage1+"\n date1 = "+date1+"\n detail1 = "+detail1);

		//HTML Inner
		boxRplHTML="";
		boxRplHTML+="<div class=\"floatLeft txtCMname\">";
		if(sessuserID!=""||sessuserID!=0){
			boxRplHTML+="<a href=\"javascript:void(0)\" onclick=\"return isCard.start(this,"+sessuserID+",event);\" style=\"color:#3770A7\">";
			boxRplHTML+=""+name1+"</a>";
		}else if(homepage1){
			boxRplHTML+="<a href=\""+homepage1+"\" target=\"_blank\" style=\"color:#3770A7\">";
			boxRplHTML+=""+name1+"</a>";
		}else{
			boxRplHTML+=""+name1+"";
		}
		boxRplHTML+="</div>";
		boxRplHTML+="<div class=\"floatRight txtCMTime\">"+date1+"&nbsp;&nbsp;<span class=\"txtCMEdit\">";
		boxRplHTML+="&nbsp;<a href=\"javascript:void(0);\" onClick=\"inputDelCM('1',"+rpl1itemsID+");\">"+lgDelete+"</a>";
		boxRplHTML+="&nbsp;|&nbsp;<a href=\"javascript:void(0);\" onClick=\"inputEdit('1',"+rpl1itemsID+");\">"+lgEdit+"</a>";
		boxRplHTML+="&nbsp;|&nbsp;<a href=\"javascript:void(0);\" onClick=\"showBoxRpl(1,"+rpl1itemsID+");\">"+lgReply+"</a>";
		boxRplHTML+="</span></div>";
		boxRplHTML+="<div class=\"clear\"></div>";
		boxRplHTML+="<div class=\"txtCMDetail\" id=\"boxRplDetail1"+rpl1itemsID+"\">"+detail1+"</div>";
		boxRplHTML+="<div class=\"bCommentBG\" id=\"boxInputRpl1_"+rpl1itemsID+"\" style=\"display:none;\">";
		
		boxRplHTML+="<div class=\"\"><div class=\"floatLeft cmName\">&nbsp;&nbsp;</div>";
		boxRplHTML+="<div class=\"floatLeft txtCMTime\">";
		if(sessuserID==""||sessuserID==0){
		boxRplHTML+="<a href=\"http://member.mediathai.net/\" target=\"_blank\">"+lgRegister+"</a>&nbsp;|&nbsp;";
		boxRplHTML+="<a href=\"javascript:void(0);\" onClick=\"chklogin('"+sessuserID+"','"+pathLogin+"'); return false;\">";
		boxRplHTML+=""+lgLogin+"</a>";
		}
		boxRplHTML+="</div>";
		boxRplHTML+="<div class=\"clear\"></div></div>";
		boxRplHTML+="<div class=\"\"><div class=\"floatLeft cmName\">"+lgName+"&nbsp;:</div><div class=\"floatLeft\">";
		if(sessuserID!=""||sessuserID!=0){
			boxRplHTML+="<input type=\"taxt\" class=\"inputCM\" id=\"name2"+rpl1itemsID+"\" value=\""+name1+"\" readonly=\"true\" />";
		}else{
			boxRplHTML+="<input type=\"taxt\" class=\"inputCM\" id=\"name2"+rpl1itemsID+"\" />";
		}
		boxRplHTML+="</div><div class=\"clear\"></div></div>";
		boxRplHTML+="<div class=\"\"><div class=\"floatLeft cmName\">"+lgPassword+"&nbsp;:</div><div class=\"floatLeft\">";
		if(sessuserID!=""||sessuserID!=0){
			boxRplHTML+="<input type=\"password\" class=\"inputCM\" id=\"pass2"+rpl1itemsID+"\" value=\"********\" readonly=\"true\" />";
		}else{
			boxRplHTML+="<input type=\"password\" class=\"inputCM\" id=\"pass2"+rpl1itemsID+"\" />";
		}
		boxRplHTML+="</div><div class=\"clear\"></div></div>";
		boxRplHTML+="<div class=\"\"><div class=\"floatLeft cmName\">"+lgHomepage+"&nbsp;:</div><div class=\"floatLeft\"><div class=\"\">";
		if(sessuserID!=""||sessuserID!=0){
			boxRplHTML+="<input type=\"taxt\" class=\"inputCM\" id=\"homepage2"+rpl1itemsID+"\" readonly=\"true\" />";
		}else{
			boxRplHTML+="<input type=\"taxt\" class=\"inputCM\" id=\"homepage2"+rpl1itemsID+"\" value=\"http://\" />";
		}
		boxRplHTML+="</div><div class=\"clear\"></div></div>";
		boxRplHTML+="<div class=\"\"><div class=\"floatLeft cmName\">"+lgDescription+"&nbsp;:</div><div class=\"floatLeft\">";
		boxRplHTML+="<textarea class=\"textareaCM\" id=\"description2"+rpl1itemsID+"\"></textarea></div><div class=\"clear\"></div></div>";
		boxRplHTML+="<div class=\"\"><div class=\"floatLeft cmName\">&nbsp;&nbsp;</div><div class=\"floatLeft\">";
		boxRplHTML+="<input type=\"button\" id=\"bttCM2\" value=\""+lgPost+"\" style=\"vertical-align:middle;\" onClick=\"Reply2('2',"+rpl1itemsID+","+tvID+")\" /></div>";
		boxRplHTML+="<div class=\"clear\"></div></div></div>";
		boxRplHTML+="<div class=\"clear\"></div>";
		
		//Clear Box Comment
		if(i1==0){
			$('boxAllCM').innerHTML="";
		}
		//Create New Box Node
		boxNode=document.createElement('div');
		boxNode.id="boxRpl1"+rpl1itemsID;
		boxNode.className="bDComment";
		//Add Node
		boxNode.innerHTML=boxRplHTML;
		if(i1==0){
			$('boxAllCM').insertBefore(boxNode,$('boxAllCM').lastChild);
		}else{
			$('boxAllCM').insertBefore(boxNode,$('boxAllCM').lastChild.nextSibling);
		}

		var rpl2items=rpl1items[i1].getElementsByTagName('rpl2items');
		if(rpl2items.length>0){
			for(var i2 =0;i2<rpl2items.length;i2++){
				var rpl2itemsID = rpl2items[i2].getAttribute('id');
				var fmbID2 = $value(rpl2items[i2],'fmbID2');
				var name2 = spacialChar($value(rpl2items[i2],'name2'));
				var homepage2 = spacialChar($value(rpl2items[i2],'homepage2'));
				var date2 = $value(rpl2items[i2],'date2');
				var detail2 = spacialChar($value(rpl2items[i2],'detail2'));
//				alert("rpl2itemsID = "+rpl2itemsID+"\n fmbID2 = "+fmbID2+"\n name2 = "+name2+"\n homepage2 = "+homepage2+"\n date2 = "+date2+"\n detail2 = "+detail2);

				boxRplHTML="";
				boxRplHTML+="<div class=\"floatLeft txtCMname\">";
				if(sessuserID!=""||sessuserID!=0){
					boxRplHTML+="<a href=\"javascript:void(0)\" onclick=\"return isCard.start(this,"+sessuserID+",event);\" style=\"color:#3770A7\">";
					boxRplHTML+=""+name2+"</a>";
				}else if(homepage2){
					boxRplHTML+="<a href=\""+homepage2+"\" target=\"_blank\" style=\"color:#3770A7\">";
					boxRplHTML+=""+name2+"</a>";
				}else{
					boxRplHTML+=""+name2+"";
				}
				boxRplHTML+="</div>";
				boxRplHTML+="<div class=\"floatRight txtCMTime\">"+date2+"&nbsp;&nbsp;<span class=\"txtCMEdit\">";
				boxRplHTML+="&nbsp;<a href=\"javascript:void(0);\" onClick=\"inputDelCM('2',"+rpl2itemsID+");\">"+lgDelete+"</a>";
				boxRplHTML+="&nbsp;|&nbsp;<a href=\"javascript:void(0);\" onClick=\"inputEdit('2',"+rpl2itemsID+");\">"+lgEdit+"</a>";
				boxRplHTML+="&nbsp;|&nbsp;<a href=\"javascript:void(0);\" onClick=\"showBoxRpl(2,"+rpl2itemsID+");\">"+lgReply+"</a>";
				boxRplHTML+="</span></div>";
				boxRplHTML+="<div class=\"clear\"></div>";
				boxRplHTML+="<div class=\"txtCMDetail\" id=\"boxRplDetail2"+rpl2itemsID+"\">"+detail2+"</div>";
				boxRplHTML+="<div class=\"bCommentBG2\" id=\"boxInputRpl2_"+rpl2itemsID+"\" style=\"display:none;\">";
				
				boxRplHTML+="<div class=\"\">";
				boxRplHTML+="<div class=\"floatLeft cmName\">&nbsp;&nbsp;</div>";
				boxRplHTML+="<div class=\"floatLeft txtCMTime\">";
				if(sessuserID==""||sessuserID==0){
				boxRplHTML+="<a href=\"http://member.mediathai.net/\" target=\"_blank\">"+lgRegister+"</a>&nbsp;|&nbsp;";
				boxRplHTML+="<a href=\"javascript:void(0);\" onClick=\"chklogin('"+sessuserID+"','"+pathLogin+"'); return false;\">";
				boxRplHTML+=""+lgLogin+"</a>";
				}
				boxRplHTML+="</div>";
				boxRplHTML+="<div class=\"clear\"></div></div>";
				boxRplHTML+="<div class=\"\"><div class=\"floatLeft cmName\">"+lgName+"&nbsp;:</div><div class=\"floatLeft\">";
				if(sessuserID!=""||sessuserID!=0){
					boxRplHTML+="<input type=\"text\" id=\"name3"+rpl2itemsID+"\" class=\"inputCM2\" value=\""+name2+"\" readonly=\"true\"/>";
				}else{
					boxRplHTML+="<input type=\"text\"  id=\"name3"+rpl2itemsID+"\"class=\"inputCM2\"/>";
				}
				boxRplHTML+="</div><div class=\"clear\"></div></div>";
				boxRplHTML+="<div class=\"\"><div class=\"floatLeft cmName\">"+lgPassword+"&nbsp;:</div><div class=\"floatLeft\">";
				if(sessuserID!=""||sessuserID!=0){
					boxRplHTML+="<input type=\"password\" id=\"pass3"+rpl2itemsID+"\" class=\"inputCM2\" value=\"********\" readonly=\"true\" />";
				}else{
					boxRplHTML+="<input type=\"password\" id=\"pass3"+rpl2itemsID+"\" class=\"inputCM2\" />";
				}
				boxRplHTML+="</div><div class=\"clear\"></div></div>";
				boxRplHTML+="<div class=\"\"><div class=\"floatLeft cmName\">"+lgHomepage+"&nbsp;:</div><div class=\"floatLeft\">";
				if(sessuserID!=""||sessuserID!=0){
					boxRplHTML+="<input type=\"taxt\" class=\"inputCM2\" id=\"homepage3"+rpl2itemsID+"\" value=\"http://\" readonly=\"true\" />";
				}else{
					boxRplHTML+="<input type=\"taxt\" class=\"inputCM2\" id=\"homepage3"+rpl2itemsID+"\" />";
				}
				boxRplHTML+="</div><div class=\"clear\"></div></div>";
				boxRplHTML+="<div class=\"\">";
				boxRplHTML+="<div class=\"floatLeft cmName\">"+lgDescription+"&nbsp;:</div><div class=\"floatLeft\">";
				boxRplHTML+="<textarea name=\"description3"+rpl2itemsID+"\" id=\"description3"+rpl2itemsID+"\" class=\"textareaCM2\"></textarea>";
				boxRplHTML+="</div><div class=\"clear\"></div></div>";
				boxRplHTML+="<div class=\"\"><div class=\"floatLeft cmName\">&nbsp;&nbsp;</div><div class=\"floatLeft\">";
				boxRplHTML+="<input type=\"button\" id=\"bttCM3\" value=\""+lgPost+"\" onClick=\"Reply3('3',"+rpl1itemsID+","+rpl2itemsID+","+tvID+")\" style=\"vertical-align:middle;\"/>";
				boxRplHTML+="</div><div class=\"clear\"></div></div></div><div class=\"clear\"></div>";
				
				//Create New Box Node
				boxNode=document.createElement('div');
				boxNode.id="boxRpl2"+rpl2itemsID;
				boxNode.className="bDComment2";
				//Add Node
				boxNode.innerHTML=boxRplHTML;
				$('boxRpl1'+rpl1itemsID).insertBefore(boxNode,$('boxRpl1'+rpl1itemsID).lastChild.nextSibling);

				var rpl3items=rpl2items[i2].getElementsByTagName('rpl3items');
				if(rpl3items.length>0){
					for(var i3 =0;i3<rpl3items.length;i3++){
						var rpl3itemsID = rpl3items[i3].getAttribute('id');
						var fmbID3 = $value(rpl3items[i3],'fmbID3');
						var name3 = spacialChar($value(rpl3items[i3],'name3'));
						var homepage3 = spacialChar($value(rpl3items[i3],'homepage3'));
						var date3 = $value(rpl3items[i3],'date3');
						var detail3 = spacialChar($value(rpl3items[i3],'detail3'));
//						alert("rpl3itemsID = "+rpl3itemsID+"\n fmbID3 = "+fmbID3+"\n name3 = "+name3+"\n homepage3 = "+homepage3+"\n date3 = "+date3+"\n detail3 = "+detail3);

						boxRplHTML="";
						boxRplHTML+="<div class=\"floatLeft txtCMname\">";
						if(sessuserID!=""||sessuserID!=0){
							boxRplHTML+="<a href=\"javascript:void(0)\" onclick=\"return isCard.start(this,"+sessuserID+",event);\" style=\"color:#3770A7\">";
							boxRplHTML+=""+name3+"</a>";
						}else if(homepage3){
							boxRplHTML+="<a href=\""+homepage3+"\" target=\"_blank\" style=\"color:#3770A7\">";
							boxRplHTML+=""+name3+"</a>";
						}else{
							boxRplHTML+=""+name3+"";
						}
						boxRplHTML+="</div>";
						boxRplHTML+="<div class=\"floatRight txtCMTime\">"+date3+"&nbsp;&nbsp;<span class=\"txtCMEdit\">";
						boxRplHTML+="&nbsp;<a href=\"javascript:void(0);\" onClick=\"inputDelCM('3',"+rpl3itemsID+");\">"+lgDelete+"</a>";
						boxRplHTML+="&nbsp;|&nbsp;<a href=\"javascript:void(0);\" onClick=\"inputEdit('3',"+rpl3itemsID+");\">"+lgEdit+"</a></span></div>";
						boxRplHTML+="<div class=\"clear\"></div>";
						boxRplHTML+="<div class=\"txtCMDetail\" id=\"boxRplDetail3"+rpl3itemsID+"\">"+detail3+"</div>";
						boxRplHTML+="<div class=\"clear\"></div>";
						
						//Create New Box Node
						boxNode=document.createElement('div');
						boxNode.id="boxRpl3"+rpl3itemsID;
						boxNode.className="bDComment3";
						//Add Node
						boxNode.innerHTML=boxRplHTML;
						$('boxRpl2'+rpl2itemsID).insertBefore(boxNode,$('boxRpl2'+rpl2itemsID).lastChild.nextSibling);
					}
				}
			}
		}
	}
}

