//////////////////////////////////////////////////////////////////////////////////////////////////
//
// LayerUtil.js
//
//////////////////////////////////////////////////////////////////////////////////////////////////
var LayerUtil = {
	"getBody" : function(){
		return document.getElementsByTagName( "body" ).item(0);
	},
	"show" : function( div, isShow ){
		var div = div.style ? div : document.getElementById( div );
		div.style.display = isShow ? "block" : "none";
	},//function	
	"toggleDivShow" : function( div ){
		var div = div.style ? div : document.getElementById( div );
		div.style.display = ( !div.style.display || div.style.display != "block" ) ? "block" : "none"; 
	},//function
	"ctrlDivShow" : function( chkboxId, tgtDivId ){ 
		document.getElementById( tgtDivId ).style.display = document.getElementById( chkboxId ).checked ? "block" : "none";
	},//function
	"setPositionToCenter" : function( div ){
		var div = div.style ? div : document.getElementById( div );
		if( document.all ){//IE
			div.style.pixelTop = document.body.clientHeight / 2 - div.style.pixelHeight / 2 + document.body.scrollTop;
			div.style.pixelLeft = document.body.clientWidth / 2 - div.style.pixelWidth / 2;
		}else{
			var bounds = LayerUtil.getBounds( LayerUtil.getBody() );
			div.style.left = bounds.width / 2 - div.style.width.replace( /px/, "" ) / 2;
			div.style.top = bounds.height / 2 - div.style.height.replace( /px/, "" ) / 2 + document.body.scrollTop;
		}//if
	},//function
	"setPositionToCursor" : function( tgtDivId, event ){
		var div = document.getElementById( tgtDivId );
		div.style.pixelTop = event.clientY + document.body.scrollTop;
		div.style.pixelLeft = event.clientX;
	},//function
	"setPositionToCursor2" : function( tgtDivId, event, moveX, moveY ){
		var div = document.getElementById( tgtDivId );
		div.style.pixelTop = event.clientY + document.body.scrollTop + moveY;
		div.style.pixelLeft = event.clientX + moveX;
	},//function
	"deactivateWindow" : function(){
		var div = document.getElementById( "divToggleWindowActivate" );
		if( !div ){ 
			var body = document.getElementsByTagName("body").item(0);
			
			div = document.createElement( "div" );
			div.setAttribute( "id", "divToggleWindowActivate" );
			div.style.position = "absolute";
			div.style.zIndex = "100";
			div.style.width = "100%";
			div.style.height = "100%";
			div.style.top = "0";
			div.style.left = "0";
			div.style.background = "black";
			div.style.filter = "alpha(opacity=20)";
			div.style.display = "none";
			
			body.insertBefore( div, body.firstChild );
		}//if
		
		this.deactivateAllSelectbox();
		//div.style.height = this.getPageHeight();
		//div.style.width = this.getPageWidth();
		div.style.display = "block";
	},//function
	"deavtivateWindow" : function(){
		this.deactivateWindow();
	},
	"deactiveWindowEx" : function( arrExSelectboxId ){
		this.deavtivateWindow();
		for( var i = 0; i < arrExSelectboxId.length; i++ ){
		 	var s = document.getElementById( arrExSelectboxId[ i ] );
		 	s.style.visibility = 'visible'; 
		}//for
	},//function
	"activateWindow" : function(){
		var div = document.getElementById( "divToggleWindowActivate" );
		if( div ){
			div.style.display = "none";
		}//if
		
		this.activateSelectbox();
	},//function	
	"activeSelectObject" : function(divName){
		var div = document.getElementById( divName );
		if( div ){
			div.style.display = "block";
			div.style.zIndex = "110";
		}//if
	},//function	
	"deactivateSelectbox" : function( layer_id ){
       
        var ly = document.getElementById( layer_id ); 

        var ly_left  = ly.offsetLeft; 
        var ly_top    = ly.offsetTop; 
        var ly_right  = ly.offsetLeft + ly.offsetWidth; 
        var ly_bottom = ly.offsetTop + ly.offsetHeight; 
		
        var el; 

        for (i=0; i<document.forms.length; i++) { 
            for (k=0; k<document.forms[i].length; k++) { 
                el = document.forms[i].elements[k];    
                if (el.type == "select-one") { 
                    var el_left = el_top = 0; 
                    var obj = el; 
                    if (obj.offsetParent) { 
                        while (obj.offsetParent) { 
                            el_left += obj.offsetLeft; 
                            el_top  += obj.offsetTop; 
                            obj = obj.offsetParent; 
                        } 
                    } 
                    el_left  += el.clientLeft; 
                    el_top    += el.clientTop; 
                    el_right  = el_left + el.clientWidth; 
                    el_bottom = el_top + el.clientHeight; 

                    if ( (el_left >= ly_left && el_top >= ly_top && el_left <= ly_right && el_top <= ly_bottom) || 
                        (el_right >= ly_left && el_right <= ly_right && el_top >= ly_top && el_top <= ly_bottom) || 
                        (el_left >= ly_left && el_bottom >= ly_top && el_right <= ly_right && el_bottom <= ly_bottom) || 
                        (el_left >= ly_left && el_left <= ly_right && el_bottom >= ly_top && el_bottom <= ly_bottom) ) 

                        el.style.visibility = 'hidden'; 
                } 
            } 
        } 
    },//function
    "deactivateAllSelectbox" : function(){ 
        for (i=0; i<document.forms.length; i++) { 
            for (k=0; k<document.forms[i].length; k++) { 
                el = document.forms[i].elements[k];    
                if (el.type == "select-one") { 
                   el.style.visibility = 'hidden'; 
                }//if
            }//for
        }//for
    },//function
    "activateSelectbox" : function(){ 
        for (i=0; i<document.forms.length; i++) { 
            for (k=0; k<document.forms[i].length; k++) { 
                el = document.forms[i].elements[k];    
                if (el.type == "select-one" && el.style.visibility == 'hidden') 
                    el.style.visibility = 'visible'; 
            } 
        } 
    },//function
	//this method return absolute top position of Object
	"getAbsoluteTop" : function(obj){ 
	    var iTop=0; 
	    while(obj.tagName != 'BODY') {	
	        iTop += obj.offsetTop; 
	        obj = obj.offsetParent; 
	    }//while
	    return iTop; 
	}, 
	//this method return absolute left position of Object
	"getAbsoluteLeft" : function(obj){ 
	    var iLeft=0; 
	    while(obj.tagName != 'BODY'){ 
	        iLeft += obj.offsetLeft; 
	        obj = obj.offsetParent; 
	    }//while
	    return iLeft; 
	},
	"getAbsoluteTop2" : function( obj ){ 
		return obj ? obj.offsetTop + this.getAbsoluteTop2( obj.offsetParent ) : 0; 
	}, 
	"getAbsoluteLeft2" : function( obj ){ 
		return obj ? obj.offsetLeft + this.getAbsoluteLeft2( obj.offsetParent ) : 0; 
	}, 
	"getBounds" : function( obj ){ 
	    var ret = new Object(); 
	    if(document.all) { 
	        var rect = obj.getBoundingClientRect(); 
	        ret.left = rect.left + (document.documentElement.scrollLeft || document.body.scrollLeft); 
	        ret.top = rect.top + (document.documentElement.scrollTop || document.body.scrollTop); 
	        ret.width = rect.right - rect.left; 
	        ret.height = rect.bottom - rect.top; 
	    } else { 
	        var box = document.getBoxObjectFor( obj ); 
	        ret.left = box.x; 
	        ret.top = box.y; 
	        ret.width = box.width; 
	        ret.height = box.height; 
	    } 
	    return ret; 
	},
	"getPageWidth" : function(){
		return this.getPageSize()[ 0 ];
	},
	"getPageHeight" : function(){
		return this.getPageSize()[ 1 ]
	},
	"getWindowWidth" : function(){
		return this.getPageSize()[ 2 ];
	},
	"getWindowHeight" : function(){
		return this.getPageSize()[ 3 ];
	},
	/////////////////////////////////////////////////////////////////////
	// GET getPageSize() FUNCTION FROM LightBox
	/////////////////////////////////////////////////////////////////////
	// getPageSize()
	// Returns array with page width, height and window width, height
	// Core code from - quirksmode.org
	// Edit for Firefox by pHaez
	//
	"getPageSize" : function(){
		
		var xScroll, yScroll;
		
		if (window.innerHeight && window.scrollMaxY) {	
			xScroll = document.body.scrollWidth;
			yScroll = window.innerHeight + window.scrollMaxY;
		} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
			xScroll = document.body.scrollWidth;
			yScroll = document.body.scrollHeight;
		} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
			xScroll = document.body.offsetWidth;
			yScroll = document.body.offsetHeight;
		}
		
		var windowWidth, windowHeight;
		if (self.innerHeight) {	// all except Explorer
			windowWidth = self.innerWidth;
			windowHeight = self.innerHeight;
		} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
			windowWidth = document.documentElement.clientWidth;
			windowHeight = document.documentElement.clientHeight;
		} else if (document.body) { // other Explorers
			windowWidth = document.body.clientWidth;
			windowHeight = document.body.clientHeight;
		}	
		
		// for small pages with total height less then height of the viewport
		if(yScroll < windowHeight){
			pageHeight = windowHeight;
		} else { 
			pageHeight = yScroll;
		}
	
		// for small pages with total width less then width of the viewport
		if(xScroll < windowWidth){	
			pageWidth = windowWidth;
		} else {
			pageWidth = xScroll;
		}
	
	
		arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
		return arrayPageSize;
	}
}//object
