﻿    var leftDivID="";
    var rightDivID="";
    function OnLookupPost(blogid,postid,channel)
    {           
        var wRequest =  new Sys.Net.WebRequest();    
        wRequest.set_url("./loadpost.aspx?m=post&b="+blogid+"&p="+postid+"&c="+channel+ "&ts=" + Date.parse(new Date()));
        rightDivID="post";
        wRequest.add_completed(OnLookupCompleteRight);    
        wRequest.invoke();  
    }
    function OnLookupTricks(blogid,postid,channel)
    {           
        var wRequest =  new Sys.Net.WebRequest();    
        wRequest.set_url("./loadpost.aspx?m=tricks&b="+blogid+"&c="+channel+"&p="+postid+ "&ts=" + Date.parse(new Date()));   
        leftDivID="tricks";
        wRequest.add_completed(OnLookupCompleteLeft);     
        wRequest.invoke();  
    }
    function OnLoadMemberTricksList(type,channel,div)
    {           
        var wRequest =  new Sys.Net.WebRequest();    
        if(channel=='')
            wRequest.set_url("./loadtrickslist.aspx?t="+type+"&d="+div);
        else 
            wRequest.set_url("./loadtrickslist.aspx?t="+type+"&c="+channel+"&d="+div+ "&ts=" + Date.parse(new Date()));  
        rightDivID="Tricks";
        wRequest.add_completed(OnLookupCompleteRight); 
        wRequest.invoke();  
    }
     function OnLoadMemberTopTricksList(type,channel)
    {           
        var wRequest =  new Sys.Net.WebRequest();    
        if(channel=='')
            wRequest.set_url("./loadtrickslist.aspx?t="+type+ "&ts=" + Date.parse(new Date()));
        else 
            wRequest.set_url("./loadtrickslist.aspx?t="+type+"&c="+channel+ "&ts=" + Date.parse(new Date()));  
        leftDivID="TopTricks";
        wRequest.add_completed(OnLookupCompleteLeft); 
        wRequest.invoke();  
    }
    function OnLoadMemberTricks(channel,postid,div)
    {           
        var wRequest =  new Sys.Net.WebRequest();    
        wRequest.set_url("./loadtricks.aspx?c="+channel+"&p="+postid+ "&ts=" + Date.parse(new Date()));
        rightDivID=div;
        wRequest.add_completed(OnLookupCompleteRight);   
        wRequest.invoke();  
    }
    function OnLookupCompleteLeft(executor, eventArgs)
    {
         if(executor.get_responseAvailable())     
         {        
            //由Response中取出XML            
              var res = document.getElementById(leftDivID);
              res.innerHTML =  executor.get_responseData();    
         }
         else    
         {        
            if (executor.get_timedOut())            
                res.innerHTML ="網路繁忙,資料傳遞逾時,請重試!!";        
            else if (executor.get_aborted())            
                res.innerHTML ="網路中斷,請重試!!";  
          } 
          //xs_scroll();
          leftDivID="";
    }
    function OnLookupCompleteRight(executor, eventArgs)
    {
         if(executor.get_responseAvailable())     
         {        
            //由Response中取出XML            
              var res = document.getElementById(rightDivID);
              res.innerHTML =  executor.get_responseData();              
         }
         else    
         {        
            if (executor.get_timedOut())            
                res.innerHTML ="網路繁忙,資料傳遞逾時,請重試!!";        
            else if (executor.get_aborted())            
                res.innerHTML ="網路中斷,請重試!!";  
          } 
          //xs_scroll();
          rightDivID="";
    }

    function Pagging(blogid,postid,channel,page)
    {           
        var wRequest =  new Sys.Net.WebRequest();   
        wRequest.set_url("./loadpost.aspx?m=post&b="+blogid+"&p="+postid+"&page="+page+"&c="+channel+ "&ts=" + Date.parse(new Date()));     
        rightDivID="post";

        wRequest.add_completed(OnLookupCompleteRight);    
        wRequest.invoke();  
    }
    
    function TricksPagging(div,type,channel,page)
    {           
        var wRequest =  new Sys.Net.WebRequest();    
        wRequest.set_url("./loadtrickslist.aspx?t="+type+"&c="+channel+"&page="+page+"&d="+div+ "&ts=" + Date.parse(new Date()));
        rightDivID="Tricks";
        
        wRequest.add_completed(OnLookupCompleteRight);    
        wRequest.invoke();  
    }
    function checkaccount()
    {
            var wRequest =  new Sys.Net.WebRequest();    
            wRequest.set_url("./login.aspx");              
            wRequest.add_completed(OnCheckAccountComplete);    
            wRequest.invoke();  
    }
     function OnCheckAccountComplete(executor, eventArgs)
    {
         if(executor.get_responseAvailable())     
         {        
            //由Response中取出XML            
              var res = document.getElementById("checka");
              //alert(executor.get_responseData());
              res.innerHTML =  executor.get_responseData();              
         }
          //xs_scroll();
    }
//Popup Iframe when Admin User Reply Post.
function PostReply(bid,pid, cid)
{
    popupiframe('./dmcomment.aspx?b='+bid+'&p=' + pid + '&c=' + cid,'500','380');  
}
function TrickReply(channel,postid)
{
    popupiframe('./trickcomment.aspx?c='+channel+'&p=' + postid ,'500','380');  
}
function dmLogin()
{
    popupiframe('./login.aspx?','330','480');  
}


function popupiframe(url,width,height)
{

//document.write("");
//document.write("<style type='text/css'>");
//document.write(".popUp");
//document.write("{");
//document.write("	position : 'fixed';");
//document.write("	zIndex : 3;");
//document.write("	backgroundColor:= 'transparent';");
//document.write("	border : '0';");
//document.write("	frameborder : 'no'; ");
//document.write("	framespacing : '0';");
//document.write("	allowTransparency : 'true'; ");
//document.write("}");
//document.write("</style>");

window.scrollTo(0, 0);
  var screenwidth =  document.body.clientWidth ;//document.documentElement.clientWidth + document.documentElement.scrollLeft;
 var screenheight =  screen.height;

  var layer = document.createElement('div');
  layer.style.zIndex = 2;
  layer.id = 'layer';
//  layer.style.position = 'absolute';
//  layer.style.top = '0px';
//  layer.style.left = '0px';
//  layer.style.height =screenheight+"px";// document.documentElement.scrollHeight + 'px';
//  layer.style.width = screenwidth + 'px';
//  layer.style.backgroundColor = 'transparent';
//  layer.style.opacity = '.6';
//  layer.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=60)");
//  document.body.style.position = 'static';
  document.body.appendChild(layer);  
  
  var size = { 'height':height , 'width':width };
  var iframe = document.createElement('iframe');
  iframe.name = 'Post Reply';
  iframe.id = 'iframePostReply';
	iframe.src = url + "&ts=" + Date.parse(new Date());
	iframe.style.height = size.height + 'px';
	iframe.style.width = size.width + 'px';
	iframe.style.position = 'fixed';
	iframe.style.zIndex = 3;
	iframe.style.backgroundColor = 'transparent';
	iframe.style.border = '0';
    iframe.style.framespacing = '0';
	//iframe.style.frameborder = 'no';//	frameborder
	//iframe.style.allowTransparency='true';//
	
	iframe.setAttribute('frameborder' , 'no',0);//	frameborder
	iframe.setAttribute('allowTransparency','true',0);//
	

	iframe.style.top =100 + ((screenheight + document.documentElement.scrollTop) / 3) - (size.height / 2) + 'px';
	iframe.style.left = (screenwidth / 2) - (size.width / 2) + 'px';	
	
  document.body.appendChild(iframe);  
}

function closeiframe(iframe,layer)
{
    var layer = parent.document.getElementById(layer);
    layer.parentNode.removeChild (layer);
    var ifr = parent.document.getElementById(iframe);
    ifr.parentNode.removeChild(ifr);       
}
function parentredirect(page)
{
     parent.location.href=page;
}

function getQueryParameter ( parameterName ) {
  var queryString = window.top.location.search.substring(1);
  var parameterName = parameterName + "=";
  if ( queryString.length > 0 ) {
    begin = queryString.indexOf ( parameterName );
    if ( begin != -1 ) {
      begin += parameterName.length;
      end = queryString.indexOf ( "&" , begin );
        if ( end == -1 ) {
        end = queryString.length
      }
      return unescape ( queryString.substring ( begin, end ) );
    }
  }
  return "null";
} 

