	
	<!--
	
	
 
  function getCookie(c_name)
	{
		if (document.cookie.length>0)
	  {
	  c_start=document.cookie.indexOf(c_name + "=");
	  
	  if (c_start!=-1)
	    { 
	    c_start=c_start + c_name.length+1 
	    c_end=document.cookie.indexOf(";",c_start)
	    if (c_end==-1) c_end=document.cookie.length
	    return unescape(document.cookie.substring(c_start,c_end))
	    } 
	  }
		return "";
	}

	function setCookie(cookieVarName,cookieVal)
	{
		var cmd = cookieVarName+"="+cookieVal;
		document.cookie = cmd;
	}
	
	
	function change_hide_show_state(cookieflag)				
	{
		var current_state = cookieflag;
		if(current_state=="")
			current_state=0;
	
		state_hideArr = document.getElementsByName("state_hide");
		for(var i=0;i<state_hideArr.length;i++)
		{
			if(current_state==0)
				state_hideArr[i].style.display = 'none';
			else if(current_state==1)
				state_hideArr[i].style.display = 'inline';
		}
	
		state_showArr = document.getElementsByName("state_show");
		for(var i=0;i<state_showArr.length;i++)
		{
			if(current_state==1)
				state_showArr[i].style.display = 'none';
			else if(current_state==0)
				state_showArr[i].style.display = 'inline';
		}		
	}
	
	
	

  function change_comment_hide_show_state(changeID){
  	var cookieName = "showcommentflag_"+changeID;
  	var current_state = getCookie(cookieName);
		var commentName = "commentcontext_"+changeID;
		commentNameArr = document.getElementsByName(commentName);
		
		if(current_state==0)
		{
			commentNameArr[0].style.display='none';
		}
		else if(current_state==1)
		{
			commentNameArr[0].style.display='inline';
		}
	}
	
	function changecommentVar(changeID)
	{
		
		var cookieName = "showcommentflag_"+changeID;
		var current_state = getCookie(cookieName);
		if(current_state==0)
			setCookie(cookieName,1);
		else if(current_state==1)
			setCookie(cookieName,0);
		change_hide_show_state(getCookie(cookieName));
		change_comment_hide_show_state(changeID);
		
	}
	
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////	
	
	
	function openURL(strlink)
  { 
   location.href = "./index.php?option=com_opening&id=" + strlink+"&dynamic="+document.adminForm.dynamic.value+"&lang="+get_current_language();
  }  
	
	
	
	function redirect()
  {
  	location.href = "./index.php?option=com_opening&id=" + document.Query.id.value+"&lang="+get_current_language();
  }

	function comment_vote(comment_id)
	{
		location.href = "./index.php?option=com_opening&task=pushcomment&history_id=" + document.adminForm.history_id.value+"&comment_id="+comment_id+"&lang="+get_current_language();	
	}
  
  





  function get_blockpagelink(id,languageobj,currentpage,pagesize,totalnum,blocktagname,days)
  {
  	var res='<span class=pagelink style="float:left;position:relative;left:3%;">';
  	/*
  	if(currentpage<0)
  		res += languageobj.allpage+' | ';
  	else
  		res += '<a class=pagelink href="javascript:toPage( -1,'+id+',4 ,\''+blocktagname+'\','+days+')">'+languageobj.allpage+' | </a>';
		*/
		var start = parseInt(currentpage)-5;
		var end = parseInt(currentpage)+5;
		var start_hint=1;
		var end_hint=1 ;
		if(start<=1)
		{
			end = end + 5- parseInt(currentpage) ;
			start = 1; 
			start_hint=0;
		}
		if(end>=totalnum)
		{
			end=totalnum;
			end_hint=0;
		}

		if(start_hint)
			res +='......';

  	//for(i=1;i<=totalnum;i++)
  	for(i=start;i<=end;i++)
  	{
  		//if(i>parseInt(currentpage)-5&&i<parseInt(currentpage)+5)
  		if(i!=(currentpage))
  			res += '<a class=pagelink href="javascript:toPage('+i+','+id+','+pagesize+',\''+blocktagname+'\','+days+')">'+' ['+i+']</a>';
  		else
  			res += ' '+i;
  	} 
  	
  	if(end_hint)
			res +='......';
  	
  	return res+'</span>';
  }
   
  function get_blockhead(languageobj,currentpage,id,pagesize,totalnum,blocktagname,days)
  {
  	var res = '<div class="title" style = "width : 100%">';
  	res += '<span style="float:left">'+languageobj.title+'</span>';
  	res += get_blockpagelink(id,languageobj,currentpage,pagesize,totalnum,blocktagname,days);
  	res += get_blockheadRight(blocktagname,days,languageobj);
  	res += '</div>';
		return res;
  }
   
  function get_blockheadRight(blocktagname,days,languageobj)
  { 
   	var res='';
   	if(blocktagname!='CommentList')
   		res += BlockImgNumber(blocktagname,languageobj);
   	if(blocktagname=='Latestblock')
   	{  
   		res += submitchangeRecentDay(days,languageobj);
   	} 
   	else if(blocktagname=='CommentList')
   	{  
   		res += '<span style="float:right;"><a href="javascript:changeCommentlanguage(0)">'+languageobj.forum_only_chinese+'|</a><a href="javascript:changeCommentlanguage(1)">'+languageobj.forum_chinese_and_english+'</a></span>';
   		res += '<span style="float:right;margin-right: 1em;"><a href="./index.php?task=newcomment&option=com_opening&history_id='+document.adminForm.history_id.value+'&lang='+get_current_language()+'">'+languageobj.forum_add_new_comments+'</a></span>'; 
   		//res += '<span style="float:right;margin-right: 1em;"><a href="./index.php?task=newhistory&option=com_opening&history_id='+document.adminForm.history_id.value+'&lang='+get_current_language()+'">'+languageobj.add_new_history+'</a></span> '
   		
   	}
   	
   	return res;
  }
    
  function BlockImgNumber(blocktagname,languageobj)
  {  
   	var res = '';  
   	
   	var curNum = getCookie(blocktagname+'_ImgNumber');
   	var image_number = new Array("4","6","8","12","16");

  	res += '<form class="title" style="float:right;" method="POST" name="selectimagenumber">'+languageobj.show_pictures+'<select name="imagenumber" size="1" onchange="changeBlockImgNumber(this.value,\''+blocktagname+'\')">';
   	for(i=0;i<image_number.length;i++)
   	{
 
   		if(curNum==image_number[i])
   			res += '<option SELECTED value="'+image_number[i]+'">'+image_number[i]+'</option>';
   		else
   			res += '<option value="'+image_number[i]+'">'+image_number[i]+'</option>';
   	} 
   	res += '</select></form>';
   	return res;
  }  
   
  function changeBlockImgNumber(ImgNum,blocktagname)
  {  
   	setCookie(blocktagname+'_ImgNumber',ImgNum);
		toPage(1,document.adminForm.history_id.value,ImgNum,blocktagname,0);
  }
	
	
          
  function get_imagetitle(info,lang)
  { 
   	//res = '<span class=statelink><a href=./index.php?option=com_opening&id='+info.id+'>'+lang.imgtitle+info.id+info.status+'<br>'+info.historytitle+'</a></span>' ;
   	langtype = get_current_language();
   	switch(langtype)
   	{
   		case 'en':
   			if(info.historyenglishtitle=="" || info.historyenglishtitle==undefined)   
   				res = '<span class=statelink><a href="javascript:openURL('+info.id+')">'+lang.imgtitle+info.id+info.status+'</a></span>' ;
   			else
   				res = '<span class=statelink><a href="javascript:openURL('+info.id+')">'+lang.imgtitle+info.id+' &lt;'+info.historyenglishtitle+'&gt;'+info.status+'</a></span>' ;
   			break;
   		default:
   			if(info.historytitle=="" || info.historytitle==undefined)   
   				res = '<span class=statelink><a href="javascript:openURL('+info.id+')">'+lang.imgtitle+info.id+info.status+'</a></span>' ;
   			else
   				res = '<span class=statelink><a href="javascript:openURL('+info.id+')">'+lang.imgtitle+info.id+' &lt;'+info.historytitle+'&gt;'+info.status+'</a></span>' ;
   			break;
   	}
   	
   	
   	
   		
   
  	return res;
  }
  
  function get_frame_head()
  { 
   	return '<TABLE cellSpacing=0 cellPadding=0 style="width:100%"><TBODY><TR><TD class=frame_border_line><TABLE cellSpacing=1 cellPadding=6 style="width:100%"><TBODY><TR><TD class=frame_head>';
  	//return '<TABLE cellSpacing=0 cellPadding=0 style="width:100%"><TBODY><TR><TD class=frame_border_line ><TABLE cellSpacing=1 cellPadding=6 style="width:100%"><TBODY><TR><TD class=frame_head>';
  } 
  
	function get_frame_body()
  { 
   	return '</TD></TR><TR class=frame_body><TD>';
  	//return '</TD></TR><TR class=frame_body><TD>';
  } 
  function get_frame_end()
  { 
   	return '</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>';
  	//return '</TD></TR></TBODY></TABLE></TD></TR></TBODY></TABLE>';
  } 
  
  function get_commenttitle(langobj)
  { 
  	return '<div class="commenttitle"><span style="width:55%;">'+langobj.entrytitle+'</span><span style="width:15%;">'+langobj.author+'</span><span style="width:20%;">'+langobj.createtime+'</span><span style="width:5%;">'+langobj.recommend+'</span></div>';
  }
  
  
   
  function get_commententry(i,commentcount,Dataarray,languageflag)
  {
 
  	var res=""; 
  	if(commentcount%2==0)
  		res = '<div class="commententry">';
  	else
  		res = '<div class="commententry2">'; 
  	res += '<span style="width:10%;float:left;">';
		if(languageflag==0)			//chinese
 			res +=  Dataarray.language.entrytitle+' : '; 
 		else if(languageflag==1)			//chinese
 			res +=  Dataarray.language.entryenglishtitle+' : '; 

  	res += '</span>';
  	res += '<span style="width:40%;float:left;"><a href="javascript:changstate(commenttag'+commentcount+')">';
  	if(languageflag==0)			//chinese
  		res += Dataarray.info[i].title;
  	else if(languageflag==1)			//chinese
  		res += Dataarray.info[i].englishtitle;
  	res += '</a></span>'	
  	res += '<span style="float:left;width:15%;">';
  	res += Dataarray.info[i].author; 
  	res += ' / ';
  	res +=  Dataarray.info[i].inventor; 
  	res += '</span>'	
  	res += '<span style="float:left;width:20%;">';
  	res += Dataarray.info[i].createtime;
  	res += '</span>'	
  	
  	
  	
  	if(Dataarray.info[i].auth==1)
  	{
			  	if(Dataarray.info[i].canpush==1)
					{
						res += '<span style="float:left;width:5%;">'; 	
						res += '<a href="javascript:comment_vote('+Dataarray.info[i].comment_id+')">'+Dataarray.language.recommend+'</a>';
						res += '|'+Dataarray.info[i].recommendcount ;
						res += '</span>';
					}
					else
					{
						res += '<span style="float:left;width:5%;"><center>'; 	
						res += Dataarray.language.recommend+'|'+Dataarray.info[i].recommendcount ;
						res += '</center></span>';
					} 
			  	if(Dataarray.info[i].canchangeedit==1)
			  	{
				  	res += '<span style="float:left;width:5%;">'; 
				  	res += '<a href="./index.php?option=com_opening&task=unpublishcomment&history_id='+Dataarray.history_id+'&comment_id='+Dataarray.info[i].comment_id+'">'+Dataarray.language.deletebutton+'</a>';
				  	//res += '<a href="./index.php?option=com_opening&task=editcomment&history_id='+Dataarray.history_id+'&comment_id='+Dataarray.info[i].comment_id+'"><img src="./images/M_images/edit.png"  alt="edit" name="edit" align="middle" border="0" /></a>';
				  	//res += '<a href="./index.php?option=com_opening&task=editcomment&history_id='+Dataarray.history_id+'&comment_id='+Dataarray.info[i].comment_id+'">Edit</a>';
				  	res += '</span>';
				  }
	  }
  	
  	
  	res += '</div>';
  	return res;
  }
    
  function get_imageblock(id,movelist,filter)
  {    
   	return '<div class="imageblock"><img class="button" name="chessboardimg" onclick="javascript:openURL('+id+')" src="http://www.connect6.org/web/components/com_opening/showboard/Board.php?input='+movelist+'&by=0&format=simplesgf&filter='+filter+'&b_i=0" border="0"></div>';
  	//return '<div class="imageblock"><img src="http://java.csie.nctu.edu.tw/~jtfang/web/components/com_opening/showboard/Board.php?input='+movelist+'&size=170&filter=0&b_i=0" border="0"></div>';		
  }

	function get_current_language()
	{
		langtype = new String();
		//get langtype form cookie;
		c_name = "mbfcookie[lang]=";
		if (document.cookie.length>0)
	    {
		    c_start=document.cookie.indexOf(c_name);
		    if (c_start!=-1)
		    { 
		    	c_start=c_start + c_name.length;
		    	c_end = c_start + 2;
		    	langtype = unescape(document.cookie.substring(c_start,c_end));
	  		} 
		}
		return langtype;
	}

  function toPage(pagenumber,id,pagesize,blocktagname,days)
  {  
   	pagesize=getCookie(blocktagname+'_ImgNumber');
   	if(pagesize=="")
   	{
			setCookie(blocktagname+'_ImgNumber',16);
			pagesize=16;
   	} 
   	sendRequest(loadPage, 
  	'&option=com_opening&changeblock=1&page='+pagenumber+'&id='+id+'&pagesize='+pagesize+'&blocktagname='+blocktagname+'&days='+days+'&lang='+get_current_language(),  
  	'POST',
  	'./index.php',
  	true,
  	true
      )
   	
   	/*
  	sendRequest(loadPage, 
  	'',  
  	'GET',
  	'./index.php?option=com_opening&nextpage=1&page='+pagenumber+'&id='+id+'&pagesize='+pagesize+'&blocktagname='+blocktagname,
  	true,
  	true
      )
       */
   
  }
  //./components/com_opening/getNextIDPage.php
  //./index.php?option=com_opening
  
  function loadPage(oj)
  {
    var res  =  decodeURIComponent(oj.responseText)
    //alert(res);
    eval('var ary='+res) ;
     //alert(ary.language.keyword_state);
    //alert(ary.info[0].movelist);
     //alert(ary.blocktagname);
      
    if(ary.blocktagname=='CommentList') 
     	changeCommentBlock(ary);
    else
    	changeImgBlock(ary);
     
    
  }
  
 
   
	function changeCommentBlock(Dataarray)
  {
  	var commentlist = document.getElementById(Dataarray.blocktagname);	
  	var newblock = '';
  	newblock += get_frame_head();
  	newblock += get_blockhead(Dataarray.language,Dataarray.currentpage,Dataarray.history_id,Dataarray.pagesize,Dataarray.total,Dataarray.blocktagname,Dataarray.days);
  	newblock += get_frame_body(); 	
  	//newblock += get_commenttitle(Dataarray.language);
  	//newblock += '<span style="float:left"><hr style="color: #9e9ed7;height:2px;width	: 100%;"></hr></span>';   
  	
  	for(var i=0,j=0;i<Dataarray.info.length;i++,j+=2)
  	{   
  			if(get_current_language()=='en')
	  			newblock += get_commententry(i,j,Dataarray,1);
	  		else
	  			newblock += get_commententry(i,j,Dataarray,0);
	  		newblock += '<span id="commenttag'+j+'" style="width:95%;float:left;position:relative;left:5%;display:inline;">';
	  		if(get_current_language()=='en')
	  			newblock += Dataarray.info[i].englishcomment;
	  		else
	  			newblock += Dataarray.info[i].comment;
	  		
	  		//newblock += Dataarray.info[i].englishcomment;
	  		newblock += '</span>';    
	  		if(!(document.adminForm.commentlanguage.value==0 && i==Dataarray.info.length-1))newblock += '<div class="spacer"></div><hr style="color: #9e9ed7;height:2px;width	: 100%;float:left;"></hr>';
  		  
  		if(document.adminForm.commentlanguage.value==1)
  		{
  			if(get_current_language()=='en')
	  			newblock += get_commententry(i,(parseInt(j)+1),Dataarray,0);
	  		else
	  			newblock += get_commententry(i,(parseInt(j)+1),Dataarray,1);
	  		newblock += '<span id="commenttag'+(parseInt(j)+1)+'" style="width:95%;float:left;position:relative;left:5%;display:inline;">';
	  		if(get_current_language()=='en')
	  			newblock += Dataarray.info[i].comment;
	  		else
	  			newblock += Dataarray.info[i].englishcomment;
	  		
	  		newblock += '</span>';     
	  		if(i!=Dataarray.info.length-1)newblock += '<div class="spacer"></div><hr style="color: #9e9ed7;height:2px;width	: 100%;float:left;"></hr>';   
	  	}
			


  	} 
  	newblock += get_frame_end();
  	commentlist.innerHTML = newblock;
  }    
     




             
  function changeImgBlock(Dataarray)
  {
  	var img = document.getElementById(Dataarray.blocktagname);
  	var newblock = ''; 
  	if(Dataarray.info.length==0&&Dataarray.blocktagname!='Latestblock')
  	{ 
  		img.innerHTML = newblock;		
  		img.style.display='none';  	
  		return;	
  	}
  	newblock += get_frame_head();
  	newblock += get_blockhead(Dataarray.language,Dataarray.currentpage,Dataarray.history_id,Dataarray.pagesize,Dataarray.total,Dataarray.blocktagname,Dataarray.days);
  	newblock += get_frame_body();
  	for(var i=0;i<Dataarray.info.length;i++)
  	{
			newblock += '<div class=imageblockandlink>';
			var _title = get_imagetitle(Dataarray.info[i] , Dataarray.language);  
			var _imageblock = ''
			if(Dataarray.blocktagname=='Latestblock')
				_imageblock = get_imageblock(Dataarray.info[i].id,Dataarray.info[i].movelist, 0);
			else
				_imageblock = get_imageblock(Dataarray.info[i].id,Dataarray.info[i].movelist, document.adminForm.movecount.value);
			newblock += _title + _imageblock;
			newblock += '</div>';
		} 
		
		
		
		
		if(Dataarray.info.length==0)
			newblock += '<div >無</div>';
		else if(Dataarray.total>Dataarray.currentpage)
			newblock += getMoreButton(Dataarray) ;
		
		newblock += '<div class="spacer"></div>';
		
		newblock += get_frame_end();
		
		img.innerHTML = newblock;		  	
  }
	
	function getMoreButton(Dataarray)
	{
		res = '';
		//res += '<div style=" width :100%;BORDER: 5px outset red;" class=imageblockandlink>';
		//res += '<div style=" width :100%;" class=imageblockandlink>';
		res += '<div style="width :10 px ; height:240 px; padding-left:10 px;padding-top:120 px;font-weight: bold;" >';
		res += '<a href="javascript:toPage('+(parseInt(Dataarray.currentpage)+1)+','+Dataarray.history_id+','+Dataarray.pagesize+',\''+Dataarray.blocktagname+'\',0)">more</>';
		res += '</div>';
		return res;
	}
	
	
  function changstate(commenttagobj)
  { 
   	if(commenttagobj.style.display == 'none')
   		commenttagobj.style.display  = 'inline';
   	else if(commenttagobj.style.display == 'inline')
   		commenttagobj.style.display  = 'none';
   	
  }
   
   
  function changeRecentDay(days)
  { 
  	//alert(document.adminForm.history_id.value);
  	toPage(1,document.adminForm.history_id.value,4,'Latestblock',days);
  }
   
  function submitchangeRecentDay(days,languageobj)
  {  
   	var res = ''; 
   	var days_arr=new Array("1","2","3","5","7","14");
   	res += '<form class="title" style="float:right;" method="POST" name="recentday">'+languageobj.recent+'<select name="days" size="1" onchange="changeRecentDay(this.value)">';
   	for(i=0;i<days_arr.length;i++)
   	{ 
   		if(days==days_arr[i])
   			res += '<option SELECTED value="'+days_arr[i]+'">'+days_arr[i]+languageobj.day+'</option>';
   		else
   			res += '<option value="'+days_arr[i]+'">'+days_arr[i]+languageobj.day+'</option>';
   	}
   	res += '</select></form>';
   	return res;
  }

  function changeCommentlanguage(tmp)
  {  
  	//document.adminForm.commentlanguage.value = (parseInt(document.adminForm.commentlanguage.value) + 1)%2;
  	document.adminForm.commentlanguage.value  = tmp;
  	toPage(1,document.adminForm.history_id.value,4,'CommentList',0);
   	
  }
	
	function MirrorImage(historyid)
	{ 
		 document.adminForm.imgmirror.value = (parseInt(document.adminForm.imgmirror.value)+1)%2;
		 location.href = "./index.php?option=com_opening&id=" + historyid + "&imgmirror="+document.adminForm.imgmirror.value+"&lang="+get_current_language();
	}
	
	function Dynamic_change(historyid)
	{
 		 document.adminForm.dynamic.value = (parseInt(document.adminForm.dynamic.value)+1)%2;
		 location.href = "./index.php?option=com_opening&id=" + historyid + "&dynamic="+document.adminForm.dynamic.value+"&lang="+get_current_language();
	}
	
	
	
	
	//-->
