/**************************************************************************
  레이어 팝업 모듈            - 07. 2. 13  by Hamt -



  모든 페이지에 인클루드 되는 파일에 이 소스를 추가한다.

  <!-- new popup start -->
  <div id="dialogbackgroundlayer" style="display:none;position:absolute;z-index:11;" onclick="win.dialog_close()">
  </div>
  <div id="dialoglayer" style="display:none;position:absolute;z-index:12;">
  </div>
  <div id=message style="display:none;position:absolute;left:0px;top:0px;padding:3px;background:#cc0000;color:#ffffff;font-size:13px;font-weight:bold;z-index:100;"></div>
  <script>
  var win = new new_popup();
  </script>
  <!-- new popup end -->
/***************************************************************************/

var popup_req = false;//for popup ajax
var popup_script = false;//dialog_open 네번째 인자로, 레이어 팝업창을 띄운 직후 실행할 스크립트 값
var in_alertcount = 0;

var sl_url = "";
var sl_w_width = "";
var sl_w_height = "";
var sl_run_script = "";
var sl_type = "";
var sl_base_dir = "";

var arrProductList = new Array();
arrProductList = new Array('AA1','AA2','AA3','AA4','AB1','AB2','AC1','AC2','BA1','BA2','BA3','BB1','BB2','BC1','BC2','BC3','BC4','BD1','BD2','BD3','BD4');


var curfullURL = document.location.href;

if(curfullURL.indexOf("/Korea/") != -1){
	sl_base_dir = "/Korea";
}else if(curfullURL.indexOf("/Global/") != -1){
	sl_base_dir = "/Global";
}else{
	sl_base_dir = "/China";
}

function new_popup()
{
	this.agent_name = navigator.userAgent.toLowerCase();
	this.is_ie		= ((this.agent_name.indexOf("msie") != -1) && (this.agent_name.indexOf("opera") == -1));
	this.is_gecko	= navigator.product;

	this.position_x = 0;
	this.position_y = 0;
	this.ajax_url	= '';

	this.dlg_bg = document.getElementById('dialogbackgroundlayer');
	this.dlg	= document.getElementById('dialoglayer');
	this.msg	= document.getElementById('message');

	this.dlg_bg.style.left			= '0px';
	this.dlg_bg.style.top			= '0px';
	this.dlg_bg.style.width			= '100%';
	this.dlg_bg.style.background	= "#000";
	this.dlg_bg.style.opacity		= (50/100);
	this.dlg_bg.style.MozOpacity	= (50/100);
	this.dlg_bg.style.KhtmlOpacity	= (50/100);
	this.dlg_bg.style.filter		= "alpha(opacity=50)";
	
	this.dialog_left= function()
	{
		var curProductCode = sl_url.substr(sl_url.length-3,3);
	
		for(var i=0;i<=arrProductList.length-1;i++){
			if(curProductCode == arrProductList[i]){
				if(i!=0){
					sl_url = sl_base_dir + "/product/popup.asp?code=" + arrProductList[i-1];
					this.dialog_open(sl_url, sl_w_width, sl_w_height, sl_run_script, sl_type);
				}else{
					alert("제품의 처음입니다.");
					break;
				}
			}
		}
	}
	this.dialog_right= function()
	{
		var curProductCode = sl_url.substr(sl_url.length-3,3);
	
		for(var i=0;i<=arrProductList.length-1;i++){
			if(curProductCode == arrProductList[i]){
				if(i!=arrProductList.length-1){
					sl_url = sl_base_dir + "/product/popup.asp?code=" + arrProductList[i+1];
					this.dialog_open(sl_url, sl_w_width, sl_w_height, sl_run_script, sl_type);
				}else{
					alert("제품의 끝입니다.");
					break;
				}
			}
		}
	}
	this.dialog_open= function(url, w_width, w_height, run_script, type)
	{
		sl_url			= url;
		sl_w_width		= w_width;
		sl_w_height		= w_height;
		sl_run_script	= run_script;
		sl_type			= type;
		
		//(document.body.scrollWidth/2)-(sl_w_width/2)

		var height = document.body.scrollHeight;
		if(!w_height) w_height = 170;
		if (this.is_gecko) height += 10;

		this.dlg_bg.style.height = height + 'px';
		this.dlg_bg.style.display = '';
		
		if(type == "Product"){
			var tmpLeft = "40%";
			var top		= "50%";
		}else{
			var tmpLeft = "40%";
			var top		= "10%";
		}

		this.dlg.style.left = (document.body.clientWidth/2)-(sl_w_width/2) + "px";
		this.dlg.style.top = ((document.body.clientHeight/2)-(sl_w_height/2))+ document.body.scrollTop + "px";

		//this.dlg.style.marginLeft = w_width/2*-1+"px";
		
		if (run_script)
			popup_script = run_script;
		else
			popup_script = false;

		this.load(url);
		this.dlg.style.display = '';

	}
	this.dialog_close= function()
	{
		this.dlg_bg.style.display = 'none';
		this.dlg.style.display = 'none';
		this.dlg.innerHTML = '';
	}

	this.in_alert = function(message)
	{
		this.msg.innerHTML = message;
		this.msg.style.display = '';
		window.setTimeout(this.in_alert_hidden, 2000);
		in_alertcount++;
	}
	this.in_alert_hidden = function()
	{
		in_alertcount--;
		if(!in_alertcount)
			document.getElementById('message').style.display = 'none';
	}

	this.load = function(url) {
		popup_req= false;
		// branch for native XMLHttpRequest object
		if (window.XMLHttpRequest) {
			try {
				popup_req = new XMLHttpRequest();
			}
			catch(e) {
				popup_req = false;
			}
		}
		// branch for IE/Windows ActiveX version
		else if (window.ActiveXObject) {
			try {
				popup_req = new ActiveXObject("Msxml2.XMLHTTP");
			}
			catch(e) {
				try {
					this.req= new ActiveXObject("Microsoft.XMLHTTP");
				}
				catch(e) {
					popup_req  = false;
				}
			}
		}
		if (popup_req ) {

			popup_req.onreadystatechange = this.processPopup;
			popup_req.open("GET", url, true);
			popup_req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
			popup_req.send("");
		}
	}
	this.processPopup = function() {
		// only if req shows "loaded"
		var obj = document.getElementById('dialoglayer');
		if (popup_req.readyState == 4) {
			// only if "OK"
			obj.innerHTML = popup_req.responseText;
			if (popup_script)
				eval(popup_script);
		}
	}
}