var req;

function getXMLHttpRequest() {
 if (window.ActiveXObject) {
  try {
   return new ActiveXObject("Msxml2.XMLHTTP");
  } catch(e) {
   try {
    return new ActiveXObject("Microsoft.XMLHTTP");
   } catch(e1) { return null; }
  }
 } else if (window.XMLHttpRequest) {
  return new XMLHttpRequest();
 } else {
  return null;
 }
}

function pop_float(url,width,height){
	var left , top , float_height , float_width , margin_top;

	if(document.body.offsetWidth){
		left = Math.ceil((document.body.offsetWidth - (width))/2) + 'px';
		top = (Math.ceil((window.screen.height - (height))/2) - 100) + 'px';
	}
	else{
		left = 600 + 'px';
		top = 500 + 'px';
	}

	if(top < 0) top = 0;
	if(left < 0) left = 0;

	if(document.documentElement){
		float_height = document.documentElement.scrollHeight + 'px';
		float_width = document.documentElement.scrollWidth + 'px';
	}
	else if(document.all.tags('html')[0]){
		float_height = document.all.tags('html')[0].scrollHeight + 'px';
		float_width = document.all.tags('html')[0].scrollWidth + 'px';
	}
	else{
		float_height = '150%'
		float_height = window.screen.width + 'px';
	}

	var i;
	if(document.body.getElementsByTagName('select').length){
		for(i = 0;i < document.body.getElementsByTagName('select').length;i++){
			document.body.getElementsByTagName('select')[i].style.visibility = 'hidden';
		}
	}

	if(document.getElementById('pop_float') == null){
		var pop_float = document.createElement('DIV');
		pop_float.id = 'pop_float';
		pop_float.style.position = 'absolute';
		pop_float.style.zIndex = 19999;
		pop_float.style.width = float_width;
		pop_float.style.height = float_height;
		pop_float.style.top = 0;
		pop_float.style.left = 0;
		pop_float.style.backgroundColor = 'black';
		pop_float.style.filter = 'Alpha(Opacity=20)';
		pop_float.style.opacity = '0.2';
		document.body.appendChild(pop_float);
	}

	if(document.getElementById('pop_content') == null){
		var pop_content = document.createElement('DIV');
		pop_content.id = 'pop_content';
		pop_content.style.position = 'absolute';
		pop_content.style.zIndex = 20000;
		pop_content.style.width = width + 'px';
		pop_content.style.height = height + 'px';
		pop_content.style.marginTop = top;
		pop_content.style.marginLeft = left;
		pop_content.style.top = 0;
		pop_content.style.left = 0;
		pop_content.style.backgroundColor = 'white';
		pop_content.innerHTML = '<div style="text-align:center;margin-top:' + (parseInt(height / 2) - 50) + 'px"><img src="/images/loader.gif"></div>';
		document.body.appendChild(pop_content);
	}
	else{
		document.getElementById('pop_content').style.width = width + 'px';
		document.getElementById('pop_content').style.height = height + 'px';
		document.getElementById('pop_content').style.marginTop = top;
		document.getElementById('pop_content').style.marginLeft = left;
		document.getElementById('pop_content').innerHTML = '<div style="text-align:center;margin-top:' + (parseInt(height / 2) - 50) + 'px"><img src="/images/loader.gif"></div>';
	}

	req = getXMLHttpRequest();
	req.onreadystatechange = view_pop_float;
    req.open("GET", url, true);
    req.send(null);
	view_pop_float();
}

function view_pop_float(){ 
	if(req.readyState == 4) {
		if(req.status == 200){           
            var xmlDoc = req.responseText;
			document.getElementById('pop_content').innerHTML = xmlDoc;
        } 
		else{
            alert("잠시후 다시 시도해 주세요.");
        }
	}
}

function close_float(){
	var i;
	if(document.body.getElementsByTagName('select').length){
		for(i = 0;i < document.body.getElementsByTagName('select').length;i++){
			document.body.getElementsByTagName('select')[i].style.visibility = 'visible';
		}
	}
	
	if(document.getElementById('pop_content')) document.body.removeChild(document.getElementById('pop_content'));
	if(document.getElementById('pop_float')) document.body.removeChild(document.getElementById('pop_float'));
}

function pop_float_img(src){ 
	var tmp_img;
	tmp_img = new Image();
	tmp_img.src = src;
	tmp_img.alt = '닫기';

	var left , top , float_height , float_height;

	if(document.body.offsetWidth){
		left = Math.ceil((document.body.offsetWidth - 100)/2) + 'px';
		top = (Math.ceil((window.screen.height - 100)/2)-100) + 'px';
	}
	else{
		left =  600 + 'px';
		top = 500 + 'px';
	}
	if(top < 0) top = 0;
	if(left < 0) left = 0;

	if(document.documentElement){
		float_height = document.documentElement.scrollHeight + 'px';
		float_width = document.documentElement.scrollWidth + 'px';
	}
	else if(document.all.tags('html')[0]){
		float_height = document.all.tags('html')[0].scrollHeight + 'px';
		float_width = document.all.tags('html')[0].scrollWidth + 'px';
	}
	else{
		float_height = '150%'
		float_width = window.screen.width + 'px';
	}

	var i;
	if(document.body.getElementsByTagName('select').length){
		for(i = 0;i < document.body.getElementsByTagName('select').length;i++){
			document.body.getElementsByTagName('select')[i].style.visibility = 'hidden';
		}
	}
//	if(document.getElementById('pop_float') == null){
		var pop_float = document.createElement('DIV');
		pop_float.id = 'pop_float';
		pop_float.style.position = 'absolute';
		pop_float.style.zIndex = 19999;
		pop_float.style.width = float_width;
		pop_float.style.height = float_height;
		pop_float.style.top = 0;
		pop_float.style.left = 0;
		pop_float.style.backgroundColor = 'black';
		pop_float.style.filter = 'Alpha(Opacity=20)';
		pop_float.style.opacity = '0.2';
		document.body.appendChild(pop_float);
//	}

//	if(document.getElementById('pop_float') == null){
		var pop_content = document.createElement('DIV');
		pop_content.id = 'pop_content';
		pop_content.style.position = 'absolute';
		pop_content.style.zIndex = 20000;
		pop_content.style.marginTop = top;
		pop_content.style.marginLeft = left;
		pop_content.style.top = 0;
		pop_content.style.left = 0;
		pop_content.style.backgroundColor = 'white';
		pop_content.innerHTML = '<div style="cursor:pointer;font-size:0;line-height:0;border:5px solid #000;"><img src="/images/loader.gif"></div>';
		document.body.appendChild(pop_content);
/*	}
	else{
		document.getElementById('pop_float').marginTop = top;
		document.getElementById('pop_float').marginLeft = left;
		document.getElementById('pop_float').innerHTML = '<div style="cursor:pointer;font-size:0;line-height:0;border:5px solid #000;"><img src="/images/loader.gif"></div>';
	}*/

	if(tmp_img.width!=0){
		view_pop_float_img(tmp_img);
	}
	else{
		idleID = setTimeout('pop_float_img_loading("' + src + '")',50);
	}
}

function pop_float_img_loading(src){
	var tmp_img;
	tmp_img = new Image();
	tmp_img.src = src;
	tmp_img.alt = '닫기';

	if(tmp_img.width!=0){
		view_pop_float_img(tmp_img);
	}
	else{
		idleID = setTimeout('pop_float_img_loading("' + src + '")',50);
	}
}

function view_pop_float_img(tmp_img){
	var top , left;

	if(document.body.offsetWidth){
		left = Math.ceil((document.body.offsetWidth - tmp_img.width)/2) + 'px';
		top = (Math.ceil((window.screen.height - tmp_img.height)/2)-100) + 'px';
	}
	else{
		left =  600 + 'px';
		top = 500 + 'px';
	}
	if(top < 0) top = 0;
	if(left < 0) left = 0;

	document.getElementById('pop_content').style.marginTop = top;
	document.getElementById('pop_content').style.marginLeft = left;
	document.getElementById('pop_content').innerHTML = '<div onclick="close_float();" id="pop_content_inner" style="cursor:pointer;font-size:0;line-height:0;border:5px solid #000;"></div>';
	document.getElementById('pop_content_inner').appendChild(tmp_img);
}