/*
 * Generic popup class
 * opens a popup
 */

/**
   * @author Bernard Brink
   * @parms String titleString The title for the popup
   * @parms String descriptionString The info for the popup
   * @parms int width The width for the popup
   * @parms String id The unique id for the popup (if there is more than one on a page)
   * @parms boolean centerAlign - false by default. if true is passed as parameter, the popup wil be vertically aligned in the center (added by Henk Scheepers)
**/

var popupID = "";
var popupWidth = "600";
function populatePopup(titleString, descriptionString, width, id, centerAlign) {

       popupWidth = width;
       popupID = id;
	   centerAlign = (undefined == centerAlign) ? false : centerAlign;

       popupString = '<div id="'+popupID+'" class="genericPopup-bg">';
	   if(!centerAlign){
       		popupString += '<div>';
	   }else{
		    popupString += '<table width="100%" height="100%;" style="width:100%; height:100%;"><tr><td valign="middle" style="vertical-align:middle">'
	   }
       popupString += '<div class="genericPopupDiv" style="width:'+popupWidth+'px">';
       popupString += '<div class="genericPopupDivHeading">';
       popupString += '<input type="button" class="genericPopupCancel" value="" onclick="hidePopup()"/>';
       popupString += '<h2 class="genericPopupFormHeading">' + titleString + '</h2>';
       popupString += '</div>';
       popupString += '<div class="genericPopupDivContent">';
       popupString += descriptionString.join("<div style='margin-top:10px'></div>");
       popupString +=  '</div>';
       popupString += '</div>';
	   if(!centerAlign){
       		popupString += '</div>';
	   }else{
			popupString += '</td></tr></table>'
	   }
       popupString += '</div>';

       //get the body tag of the html page
       var mainBody = document.getElementsByTagName('body')[0];

       //populate the popup div with the popup
       var popupDiv = document.createElement('div');
       popupDiv.innerHTML = popupString;
	   popupDiv.id = "popup";

       //add the popup div to the body
       mainBody.appendChild(popupDiv);

       showPopup();
}//

/**
 * @author David du Toit
 * @abstract Display the CPF Issues Map in the popup
 **/
function populatePopupWithCPFmap(readView, cpfGUID, titleString, descriptionString, id)
{
  popupID= id;
  popupWidth= 750;

  iframeContent= '<iframe src="'+readView+'" width="'+popupWidth+'px" height="500px"><p>Your browser does not support iframes.</p></iframe>';
  testContent= "";

  popupString = '<div id="'+popupID+'" class="genericPopup-bg">'+
  '<div>'+
  '<div class="genericPopupDiv" style="width:'+popupWidth+'px">'+
  '<div class="genericPopupDivHeading">'+
  '<input type="button" class="genericPopupCancel" value="" onclick="hidePopup()"/>'+
  '<h2 class="genericPopupFormHeading">' + titleString + '</h2>'+
  '</div>'+
  '<div class="genericPopupDivContent">'+
  iframeContent+"<div style='margin-top:10px'></div>"+
  '</div>'+
  '</div>'+
  '</div>'+
  '</div>';

  //get the body tag of the html page
  var mainBody = document.getElementsByTagName('body')[0];

  //populate the popup div with the popup
  var popupDiv = document.createElement('div');
  popupDiv.innerHTML = popupString;

  //add the popup div to the body
  mainBody.appendChild(popupDiv);

  showPopup();
}//

/**
   * @author Bernard Brink
**/
function showPopup() {
	//show the popup
	$("#"+popupID+"").show();
}

/**
   * @author Bernard Brink
**/
function hidePopup() {
        //hide the popup
	$("#"+popupID+"").hide();
}

/**
   * @author Henk Scheepers
**/
function fadeInPopup(){
	$("#"+popupID+"").fadeIn("fast");
}

/**
   * @author Henk Scheepers
**/
function fadeOutPopup(){
	$("#"+popupID+"").fadeOut("fast");
}
