var currentPopUp = -1;
var mouseDown = false
var newX;
var move = false;

var infowindow;

function onBodyClick()
{ 
  killPopup();
}

function toggleMouse(isDown)
{
	mouseDown = isDown;
}

function getWindowWidth()
{
	if (window.self && self.innerWidth) {return self.innerWidth;}
	if (document.documentElement && document.documentElement.clientWidth) {return document.documentElement.clientWidth;}return 0;
}

function getWindowHeight()
{
	if (window.self && self.innerHeight) {return self.innerHeight;}
	if (document.documentElement && document.documentElement.clientHeight) {return document.documentElement.clientHeight;}return 0;
}

function getScrollXY() {
  var scrOfX = 0, scrOfY = 0;
  if( typeof( window.pageYOffset ) == 'number' ) {
    //Netscape compliant
    scrOfY = window.pageYOffset;
    scrOfX = window.pageXOffset;
  } else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
    //DOM compliant
    scrOfY = document.body.scrollTop;
    scrOfX = document.body.scrollLeft;
  } else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
    //IE6 standards compliant mode
    scrOfY = document.documentElement.scrollTop;
    scrOfX = document.documentElement.scrollLeft;
  }
  return [ scrOfX, scrOfY ];
}

function getScrollWidth()
{
	scrollb = getScrollXY();
    return scrollb[0];
}

function getScrollHeight()
{
	scrollb = getScrollXY();
	return scrollb[1];   
}

function getLeft(el){
	element = document.getElementById(el);
  left=0;
  while (element) {
	 left += element.offsetLeft;
	 element = element.offsetParent;
  }
  return left;
}

function getTop(el) {
	element = document.getElementById(el);	
  atop=0;
  while (element) {
	 atop += element.offsetTop;
	 element = element.offsetParent;
  }
  return atop;
}


function moveElement(e, element)
{
	// calculate offset bewteen clientX and elementX
	elementX = getLeft(element);

	if(mouseDown)
	{
		newX = e.clientX;
		verschil = newX - elementX;
		document.getElementById(element).style.Left = verschil;
	}
	else
	{
		if(move)
		{
			move = false;
		}
	}
}

function killPopup()
{
  var popups = document.getElementsByClassName('popup_base');

  for(var i=0; i<popups.length; i++)
  {
    if(popups[i].id != currentPopUp)
    {
		if(popups[i].id == 'advert_popup')
		{
			popups[i].style.visibility = 'hidden';			
		}
		else
		{
		  popups[i].style.visibility = 'hidden';
		  obje = popups[i].id.split('div');
		//document.getElementById('divContent'+obje[1]).innerHTML = '';
		} 
    }
    else
    {
      currentPopUp = -1;
    }
  }
}

function closeInfoWindow()
{
	infowindow.close();	
}

function window_popup(href, width, height)
{
	effectduration = 0.25;
	effectshow = Effect.Appear;
	
		// screen already exists, so destroy it before making a new one
	if($('info_popup_div'))
	{
		infowindow.destroy();
		effectduration = 0;
		effectshow = Effect.Appear;
	}
	  

	infowindow = new casco_PopupWindow('info_popup_div', {width: width, height: height, url: href, effectShow: effectshow, duration: effectduration, durationHide: 0, isModal: true});

	return false;
}

function popup_base(windowName, title, html, width, height)
{
	base_popup = new casco_PopupWindow(windowName, {content: html , width: width, height: height, isModal: false, duration: 0, durationHide: 0, title: title});
	return base_popup;
}

function popup_billboard(windowName, title, url, width, height, minWidth, minHeight, maxWidth, maxHeight)
{
	base_popup = new casco_PopupWindow(windowName, {url: url , width: width, height: height, minHeight: minHeight, minWidth: minWidth, maxHeight: maxHeight, maxWidth: maxWidth, isModal: false, duration: 0, durationHide: 0, title: title});
	
	return base_popup;
}

function window_div(windowName, elementID, width, height, title)
{
	handle = new casco_PopupWindow(windowName, {content: $(elementID).innerHTML , width: $(elementID).offsetWidth, height: $(elementID).offsetHeight, isModal: true, duration: 0, durationHide: 0, title: title});
	$(elementID).style.visibility = 'hidden';
	
	popup_form = getChildElementById(elementID, handle.win.getId(), 'form');
	if(popup_form) 
	{
		setTimeout("Form.focusFirstElement(popup_form)", 100);	
	}
	
	myObserver = 
	{
		onDestroy: function(eventName, win)
		{
			hiddenDivs = document.getElementsByClassName('hiddenDiv');
			for(i=0; i<hiddenDivs.length; i++)
			{
				/*
				width = hiddenDivs[i].offsetWidth + 'px';
				height = hiddenDivs[i].offsetHeight + 'px';				
				alert(width);
				alert(height);
				hiddenDivs[i].style.display = 'none';
				hiddenDivs[i].style.height = height;
				hiddenDivs[i].style.width = width;
				hiddenDivs[i].style.visibility = 'hidden';				
				hiddenDivs[i].style.display = 'block';
				*/
			}
			Windows.removeObserver(this);
		}
	}
	Windows.addObserver(myObserver);
	return false;
}

