
//var  webpath="http://test1.morgenstern.com.tw/users/";
var  xmldata = null;
var  current_layer = null;
var  path = null;
var  currentnum = null;
var  contentnum;
var  width = null;
var  height = null;
var  info = null;

var  rownum = null;
var  colnum = null;
var  pathencode= null;
var  resetFile = null; 		//G5-003
var  set_layer = null; 		//H7-004
var  set_focus = null; 		//H7-004 
var  numoflayer = null;		//H7-004 
var  focused_content = null;	//H7-006
/*
var  describe = null;
var  uploader = null;
var  uploadtime = null;
var  title = null;
*/

//G5-000 start ********

var convFlash = null; //converted flash file name
var convPdf = null;   //converted flash file name 
var convSnapshot = null;  //converted flash file name

var sBrowser = browserdetect();
function browserdetect()
{
  if($.browser.msie)
    return "IE";
  if($.browser.mozilla)
    return "Mozilla";
  if($.browser.safari)
    return "Safari";
  if($.browser.opera)
    return "Opera";
  else
    return "Unknown Browser"
}
//window.onload = function(){
//  alert(sBrowser);
//}

//H7-019 start
if($.browser.msie){
	var is_IE = 1;	//browser is IE
}else{
	var is_IE = 0;	//browser is Not IE
}
//H7-019 end

//G5-000 end  *********

//==========Programe for Self-Portrait Advertisement===================================================
var menuheight=60
function ChangePic(e,pic){
    jQuery(e).attr('src','./img/'+pic)
  fixPng(e)
}

function Close_Layout_AD(){
   jQuery('#ad_background').remove();
   jQuery('#ad_content').remove();
   jQuery('#ad_menu').remove();
  
  jQuery("iframe[isoffice='yes']").each(function() {
        if($(this).attr('isonad')!="yes" && $(this).attr('pre_content_isoffice')=="yes"){
          ori_path=$(this).attr('ori_path')
        $(this).attr('src',ori_path)      
    }
  }); 
  jQuery("iframe[isflash='yes']").each(function() {
        if($(this).attr('isonad')!="yes" && $(this).attr('pre_content_isflash')=="yes"){
          ori_path=$(this).attr('ori_path')
        $(this).attr('src',ori_path)      
    }
  });   
   
}
function Fit_Layout_AD(){
  widthall = Math.ceil($(document.body).width()); 
  heightall  = Math.ceil($(document.body).attr('clientHeight'));  

     
    //先加上背景半透明遮罩變動大小
    $('#ad_background').css('top',menuheight-5)
    $('#ad_background').css('left',0)   
    $('#ad_background').css('width',widthall)
    $('#ad_background').css('height',heightall-menuheight+5)
    
    //廣告的功能列layout變動位置
    admenuwidth=100
    admenuheight=50
    admenutop=menuheight+10
    admenuleft=widthall-admenuwidth   
    $('#ad_menu').css('top',admenutop)
    $('#ad_menu').css('left',admenuleft)    
    $('#ad_menu').css('width',admenuwidth)
    $('#ad_menu').css('height',admenuleft)    
    
  if(document.getElementById('ad_iframe')){
    ad_iframe_width=Math.ceil(widthall*0.8)
    ad_iframe_height=Math.ceil(heightall*0.8)
    $('#ad_iframe') .css('width',ad_iframe_width)
    $('#ad_iframe') .css('height',ad_iframe_height)
  }
  if(document.getElementById('ad_swf')){
    ad_iframe_width=Math.ceil(widthall*0.8)
    ad_iframe_height=Math.ceil(heightall*0.8)
    $('#ad_swf') .css('width',ad_iframe_width)
    $('#ad_swf') .css('height',ad_iframe_height)
    $('#ad_swf_emd') .css('width',ad_iframe_width)
    $('#ad_swf_emd') .css('height',ad_iframe_height)    
  }
    //以下修正廣告內容的座標位置       

        contentHeight=$('#ad_content').height()
        contentWidth=$('#ad_content').width()
        newTop=(heightall-contentHeight)/2
        newLeft=(widthall-contentWidth)/2
        $('#ad_content').css('top',newTop)  
        newLeft=0
        $('#ad_content').css('left',newLeft)
                $('#ad_content').css('width',widthall)        
}

function Close_All_AD(){
  jQuery('.AD_Close_Button').each(function() {
    $(this).remove();

  });
}
function Close_One_AD(e){
     //alert("Close_One_AD")
   //ori_path=$('#content'+e).attr('ori_path')
   //$('#content'+e).attr('src',ori_path) 
     jQuery('#content'+e).attr('src','img/loadinfo.gif')
     jQuery('#content'+e).fadeOut(500, function () {   
          ori_path=$('#content'+e).attr('ori_path')
        $('#content'+e).attr('src',ori_path)   
              jQuery('#content'+e).fadeIn(700, function () {
        });
      });
      
   /*
     jQuery('#AD_Close_Button'+e).fadeOut(800, function () {
          ori_path=$('#content'+e).attr('ori_path')
        $('#content'+e).attr('src',ori_path)
      });
     */   

}

function Rnd(min,max) {  
 x=Math.floor(Math.random()*(max-min+1)+min); 
 return x
}
function AD_Close_Button_Reposition(){
  jQuery('.AD_Close_Button').each(function() {
    pos_top=$(this).attr('pos_top')
    pos_left=$(this).attr('pos_left')
    
  });
}
function temp_function(){
hh="<table border='0'>"
hh=hh+"<tr><td><div id='temp1'></div></td><td><div id='temp2'></div></td><td><div id='temp3'></div></td></tr>"
hh=hh+"</table>"
  admenuwidth=250
  admenuheight=50
  admenutop=90
  admenuleft=0
$('body').append("<div id='tempp'  style='position:absolute;z-index:90;top:"+admenutop+";left:"+admenuleft+";padding:0px;margin:0px;border:0px;color:#ffffff'  align='center'>"+hh+"</div>");
$('body').append("<div id='tempp_back'  style='width:"+admenuwidth+"px;height:"+admenuheight+"px;position:absolute;z-index:89;top:"+admenutop+";left:"+admenuleft+";padding:0px;margin:0px;border:0px;color:#ffffff;background:#000000'  align='center'></div>"); 
$('#temp3').html("<img src='img/Star40.png'  style='cursor:pointer'  onclick=\"toggle_temp_function()\"  onload=\"fixPng(this)\"  w='28'  h='28' width='28' height='28'/>");  
    

$('#tempp_back').fadeTo(10, 0.8);
  //加上造型選單
  admenuwidth=80
  admenuheight=50
  admenutop=10
  admenuleft=0
  //$('body').append("<div id='adcss' name='adcss'  style='width:"+admenuwidth+"px;height:"+admenuheight+"px;position:absolute;z-index:90;top:"+admenutop+";left:"+admenuleft+";padding:0px;margin:0px;border:0px;color:#ffffff'  align='center'>Hello!</div>");
  hh="<table border='0'><tr><td><div style='color:#ffffff;font-size:14px' >KM<br>風格</div></td>"
  hh=hh+"<td><div style='color:#ffffff;font-size:12px;cursor:pointer'  onclick=\"changeCSS('country')\" class='subbutten'>鄉村風格</div>"
  hh=hh+"<div style='color:#ffffff;font-size:12px;cursor:pointer'  onclick=\"changeCSS('city')\" class='subbutten'>都會風格</div></td></tr></table>"
  $('#temp1').html(hh)
  
  //加上全幅廣告類型選單
  //$('body').append("<div id='adtype' name='adtype'  style='width:150px;height:"+admenuheight+"px;position:absolute;z-index:90;top:"+admenutop+";left:"+(admenuleft+60)+";padding:0px;margin:0px;border:0px;color:#ffffff'  align='center'>Hello!</div>");
  hh="<table border='0'><tr><td><div style='color:#ffffff;font-size:14px' >全幅廣告<br>選擇類型</div></td>"
  hh=hh+"<td><div style='font-size:12px;cursor:pointer'  onclick=\"changeTYPE('1')\" class='subbutten'>IMG類型</div>"
  hh=hh+"<div style='font-size:12px;cursor:pointer'  onclick=\"changeTYPE('2')\" class='subbutten'>SWF類型</div>"
  hh=hh+"<div style='font-size:12px;cursor:pointer'  onclick=\"changeTYPE('3')\" class='subbutten'>網頁類型</div></td></tr></table>"
  $('#temp2').html(hh)  
$('#tempp_back').width($('#tempp').width())
$('#tempp_back').height($('#tempp').height()) 
toggle_temp_function()
  /*
  */
}
var temp_opcl_status="open"
function toggle_temp_function(){
  if(temp_opcl_status=="open"){
    close_temp_function()
    temp_opcl_status="close"
  }else{  
    if(temp_opcl_status=="close"){
      open_temp_function()
      temp_opcl_status="open"
    }
  }
}

function close_temp_function(){
  leftt=($("#tempp_back").width()-$("#temp3").width()-5)*(-1)
  $("#tempp").animate({left: leftt+'px'}, 500);
  $("#tempp_back").animate({left: leftt+'px'}, 500);
  $('#tempp_back').fadeTo(10, 0.3);
  $('#temp3').fadeTo(10, 0.3);
}
function open_temp_function(){
  leftt=0
  $("#tempp").animate({left: leftt+'px'}, 500);
  $("#tempp_back").animate({left: leftt+'px'}, 500);
  $('#tempp_back').fadeTo(10, 0.8);
  $('#temp3').fadeTo(10, 1);
}
function Close_None_Cover_iFrame(){
  jQuery("iframe[isoffice='yes']").each(function() {
        if($(this).attr('isonad')=="yes" && $(this).attr('pre_content_isppt')=="yes"){
        $(this).attr('src','')      
    }
  });  
}
//負責撈出全頁全幅廣告內容
function make_ad_layout_content(){

   Close_Layout_AD()
if(JSgetCookie("web_km_show_adsmart_layout_ad_"+current_layer)!="no"){
   
  current_layer = current_layer;
  layerinfo = $(xmldata).find("ses[id="+current_layer+"]");
  adPath = $(layerinfo).attr('adPath'); 
  //alert(current_layer+":layout:"+adPath)
  if(adPath!=undefined){

    jQuery("iframe[isoffice='yes']").each(function() {
      if($(this).attr('isonad')!="yes"){
          ori_path=$(this).attr('src')
          $(this).attr('ori_path',ori_path)
          $(this).attr('src','')
          $(this).attr('pre_content_isoffice','yes')        
      }
    }); 
    jQuery("iframe[isflash='yes']").each(function() {
      if($(this).attr('isonad')!="yes"){
          ori_path=$(this).attr('src')
          $(this).attr('ori_path',ori_path)
          $(this).attr('src','')
          $(this).attr('pre_content_isflash','yes')       
      }
    }); 
    widthall = Math.ceil($(document.body).width()); 
    heightall  = Math.ceil($(document.body).attr('clientHeight'));  
    adtop=menuheight-5
    adleft=0
    //先加上背景半透明遮罩
    $('body').append("<div id='ad_background' name='ad_background'  style='width:"+widthall+"px;height:"+heightall+"px;position:absolute;z-index:2;top:"+adtop+";left:"+adleft+";padding:0px;margin:0px;border:0px;background:#000000;color:#ffffff' ></div>");
    $('#ad_background').fadeTo(10, 0.5);

    //加上廣告內容的layout
    $('body').append("<div id='ad_content' name='adcontent'  style='width:"+widthall+"px;position:absolute;z-index:3;top:"+adtop+";left:"+adleft+";padding:0px;margin:0px;border:0px;color:#ffffff'  align='center'>Hello!</div>");
    //make_ad_content() 
      srcpath="./Ad_Layout_Show.php?ad_id="+adPath;   
      $('#ad_content').html("<img src='img/loadinfo.gif'  width='30' height='30' />")
        //取得廣告資訊    
      $.get(srcpath,function(data)                                                      
      { 
          JSsetCookie("web_km_test_cookies","ok",1)
        if(JSgetCookie("web_km_test_cookies")!=""){
          data=data+"<div><input type='checkbox' name='checkbox_ad' id='checkbox_ad' onchange='checkbox_if_show_layout_ad(this)' onclick='checkbox_if_show_layout_ad(this)'>下次不再顯示這則訊息!</div>"
                }else{
          data=data+"<div style='color:#cac9c9;font-size:12px'>您的瀏覽器目前不支援Cookies的設定! 打開後方能設定下次不再顯示此訊息的功能.造成您的不便,深感抱歉!</div>"
        }
        $('#ad_content').html(data)    
        Fit_Layout_AD() 
        setTimeout('Fit_Layout_AD()',300)     
      }
      );        
      
    //加上廣告的功能列layout
    admenuwidth=100
    admenuheight=50
    admenutop=menuheight+10
    admenuleft=widthall-admenuwidth
    $('body').append("<div id='ad_menu' name='admenu'  style='width:"+admenuwidth+"px;height:"+admenuheight+"px;position:absolute;z-index:3;top:"+admenutop+";left:"+admenuleft+";padding:0px;margin:0px;border:0px;color:#ffffff'  align='center'>Hello!</div>");
    $('#ad_menu').html("<img src='img/ad_close_bt.png'  style='cursor:pointer'  onclick=\"Close_Layout_AD()\" onmouseover=\"ChangePic(this,'ad_close_bt_over.png')\"   onmouseout=\"ChangePic(this,'ad_close_bt.png')\" onload=\"fixPng(this)\"  w='25'  h='25'/>");      

  }else{
      //$('#ad_content').html("No ad_layout")
  }
}

}


//負責撈出單一格子廣告內容
function make_ad_grid_content(){
    
  Close_All_AD()
  $('#adcontent').html("<img src='../img/morg1_images/magic/soul_match/mc_04ph.gif' />");
  current_layer = current_layer;
  layerinfo = $(xmldata).find("ses[id="+current_layer+"]");
  rownum = $(layerinfo).attr('vScreenNum');
  colnum = $(layerinfo).attr('hScreenNum');
  //menuheight = 65;
  widthall = Math.ceil($(document.body).width()); 
  heightall  = Math.ceil($(document.body).attr('clientHeight') - menuheight);
  width = widthall / colnum ;
  height  = heightall / rownum;
   
    
  rownum_R=Rnd(1,rownum)
  colnum_R=Rnd(1,colnum)
  
  contentHeight=$('#adcontent').height()
  contentWidth=$('#adcontent').width()
  newTop=(heightall-contentHeight)/2
  newLeft=(widthall-contentWidth)/2



  current_layer = current_layer;
  layerinfo = $(xmldata).find("ses[id="+current_layer+"]");
  rownum = $(layerinfo).attr('vScreenNum');
  colnum = $(layerinfo).attr('hScreenNum');
  //menuheight = 65;
  widthall = Math.ceil($(document.body).width()); 
  heightall  = Math.ceil($(document.body).attr('clientHeight') - menuheight);
  width = widthall / colnum ;
  height  = heightall /rownum;  
  $('#adcontent').empty();
  $('#adcontent').width(widthall);
  $('#adcontent').height(heightall);  
    $('#adcontent').css('z-index','2');   

  var k = 0;
  for (i = 0 ; i < rownum ; i++)
  {
   for (j = 0 ; j < colnum ; j++)
    {
    isflash = false;
    contid = $(layerinfo).find("screens[pos='"+k+"']").attr('contId');    
    cont = $(layerinfo).find("screens[pos='"+k+"']");
    srcpath  = $(cont).attr('adPath');
        
    
    if(srcpath!="" && srcpath!=undefined){
    //H7-009	srcpath="/users2/app/webroot/WSM/Ad_Show.php?ad_id="+$(cont).attr('adPath')+"&ad_pos="+k;
	srcpath="./Ad_Show.php?ad_id="+$(cont).attr('adPath')+"&ad_pos="+k;	//H7-009
	
	if ( $(cont).attr('file') == 'true' ) 
    {
      filetype = srcpath.split('.');  
      if (filetype.length > 1 )
        //srcpath  = path + 'content'+contid+'.bin.'+filetype[filetype.length - 1];         
      if (filetype[filetype.length - 1] == 'swf')
        isflash = true;
    }
    
      iframeleft = width * j;
      iframetop =  i * height+menuheight;


        //$('body').append("<iframe id='AD_Content"+k+"' name='AD_Content"+k+"'  style='width:"+(width+1)+"px;height:"+(height+1)+"px;position:absolute;z-index:5;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px;background-color:transparent'  allowTransparency='true' src='"+srcpath+"'/>");
          //alert("not swf="+srcpath)  
        ori_path=$('#content'+k).attr('src')
        $('#content'+k).attr('ori_path',ori_path)
        $('#content'+k).attr('src',srcpath)
        $('#content'+k).attr('isonad','yes')
      
      //$('body').append("<div id='AD_Close_Button"+k+"' name='AD_Close_Button"+k+"'    class='AD_Close_Button'   pos='"+k+"'   pos_top='"+iframetop+"'   pos_left=''"+iframeleft+"  style='width:30px;height:30px;position:absolute;z-index:6;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px;color:#ffffff'  align='center'>Hello!</div>");
            //$('#AD_Close_Button'+k).html("<img src='img/ad_close_bt.png'  style='cursor:pointer'  onclick=\"Close_One_AD("+k+")\" onmouseover=\"ChangePic(this,'ad_close_bt_over.png')\"   onmouseout=\"ChangePic(this,'ad_close_bt.png')\" />");

        } 
        k++;    
   }

    }   

}

function changeCSS(e){     
      iinfo="./ChangeCssSession.php?layout_style="+e
      //alert(iinfo)
      $.get(iinfo,function(data)                                                      
      { 
                 //alert(data)
         location.reload()
      }
      );  
}
function changeTYPE(e){
  JSsetCookie('wsm_ad_layout_type',e,1)
  location.reload()
  
}

function checkbox_if_show_layout_ad(e){
  if_agree=jQuery(e).attr('checked')
  if(if_agree){
     JSsetCookie("web_km_show_adsmart_layout_ad_"+current_layer, "no",365)
  }else{
     JSsetCookie("web_km_show_adsmart_layout_ad_"+current_layer, "yes",365)
  }
  //alert("web_km_show_adsmart_layout_ad_"+current_layer+":"+JSgetCookie("web_km_show_adsmart_layout_ad"+current_layer))
}

//用Javascript設定cookies   (cookies_name:cookies的名稱,value:cookies的值,expiredays:過期天數)
function JSsetCookie(cookies_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=cookies_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
 
 cookies=JSgetCookie(cookies_name)
}

//用Javascript取得cookies
function JSgetCookie(cookies_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(cookies_name + "=");
  if (c_start!=-1)
    { 
    c_start=c_start + cookies_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 fixPng(png) {
   var badBrowser = (/MSIE ((5\.5)|6)/.test(navigator.userAgent) && navigator.platform == "Win32");
   if (badBrowser) {    
     var blank = new Image();
  
     blank.src = '../img/blank.gif';
  
     var src = png.src;
     //if (!png.style.width) { png.style.width = png.offsetWidth; }
     //if (!png.style.height) { png.style.height = png.offsetHeight; }
     if (!png.style.width) { png.style.width = png.w;; }
     if (!png.style.height) { png.style.height = png.h; }    
     png.onload = function() { };
     png.src = blank.src;
     png.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "',sizingMethod='scale')";
   }
}
//=============================================================

$(document).ready(function(){
//temp_function()
//自動調整修正menubar_table的寬度
Fit_Menubar_Table_Size()

 $("#repkm").click(function()
  {  

  wwidth=700;
  hheight=250;
  iframetop=($(document.body).height()/2)-(hheight/2)
  iframeleft=($(document.body).width()/2)-(wwidth/2)
  
  if(document.getElementById('rep_iframe')){
  close_iframe('rep_iframe')  
  }
    
  //$("body").append("<iframe id='rep_iframe' name='rep_iframe'  style='width:"+(wwidth)+"px;height:"+(hheight)+"px;position:absolute;z-index:1;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px' src='"+webpath+"index.php/bunny/smart_matrix_message_wsm/"+pathencode+"/1/"+rownum+"/"+colnum+"'/>");    

   });
  });

function close_iframe(who){
  $('#'+who).remove();
   //$('#'+who).empty();
    //$('#'+who).replaceWith("");
}


var km_id
$(document).ready(function()
{  
  try{
      km_id=km_id_from_username
  }catch(e){
    km_id=getURLParam("id")
  }
	
	set_layer=getURLParam("layer"); 		//H7-004
	set_focus=getURLParam("focus"); 		//H7-004 
	$("#teach_button").attr("style","");		//H7-008
  $.get("./getSMContent.php?km_id="+km_id,function(data)                                                      
  {
    
	xmldata = data;   
    numoflayer = $(data).find('ses').size();        
    result = $(data).find("Result").attr("error");
    if ( result == 0 )
    {
      path = $(data).find("WSM_Info").attr('path'); 
      pathencode=$(data).find("WSM_Info").attr('pathencode');
      info = $(data).find("WSM_Info");
      document.title = $(data).find("WSM_Info").attr('title');
	
	  //H7-002 start *****************     
	  mask_flash_url = $(data).find("WSM_Info").attr('Mask_Flash_Path');
	  
	  if( mask_flash_url != "" )
	  {			
			embedstring='<embed id=mask style="width:100%;height:100%;position:absolute;z-index:100;border:0;margin:0px;padding:0px;"  wmode="transparent" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" allowfullscreen="false" allowscriptaccess="sameDomain" name="dadv" bgcolor="#ffffff" quality="high" src="'+mask_flash_url+'"/>';  
			buttonstring='<img style="border:0;margin:0px;padding:0px;width:45px;height:45px;position:absolute;z-index:101;top:20px;left:90px;" id="close_img" onclick="goNext()" src="./img/ad_close_bt.png"/>'
			//H7-005	$('body').append(embedstring);
			//H7-005	$('body').append(bottonstring);	
			$('#mask_flash').append(embedstring);		//H7-005
			$('#cancel_button').append(buttonstring);	//H7-005
	  }
	  else
	  {//H7-002 end *****************
		for (i = 0 ; i< numoflayer ; i++)
		{
			//H7-007	$('#pagelayer').append("<span class='bk_font'><a  class='subbutten' href='javascript:changelayer("+i+")'>"+(i+1)+"</a></span>");
			$('#pagelayer').append("<span class='bk_font'><a  class='subbutten' href='javascript:changelayer("+i+")' onclick='focused_content = null'>"+(i+1)+"</a></span>");	//H7-007
		}
				
		Redirect_Layer_Focus(set_layer,set_focus)	//H7-004
		//H7-004	changelayer(0);
		
      }//H7-002  
    }
    else  
    {
      alert($(data).find("Result").attr("Describe"))
	  if ( $(data).find("Result").attr("Describe") == "Please login U-match and try again." )
	  {
		//use ajax to judge km type: type4km --> FQfun.    else --> umatch1.
		
		if( km_type == 4){
			window.location.replace('http://www.morgenstern.com.tw/fqfun/index.html');
		}
		else{
			window.location.replace('http://www.morgenstern.com.tw/users2/index.php/u_match1');
		}
	  }
    }
	});
});

//H7-002 start *******************
function goNext()
{
	//H7-004	//H7-003	$("#mask").attr('style','visibility: hidden');
	//H7-004	$("#mask").css('visibility','hidden');	//H7-003 change the way write code
	//H7-004	$("#mask").css('display','none');		//H7-003 change the way write code [add ('display','none'), that free resource]
	//H7-004	$("#close_img").attr('style','visibility: hidden');
  	
	$("#mask").remove();		//H7-004
	$("#close_img").remove();	//H7-004
	
	for (i = 0 ; i< numoflayer ; i++)
	{
		$('#pagelayer').append("<span class='bk_font'><a  class='subbutten' href='javascript:changelayer("+i+")'>"+(i+1)+"</a></span>");
	} 
	
	Redirect_Layer_Focus(set_layer,set_focus)	//H7-004
	//H7-004	changelayer(0);
}
//H7-002 end *******************

//H7-002 var current_layer
function changelayer(layer)
{
//先關掉目前的擴大項目為空項目
currentnum = null
//============================
  close_iframe('rep_iframe')
  current_layer = layer;
  
  genChangeFileButton(current_layer); //G5-003
  
  layerinfo = $(xmldata).find("ses[id="+layer+"]");
  rownum = $(layerinfo).attr('vScreenNum');
  colnum = $(layerinfo).attr('hScreenNum');
  menuheight = 65;
  
  //增加此行用來判別適當的menuheight
  if(rownum>3){menuheight =5+rownum*20}
  
  widthall = Math.ceil($(document.body).width()); 
  heightall  = Math.ceil($(document.body).attr('clientHeight') - menuheight);
  width = widthall / colnum ;
  height  = heightall /rownum;  
  $('#contentarea').empty();
  $('#contentarea').width(widthall);
  $('#contentarea').height(heightall);  
  $('#contentarea').css('z-index','1');
  $('#contentarea').css('top',menuheight)   
  $('#maxview').empty();
  genMaxMatrix(rownum,colnum);
  $('#menubar').attr('style','width:'+$(document).width()+';height:'+menuheight+';overflow2:hidden;z-index:50');
  var k = 0;
  for (i = 0 ; i < rownum ; i++)
  {
   for (j = 0 ; j < colnum ; j++)
    {
	  if( focused_content == k)		//H7-006 start ************
	  {
		contid = $(layerinfo).find("screens[pos='"+k+"']").attr('contId');    
		cont = $(xmldata).find("conts[id='"+contid+"']");
		srcpath  = $(cont).attr('originalPath');
		
		//H7-019 start
		var conv_pdf_success = $(cont).attr('conv_pdf_success');	// if converting office file to pdf fails, has an attribute "conv_pdf_success" = 0;
		var conv_pdf_result = 1;
		if(conv_pdf_success != null)
		{
			conv_pdf_result = conv_pdf_success;
		}	//if conv_pdf_result = 0; means converting office to pdf fails.
		//H7-019 end
		
		convPdf = $(cont).attr('convPdf');
		var	exist_conv_Pdf_for_focus = false;
		if(convPdf!=null) //old version xml didn't have convPdf tag
		{                                                          
			filetype = convPdf.toLowerCase().split('.');           
			if (filetype.length > 1 )                                 
			{ //has converted Pdf                                       
				exist_conv_Pdf_for_focus = true;                                 
			}                                                        
		}
		
		if ( $(cont).attr('file') == 'true' ) 
		{
			iframeleft = width * j;
			iframetop =  i * height;
			
			filetype = srcpath.toLowerCase().split('.');
			
			if (filetype.length > 1 )
			{
				if( exist_conv_Pdf_for_focus == true)
				{
					srcpath  = path + 'content'+contid+'.bin.converted.pdf.pdf';
					$("#contentarea").append("<iframe id='content"+k+"' name='content"+k+"'  style='width:"+(width+1)+"px;height:"+(height+1)+"px;position:absolute;z-index:1;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px' src='"+srcpath+"#toolbar=0&navpanes=0&scrollbar=0''/>");					
				}
				else if (filetype[filetype.length - 1] == 'pdf')//H7-007 ******* start
				{
					srcpath  = path + 'content'+contid+'.bin.'+filetype[filetype.length - 1];
					$("#contentarea").append("<iframe id='content"+k+"' name='content"+k+"'  style='width:"+(width+1)+"px;height:"+(height+1)+"px;position:absolute;z-index:1;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px' src='"+srcpath+"#toolbar=0&navpanes=0&scrollbar=0''/>");
				}												
				else if (filetype[filetype.length - 1] == 'jpg'  ||  filetype[filetype.length - 1] == 'png'  
				||  filetype[filetype.length - 1] == 'gif'  ||	filetype[filetype.length - 1] == 'bmp'  )
				{
					srcpath  = path + 'content'+contid+'.bin.'+filetype[filetype.length - 1];
					$("#contentarea").append("<iframe id='content"+k+"' name='content"+k+"'  style='width:"+(width+1)+"px;height:"+(height+1)+"px;position:absolute;z-index:1;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px;overflow:hidden' src='"+srcpath+"'/>");
				}
				//H7-007 ******* end
				//H7-019 start
				else if( is_IE==0 && conv_pdf_result==0 ) // NON IE browser and Converting office to pdf fails
				{
					contid = $(layerinfo).find("screens[pos='"+k+"']").attr('contId');    
					cont = $(xmldata).find("conts[id='"+contid+"']");
					srcpath  = $(cont).attr('originalPath');
					if ( $(cont).attr('file') == 'true' ) 
					{
						filetype = srcpath.toLowerCase().split('.');
						
						if (filetype[filetype.length - 1] =='ppt'   ||  filetype[filetype.length - 1] == 'doc'  ||  filetype[filetype.length - 1] == 'xls'){ //2003 office
							//H7-022	srcpath = "./img/H_user_hint1.png";
							srcpath = "./KmErrorPage2003.html";	//H7-022
						}else if(filetype[filetype.length - 1] =='pptx'  ||  filetype[filetype.length - 1] == 'docx' ||  filetype[filetype.length - 1] == 'xlsx'){	//2007 office
							//H7-022	srcpath = "./img/H_user_hint2.png";
							srcpath = "./KmErrorPage2007.html";	//H7-022
						}else if(filetype[filetype.length - 1] =='odp'   ||  filetype[filetype.length - 1] == 'odt'  ||  filetype[filetype.length - 1] == 'ods' ){	//open office
							//H7-022	srcpath = "./img/H_user_hint3.png";
							srcpath = ".KmErrorPageOOg.html";//H7-022
						}else{	//exception
							//H7-022	srcpath = "./img/H_user_hint1.png";
							srcpath = "./KmErrorPage2003.html";	//H7-022
						}					
					}
					try{
						km_id=km_id_from_username
					}catch(e){
						km_id=getURLParam("id")
					}
					//$("#contentarea").append("<iframe id='content"+k+"' name='content"+k+"'  style='width:"+(width+1)+"px;height:"+(height+1)+"px;position:absolute;z-index:1;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px' src='iFrame_Special_for_Pic_type.php?pic_path="+srcpath+"&layer="+current_layer+"&pos="+k+"&km_id="+km_id+"'/>");
					//H7-022	$("#contentarea").append("<iframe id='content"+k+"' name='content"+k+"'  style='width:"+(width+1)+"px;height:"+(height+1)+"px;position:absolute;z-index:1;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px;overflow:hidden' src='"+srcpath+"'/>");	//H7-019
					$("#contentarea").append("<iframe id='content"+k+"' name='content"+k+"'  style='width:"+(width+1)+"px;height:"+(height+1)+"px;position:absolute;z-index:1;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px' src='"+srcpath+"'>"); //H7-022
				}
				//H7-019 end
				else
				{
					srcpath  = path + 'content'+contid+'.bin.'+filetype[filetype.length - 1];
					$("#contentarea").append("<iframe id='content"+k+"' name='content"+k+"'  style='width:"+(width+1)+"px;height:"+(height+1)+"px;position:absolute;z-index:1;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px' src='"+srcpath+"'/>");
				}
			}
		}
		else//H7-007 ******* start
		{
			//H7-012	$("#contentarea").append("<iframe id='content"+k+"' name='content"+k+"'  style='width:"+(width+1)+"px;height:"+(height+1)+"px;position:absolute;z-index:1;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px' src='undefined'/>");
			//H7-012 ****** start
			iframeleft = width * j;
			iframetop =  i * height;
			srcpath  = $(cont).attr('originalPath');
			if( srcpath=="" ){
				$("#contentarea").append("<iframe id='content"+k+"' name='content"+k+"'  style='width:"+(width+1)+"px;height:"+(height+1)+"px;position:absolute;z-index:1;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px' src='undefined'/>");
			}
			else{
				$("#contentarea").append("<iframe id='content"+k+"' name='content"+k+"'  style='width:"+(width+1)+"px;height:"+(height+1)+"px;position:absolute;z-index:1;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px' src='"+srcpath+"'>");
			}	//H7-012 ****** end
		}	//H7-007 ******* end		
	  }
	  else
	  {								//H7-006 end **********
	  ispdf = false; // G5-000
      isoffice= false
      ispic = false;
      isflash = false;
      isppt = false;
      contid = $(layerinfo).find("screens[pos='"+k+"']").attr('contId');    
      cont = $(xmldata).find("conts[id='"+contid+"']");
      srcpath  = $(cont).attr('originalPath');
	  
	  //H7-019 start
	  var conv_pdf_success = $(cont).attr('conv_pdf_success');	// if converting office file to pdf fails, has an attribute "conv_pdf_success" = 0;
	  var conv_pdf_result = 1;
	  if(conv_pdf_success != null)
	  {
		conv_pdf_result = conv_pdf_success;
	  }	//if conv_pdf_result = 0; means converting office to pdf fails.
	  //H7-019 end
	  
      if ( $(cont).attr('file') == 'true' ) 
      {
      filetype = srcpath.toLowerCase().split('.');
                  
      if (filetype.length > 1 )
        srcpath  = path + 'content'+contid+'.bin.'+filetype[filetype.length - 1]; 
      if (filetype[filetype.length - 1] == 'jpg'  ||  filetype[filetype.length - 1] == 'png'  ||  filetype[filetype.length - 1] == 'gif'  ||
        filetype[filetype.length - 1] == 'bmp' ||  filetype[filetype.length - 1] == 'jpeg'  )//H7-007 add jpeg
        ispic = true;   
      if (filetype[filetype.length - 1] == 'pdf') //G5-000 改pdf自成一類
        ispdf = true;                             //G5-000        
      if (filetype[filetype.length - 1] =='ppt'   ||  filetype[filetype.length - 1] == 'doc'  ||  filetype[filetype.length - 1] == 'xls'  ||
          filetype[filetype.length - 1] =='pptx'  ||  filetype[filetype.length - 1] == 'docx' ||  filetype[filetype.length - 1] == 'xlsx' ||   // 多增加一些是office的副檔名G5-000
          filetype[filetype.length - 1] =='odp'   ||  filetype[filetype.length - 1] == 'odt'  ||  filetype[filetype.length - 1] == 'ods' )     // 多增加一些是office的副檔名G5-000
        isoffice = true;                    
      if (filetype[filetype.length - 1] == 'swf')
        isflash = true;
      if (filetype[filetype.length - 1] == 'ppt')
        isppt = true;       
      }
      iframeleft = width * j;
      iframetop =  i * height;
            
      //G5-000 start **********************
      
      var snapshotpath; //多宣告snapshotpath
      convFlash = $(cont).attr('convFlash');  
      convPdf = $(cont).attr('convPdf');  
      convSnapshot = $(cont).attr('convSnapshot');
      //alert("convSnapshot="+convSnapshot);  

      exist_conv_Flash = false;      
      exist_conv_Pdf = false;        
      exist_conv_Snapshot = false;
      
      //G5-000 end ***************** 
      
      if(convSnapshot==null)//old version xml hasn't convSnapshot tag, thus go original logic //G5-000
      {//G5-000
          if (!isflash)
          {
              if(!ispic){
            	if(ispdf){ //G5-003
            		$("#contentarea").append("<iframe id='content"+k+"' name='content"+k+"'  style='width:"+(width+1)+"px;height:"+(height+1)+"px;position:absolute;z-index:1;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px' src='"+srcpath+"#toolbar=0&navpanes=0&scrollbar=0''/>");	//G5-003
            	}else{	//G5-003
              		$("#contentarea").append("<iframe id='content"+k+"' name='content"+k+"'  style='width:"+(width+1)+"px;height:"+(height+1)+"px;position:absolute;z-index:1;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px' src='"+srcpath+"'/>");
            	}	//G5-003
              if (isppt){$('#content'+k).attr('isppt','yes')}else{$('#content'+k).attr('isppt','no')}
                  if (isoffice){$('#content'+k).attr('isoffice','yes')}else{$('#content'+k).attr('isoffice','no')}
            }else{
			    try{
				km_id=km_id_from_username
				}catch(e){
				km_id=getURLParam("id")
				} //H7-019
			  $("#contentarea").append("<iframe id='content"+k+"' name='content"+k+"'  style='width:"+(width+1)+"px;height:"+(height+1)+"px;position:absolute;z-index:1;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px' src='iFrame_Special_for_Pic_type.php?pic_path="+srcpath+"&layer="+current_layer+"&pos="+k+"&km_id="+km_id+"'/>");	//H7-019
			  //H7-019	$("#contentarea").append("<iframe id='content"+k+"' name='content"+k+"'  style='width:"+(width+1)+"px;height:"+(height+1)+"px;position:absolute;z-index:1;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px' src='iFrame_Special_for_Pic_type.php?pic_path="+srcpath+"&layer="+current_layer+"&pos="+k+"'/>");//G5-003 add "?layer="+current_layer+"	//H7-004 change to [&layer="+current_layer+"&pos="+k+"]
			}
          }
          else 
          {
            //$("#contentarea").append("<div id='content"+k+"' name='content"+k+"'  style='width:"+(width+1)+"px;height:"+(height+1)+"px;position:absolute;z-index:1;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px' ><object><param name='wmode' value='opaque'/><embed type=application/x-shockwave-flash fullscreen='yes' wmode='opaque' src='"+srcpath+"' quality='high' bgcolor='#000000' width='100%' height='100%'></embed></object></div>");
            $("#contentarea").append("<iframe id='content"+k+"' name='content"+k+"'  style='width:"+(width+1)+"px;height:"+(height+1)+"px;position:absolute;z-index:1;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px' src='"+srcpath+"'/>");
                    if (isflash){$('#content'+k).attr('isflash','yes')}else{$('#content'+k).attr('isflash','no')}       
          }
      }//G5-000
      else //G5-000 start ************** //has convSnapshot tag 
      {
          filetype = convSnapshot.toLowerCase().split('.');                               
          if(filetype.length > 1 ) //snapshot exist
          { 
            snapshotpath = path + convSnapshot;
			  try{
				km_id=km_id_from_username
				}catch(e){
				km_id=getURLParam("id")
				} //H7-019
			$("#contentarea").append("<iframe id='content"+k+"' name='content"+k+"'  style='width:"+(width+1)+"px;height:"+(height+1)+"px;position:absolute;z-index:1;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px' src='iFrame_Special_for_Pic_type.php?pic_path="+snapshotpath+"&layer="+current_layer+"&pos="+k+"&km_id="+km_id+"'/>");
            //H7-019	$("#contentarea").append("<iframe id='content"+k+"' name='content"+k+"'  style='width:"+(width+1)+"px;height:"+(height+1)+"px;position:absolute;z-index:1;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px' src='iFrame_Special_for_Pic_type.php?pic_path="+snapshotpath+"&layer="+current_layer+"&pos="+k+"'/>");//G5-003 add "?layer="+current_layer+"	//H7-004 change to [&layer="+current_layer+"&pos="+k+"]			
		  } //G5-000 end ***************************
          else //G5-000 has convSnapshot tag but no snapshot
          {    //G5-000
            if (!isflash) //go original logic 
            {
                if(!ispic){            	
                	if(ispdf){ //G5-003
            			$("#contentarea").append("<iframe id='content"+k+"' name='content"+k+"'  style='width:"+(width+1)+"px;height:"+(height+1)+"px;position:absolute;z-index:1;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px' src='"+srcpath+"#toolbar=0&navpanes=0&scrollbar=0''/>");	//G5-003
            		}else{	//G5-003						
						//H7-019 start
					    if( is_IE==0 && conv_pdf_result==0 ) // NON IE browser and Converting office to pdf fails
					    {
							contid = $(layerinfo).find("screens[pos='"+k+"']").attr('contId');    
							cont = $(xmldata).find("conts[id='"+contid+"']");
							srcpath  = $(cont).attr('originalPath');
							if ( $(cont).attr('file') == 'true' ) 
							{
								filetype = srcpath.toLowerCase().split('.');
						
								if (filetype[filetype.length - 1] =='ppt'   ||  filetype[filetype.length - 1] == 'doc'  ||  filetype[filetype.length - 1] == 'xls'){ //2003 office
									srcpath = "./KmErrorPage2003.html";	//H7-022
									//H7-022	srcpath = "./img/H_user_hint1.png";
								}else if(filetype[filetype.length - 1] =='pptx'  ||  filetype[filetype.length - 1] == 'docx' ||  filetype[filetype.length - 1] == 'xlsx'){	//2007 office
									srcpath = "./KmErrorPage2007.html";	//H7-022
									//H7-022	srcpath = "./img/H_user_hint2.png";
								}else if(filetype[filetype.length - 1] =='odp'   ||  filetype[filetype.length - 1] == 'odt'  ||  filetype[filetype.length - 1] == 'ods' ){	//open office
									srcpath = "./KmErrorPageOOg.html";	//H7-022
									//H7-022	srcpath = "./img/H_user_hint3.png";
								}else{	//exception
									srcpath = "./KmErrorPage2003.html";	//H7-022
									//H7-022	srcpath = "./img/H_user_hint1.png";
								}					
							}
							  try{
							km_id=km_id_from_username
							}catch(e){
							km_id=getURLParam("id")
							}
							//$("#contentarea").append("<iframe id='content"+k+"' name='content"+k+"'  style='width:"+(width+1)+"px;height:"+(height+1)+"px;position:absolute;z-index:1;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px' src='iFrame_Special_for_Pic_type.php?pic_path="+srcpath+"&layer="+current_layer+"&pos="+k"'/>");
							//H7-022	$("#contentarea").append("<iframe id='content"+k+"' name='content"+k+"'  style='width:"+(width+1)+"px;height:"+(height+1)+"px;position:absolute;z-index:1;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px' src='iFrame_Special_for_Pic_type.php?pic_path="+srcpath+"&layer="+current_layer+"&pos="+k+"&km_id="+km_id+"'/>");		//H7-019
							$("#contentarea").append("<iframe id='content"+k+"' name='content"+k+"'  style='width:"+(width+1)+"px;height:"+(height+1)+"px;position:absolute;z-index:1;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px' src='"+srcpath+"'>"); //H7-022
						}
						//H7-019 end
						else
						{//H7-019 end
							$("#contentarea").append("<iframe id='content"+k+"' name='content"+k+"'  style='width:"+(width+1)+"px;height:"+(height+1)+"px;position:absolute;z-index:1;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px' src='"+srcpath+"'/>");
						}//H7-019
            		}	//G5-003                
            		if (isppt){$('#content'+k).attr('isppt','yes')}else{$('#content'+k).attr('isppt','no')}
                    if (isoffice){$('#content'+k).attr('isoffice','yes')}else{$('#content'+k).attr('isoffice','no')}
              }else{
				  try{
				km_id=km_id_from_username
				}catch(e){
				km_id=getURLParam("id")
				} //H7-019
				$("#contentarea").append("<iframe id='content"+k+"' name='content"+k+"'  style='width:"+(width+1)+"px;height:"+(height+1)+"px;position:absolute;z-index:1;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px' src='iFrame_Special_for_Pic_type.php?pic_path="+srcpath+"&layer="+current_layer+"&pos="+k+"&km_id="+km_id+"'/>");		//H7-019
				//H7-019	$("#contentarea").append("<iframe id='content"+k+"' name='content"+k+"'  style='width:"+(width+1)+"px;height:"+(height+1)+"px;position:absolute;z-index:1;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px' src='iFrame_Special_for_Pic_type.php?pic_path="+srcpath+"&layer="+current_layer+"&pos="+k+"'/>");//G5-003 add "?layer="+current_layer+"	//H7-004 change to [&layer="+current_layer+"&pos="+k+"]
                }
            } 
            else 
            { 
              //$("#contentarea").append("<div id='content"+k+"' name='content"+k+"'  style='width:"+(width+1)+"px;height:"+(height+1)+"px;position:absolute;z-index:1;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px' ><object><param name='wmode' value='opaque'/><embed type=application/x-shockwave-flash fullscreen='yes' wmode='opaque' src='"+srcpath+"' quality='high' bgcolor='#000000' width='100%' height='100%'></embed></object></div>");
              $("#contentarea").append("<iframe id='content"+k+"' name='content"+k+"'  style='width:"+(width+1)+"px;height:"+(height+1)+"px;position:absolute;z-index:1;top:"+iframetop+";left:"+iframeleft+";padding:0px;margin:0px;border:0px' src='"+srcpath+"'/>");
                    if (isflash){$('#content'+k).attr('isflash','yes')}else{$('#content'+k).attr('isflash','no')}       
            }
          }    //G5-000   
      //$("#contentarea").append("<div id='maxview"+k+"' style='width:26px;height:26px;position:absolute;z-index:10;background-image:url(./img/maxview2.png);padding:0px;margin:0px;border:0px;top:"+iframetop+";left:"+(iframeleft+width-26)+";'  onclick='maxview("+k+")' ></div>");
	  }				
	}							//H7-006
      
      k++;     
   }

    }
$("#page_layer_num").html((current_layer+1)+"/"+numoflayer); //H7-016	
    make_ad_grid_content()
  make_ad_layout_content()
}

function nonomalview()
{
  
  rownum =  $(xmldata).find("ses[id="+current_layer+"]").attr('vScreenNum');
  colnum =  $(xmldata).find("ses[id="+current_layer+"]").attr('hScreenNum');

  for(i = 0 ; i < rownum ; i++ )
      for(j = 0 ; j < colnum ; j++ )  
      {
              $('#content'+ ( i * colnum + j)).css('visibility','visible');
              $('#content'+ ( i * colnum + j)).css('top', i * height);
              $('#content'+ ( i * colnum + j)).css('left',j * width);
              $('#content'+ ( i * colnum + j)).css('width',(width+1) );
              $('#content'+ ( i * colnum + j)).css('height',(height+1));
              $('#content'+ ( i * colnum + j)).css('z-index','1');
              $('#maxview'+ ( i * colnum + j)).css('top',i * height);
              $('#maxview'+ ( i * colnum + j)).css('left',(j+1) * width - 26);
              $('#maxview'+ ( i * colnum + j)).css('visibility','visible');
              $('#content'+ (( i * colnum )+ j)).css('display','block');              
      }
       jQuery('.AD_Close_Button').each(function() {
           $(this).show();
       });  
}


function maxview(contentnum,resetFile) //G5-003 add resetFile
{ 
    close_iframe('rep_iframe')
    //H7-003 nonomalview();
    if (currentnum != contentnum)
	{		
		//H7-003 start *********** major revert the last enlarged iframe status
		rownum =  $(xmldata).find("ses[id="+current_layer+"]").attr('vScreenNum');	//H7-003
		colnum =  $(xmldata).find("ses[id="+current_layer+"]").attr('hScreenNum');	//H7-003
		  for(i = 0 ; i < rownum ; i++ )
		for(j = 0 ; j < colnum ; j++ )  
		{
             $('#content'+ ( i * colnum + j)).css('visibility','visible');       
		} //in ifrmae enlarge step, set other iframes invisible. this line set all iframes return visible 
		$('#content'+ (currentnum)).css('top', Math.floor(currentnum/rownum) * height);
        $('#content'+ (currentnum)).css('left', (currentnum%colnum) * width);
        $('#content'+ (currentnum)).css('width',(width+1) );
        $('#content'+ (currentnum)).css('height',(height+1));
        $('#content'+ (contentnum)).css('z-index','1');
		$('#maxview'+ (contentnum)).css('top',Math.floor(currentnum/rownum) * height);
        $('#maxview'+ (contentnum)).css('left',((currentnum%colnum)+1) * width - 26);
        $('#maxview'+ (contentnum)).css('visibility','visible');
        $('#content'+ (contentnum)).css('display','block');
		
		jQuery('.AD_Close_Button').each(function() {
           $(this).show();
       });
		//H7-003 end ***********
		
		currentnum = contentnum;
		
		//H7-015 start		
		rownum =  $(xmldata).find("ses[id="+current_layer+"]").attr('vScreenNum');
		colnum =  $(xmldata).find("ses[id="+current_layer+"]").attr('hScreenNum');	
		grid_width = Math.floor(40/colnum);
		grid_height = Math.floor(40/rownum);
		
		$('td.gridbuttom').html("<img src='./img/H_grid.png' width='"+grid_width+"px' height='"+grid_height+"px'/>");
		$('#maxview'+ currentnum).html("<img src='./img/H_grid_mouseover.png' width='"+grid_width+"px' height='"+grid_height+"px'/>");
		//H7-015 end		
		
		//$('#maxview'+ currentnum).css('background-color','black');
		//H7-015	$('td.gridbuttom').html("<img src='./img/grid_out.png' width='15px' height='15px'/>");
		//H7-015	$('#maxview'+ currentnum).html("<img src='./img/grid_over.png' width='15px' height='15px' />");
		screenpos = $(xmldata).find("ses[id="+current_layer+"]").find("screens[pos='"+contentnum+"']");
		lefttop = $(screenpos).attr('enlargeFromLeftTop');
		rightbottom = $(screenpos).attr('enlargeToRightBottom');
		
		//H7-003	rownum =  $(xmldata).find("ses[id="+current_layer+"]").attr('vScreenNum');
		//H7-003	colnum =  $(xmldata).find("ses[id="+current_layer+"]").attr('hScreenNum'); 
		
		layerenlarge = $(xmldata).find("ses[id="+current_layer+"]").attr('enlargeToMax')
		//if(layerenlarge=="true"){
		  if(lefttop ==-1){lefttop =0;}
		  if(rightbottom ==-1){rightbottom =(rownum*colnum)-1;}
		//}
		leftrow = Math.floor(lefttop / colnum);
		leftcol = lefttop % colnum;
		
		rightrow = Math.floor(rightbottom / colnum);
		rightcol = rightbottom % colnum;  
		
		//G5-001 alert("leftrow="+leftrow);alert("rightrow="+rightrow);alert("leftcol="+leftcol);alert("rightcol="+rightcol);
		
		for(i = leftrow ; i <= rightrow ; i++ )
		  for(j = leftcol ; j <= rightcol ; j++ ) 
		  {
		        if ( (( i * colnum  ) + j) != contentnum) 
		        {
		           //alert((( i * colnum )+ j))
		          
		          $('#content'+ (( i * colnum )+ j)).css('visibility','hidden');
		          //Kevin.W [for not to reload purpose] $('#content'+ (( i * colnum )+ j)).css('display','none');
		          //$('#maxview'+ (( i * colnum )+ j)).css('visibility','hidden');
		        }
		        else if(resetFile == 1)  //G5-003 start ************  contentnum will enlarge //G5-003 add resetFile
		        {         			  
					defaultModDisplay(currentnum);
		  		}//G5-003 end ************
								
				$('#content'+ contentnum).css('width',(rightcol - leftcol + 1)*width+'px');
				$('#content'+ contentnum).css('height',(rightrow - leftrow + 1)*height+'px');
				$('#content'+ contentnum).css('top',height * leftrow);
				$('#content'+ contentnum).css('left',width * leftcol);
				$('#maxview'+ contentnum).css('top',height * leftrow);      
				$('#maxview'+ contentnum).css('left',(width * (rightcol + 1) ) -26);  
				
				$('#AD_Close_Button'+ contentnum).css('top',height * leftrow+menuheight);
				$('#AD_Close_Button'+ contentnum).css('left',width * leftcol);
		   
		   		jQuery('.AD_Close_Button').each(function() {
		   		         pos=$(this).attr('pos')
		   		 if(pos>=lefttop && pos<=rightbottom){
		   		    $(this).hide();
		   		 }
		   		 });
				
					try{										//H7-010
						to_morgenstern = morgenstern_root_path;	//H7-010
					}catch(e){									//H7-010
						to_morgenstern = false;					//H7-010
					}											//H7-010
					
					//送出使用者按下放大的資訊  
		        	//H7-009 iinfo="../../../../users2/index.php/sm_record/action_record/"+km_id+"/"+current_layer+"/"+contentnum+"/0/"
		  			//H7-009 ***********start
					//H7-010	if( sm_record_path == "" || sm_record_path=="undefined" )//go original path if sm_record_path is not setted on db_connect.php
					
					if( to_morgenstern == false )	//go original path if morgenstern_root_path is not setted on db_connect.php //H7-010
					{
						iinfo="../../../../users2/index.php/sm_record/action_record/"+km_id+"/"+current_layer+"/"+contentnum+"/0/";
					}
					else
					{
						//H7-010	iinfo= sm_record_path+"/action_record/"+km_id+"/"+current_layer+"/"+contentnum+"/0/"
						//H7-018 	iinfo= to_morgenstern+"/sm_record/action_record/"+km_id+"/"+current_layer+"/"+contentnum+"/0/"; //H7-010
						iinfo= "./sm_record.php?km="+km_id+"&layer="+current_layer+"&content="+contentnum;	//H7-018
					}
					//H7-009 ***********end
					//iinfo="../../../../users2/index.php/users/welcome/"
		        	//alert(iinfo)      

					//H7-010 Kevin mark : sm_record cause authority problem.
					//H7-010	try{										//H7-010
					//H7-010	$.get(iinfo,function(data)					//H7-010                                                      
					//H7-010	{ 											//H7-010
		  			//H7-010            //alert(data)						//H7-010
					//H7-010	}											//H7-010
					//H7-010	);											//H7-010
					//H7-010	}catch(e){									//H7-010
					//H7-010	}											//H7-010
					
					try{										//H7-018
						$.get(iinfo,function(data)				//H7-018                                                     
						{ 										//H7-018
							//alert(data)						//H7-018
						});										//H7-018
					}catch(e){									//H7-018
					}											//H7-018				
		}
	}
	else
	{	
		nonomalview();  //H7-003
		
		//H7-015 start
		rownum =  $(xmldata).find("ses[id="+current_layer+"]").attr('vScreenNum');
		colnum =  $(xmldata).find("ses[id="+current_layer+"]").attr('hScreenNum');		
		grid_width = Math.floor(40/colnum);
		grid_height = Math.floor(40/rownum);
		$('#maxview'+ currentnum).html("<img src='./img/H_grid.png' width='"+grid_width+"px' height='"+grid_height+"px'/>");
		//H7-015 end
		
		//H7-015	$('#maxview'+ currentnum).html("<img src='./img/grid_out.png' width='15px' height='15px' />");
		currentnum = null;
//G5-003    //G5-001 start ********** (resume to snapshot)
//G5-003    for(i = leftrow ; i <= rightrow ; i++ )
//G5-003    { 
//G5-003      for(j = leftcol ; j <= rightcol ; j++ ) 
//G5-003      { 
//G5-003        layerinfo = $(xmldata).find("ses[id="+current_layer+"]");
//G5-003        contid = $(layerinfo).find("screens[pos='"+contentnum+"']").attr('contId');   
//G5-003        cont = $(xmldata).find("conts[id='"+contid+"']"); 
//G5-003        convSnapshot = $(cont).attr('convSnapshot');
//G5-003        if(convSnapshot!=null)
//G5-003        {
//G5-003          filetype = convSnapshot.toLowerCase().split('.');           
//G5-003          if (filetype.length > 1 )                                 
//G5-003          { //has converted Snapshot, resume to converted Snapshot                                      
//G5-003              srcpath  = path + convSnapshot;
//G5-003              var snapshotpath = "iFrame_Special_for_Pic_type.php?pic_path="+srcpath+"&layer="+current_layer;
//G5-003              //alert(snapshotpath);
//G5-003              $('#content'+ contentnum).attr('src',snapshotpath);                               
//G5-003          } 
//G5-003        }
//G5-003      }   
//G5-003    }
//G5-003    //G5-001 end      *******       
	} 
}

function genMaxMatrix(row,col)
{
  layerinfo = $(xmldata).find("ses[id="+current_layer+"]");
  //enlargeToMax = $(layerinfo).attr('enlargeToMax');
  //alert(enlargeToMax)
  
  var addstring = '<table id=maxviewtable style="border-color:black;position:static;margin-top:2px;" >';
  for ( i = 0 ; i < row ; i++) 
  {
    rownum =  $(xmldata).find("ses[id="+current_layer+"]").attr('vScreenNum');	//H7-015
	colnum =  $(xmldata).find("ses[id="+current_layer+"]").attr('hScreenNum');	//H7-015		
	grid_width = Math.floor(40/colnum); 	//H7-015
	grid_height = Math.floor(40/rownum);	//H7-015
		
	 addstring = addstring + '<tr>';
   for ( j = 0 ; j < col ; j++)
   {
       k=( i * col ) + j
       enlargeToMax = $(layerinfo).find("screens[pos='"+k+"']").attr('enlargeToMax'); 
     enlargeToMax = true
     //alert(enlargeToMax)
     if(enlargeToMax==true || enlargeToMax=="true"){
     var resetFile = 1; //G5-003
		//H7-015	addstring = addstring + '<td id="maxview'+(( i * col ) + j )+'" onclick=\'maxview('+ (( i * col ) + j )+','+resetFile+')\' style=\'cursor:pointer;width:15px;height:15px;background-color:white\' id=\'max'+ (( i * col ) + j )+'\' class="gridbuttom"><img src="./img/grid_out.png" width="15px" height="15px" /></td>';   //G5-003 add +resetFile+
     	 addstring = addstring + '<td id="maxview'+(( i * col ) + j )+'" onclick=\'maxview('+ (( i * col ) + j )+','+resetFile+')\' style=\'cursor:pointer;width:15px;height:15px;background-color:white\' id=\'max'+ (( i * col ) + j )+'\' class="gridbuttom"><img src="./img/H_grid.png" width='+grid_width+'"px height='+grid_height+'px/></td>';//H7-015
	 }else{
     addstring = addstring + '<td id="maxview'+(( i * col ) + j )+'"  style=\'width:15px;height:15px;background-color:white\' id=\'max'+ (( i * col ) + j )+'\' class="gridbuttom_nomax"><img src="./img/grid_nomax.png" width="15px" height="15px" /></td>';  
     }
   }
     addstring = addstring + '</tr>'; 
  }   
  addstring = addstring + '</table>';
    
  $('#maxview').append(addstring);
}

function getURLParam( name )
{
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return "";
  else
    return results[1];
}

$(window).resize(function(){  
  layerinfo = $(xmldata).find("ses[id="+current_layer+"]");
  rownum = $(layerinfo).attr('vScreenNum');
  colnum = $(layerinfo).attr('hScreenNum');
  menuheight = 65;
  //增加此行用來判別適當的menuheight
  if(rownum>3){menuheight =5+rownum*20}
  
  widthall = Math.ceil($(document.body).attr('clientWidth')); 
  heightall  = Math.ceil($(document.body).attr('clientHeight') - menuheight);
  width = widthall / colnum ;
  height  = heightall /rownum;
  $('#contentarea').css('top',menuheight) 
  $('#contentarea').width(widthall);
  $('#contentarea').height(heightall);

  nonomalview();
  var resetFile = 0; //G5-003
  if(currentnum != null){
    contentnum = currentnum;
    currentnum = null
    maxview(contentnum,resetFile); //G5-003 add resetFile
  }
  
  Fit_Layout_AD()
  Fit_Menubar_Table_Size()

});

function Fit_Menubar_Table_Size()
{
  menuheight = 65;
  widthall = Math.ceil($(document.body).attr('clientWidth')); 
  heightall  = Math.ceil($(document.body).attr('clientHeight') - menuheight);
  //自動調整修正menubar_table的寬度
  $('#menubar').width(widthall);
    $('#menubar_table').width(widthall);
}

//G5-003 start *************** get iframe innerHTML
function onSnapshotStatus(iFrameName)
{   
    var myIFrame = document.getElementById(iFrameName);
    var content = myIFrame.contentWindow.document.body.innerHTML;
     
    if($(content).find("#ad_img").attr("src").match(".converted.snapshot.")!=null)
    {
      on_snapshot = 1;
    } 
    else
    {
      on_snapshot = 0;
    }
    return on_snapshot;
}                                             

function defaultModDisplay(contentnum) //call by maxview(currentnum), open the file it should be
{ 
	//G5-000 start *****************
	layerinfo = $(xmldata).find("ses[id="+current_layer+"]");
	contid = $(layerinfo).find("screens[pos='"+contentnum+"']").attr('contId');   
	cont = $(xmldata).find("conts[id='"+contid+"']"); 
	var oripath = $(cont).attr('originalPath');
               
	if ( $(cont).attr('file') == 'true')
	{
		isoffice = false;
		filetype = oripath.toLowerCase().split('.');
		if (filetype[filetype.length - 1] =='ppt'   ||  filetype[filetype.length - 1] == 'doc'  ||  filetype[filetype.length - 1] == 'xls'  ||
		    filetype[filetype.length - 1] =='pptx'  ||  filetype[filetype.length - 1] == 'docx' ||  filetype[filetype.length - 1] == 'xlsx' ||   
		    filetype[filetype.length - 1] =='odp'   ||  filetype[filetype.length - 1] == 'odt'  ||  filetype[filetype.length - 1] == 'ods' )// 多增加一些是office的副檔名G5-000
		isoffice = true;
		
		//H7-007 start ******
		ispic = false;
		if (filetype[filetype.length - 1] == 'jpg'  ||  filetype[filetype.length - 1] == 'png'  ||  filetype[filetype.length - 1] == 'gif'  ||
        filetype[filetype.length - 1] == 'bmp' ||  filetype[filetype.length - 1] == 'jpeg' )
        ispic = true;
		//H7-007 end   ******
	}                                     
                  
    convSnapshot = $(cont).attr('convSnapshot'); //G5-001
    convPdf = $(cont).attr('convPdf');      //G5-001
    convFlash = $(cont).attr('convFlash'); //G5-000
                          
    exist_conv_Snapshot = false; //G5-001
    exist_conv_Pdf = false;   //G5-001      
    exist_conv_Flash = false; //G5-001
                  
    //G5-000 end *****************
    //G5-001 start **************                 
                  
	if(convSnapshot!=null) //old version xml didn't have convSnapshot tag
	{                                                          
		filetype = convSnapshot.toLowerCase().split('.');           
		if (filetype.length > 1 )                                 
		{ //has converted Snapshot                                      
			exist_conv_Snapshot = true;                                 
		}                                                        
	}
                              
	if(convFlash!=null) //old version xml didn't have convFlash tag
	{                                                          
	    filetype = convFlash.toLowerCase().split('.');           
	    if (filetype.length > 1 )                                 
	    { //has converted Flash                                       
	      exist_conv_Flash = true;                                 
	    }                                                        
	}
                  
	if(convPdf!=null) //old version xml didn't have convPdf tag
	{                                                          
	    filetype = convPdf.toLowerCase().split('.');           
	    if (filetype.length > 1 )                                 
	    { //has converted Pdf                                       
	      exist_conv_Pdf = true;                                 
	    }                                                        
	}
                       
	//G5-003 start *************** examine iframe is a snapshot or other file                  
	if( $('#content'+ contentnum).attr("src").match("iFrame_Special_for_Pic_type.php")!=null ) 
	{
	 	var content_num_string = "content"+currentnum;
		var on_snapshot = onSnapshotStatus(content_num_string);
	}
	else
	{
		if( $('#content'+ contentnum).attr("src").match(".snapshot.")==null ) //not a snapshot
		{
			var on_snapshot = 0;
		}
		else
		{
			var on_snapshot = 1;
		}
	}
    //G5-003 end  ***************
	if(on_snapshot == 1) //G5-003            					
	{					 //G5-003
	    if(isoffice)
	    {
	        if(exist_conv_Pdf)
	        {
	          srcpath = path + convPdf + "#toolbar=0&navpanes=0&scrollbar=0";  //G5-002
	          $('#content'+ contentnum).attr('src',srcpath);
	        }
	        else if(exist_conv_Flash)
	        {
	          srcpath = path + convFlash;
	          $('#content'+ contentnum).attr('src',srcpath);
	        }	
	        else if(exist_conv_Snapshot) //G5-002
	        {
	          filetype = oripath.toLowerCase().split('.');
	          srcpath  = path + 'content'+contid+'.bin.'+filetype[filetype.length - 1];
	          $('#content'+ contentnum).attr('src',srcpath);  
	        }
	    }
	    else //not a office file
	    { 
	        if(exist_conv_Snapshot)
	        {
	           	filetype = oripath.toLowerCase().split('.');
	          	if (filetype[filetype.length - 1] =='pdf')
     	    	{
    	    	   	filetype = oripath.toLowerCase().split('.');
    		    	srcpath  = path + 'content'+contid+'.bin.'+filetype[filetype.length - 1]+'#toolbar=0&navpanes=0&scrollbar=0';
    		    	$('#content'+ contentnum).attr('src',srcpath);
    		    }
    	    	else
    	    	{
    	    		filetype = oripath.toLowerCase().split('.');
    		    	srcpath  = path + 'content'+contid+'.bin.'+filetype[filetype.length - 1];
    	    		$('#content'+ contentnum).attr('src',srcpath);
    	    	}
	        }
	    }
	}    		//G5-003               
	
	//H7-007 start ******
	if( contentnum==focused_content && ispic )
	{
		filetype = oripath.toLowerCase().split('.');	//H7-013
		  try{
		km_id=km_id_from_username
		}catch(e){
		km_id=getURLParam("id")
		} //H7-019
		srcpath  = 'iFrame_Special_for_Pic_type.php?pic_path='+path+'content'+contid+'.bin.'+filetype[filetype.length - 1]+'&layer='+current_layer+'&pos='+contentnum+'&km_id='+km_id;	//H7-019
    	//H7-019	srcpath  = 'iFrame_Special_for_Pic_type.php?pic_path='+path+'content'+contid+'.bin.'+filetype[filetype.length - 1]+'&layer='+current_layer+'&pos='+contentnum;
		$('#content'+ contentnum).attr('src',srcpath);
	}
	//H7-007 end   ******

	var conv_pdf_success = $(cont).attr('conv_pdf_success');	// if converting office file to pdf fails, has an attribute "conv_pdf_success" = 0;
	var conv_pdf_result = 1;
	if(conv_pdf_success != null)
	{
		conv_pdf_result = conv_pdf_success;
	}	//if conv_pdf_result = 0; means converting office to pdf fails.
	//H7-019 start ******
//H7-022	if( contentnum==focused_content && is_IE==0 && conv_pdf_result==0 )
//H7-022	{
//H7-022		
//H7-022		layerinfo = $(xmldata).find("ses[id="+current_layer+"]");
//H7-022		contid = $(layerinfo).find("screens[pos='"+contentnum+"']").attr('contId');   
//H7-022		cont = $(xmldata).find("conts[id='"+contid+"']"); 
//H7-022		oripath = $(cont).attr('originalPath');
//H7-022		
//H7-022		if ( $(cont).attr('file') == 'true' ) 
//H7-022		{
//H7-022			filetype = oripath.toLowerCase().split('.');
//H7-022						
//H7-022			if (filetype[filetype.length - 1] =='ppt'   ||  filetype[filetype.length - 1] == 'doc'  ||  filetype[filetype.length - 1] == 'xls'){ //2003 office
//H7-022				var hint_path = "./img/H_user_hint1.png";
//H7-022			}else if(filetype[filetype.length - 1] =='pptx'  ||  filetype[filetype.length - 1] == 'docx' ||  filetype[filetype.length - 1] == 'xlsx'){	//2007 office
//H7-022				var hint_path = "./img/H_user_hint2.png";
//H7-022			}else if(filetype[filetype.length - 1] =='odp'   ||  filetype[filetype.length - 1] == 'odt'  ||  filetype[filetype.length - 1] == 'ods' ){	//open office
//H7-022				var hint_path = "./img/H_user_hint3.png";
//H7-022			}else{	//exception
//H7-022				var hint_path = "./img/H_user_hint1.png";
//H7-022			}					
//H7-022		}
//H7-022		
//H7-022		km_id=getURLParam("id");
//H7-022		srcpath  = 'iFrame_Special_for_Pic_type.php?pic_path='+hint_path+'&layer='+current_layer+'&pos='+contentnum+'&km_id='+km_id;	//H7-019
//H7-022		$('#content'+ contentnum).attr('src',srcpath);
//H7-022	}
	//H7-019 end   ******
	
 // $('#content'+ contentnum).attr('src',srcpath);     this code in here will cause file reload           
} 
// G5-001 end ****************
	
function genChangeFileButton(currentlayer)
{	
	current_layer = currentlayer;
 	$('#changefile').find('#ChangeFileButton').remove();
 	
 	var buttonDesign = null;
 	// H7-008	if(sBrowser=="Mozilla")
	if(sBrowser!="IE")		// H7-008
	{	
		if( KM_ExistConvPDF(current_layer) )
		{
			//H7-010	buttonDesign = "<table id='ChangeFileButton' border='0'><tr><td><span><img src=./img/Redirect_PDF.png title='PDF' onmouseover='ChangeOverClass_PM(this)' onmouseout='ChangeOutClass_PM(this)' style='cursor:pointer' onclick='file2PDF(currentnum)'/></span></td></tr><tr><td colspan=2><div id='Change_File_Buttons_Title' style='font-size:12px;color:#ffffff'></div></td></tr></table>"	// H7-008
			buttonDesign = "<table id='ChangeFileButton' border='0'><tr><td><span><img width='20px' height='20px' src=./img/Redirect_PDF.png title='PDF'  style='cursor:pointer' onclick='file2PDF(currentnum)'/></span></td></tr></table>"	// H7-010
		}
	}
	else if(sBrowser=="IE")
	{
		if( KM_ExistConvPDF(current_layer) && KM_ExistOriOffice(current_layer) && KM_ExistSnapshot(current_layer))
		{
			// H7-008	buttonDesign = "<span id='ChangeFileButton'><img src=./img/Redirect_PDF.png title='PDF' onclick='file2PDF(currentnum)'/></span><span id='ChangeFileButton'><img src=./img/Redirect_Office.png title='Office' onclick='file2Office(currentnum)'/></span>"
			// H7-010	buttonDesign = "<table id='ChangeFileButton' border='0'><tr><td><span><img src=./img/Redirect_PDF.png title='PDF' onmouseover='ChangeOverClass_PM(this)' onmouseout='ChangeOutClass_PM(this)' style='cursor:pointer' onclick='file2PDF(currentnum)'/></span></td><td><span><img src=./img/Redirect_Office.png title='Office' onmouseover='ChangeOverClass_PM(this)' onmouseout='ChangeOutClass_PM(this)' style='cursor:pointer' onclick='file2Office(currentnum)'/></span></td></tr><tr><td colspan=2><div id='Change_File_Buttons_Title' style='font-size:12px;color:#ffffff'></div></td></tr></table>"	// H7-008
			buttonDesign = "<table id='ChangeFileButton' border='0'><tr><td><span><img width='20px' height='20px' src=./img/Redirect_PDF.png title='PDF'  style='cursor:pointer' onclick='file2PDF(currentnum)'/></span></td><td><span><img width='20px' height='20px' src=./img/Redirect_Office.png title='Office'' style='cursor:pointer' onclick='file2Office(currentnum)'/></span></td></tr></table>"	//H7-010
		}
		else if( KM_ExistConvPDF(current_layer) )
		{
			//H7-010	buttonDesign = "<table id='ChangeFileButton' border='0'><tr><td><span><img src=./img/Redirect_PDF.png title='PDF' onmouseover='ChangeOverClass_PM(this)' onmouseout='ChangeOutClass_PM(this)' style='cursor:pointer' onclick='file2PDF(currentnum)'/></span></td></tr><tr><td colspan=2><div id='Change_File_Buttons_Title' style='font-size:12px;color:#ffffff'></div></td></tr></table>"	// H7-008
			buttonDesign = "<table id='ChangeFileButton' border='0'><tr><td><span><img width='20px' height='20px' src=./img/Redirect_PDF.png title='PDF'  style='cursor:pointer' onclick='file2PDF(currentnum)'/></span></td></tr></table>"	// H7-010
		}
		else if( KM_ExistOriOffice(current_layer) && KM_ExistSnapshot(current_layer))
		{
			//H7-010	buttonDesign = "<table id='ChangeFileButton' border='0'><tr><td><span><img src=./img/Redirect_Office.png title='Office' onmouseover='ChangeOverClass_PM(this)' onmouseout='ChangeOutClass_PM(this)' style='cursor:pointer' onclick='file2Office(currentnum)'/></span></td></tr><tr><td colspan=2><div id='Change_File_Buttons_Title' style='font-size:12px;color:#ffffff'></div></td></tr></table>"	// H7-008
			buttonDesign = "<table id='ChangeFileButton' border='0'><tr><td><span><img width='20px' height='20px' src=./img/Redirect_Office.png title='Office'' style='cursor:pointer' onclick='file2Office(currentnum)'/></span></td></tr></table>"    // H7-010
		}
	}
	$('#changefile').append(buttonDesign);
}

function file2PDF(currentnum)
{
	contentnum = currentnum ;
	if( contentnum != null ) //status : view has been enlarged to max 
	{                 		
		file2PDFbyNum(contentnum);
    }
    else //in nonomalview, each content try change to PDF    	
	{
		rownum =  $(xmldata).find("ses[id="+current_layer+"]").attr('vScreenNum');
  		colnum =  $(xmldata).find("ses[id="+current_layer+"]").attr('hScreenNum');

		for(i = 0 ; i < rownum ; i++ )
			for(j = 0 ; j < colnum ; j++ )
		  	{	
				//H7-025 var k = i * rownum + j;
				var k = i * colnum + j; //H7-025
				file2PDFbyNum(k);
			}
	}    	
}

function file2PDFbyNum(currentnum) 
{ 
	 	contentnum = currentnum;
	 	var on_converted_pdf = 0; var on_original_pdf = 0; //judge now displayed file is pdf or not
		if( $('#content'+ contentnum).attr("src").match("iFrame_Special_for_Pic_type.php")!=null ) // analysis innerHTML
		{
			var myIFrame = document.getElementById("content"+currentnum);
    		var content = myIFrame.contentWindow.document.body.innerHTML;
    		    		   		
     		if($(content).find("#ad_img").attr("src").match(".converted.pdf.pdf")!=null)
     		{
     			on_converted_pdf = 1;
			} 
    		else if($(content).find("#ad_img").attr("src").match(".pdf")!=null)
    		{
				on_original_pdf = 1;
    		}
    	}
    	else  //examine src inside <iframe tag    	
    	{
    		if( $('#content'+ contentnum).attr("src").match(".converted.pdf.pdf")!=null ) 
     		{
     			on_converted_pdf = 1;
			}
    		else if( $('#content'+ contentnum).attr("src").match(".pdf")!=null )
    		{
				on_original_pdf = 1;
    		} 
    	}		
		layerinfo = $(xmldata).find("ses[id="+current_layer+"]");
		contid = $(layerinfo).find("screens[pos='"+contentnum+"']").attr('contId');   
		cont = $(xmldata).find("conts[id='"+contid+"']"); 
		
		//analysis converted pdf is exist or not
    	convPdf = $(cont).attr('convPdf');
    	exist_conv_Pdf = 0;
		if(convPdf!=null) //old version xml didn't have convPdf tag
		{                                                          
		    filetype = convPdf.toLowerCase().split('.');           
		    if (filetype.length > 1 )                                 
		    { //has converted Pdf                                       
		      exist_conv_Pdf = 1;                                 
		    }                                                        
		}    	    	 
    	
    	//analysis original file is pdf or not
    	var oripath = $(cont).attr('originalPath');
    	ispdf = 0;
    	if ( $(cont).attr('file') == 'true' ) 
    	{
      		filetype = oripath.toLowerCase().split('.');
      		if (filetype[filetype.length - 1] == 'pdf')
        	ispdf = 1;
        }
                 
    	if( on_converted_pdf == 0 && on_original_pdf == 0 )   	
    	{ 
    		if(ispdf == 1)
    		{
    			srcpath  = path + 'content'+contid+'.bin.'+filetype[filetype.length - 1] + '#toolbar=0&navpanes=0&scrollbar=0';
    			$('#content'+ contentnum).attr("src",srcpath);
    		}
    		else if(exist_conv_Pdf == 1)
    		{
    			srcpath = path + convPdf + '#toolbar=0&navpanes=0&scrollbar=0';
    			$('#content'+ contentnum).attr("src",srcpath);
    		}    		
    	}
}

function file2Office(currentnum)
{
	contentnum = currentnum ;
	if( contentnum != null ) //status : view has been enlarged to max 
	{                 		
		file2OfficebyNum(contentnum);
    }
    else //in nonomalview, each content try change to PDF    	
	{
		rownum =  $(xmldata).find("ses[id="+current_layer+"]").attr('vScreenNum');
  		colnum =  $(xmldata).find("ses[id="+current_layer+"]").attr('hScreenNum');

		for(i = 0 ; i < rownum ; i++ )
			for(j = 0 ; j < colnum ; j++ )
		  	{	
				//H7-025 var k = i * rownum + j;
				var k = i * colnum + j; //H7-025
				file2OfficebyNum(k);
			}
	}    	
}

function file2OfficebyNum(currentnum)
{ 
	 	contentnum = currentnum; 
	 	
		//examine src inside <iframe tag    	
		var displayFile = $('#content'+ contentnum).attr("src")
     	var on_office = 0;
     	filetype = displayFile.toLowerCase().split('.');
        if (filetype[filetype.length - 1] =='ppt'   ||  filetype[filetype.length - 1] == 'doc'  ||  filetype[filetype.length - 1] == 'xls'  ||
        	filetype[filetype.length - 1] =='pptx'  ||  filetype[filetype.length - 1] == 'docx' ||  filetype[filetype.length - 1] == 'xlsx' ||   // 多增加一些是office的副檔名G5-000
        	filetype[filetype.length - 1] =='odp'   ||  filetype[filetype.length - 1] == 'odt'  ||  filetype[filetype.length - 1] == 'ods' )     // 多增加一些是office的副檔名G5-000
        on_office = 1;
    	
    	//analysis original file is office or not		
		layerinfo = $(xmldata).find("ses[id="+current_layer+"]");
		contid = $(layerinfo).find("screens[pos='"+contentnum+"']").attr('contId');   
		cont = $(xmldata).find("conts[id='"+contid+"']"); 
		
		var ori_isoffice = 0;
		var oripath = $(cont).attr('originalPath');
		filetype = oripath.toLowerCase().split('.');
		if (filetype[filetype.length - 1] =='ppt'   ||  filetype[filetype.length - 1] == 'doc'  ||  filetype[filetype.length - 1] == 'xls'  ||
        	filetype[filetype.length - 1] =='pptx'  ||  filetype[filetype.length - 1] == 'docx' ||  filetype[filetype.length - 1] == 'xlsx' ||   // 多增加一些是office的副檔名G5-000
        	filetype[filetype.length - 1] =='odp'   ||  filetype[filetype.length - 1] == 'odt'  ||  filetype[filetype.length - 1] == 'ods' )     // 多增加一些是office的副檔名G5-000
        ori_isoffice = 1;	    	 

    	if( on_office == 0 && ori_isoffice == 1 )   	
    	{ 
    			srcpath  = path + 'content'+contid+'.bin.'+filetype[filetype.length - 1];
    			$('#content'+ contentnum).attr("src",srcpath);
    	}
}

function KM_ExistConvPDF(currentlayer)
{
	current_layer = currentlayer
	layerinfo = $(xmldata).find("ses[id="+current_layer+"]");
	rownum = $(layerinfo).attr('vScreenNum');
	colnum = $(layerinfo).attr('hScreenNum');
	KM_HasPDF = false;
  	for(i = 0 ; i < rownum ; i++ )
		for(j = 0 ; j < colnum ; j++ )  
		{
			var k = i * rownum + j;
			contid = $(layerinfo).find("screens[pos='"+k+"']").attr('contId');   
			cont = $(xmldata).find("conts[id='"+contid+"']");      	
      		convPdf = $(cont).attr('convPdf');
      		if(convPdf!=null) //old version xml didn't have convFlash tag
			{
				filetype = convPdf.toLowerCase().split('.');
				if (filetype.length > 1 )
				{ //has converted Flash
	    			KM_HasPDF = true;
	    		}                                                        
			}
		}
	return KM_HasPDF;
			
}

function KM_ExistOriOffice(currentlayer)
{
	current_layer = currentlayer;
	layerinfo = $(xmldata).find("ses[id="+current_layer+"]");
	rownum = $(layerinfo).attr('vScreenNum');
	colnum = $(layerinfo).attr('hScreenNum');
	KM_HasOffice = false;
  	for(i = 0 ; i < rownum ; i++ )
		for(j = 0 ; j < colnum ; j++ )  
		{
			var k = i * rownum + j;
			contid = $(layerinfo).find("screens[pos='"+k+"']").attr('contId');   
			cont = $(xmldata).find("conts[id='"+contid+"']");      	
      		var oripath = $(cont).attr('originalPath');
      		
      		if ( $(cont).attr('file') == 'true' ) //H7-000
			{	//H7-000
				filetype = oripath.toLowerCase().split('.');
				if (filetype.length > 1 )
				{
					if (filetype[filetype.length - 1] =='ppt'   ||  filetype[filetype.length - 1] == 'doc'  ||  filetype[filetype.length - 1] == 'xls'  ||
						filetype[filetype.length - 1] =='pptx'  ||  filetype[filetype.length - 1] == 'docx' ||  filetype[filetype.length - 1] == 'xlsx' ||   // 多增加一些是office的副檔名G5-000
						filetype[filetype.length - 1] =='odp'   ||  filetype[filetype.length - 1] == 'odt'  ||  filetype[filetype.length - 1] == 'ods' )     // 多增加一些是office的副檔名G5-000
					KM_HasOffice = true;	
	    		}
	    	}	//H7-000	                                                             
		}
	return KM_HasOffice;			
}

function KM_ExistSnapshot(currentlayer)
{
	current_layer = currentlayer;
	layerinfo = $(xmldata).find("ses[id="+current_layer+"]");
	rownum = $(layerinfo).attr('vScreenNum');
	colnum = $(layerinfo).attr('hScreenNum');
	
	KM_HasSnapshot = false;
  	for(i = 0 ; i < rownum ; i++ )
		for(j = 0 ; j < colnum ; j++ )  
		{
			var k = i * rownum + j;
			contid = $(layerinfo).find("screens[pos='"+k+"']").attr('contId');   
			cont = $(xmldata).find("conts[id='"+contid+"']");      	
      		convSnapshot = $(cont).attr('convSnapshot');
	
			if(convSnapshot!=null) //old version xml didn't have convSnapshot tag
			{                                                          
				filetype = convSnapshot.toLowerCase().split('.');           
				if (filetype.length > 1 )                                 
				{ //has converted Snapshot                                      
					KM_HasSnapshot = true;                                 
				}                                                        
			}			                                      
		}
	return KM_HasSnapshot;			
}	
//G5-003 end ***************

//H7-004 start ************ Setting f_layer, f_focus in URL only works when iframe not contain a pic type file.**************
function Redirect_Layer_Focus(layer,focus)
{
	if( layer >= 1 && layer <= ( numoflayer ) )
	  {
		Get_Redirected_iFrame( ( layer-1 ) , focus );	//H7-006
		changelayer( ( layer - 1 ) );
		Focus_Enlarge(focus);
	  }
	  else
	  {
		Get_Redirected_iFrame( 0 , focus );	//H7-006
		changelayer(0);
		Focus_Enlarge(focus);		
		//window.setTimeout('Focus_Enlarge(focus)',1);
		//if(sBrowser=="Mozilla"){
		//	Focus_Enlarge(focus);
		//}
		//else if(sBrowser=="IE"){
		//	window.setTimeout('call_Focus_Enlarge()',1); //this way can prevent error
		//}
      }			
}

function Focus_Enlarge(focus_num)
{
	layerinfo = $(xmldata).find("ses[id="+current_layer+"]");
	rownum = $(layerinfo).attr('vScreenNum');
	colnum = $(layerinfo).attr('hScreenNum');
	if(	focus_num >= 1 && focus_num <= ( rownum * colnum ) )
	{
		resetFile = 1;
		maxview( (focus_num-1) , resetFile );
	}
	else if( focus_num != "" )
	{
		resetFile = 1;		
		maxview( 0 , resetFile );
	}
}
//H7-004 end *************

//H7-006 start *********
function Get_Redirected_iFrame(layer,focus)
{
	layerinfo = $(xmldata).find("ses[id="+layer+"]");
	rownum = $(layerinfo).attr('vScreenNum');
	colnum = $(layerinfo).attr('hScreenNum');
	
	if(	focus >= 1 && focus <= ( rownum * colnum ) )
	{
		focused_content = focus - 1;
	}
	else if( focus != "" )
	{
		focused_content = 0;
	}
}
//H7-006 end   *********
//H7-008 start *********
function ChangeOverClass_PM(e){
  class_ori=jQuery(e).attr('class')
  jQuery(e).attr('ori_class',class_ori)
  jQuery(e).attr('class',class_ori+"_hover")
  ShowOverText_PM(e)
}
function ChangeOutClass_PM(e){
  class_ori=jQuery(e).attr('ori_class')
  jQuery(e).attr('class',class_ori)
  ShowOutText_PM(e)
}
function ShowOverText_PM(e){
  title=jQuery(e).attr('title')
  jQuery("#Change_File_Buttons_Title").html(title)
}
function ShowOutText_PM(e){
  jQuery("#Change_File_Buttons_Title").html('')
}
//H7-008 end   *********

// ========================= New Web KM Functions ========================
//H7-015 ****** start
$(document).ready(
function(){
	$("#page_layer").hover(
		function ()
		{
			$("#page_info").attr('src','./img/H_page_info_mouseover.png');
				
			// check this km error mes from getSMContent.php    
			result = $(xmldata).find("Result").attr("error");
			if ( result == 0 ) //ok for fn
			{
				var P_info_st1 = "<table allowtransparency='true' background-color='transparent' align='center' id='page_title' width='95%' cellspaciing='0px' cellpadding='0px' style='position:absolute;top:0px;left:8px;'><tr><td><div allowtransparency='true' background-color='transparent' style='position:relative;left:20px;font-size:12;color:#FFFFFF;'>請選擇KM頁層</div></td></tr>";
				//<a  class='subbutten' href='javascript:changelayer("+i+")' onclick='focused_content = null'>"+(i+1)+"</a>
				var P_info_st2 = "";			
				for (i = 0 ; i <= (numoflayer-1) ; i++)
				{
					layerinfo = $(xmldata).find("ses[id="+i+"]");
					name = $(layerinfo).attr('name');
					if(name == "")
					{
						name="未設定主旨";
					}
					P_info_st2 = P_info_st2 + "<tr><td><a style='text-decoration:none;word-break:break-all;font-size:11;color:#FFFFFF;cursor:pointer;'  href='javascript:changelayer("+i+")' onclick='focused_content = null'>" + (i+1) +"." + name +"</a></td></tr>";		
				}
			
				P_info_st3 = P_info_st1  + P_info_st2 + "</table>";

				$("#layer_panel").html(P_info_st3);

				$("#layer_panel_background").css('visibility','visible');
				var children = jQuery(this).children('#layer_panel');
				children.css('visibility','visible');
			}else{ /* do nothing */}
		}
		,
		function ()
		{
			$("#page_info").attr('src','./img/H_page_info.png');
			
			// check this km error mes from getSMContent.php    
			result = $(xmldata).find("Result").attr("error");
			if ( result == 0 ) //ok for fn
			{
				$("#layer_panel_background").css('visibility','hidden');		
				jQuery(this).children('#layer_panel').css('visibility','hidden');
			}else{ /* do nothing */}
		}
	);
});
//H7-015 ****** end

//H7-014 ****** start
function recommend_system()
{	
	// check this km error mes from getSMContent.php    
    result = $(xmldata).find("Result").attr("error");
    if ( result == 0 ) //ok for operater recommend fn
	{
		  try{
			km_id=km_id_from_username
			}catch(e){
			km_id=getURLParam("id")
			}
		// check login or not
		jQuery.getJSON('check_login.php', {"noCache":Date()},function(data) {//H7-024 add noCache:Date()  ==> getJOSN without cache result
		if(data.user_id == null){
			alert ("請先登入U match，再嘗試推薦");
		}
		else{
			var user_id = data.user_id;
			jQuery.getJSON('recommend_check.php',{"noCache":Date(),user:user_id,km:km_id}, function(data) {//H7-024 add noCache:Date()  ==> getJOSN without cache result
			
				//alert(data.recommend_check);
				if(data.recommend_check){
					alert("您已經推薦過此Smart Matrix");
				}else{
				
					var recommend_confirm = confirm("確定要推薦此Smart Matrix?");//comfirm want to recommend or not

					if(recommend_confirm){
					
						//1. insert data 	
						jQuery.getJSON('recommend_record.php',{user:user_id,km:km_id}, function(data) {
							if(data.record_confirm){
								alert("推薦成功");
							}else{
								alert("推薦失敗");
							}
						});
					
						//2. update recommend number fn
						recommend_num_refresh();
				
						}else{	/*do nothing*/	}
					}
				});
			}
		});
	}else{	/*do nothing*/	}
}

function recommend_num_refresh()
{
	jQuery.getJSON('recommend_refresh.php',{"noCache":Date(),km:km_id}, function(data) {//H7-024 add noCache:Date()  ==> getJOSN without cache result
		$("#recommend_num").html(data.recommend_num);
	});
}

$(document).ready(function(){
	  try{
      km_id=km_id_from_username
		}catch(e){
		km_id=getURLParam("id")
		}
	recommend_num_refresh();
});
//H7-014 ****** end

//H7-016 ****** start
function triangle_show(e){
	var img_path = $(e).attr('src');
	var img_path_array = img_path.split(".");
	img_path_array[0]=".";
	img_path_array[img_path_array.length-1]="_mouseover."+img_path_array[img_path_array.length-1];
	var mouseover_img_path = img_path_array.join("");
	
	var tag = $(e).attr('id');
	var tag_array = tag.split("");
	var tag_num = parseInt(tag_array[tag_array.length-1]);
	
	$(e).attr('src',mouseover_img_path);
	$('#triangle_'+tag_num).attr('style','visibility:visible');
	
}

function triangle_hide(e){
	var img_path = $(e).attr('src');
	var img_path_array = img_path.split("_mouseover");
	var mouseover_img_path = img_path_array.join("");
	
	var tag = $(e).attr('id');
	var tag_array = tag.split("");
	var tag_num = parseInt(tag_array[tag_array.length-1]);
	
	$(e).attr('src',mouseover_img_path);
	$('#triangle_'+tag_num).attr('style','visibility:hidden');
}

function mail_AI()
{
	//check login or not
	//if not login, alert please login
	//else open a new page - mail to service department

	// check this km error mes from getSMContent.php    
	result = $(xmldata).find("Result").attr("error");
	if ( result == 0 ) //ok for fn
	{
		jQuery.getJSON('check_login.php',{"noCache":Date()}, function(data) {//H7-024 add noCache:Date()  ==> getJOSN without cache result
			if(data.user_id == null){
				alert ("請先登入U match，再寄信給 AI Bunny");
			}
			else{
				if(morgenstern_root_path == ""){
					window.open("../../../index.php/bunny/contact");
				}else{
					window.open("http://www.morgenstern.com.tw/users2/index.php/bunny/contact");
				}		
			}
		});
	}else{ /* do nothing */}
}

function Msg_Board()
{
	//check login or not
	//if not login, alert please login
	//else open a new page - msg board

	
	// check this km error mes from getSMContent.php    
	result = $(xmldata).find("Result").attr("error");
	if ( result == 0 ) //ok for fn
	{
		jQuery.getJSON('check_login.php',{"noCache":Date()}, function(data) {//H7-024 add noCache:Date()  ==> getJOSN without cache result
			if(data.user_id == null){
				alert ("請先登入U match，再進入作者留言板");
			}
			else{
				  try{
					km_id=km_id_from_username
					}catch(e){
					km_id=getURLParam("id")
					}
				jQuery.getJSON('get_uploader_from_km.php',{"noCache":Date(),km:km_id}, function(data) {//H7-024 add noCache:Date()  ==> getJOSN without cache result
					if(morgenstern_root_path == ""){
						window.open("../../../index.php/soul_match_messageboard/index/"+data.uploader_uid);
					}else{
						window.open("http://www.morgenstern.com.tw/users2/index.php/soul_match_messageboard/index/"+data.uploader_uid);
					}				
				});

			}
		});
	}else{ /* do nothing */}
}

function make_friend()
{	
	// 1.	check this km error mes from getSMContent.php    
	result = $(xmldata).find("Result").attr("error");
	if ( result == 0 ) //ok for fn
	{
		//	2.	check login or not
		jQuery.getJSON('check_login.php',{"noCache":Date()}, function(data) {//H7-024 add noCache:Date()  ==> getJOSN without cache result
			if(data.user_id == null){
				alert ("請先登入U match，再加入對方好友");
			}
			else{
				//	3-a check user id is soul match member or not
				//	3-b	check target( km uploader ) id is soul match member or not
				//	4.	check if they are friend or not
				user_id = data.user_id;
				  try{
					km_id=km_id_from_username
				}catch(e){
					km_id=getURLParam("id")
					}
				jQuery.getJSON('make_friend_conditions.php',{"noCache":Date(),user:user_id,km:km_id}, function(data) {//H7-024 add noCache:Date()  ==> getJOSN without cache result
					if ( data.limit_message == null ){
						//	5.	confirm : are you sure you want to make friend with this guy?
						var make_friend_confirm = confirm("確定要加此KM作者為好友?");
						if(make_friend_confirm){					
							//	insert data 							
							jQuery.getJSON('make_friend_record.php',{user:user_id,km:km_id}, function(data) {
								alert(data.record_confirm);
							});
						}else{
						// do nothing
						}					
					}
					else{
						alert(data.limit_message);
					}
				});		
			}
		});
	}else{ /* do nothing */	}
}
//H7-016 ****** end
//H7-017 ****** start
function subscribe_system()
{
	// 1.	check this km error mes from getSMContent.php    
	result = $(xmldata).find("Result").attr("error");
	if ( result == 0 ) //ok for fn
	{
		//	2.	check login or not
		jQuery.getJSON('check_login.php',{"noCache":Date()}, function(data) {//H7-024 add noCache:Date()  ==> getJOSN without cache result
			if(data.user_id == null){
				alert ("請先登入U match，再訂閱此作者KM");
			}
			else{
					user_id = data.user_id;
					  try{
					km_id=km_id_from_username
					}catch(e){
					km_id=getURLParam("id")
					}
					//	3.	check this user have subscribed this km owner or not
					jQuery.getJSON('subscribe_check.php',{"noCache":Date(),user:user_id,km:km_id}, function(data) {//H7-024 add noCache:Date()  ==> getJOSN without cache result
						if ( data.subscribed_limit == null ){
							var subscribe_confirm = confirm("確定要訂閱此作者KM?");
							if(subscribe_confirm){
								//	4.	subscribe operation : insert into smartmatrix.smartmatrix_subscribe 							
								jQuery.getJSON('subscribe_record.php',{user:user_id,km:km_id}, function(data) {
									alert(data.record_confirm_msg);
									//alert("insert data");
								});
							}else{
							// do nothing
							}
						}else{
							alert(data.subscribed_limit);
						}
					});	
				}
		});
	}else{ /* do nothing */	}
}

function accuse_system()
{
	// 1.	check this km error mes from getSMContent.php    
	result = $(xmldata).find("Result").attr("error");
	if ( result == 0 ) //ok for fn
	{
		//	2.	check login or not
		jQuery.getJSON('check_login.php',{"noCache":Date()}, function(data) {//H7-024 add noCache:Date()  ==> getJOSN without cache result
			if(data.user_id == null){
				alert ("請先登入U match，再檢舉此作者KM");
			}
			else{
				  try{
					km_id=km_id_from_username
					}catch(e){
					km_id=getURLParam("id")
					}
				window.open("./accuse_submit.php?km="+km_id);
			}
		});
	}else{ /* do nothing */	}
}

//H7-017 ****** end
//H7-018 ****** start
function forward_friends()
{
	// 1.	check this km error mes from getSMContent.php    
	result = $(xmldata).find("Result").attr("error");
	if ( result == 0 ) //ok for fn
	{
		//	2.	check login or not
		jQuery.getJSON('check_login.php',{"noCache":Date()}, function(data) {//H7-024 add noCache:Date()  ==> getJOSN without cache result
			if(data.user_id == null){
				alert ("請先登入U match，再檢舉此作者KM");
			}
			else{
				  try{
					km_id=km_id_from_username
					}catch(e){
					km_id=getURLParam("id")
					}
				window.open("http://www.morgenstern.com.tw/users2/index.php/forward_friends?km_id="+km_id);
			}
		});
	}else{ /* do nothing */	}
}
//H7-018 ****** end