
///////////////////////////////////////////////////
// funGenericAlert - script to pop a box by id and populate with html
//
// assumes jquery UI
//	INPUTS
//		strAlertMsg : string : the message
//		strTargetObjId : string : the id of the object
// 	strCloseAction : string to control the close action - 
//			clsTopBtn (close button) on the top.
//       clsBtn (close button)
//			fdOt(fade out)
//			cls_LvCnt (prepends close button but leaves the content)
//    strBG : string : 
//       undefined || '' - if the arg is omitted or empty string no background div is rendered
//       'true' - uses default transparent.png to 'subdue' background content
//       any other string value - assumes is a path to an alternate background image (not validated)
//	OUTPUTS
//	
//
///////////////////////////////////////////////////
function funGenericAlert(strAlertMsg, strTargetObjId, strCloseAction, strBG) {
   var strCloseBtn = '';

	// get the element FIRST
	objGenAlrt = document.getElementById(strTargetObjId);

	// none - no close action specified
	if (strCloseAction!='none') {
	   // set a close button
	   switch (strCloseAction) {
	      case 'clsTopBtn':
	         // small square close button on the top
	         strCloseBtn = '<div class="stdBoxOrHead" id="display_box_handle" style="overflow-x:hidden; overflow-y:hidden;"><img src="/images/buttons/square/close.png" alt="close" border="0" onclick="funGenerHidObj(\'' + strTargetObjId + '\')" style="cursor:pointer;float:right;"></div>'
	         break;
	      case 'clsBtn':
	         // large close button centered on the bottom
	         strCloseBtn = '<div align=center><img src=\'/images/buttons/close.gif\' onClick=\"funGenerHidObj(\'' + strTargetObjId + '\')\" id=\'alertCloseButton\' style=\'cursor:pointer; margin: 12px;\'></div>';
	         break;
	      case 'cls_LvCnt':
	         // close button on the right top
	         // strCloseBtn = '<div align=right><img src=\'/images/buttons/square/close.png\' onClick=\"funGenerHidObj(\'' + strTargetObjId + '\')\" id=\'alertCloseButton\' style=\'cursor:pointer; margin: 2px;\'></div>';
	         strCloseBtn = '';
	         break;
	      default:
	         strCloseBtn = '';
	         break;
      }

		// fdOt - fade out
		if (strCloseAction=='fdOt') {
			// fafe out box
			 setTimeout(function(){
				  $('#' + strTargetObjId).fadeOut(1000,function(){});
			 },1000);
		}
	}
	
	// set the inner html
	switch (strCloseAction) {
	   case 'clsTopBtn':
	      objGenAlrt.innerHTML = strCloseBtn + strAlertMsg;
	      break;
	   case 'clsBtn':
      	objGenAlrt.innerHTML = strAlertMsg + strCloseBtn;
	      break;
	   case 'cls_LvCnt':
      	objGenAlrt.innerHTML = objGenAlrt.innerHTML;
	      break;
	   default:
	      objGenAlrt.innerHTML = strAlertMsg + strCloseBtn;
	      break;
   }

	//if the close action is not 'fdOt' and strBG!='' create a background div
	if (strCloseAction != 'fdOt' && (strBG != '' && strBG!=undefined)) {
	   // create background div
	   var objBG;

	   objBG = document.getElementById(strTargetObjId + "_BG");

	   if (!objBG) {
	      objBG = document.createElement('DIV');
	      objBG.id = strTargetObjId + "_BG";
	      objBG.style.height = $(document).height() + 'px';
	      objBG.style.width = $(document).width() + 'px';
	      document.body.appendChild(objBG);
	      $('#' + strTargetObjId + "_BG").toggleClass('alrtBG');
	      if (strBG != 'true') {
	         //assume the value of strBG is a background image path
	         objBG.style.backgroundImage = "url(" + strBG + ")"
	      }
	   } else {
	      objBG.style.height = $(document).height() + 'px';
	      objBG.style.width = $(document).width() + 'px';
	   }

      objBG.style.visibility = 'visible';
      objBG.style.display = 'block';
   }

   // center on screen
   intLeft = Math.round(($(window).width() - $(objGenAlrt).width()) / 2);
   intTop = Math.round(($(window).height() - $(objGenAlrt).height()) / 2) + $(window).scrollTop();

	// make visible
	objGenAlrt.style.left = intLeft + 'px';
	objGenAlrt.style.top = intTop + 'px';
	objGenAlrt.style.display = 'block';
	objGenAlrt.style.visibility = 'visible';

}

// hides the object passed to it by name
function funGenerHidObj(strElementName) {
	objGenAlrt = document.getElementById(strElementName);
	objGenAlrt.style.visibility = 'hidden';
	objGenAlrt.style.display = 'none';

   //attempt to get the background div and hide it
	var objBG;
	objBG = document.getElementById(strElementName + "_BG");
	if (objBG) {
	   objBG.style.visibility = 'hidden';
	   objBG.style.display = 'none';
	}

}
