//================ AJAX 子視窗控制項 屬於Taiwan KTTECH 所有 ================
//若無授權請勿任意複製
//http://www.kttech.com.tw
//===================================================================

//起始值==
document.write("<div id='subwin' class='subwin' style='position: absolute; z-index:99999992;display:none;left:0px;top:0px' ><div id='subwin_title' class='subwin_title'><a href=javascript:subwin_close('');><div class='cancelbutton'></div></a></div><div id='subwin_content' class='subwin_content'></div></div><div id='all_loc' style='position:absolute; z-index:99999991;width:100%; height:100%;background-color:white;left:0px; top:0px;filter:alpha(opacity=0);opacity:0;DISPLAY:none'></div>");
document.write("<div id='subwin_1' class='subwin' style='position: absolute; z-index:9994;display:none;left:0px;top:0px' ><div id='subwin_title_1' class='subwin_title'><a href=javascript:subwin_close('_1');><div class='cancelbutton'></div></a></div><div id='subwin_content_1' class='subwin_content'></div></div><div id='all_loc_1' style='position:absolute; z-index:9993;width:100%; height:100%;background-color:white;left:0px; top:0px;filter:alpha(opacity=0);opacity:0;DISPLAY:none'></div>");
document.write("<div id='subwin_2' class='subwin' style='position: absolute; z-index:9994;display:none;left:0px;top:0px' ><div id='subwin_title_2' class='subwin_title'><a href=javascript:subwin_close('_2');><div class='cancelbutton'></div></a></div><div id='subwin_content_2' class='subwin_content'></div></div><div id='all_loc_2' style='position:absolute; z-index:9993;width:100%; height:100%;background-color:white;left:0px; top:0px;filter:alpha(opacity=0);opacity:0;DISPLAY:none'></div>");

var html_lefts,close_loc
var opacity=0;

//抓取清單 start=======================================================
function subwin_get(url,title,win_w,win_h,layer,close_loc1,filter) {
    if(typeof(layer)=="undefined"){layer=""}
    
    var subwin_HTMLs
    var ids=new Date();ids=ids.getFullYear()+''+(ids.getMonth()+1)+''+ids.getDate()+''+ids.getHours()+''+ids.getMinutes()+''+ids.getSeconds();
    if(layer){layer="_"+layer;}else{layer="";}
    
    if(url.indexOf("?")!=-1){
        url=url+"&dr="+ids
    }else{
        url=url+"?dr="+ids
    }
    
    subwin_HTMLs="<iframe name=subwin_frame"+layer+" id=subwin_frame"+layer+" marginwidth=0 marginheight=0  frameborder=0 border=0 width='" + win_w + "' height='" + win_h + "' src='" + url + "''></iframe>"
    
    
    //頁面總高度/寬度
    var pageWidth = window.innerWidth
    var pageHeight = window.innerHeight;
    pageWidth = document.body.scrollWidth;
    pageHeight =  document.body.scrollHeight;
    if(document.body.scrollHeight<window.innerHeight){pageHeight=window.innerHeight}
    
    html_lefts= (document.body.offsetWidth/2 )  - (win_w/2)+document.body.scrollLeft
    document.getElementById("all_loc"+layer).style.height =   (pageHeight)+"px"
    document.getElementById("all_loc"+layer).style.width =  (pageWidth)+"px"
    
    
    
    document.getElementById('subwin'+layer).style.left=(html_lefts+200)+"px"
    
    var ch=document.body.clientHeight
    if((document.documentElement.clientHeight>0&&document.documentElement.clientHeight<document.body.clientHeight)||ch==0){
        ch=document.documentElement.clientHeight
    }
    var scrollTops=document.body.scrollTop
    if(document.documentElement.scrollTop>0){
        scrollTops=document.documentElement.scrollTop
    }
    
    if(ch<window.innerHeight){ch=window.innerHeight}
    
    document.getElementById('subwin'+layer).style.top=((ch/2 ) - (win_h/2)+scrollTops)+"px"
    
    
    
    
    if (document.getElementById('subwin'+layer).style.top.replace("px", "") * 1 - document.body.scrollTop < 0) { document.getElementById('subwin'+layer).style.top =( 5 + document.body.scrollTop)+"px" }
    
    
    document.getElementById("subwin_content"+layer).innerHTML=subwin_HTMLs;
    //document.body.style.overflow = "hidden";
    document.getElementById("subwin"+layer).style.display = ""; document.getElementById("all_loc"+layer).style.display = ""
    document.getElementById("all_loc"+layer).style.width="100%"
    document.getElementById("all_loc"+layer).style.height="100%"
    
    if(close_loc1!=null){alert(close_loc1)
        if(typeof(close_loc1)!="undefined"){close_loc=document.getElementById(close_loc1);close_loc.style.display='none';}}
    
    opacity=0;
    
    
    //if (jQuery) {
    //$("#all_loc"+layer).css("opacity","0.2")
    //$("#all_loc"+layer).stop().animate({opacity:0.95},700, "easeOutQuint");
    //var sub_move_left=((document.getElementById("subwin"+layer).style.left.replace("px","")*1))
    //$("#subwin"+layer).stop().animate({left:html_lefts},700, "easeOutQuint");
    //}else{
    if(filter!=0){setTimeout("subwin_bk_act('"+layer+"')",30);}else{document.getElementById("all_loc"+layer).style.display="none"}
    setTimeout("subwin_open_act('"+layer+"')",30);
    //}
}


//背景動畫
function subwin_bk_act(layer){
	if(opacity<90){opacity=opacity+25;if(opacity>90){opacity=90}
        document.getElementById("all_loc"+layer).style.opacity=opacity/100
        document.getElementById("all_loc"+layer).style.filter="alpha(opacity="+opacity+")"
        setTimeout("subwin_bk_act('"+layer+"')",80);
	}else{
        
	}
}

//背景離開動畫
function subwin_bk_act_close(layer){
	if(opacity>10){opacity=opacity-25;if(opacity<10){opacity=10}
        document.getElementById("all_loc"+layer).style.opacity=opacity/100
        document.getElementById("all_loc"+layer).style.filter="alpha(opacity="+opacity+")"
        setTimeout("subwin_bk_act_close('"+layer+"')",50);
	}else{
        document.getElementById("all_loc"+layer).style.display="none";
	}
}


//動畫
function subwin_open_act(layer){
    if(typeof(layer)=="undefined"){layer=""}
    if((document.getElementById("subwin"+layer).style.left.replace("px","")*1)>html_lefts){
        document.getElementById("subwin"+layer).style.left=((document.getElementById("subwin"+layer).style.left.replace("px","")*1)-50)+"px";
        setTimeout("subwin_open_act('"+layer+"')",80);
    }
}

//離開動畫
function subwin_close(layer){
    document.body.style.overflow = "";
    
    if(typeof(layer)=="undefined"){layer=""}
    if((document.getElementById("subwin"+layer).style.left.replace("px","")*1)>html_lefts-200){
        document.getElementById("subwin"+layer).style.left=((document.getElementById("subwin"+layer).style.left.replace("px","")*1)-100)+"px";
        setTimeout("subwin_close('"+layer+"')",50);
    }else{
        if(close_loc){close_loc.style.display='';close_loc=null}
        document.getElementById("subwin"+layer).style.display="none";
        //document.getElementById("all_loc"+layer).style.display="none";
        document.getElementById("subwin_content"+layer).innerHTML="";
        document.getElementById("subwin"+layer).style.left=html_lefts;
        document.body.style.overflow = "";
        setTimeout("subwin_bk_act_close('"+layer+"')",10);
        
        
        if (typeof close_event=="function"){
            close_event();
        }
        
        
    }
}
