/*****************************************************************
clientPopUp.js
Variables and functions for showing pop up windows
*******************************************************************/


/*********************************************************************************************
**********************************************************************************************
Functions to be used by objects in the map or the menu
**********************************************************************************************
*********************************************************************************************/

/*********************************************************************************************
GetPopUpLink
*********************************************************************************************/
function GetPopUpLink(text, href, closePopUp){
return '<a href="' + href + '" target="_blank" ' + (closePopUp ? 'onclick="javascript:HidePopUp();"' : '') + '>' + text + '</a>'
}

/*********************************************************************************************
GetPopUpOpenWindowLink
*********************************************************************************************/
function GetPopUpOpenWindowLink(text, winId, url, winWidth, winHeight, features, closePopUp){
return '<button onclick="javascript:OpenWindow(\''+winId+'\', \''+url+'\', \''+(winWidth || 'null')+'\', \''+(winHeight || 'null')+'\', \''+features+'\');' + (closePopUp ? 'HidePopUp();"' : '') + 'return false;">' + text + '</button>'


return '<a onclick="javascript:OpenWindow(\''+winId+'\', \''+url+'\', \''+(winWidth || 'null')+'\', \''+(winHeight || 'null')+'\', \''+features+'\');' + (closePopUp ? 'HidePopUp();"' : '') + 'return false;">' + text + '</a>'

}


/*********************************************************************************************
ShowPopUpWindow
*********************************************************************************************/
function ShowPopUpWindow(header, src, bottomContents, extContents){
SetPopUpHeaderBottomAndExt(header, bottomContents, extContents);
PopUp_SetImage(src);
}





/*********************************************************************************************
**********************************************************************************************
Internal variables and functions
**********************************************************************************************
*********************************************************************************************/
var popUpWindowOn = false;

var popUpBackground = null;
var popUpWin        = null;
var popUpTitle      = null;
//var popUpClose      = null;
var popUpContents   = null;
var popUpBottom     = null;
var popUpExt        = null;
var popUpImage      = null;
var popUpWorking    = null;

var bodyScrollLeft = 0;
var bodyScrollTop  = 0;

var popUpTitleInnerHTML  = '';
var popUpBottomInnerHTML = '';
var popUpExtInnerHTML    = '';

/*********************************************************************************************
GetPopUp
*********************************************************************************************/
function GetPopUp(){
popUpBackground = popUpBackground || GetElement('idPopUpBackground'); if (!popUpBackground) return false;
popUpWin        = popUpWin        || GetElement('idPopUpWin');        if (!idPopUpWin)      return false;
popUpTitle      = popUpTitle      || GetElement('idPopUpTitle');      if (!popUpTitle)      return false;
//popUpClose      = popUpClose      || GetElement('idPopUpClose');      if (!popUpClose)      return false;
popUpContents   = popUpContents   || GetElement('idPopUpContents');   if (!popUpContents)   return false;
popUpBottom     = popUpBottom     || GetElement('idPopUpBottom');     if (!popUpBottom)     return false;
popUpExt        = popUpExt        || GetElement('idPopUpExt');        if (!popUpExt)        return false;
popUpImage      = popUpImage      || GetElement('idPopUpImage');      if (!popUpImage)      return false;
popUpWorking    = popUpWorking    || GetElement('idPopUpWorking');    if (!popUpWorking)    return false;

return true;
}

/*********************************************************************************************
ShowPopUp
*********************************************************************************************/
function ShowPopUp(){
if (GetPopUp() && !popUpWindowOn){
  document.body.style.overflow = 'hidden';

  bodyScrollLeft = document.body.scrollLeft;
  bodyScrollTop = document.body.scrollTop;
  
  popUpBackground.style.width = screen.width;
  popUpBackground.style.height = screen.height;

  Show(popUpBackground);
  Show(popUpWin);

  popUpWindowOn = true;
}
}

/*********************************************************************************************
HidePopUp
*********************************************************************************************/
function HidePopUp(){
if (GetPopUp() && popUpWindowOn){
  popUpWindowOn = false;
  popUpBackground.style.width = 40;
  popUpBackground.style.height = 40;
  SetPopUpSize(100, 100);
  popUpWin.style.left = 0;
  popUpWin.style.top =  0;

  Hide(popUpBackground);
  Hide(popUpWin);

  popUpTitle.innerHTML  = '';
  popUpImage.src = '';
  Hide(popUpImage);
  Hide(popUpWorking);
  popUpBottom.innerHTML = '';
  popUpExt.innerHTML    = '';


  document.body.style.overflow = '';
  document.body.scrollLeft = bodyScrollLeft;
  document.body.scrollTop = bodyScrollTop;
}
}

/*********************************************************************************************
SetPopUpHeaderBottomAndExt
*********************************************************************************************/
function SetPopUpHeaderBottomAndExt(header, bottomContents, extContents){
if (GetPopUp()){
  popUpTitle.innerHTML = header ? '&nbsp;' + header : '';
  popUpBottom.innerHTML = bottomContents || '';
  popUpExt.innerHTML = extContents || '';
}
}

/*********************************************************************************************
SetPopUpSize
*********************************************************************************************/
function SetPopUpSize(width, height){
if (GetPopUp()){
  popUpWin.style.width = width + 8;
  idPopUpContents.style.height = height;
  SetPopUpCenter();
}
}

/*********************************************************************************************
SetPopUpCenter
*********************************************************************************************/
function SetPopUpCenter(){
  function Min(arg1, arg2){return arg1 > arg2 ? arg1 : arg2;}

if (GetPopUp()){
  popUpWin.style.left = Min(document.body.scrollLeft + (document.body.clientWidth - popUpWin.scrollWidth)/2,  document.body.scrollLeft);
  popUpWin.style.top =  Min(document.body.scrollTop + (document.body.clientHeight - popUpWin.scrollHeight)/2, document.body.scrollTop);

  //popUpClose.style.left = popUpWin.scrollWidth - 18;
}
}

/*********************************************************************************************
PopUp_OnScroll_OnResize
*********************************************************************************************/
function PopUp_OnScroll_OnResize(){
if (GetPopUp() && popUpWindowOn)
  SetPopUpCenter();
}


/*********************************************************************************************
PopUp_SetImage
*********************************************************************************************/
function PopUp_SetImage(src){
if (GetPopUp()){
  //save title
  popUpTitleInnerHTML  = popUpTitle.innerHTML;  
  popUpTitle.innerHTML = '&nbsp;';

  Hide(popUpBottom);
  Hide(popUpExt);

  ShowPopUp();
  SetPopUpSize(120, 30);

  Show(popUpTitle);
  Show(popUpWorking);
  Show(popUpImage);

  popUpImage.src = src;
}
}

/*********************************************************************************************
PopUpImage_OnLoad
*********************************************************************************************/
function PopUpImage_OnLoad(){
popUpTitle.innerHTML = popUpTitleInnerHTML;
if (!popUpTitleInnerHTML)
  Hide(popUpTitle);
if (popUpBottom.innerHTML)
  Show(popUpBottom);
if (popUpExt.innerHTML)
  Show(popUpExt);
Hide(popUpWorking);
SetPopUpSize(popUpImage.width, popUpImage.height);
SetPopUpCenter();
}



