//'####################################################################
//' FILE: message.js
//'
//' AUTHOR: Kevin Wroblewski
//' DATE:
//' DESCRIPTION: message popups
//'####################################################################

//'--------------------------------------------------------------------
//' renderMessage()
//'--------------------------------------------------------------------
var intMessageTime = 2000;
var bitPlaySound = false;
var bitMessageExpanding = false;
function renderMessage(objElement,strMessage,intStatus,intWidth,objConfirmClick){
 bitMessageExpanding = true;
 var strBorderColor;
 var strImage;
 var strOut = "";

 if(document.getElementById('jsMessageBoxDiv').style.filter!="Alpha(Opacity=0)"&&document.getElementById('jsMessageBoxDiv').style.filter!=""){
  //Message box is in the process of closing from a previous message
  bitMessageExpanding=false;
  document.getElementById('jsMessageBoxDiv').style.filter="Alpha(Opacity=0)";
 }

 document.getElementById('jsMessageBoxDivStatus0').style.display="none";
 document.getElementById('jsMessageBoxDivStatus1').style.display="none";
 document.getElementById('jsMessageBoxDivStatus2').style.display="none";
 document.getElementById('jsMessageBoxDivStatus3').style.display="none";
 document.getElementById('jsMessageBoxDivStatus4').style.display="none";

 if(parseInt(intStatus)==2||parseInt(intStatus)==3){
  strMessage += "<br><center><input type='image' id='btnJSMessageOK' src='http://images.hh2.com/Legacy/message_btn_ok.gif' border='0' style='margin-top:5px;' onClick='enableDiv(document.body);hideMessageBox();'></center>";
  disableDiv(document.body,"help");
 }
 else if(parseInt(intStatus)==4){
  objConfirmClick = '"'+objConfirmClick+'"';
  strMessage += "<br><center><input type='image' id='btnJSMessageOK' src='http://images.hh2.com/Legacy/message_btn_yes.gif' border='0' style='margin-top:5px;' onClick='enableDiv(document.body);if(isObject(document.getElementById("+objConfirmClick+"))){document.getElementById("+objConfirmClick+").click();}hideMessageBox();'>&nbsp;&nbsp;<input type='image' src='http://images.hh2.com/Legacy/message_btn_no.gif' border='0' style='margin-top:5px;' onClick='enableDiv(document.body);hideMessageBox();'></center>";
  disableDiv(document.body,"help");
 }

 //Create sound
 if(parseInt(intStatus)==2||parseInt(intStatus)==3||parseInt(intStatus)==4){
  bitPlaySound = true;
  strMessage = strMessage + "<span id='jsMessageBoxDivSound'></span>"
 }
 else{
  bitPlaySound = false;
 }

 document.getElementById('jsMessageBoxDivStatus'+intStatus).style.display="block";
 document.getElementById('jsMessageBoxDivMessage').innerHTML=strMessage;

 //Popup Window
 var intZIndex = getZMax();
 document.getElementById('jsMessageBoxDiv').style.width = "250px";
 document.getElementById('jsMessageBoxFrame').style.width = "250px";
 document.getElementById('jsMessageBoxDiv').style.height = "34px";
 document.getElementById('jsMessageBoxFrame').style.height = "34px";
 document.getElementById('jsMessageBoxFrame').style.zIndex = intZIndex;
 document.getElementById('jsMessageBoxDiv').style.zIndex = (intZIndex + 1);
 document.getElementById('jsMessageBoxFrame').style.display = "block";
 document.getElementById('jsMessageBoxDiv').style.display = "block";

 objElement = window.document.body;

 if(objElement==window.document.body){
  document.getElementById('jsMessageBoxDiv').style.left = (findPosX(objElement)+Math.round(findBrowserWidth()/2)+document.body.scrollLeft-Math.round(findWidth(document.getElementById('jsMessageBoxDiv'))/2))+"px";
  document.getElementById('jsMessageBoxFrame').style.left = (findPosX(objElement)+Math.round(findBrowserWidth()/2)+document.body.scrollLeft-Math.round(findWidth(document.getElementById('jsMessageBoxDiv'))/2))+"px";
 }
 else{
  document.getElementById('jsMessageBoxDiv').style.left = (findPosX(objElement)+Math.round(findWidth(objElement)/2)-Math.round(findWidth(document.getElementById('jsMessageBoxDiv'))/2))+"px";
  document.getElementById('jsMessageBoxFrame').style.left = (findPosX(objElement)+Math.round(findWidth(objElement)/2)-Math.round(findWidth(document.getElementById('jsMessageBoxDiv'))/2))+"px";
 }

 if(objElement==window.document.body){
  document.getElementById('jsMessageBoxDiv').style.top = (findPosY(objElement)+Math.round(findBrowserHeight()/2)+document.body.scrollTop-Math.round(findHeight(document.getElementById('jsMessageBoxDiv'))/2))+"px";
  document.getElementById('jsMessageBoxFrame').style.top = (findPosY(objElement)+Math.round(findBrowserHeight()/2)+document.body.scrollTop-Math.round(findHeight(document.getElementById('jsMessageBoxDiv'))/2))+"px";
 }
 else{
  document.getElementById('jsMessageBoxDiv').style.top = (findPosY(objElement)+Math.round(findHeight(objElement)/2)+document.body.scrollTop-Math.round(findHeight(document.getElementById('jsMessageBoxDiv'))/2))+"px";
  document.getElementById('jsMessageBoxFrame').style.top = (findPosY(objElement)+Math.round(findHeight(objElement)/2)+document.body.scrollTop-Math.round(findHeight(document.getElementById('jsMessageBoxDiv'))/2))+"px";
 }

 //Reveal Box
 if(document.getElementById('jsMessageBoxFrame').style.filter==""||document.getElementById('jsMessageBoxFrame').style.filter=="Alpha(Opacity=0)"){
  expandMessageBox(1,1,findWidth(document.getElementById('jsMessageBoxDiv')),findHeight(document.getElementById('jsMessageBoxDiv')));
 }

 if(intStatus==0||intStatus==1){
  setTimeout("hideMessageBox();",intMessageTime);
 }
}

//'--------------------------------------------------------------------
//' expandMessageBox()
//'--------------------------------------------------------------------
function expandMessageBox(x,y,maxWidth,maxHeight){
 bitMessageExpanding = true;

 document.getElementById('jsMessageBoxFrame').style.filter="Alpha(Opacity=0)";
 document.getElementById('jsMessageBoxDiv').style.filter="Alpha(Opacity=0)";

 document.getElementById('jsMessageBoxDiv').style.overflow = "";
 document.getElementById('jsMessageBoxFrame').style.width = maxWidth+"px";
 document.getElementById('jsMessageBoxFrame').style.height = maxHeight+"px";
 document.getElementById('jsMessageBoxDiv').style.width = maxWidth+"px";
 document.getElementById('jsMessageBoxDiv').style.height = maxHeight+"px";

 //Resize iFrame if inner HTML of Div exceeds default width & length
 if(navigator.appName=="Microsoft Internet Explorer"){
  range = document.body.createTextRange();
  range.moveToElementText(document.getElementById('jsMessageBoxDiv'));
  document.getElementById('jsMessageBoxFrame').style.width = (range.boundingWidth + 4)+"px";
  document.getElementById('jsMessageBoxFrame').style.height = (range.boundingHeight + 4)+"px";
 }
 else{
  document.getElementById('jsMessageBoxDiv').style.width = "auto";
  document.getElementById('jsMessageBoxDiv').style.height = "auto";
  document.getElementById('jsMessageBoxFrame').style.width = (document.getElementById('jsMessageBoxDiv').offsetWidth);
  document.getElementById('jsMessageBoxFrame').style.height = (document.getElementById('jsMessageBoxDiv').offsetHeight);
 }

 //Create Sound
 if(bitPlaySound==true){
  bitPlaySound = false;
  if(isObject(document.getElementById('jsMessageBoxDivSound'))){
   document.getElementById('jsMessageBoxDivSound').innerHTML = "<embed src='/sounds/notify.mp3' style='display:none;' hidden='true' autostart='true' loop='false' width='1' height='1'></embed>";
  }
 }

 //self.setTimeout("document.getElementById('jsMessageBoxDiv').style.filter='Alpha(Opacity=25)';",50);
 //self.setTimeout("document.getElementById('jsMessageBoxDiv').style.filter='Alpha(Opacity=50)';",100);
 //self.setTimeout("document.getElementById('jsMessageBoxDiv').style.filter='Alpha(Opacity=75)';",150);
 //self.setTimeout("document.getElementById('jsMessageBoxDiv').style.filter='Alpha(Opacity=100)';bitMessageExpanding=false;if(isObject(document.getElementById('btnJSMessageOK'))){document.getElementById('btnJSMessageOK').focus();}",200);
 document.getElementById('jsMessageBoxDiv').style.filter='Alpha(Opacity=100)';bitMessageExpanding=false;if(isObject(document.getElementById('btnJSMessageOK'))){document.getElementById('btnJSMessageOK').focus();}

}

//'--------------------------------------------------------------------
//' contractMessageBox()
//'--------------------------------------------------------------------
function contractMessageBox(x,y,intBoxWidth,intBoxHeight){

 if(bitMessageExpanding==true){
  return false;
 }

 //self.setTimeout("if(bitMessageExpanding!=true){document.getElementById('jsMessageBoxDiv').style.filter='Alpha(Opacity=75)';}",50);
 //self.setTimeout("if(bitMessageExpanding!=true){document.getElementById('jsMessageBoxDiv').style.filter='Alpha(Opacity=50)';}",100);
 //self.setTimeout("if(bitMessageExpanding!=true){document.getElementById('jsMessageBoxDiv').style.filter='Alpha(Opacity=25)';}",150);
 //self.setTimeout("if(bitMessageExpanding!=true){document.getElementById('jsMessageBoxDiv').style.filter='Alpha(Opacity=0)';bitMessageExpanding=false;terminateMessageBox();}",200);
 if(bitMessageExpanding!=true){document.getElementById('jsMessageBoxDiv').style.filter='Alpha(Opacity=0)';bitMessageExpanding=false;terminateMessageBox();}

}

//'--------------------------------------------------------------------
//' terminateMessageBox()
//'--------------------------------------------------------------------
function terminateMessageBox(){
 document.getElementById('jsMessageBoxDiv').style.display = "none";
 document.getElementById('jsMessageBoxFrame').style.display = "none";
 document.getElementById('jsMessageBoxDiv').style.width = "1px";
 document.getElementById('jsMessageBoxFrame').style.width = "1px";
 document.getElementById('jsMessageBoxDiv').style.height = "1px";
 document.getElementById('jsMessageBoxFrame').style.height = "1px";
 document.getElementById('jsMessageBoxDiv').style.top = "1px";
 document.getElementById('jsMessageBoxFrame').style.top = "1px";
}

//--------------------------------------------------------------------
// hideMessageBox()
//--------------------------------------------------------------------
function hideMessageBox(){
 var intBoxWidth = document.getElementById('jsMessageBoxDiv').style.width.replace("px","");
 var intBoxHeight = document.getElementById('jsMessageBoxDiv').style.height.replace("px","");
 //document.getElementById('jsMessageBoxDiv').style.overflow = "hidden";
 contractMessageBox(intBoxWidth,intBoxHeight,intBoxWidth,intBoxHeight);
}