





// ----- Variables -----------------------------------------------------------

var DHTML_CURRENTPOPUP=null;
var displaytimeoutId=null;
document.modalElement=null;

function popup_mousepos(e)
{
  var ie = navigator.appName == "Microsoft Internet Explorer";

  popup_mouseposX = ie ? window.event.clientX : e.clientX;
  popup_mouseposY = ie ? window.event.clientY : e.clientY;
}

// ----- Attach Events ---------------------------------------------------------
if (navigator.appName == "Microsoft Internet Explorer")
     document.attachEvent('onmousedown', popup_mousepos);
else document.addEventListener('mousedown', popup_mousepos, false);

var scroll=null;
function scrollToElement(id){
      
      
      if(scroll==null){
      	var scroll = new Fx.Scroll( document, {offset: {'x': 0,'y': -100}});	
      }
      
      //alert(scroll)
      scroll.toElement(id);
      document.getElementById(id).focus();
  }


function popupShowModal(id){
	
	
	element= document.getElementById(id);
  	if(mask=document.getElementById('popupMask')){
	  	document.body.appendChild(mask);
		//element.parentNode.appendChild(mask);
  	}else{
		popmask = document.createElement('div');//
		popmask.id = 'popupMask';
		document.body.appendChild(popmask);
		//element.parentNode.appendChild(mask);
	}
	
	var clone=element.cloneNode(true);
	clone.setAttribute("id", "modal_" + id);
	document.body.appendChild(clone);
	
	clone.style.height = "2000px";
	clone.style.visibility = "visible";
	clone.style.position   = "absolute";
  	clone.style.display    = "block";
  	clone.style.zIndex=10000;
  	 
	setMaskSize();
	centerElement("modal_" + id);
	
	
}
function removeElementT(parentDiv, childDiv){
     if (childDiv == parentDiv) {
          alert("The parent div cannot be removed.");
     }
     else if (document.getElementById(childDiv)) {     
          var child = document.getElementById(childDiv);
          var parent = document.getElementById(parentDiv);
          parent.removeChild(child);
     }
     else {
          alert("Child div has already been removed or does not exist.");
          return false;
     }
}

/**
 * Sets the size of the popup mask.
 *
 */
function setMaskSize() {
	var theBody = document.getElementsByTagName("BODY")[0];
	gPopupMask = document.getElementById("popupMask");		
	var fullHeight = getViewportHeight();
	var fullWidth = getViewportWidth();
	
	// Determine what's bigger, scrollHeight or fullHeight / width
	if (fullHeight > theBody.scrollHeight) {
		popHeight = fullHeight;
	} else {
		popHeight = theBody.scrollHeight;
	}
	
	if (fullWidth > theBody.scrollWidth) {
		popWidth = fullWidth;
	} else {
		popWidth = theBody.scrollWidth;
	}

	gPopupMask.style.width =  "100%";
	gPopupMask.style.height = "100%";
	gPopupMask.style.top=0;
	gPopupMask.style.left=0;
	gPopupMask.style.position="fixed";
	gPopupMask.style.display    = "block"; 
}
function makeVisible(idElem){
	        var element= null;
			if(idElem!=null){
				DHTML_CURRENTPOPUP=idElem;
				element = document.getElementById(idElem);
			    if(element!=null){  
			        exit_element = document.getElementById(idElem+'_exit');
				  	popup_content= document.getElementById(idElem+'_content');
					element.style.visibility = "visible";
					element.style.position   = "absolute";
					document.body.appendChild(element);
					element.style.left = tempX+'px';
				    element.style.top  = tempY+'px';
					element.style.display    = "block";
					}
			}
}

function getMouseXY(e) {
  if (IE) { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.documentElement.scrollLeft
    tempY = event.clientY + document.documentElement.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
    tempY = e.pageY
  }  
  // catch possible negative values in NS4
  if (tempX < 0){tempX = 0}
  if (tempY < 0){tempY = 0}  
  // show the position values in the form named Show
  // in the text fields named MouseX and Mouse
  return true
}


function makeInVisible(idElem){
	        var element= null;
			if(idElem!=null){
				element = document.getElementById(idElem);
			    if(element!=null){  
			        exit_element = document.getElementById(idElem+'_exit');
				  	popup_content= document.getElementById(idElem+'_content');
					element.style.visibility = "visible";
					element.style.position   = "absolute";
					element.style.left = tempX+'px';
				    element.style.top  = tempY+'px';
					element.style.display    = 'none';
					document.body.appendChild(element);
					DHTML_CURRENTPOPUP=null;
				}
			}
}



function centerElement(id,width, height) {
	element=null;
	if(typeof(id)=='string'){
		document.modalElement= id;
	}else{
		if(document.modalElement!=null){
			id=document.modalElement;
		}else{
			return false;
		}
	}
	
	
	element = document.getElementById(id);	
		
	if (width == null || isNaN(width)) {
		width = element.offsetWidth;
	}
	if (height == null) {
		height = element.offsetHeight;
	}
	
	//var theBody = document.documentElement;
	var theBody = document.getElementsByTagName("BODY")[0];
	//theBody.style.overflow = "hidden";
	var scTop = parseInt(getScrollTop(),10);
	var scLeft = parseInt(theBody.scrollLeft,10);

	//window.status = gPopupMask.style.top + " " + gPopupMask.style.left + " " + gi++;
	
	var fullHeight = getViewportHeight();
	var fullWidth = getViewportWidth();
	
	var posTop=(scTop + ((fullHeight- height) /2));
	
	if (posTop<=0) {
		posTop=5;
	}
	element.style.top = posTop + "px";
	element.style.left =(scLeft + ((fullWidth - width) / 2)) + "px";
	element.style.position="absolute";
	//alert(element.style.top);
	
	//document.onscroll=centerElement;
}

/**
 * Gets the real scroll top
 */
function getScrollTop() {
	if (self.pageYOffset) // all except Explorer
	{
		return self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
	{
		return document.documentElement.scrollTop;
	}
	else if (document.body) // all other Explorers
	{
		return document.body.scrollTop;
	}
}
function getScrollLeft() {
	if (self.pageXOffset) // all except Explorer
	{
		return self.pageXOffset;
	}
	else if (document.documentElement && document.documentElement.scrollLeft)
		// Explorer 6 Strict
	{
		return document.documentElement.scrollLeft;
	}
	else if (document.body) // all other Explorers
	{
		return document.body.scrollLeft;
	}
}



function getViewportHeight() {
	if (window.innerHeight!=window.undefined) return window.innerHeight;
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight;
	if (document.body) return document.body.clientHeight; 

	return window.undefined; 
}


function getViewportWidth() {
	var offset = 17;
	var width = null;
	if (window.innerWidth!=window.undefined) return window.innerWidth; 
	if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; 
	if (document.body) return document.body.clientWidth; 
}


function $E(id){
	
	return $(id);
}

function callColorPicker(element){
				
				
				alert(element);
				element.ColorPicker({
					onSubmit: function(hsb, hex, rgb, el) {
						$(el).val(hex);
						$(el).ColorPickerHide();
					},
					onBeforeShow: function () {
						$(this).ColorPickerSetColor(this.value);
					}
				})
				.bind('keyup', function(){
					$(this).ColorPickerSetColor(this.value);
				});
			}	

