var isIE = window.navigator.userAgent.indexOf("MSIE")>-1;
var GlassWindow=null;
var Dialog=null;
var curr_x = 0;

Lib = {};
Lib.Browser = {
    IE:     !!(window.attachEvent && !window.opera),
    Opera:  !!window.opera,
    WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
    Gecko:  navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1
  };
/**
   * Lib.ScreenUtils
   */

Lib.ScreenUtils = {
    getSize: function() {
      return {
        width: this.getWidth(),
        height: this.getHeight()
      };
    },
    getWidth: function() {
      return window.innerWidth || (document.documentElement && document.documentElement.clientWidth) || document.body.clientWidth;
    },
    getHeight: function() {
      return window.innerHeight || (document.documentElement && document.documentElement.clientHeight) || document.body.clientHeight;
    },
    getScroll: function() {
      return {
        left: this.getScrollLeft(),
        top: this.getScrollTop()
      };
    },
    getScrollLeft: function() {
      return window.pageXOffset || (document.documentElement && document.documentElement.scrollLeft) || document.body.scrollLeft;
    },
    getScrollTop: function() {
      return window.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || document.body.scrollTop;
    },
    getScrollWidth: function() {
      if (Lib.Browser.IE) {
        return Math.max(document.documentElement.offsetWidth, document.body.scrollHeight);
      }
      return (document.documentElement && document.documentElement.scrollWidth) || document.body.scrollWidth;
    },
    getScrollHeight: function() {
      if (Lib.Browser.IE) {
        return Math.max(document.documentElement.offsetHeight, document.body.scrollHeight);
      }
      return (document.documentElement && document.documentElement.scrollHeight) || document.body.scrollHeight;
    }
  };

function ShowGlassWindow(show){
	bg = document.getElementById('bgc');
	if(bg){
		
	
	if(show){
		if(isIE){
			bg.style.backgroundColor = '#FFFFFF';
			bg.style.filter="progid:DXImageTransform.Microsoft.Alpha(Opacity=40, Style=0)";
		}
		else{
			bg.style.backgroundImage = 'url(images/modal.png)';
		}
		bg.style.display = 'block';
		bg.style.top = '-200px'; 
		bg.style.left = '-35px';
		bg.style.width = Lib.ScreenUtils.getWidth()-17+'px';
		//alert(Lib.ScreenUtils.getScrollHeight()+':'+);
		bg.style.height = Lib.ScreenUtils.getHeight()+'px';
		//bg.style.backgroundColor = '#FFFFFF';
		bg.style.zIndex = '9';
	}else{
		bg.style.display = 'none';
	}
	 
	}
	
}



function ShowModalWindow(show,width){
 	var modals = 'popup';
	ShowGlassWindow(show);
	
	
	Dialog=document.getElementById(modals);
	if(Dialog==null) Dialog=document.getElementById(modals);
	if(show){
		
		if(isIE){
			//Dialog.style.width = '1%';
		}else{
			Dialog.style.width = 'auto';
		}
		Dialog.style.display='block';
		//Dialog.style.zIndex = '10';
		var yc = Math.round(Lib.ScreenUtils.getWidth()/2-Dialog.clientWidth/2);
		var dh = Math.round((Lib.ScreenUtils.getScrollTop()+Lib.ScreenUtils.getHeight()/2)-getHeight(Dialog)/2);
		//var dh = '500';
		var dw = Math.round(getWidth(Dialog)/2);
		Dialog.style.top = dh-200+'px';
		Dialog.style.left = Math.round(yc+dw/2)+'px';
		if(width){
			Dialog.style.width = width+'px';
		}
		/*
		tl = document.getElementById('theme_list');
		
		if(tl){
			tl.style.display = 'none'
		}
		*/
		
		Dialog.focus();
		
	}
	else{
		/*
		tl = document.getElementById('theme_list');
		if(tl){
			tl.style.display = ''
		}
		if(document.getElementById('theme_list_d')){
		document.getElementById('theme_list_d').style.display='';
		}
		*/
		Dialog.style.display='none';
		hideTextSetting();
	}
}

function getTextSetting(){
	bg = document.getElementById('bg_setting');
	bg.style.width = document.body.clientWidth+65+'px';
	bg.style.height = document.body.clientHeight+document.body.scrollTop+15+'px';
	bg.style.display = '';
	if(isIE){
			bg.style.backgroundColor = '#FFFFFF';
			bg.style.filter="progid:DXImageTransform.Microsoft.Alpha(Opacity=40, Style=0)";
	}
	else{
			bg.style.backgroundImage = 'url(images/modal.png)';
	}
	document.getElementById('txt_setting').style.zIndex = 15;
	document.getElementById('txt_setting').style.display = 'block';
}

function hideTextSetting(){
	bg = document.getElementById('bg_setting');
	if(bg){
		bg.style.display = 'none';
		tset = document.getElementById('txt_setting');
		tset.style.display = 'none';
	}
	
}

function getWidth(elem){
	 return elem.offsetWidth || getStyle(elem,'width') || getStyle(elem,'min-width') || elem.width;
}

function getHeight(elem){
	return elem.offsetHeight || getStyle(elem,'height') || getStyle(elem,'min-height') || elem.height;
}

function getStyle(elem,property) {
      property = property == 'float' ? 'cssFloat' : property;
      var value = elem.style[property];
      if (!value) {
        if (document.defaultView && document.defaultView.getComputedStyle) {
          value = document.defaultView.getComputedStyle(elem, null)[property] || null;
        } else if (window.getComputedStyle) {
          value = window.getComputedStyle(elem, null)[property] || null;
        } else if (elem.currentStyle) {
          value = elem.currentStyle[property] || null;
        }
      }
      if (property == 'opacity') {
        return value ? parseFloat(value) : 1.0;
      }
      return value == 'auto' ? null : value;
}
