
//--------------------------------------------------------------------
// getPopupBox()
//--------------------------------------------------------------------
function getPopupBox(intBoxWidth, intBoxHeight, strURL, objPopupBoxAnchorElement, intsendHTTPID, strData) {

 var nestedDivName = "";
 if(strData!=""){
  if(isNaN(strData.match("nestedDiv="))==true){
   var arrData = strData.split("&");
   for(i=0;i<arrData.length;i++){
    if(arrData[i].match("nestedDiv=")){
     arrVariable = arrData[i].split("=");
     nestedDivName = arrVariable[1];
    }
   }
  }
 }

 document.getElementById('ajaxPopupBoxDiv').innerHTML = "";
 document.getElementById('ajaxPopupBoxDiv').style.width = intBoxWidth+"px";
 document.getElementById('ajaxPopupBoxDiv').style.height = intBoxHeight+"px";
 document.getElementById('ajaxPopupBoxFrame').style.width = intBoxWidth+"px";
 document.getElementById('ajaxPopupBoxFrame').style.height = intBoxHeight+"px";

 //Get Dimensions of Anchor Element
 if(navigator.appName=="Microsoft Internet Explorer"){
  range = document.body.createTextRange();
  range.moveToElementText(objPopupBoxAnchorElement);
  var intAnchorWidth = range.boundingWidth;
  var intAnchorHeight = range.boundingHeight+1;
 }
 else{
  var intAnchorWidth = objPopupBoxAnchorElement.offsetWidth;
  var intAnchorHeight = objPopupBoxAnchorElement.offsetHeight;
 }

 //Open DIV
 if(document.getElementById('ajaxPopupBoxDiv').style.display=="none"){
  if(document.getElementById("ajaxPopupBoxOriginalX").value==""){
   document.getElementById("ajaxPopupBoxOriginalX").value = findPosX(document.getElementById('ajaxPopupBoxDiv'));
   document.getElementById("ajaxPopupBoxOriginalY").value = findPosY(document.getElementById('ajaxPopupBoxDiv'));
  }

  var intZIndex = getZMax();
  document.getElementById('ajaxPopupBoxFrame').style.width = "1px";
  document.getElementById('ajaxPopupBoxDiv').style.width = "1px";
  document.getElementById('ajaxPopupBoxFrame').style.height = "1px";
  document.getElementById('ajaxPopupBoxDiv').style.height = "1px";
  document.getElementById('ajaxPopupBoxFrame').style.left = findPosX(objPopupBoxAnchorElement);
  document.getElementById('ajaxPopupBoxFrame').style.top = findPosY(objPopupBoxAnchorElement)+intAnchorHeight;
  document.getElementById('ajaxPopupBoxFrame').style.zIndex = intZIndex;
  document.getElementById('ajaxPopupBoxDiv').style.zIndex = (intZIndex + 1);
  document.getElementById('ajaxPopupBoxDiv').style.left = findPosX(objPopupBoxAnchorElement);
  document.getElementById('ajaxPopupBoxDiv').style.top = findPosY(objPopupBoxAnchorElement)+intAnchorHeight;

  //Offest if within a DIV
  if(nestedDivName!=""){
   document.getElementById('ajaxPopupBoxDiv').style.left = (findPosX(objPopupBoxAnchorElement)-document.getElementById("ajaxPopupBoxOriginalX").value-document.getElementById(nestedDivName).scrollLeft);
   document.getElementById('ajaxPopupBoxFrame').style.left = (findPosX(objPopupBoxAnchorElement)-document.getElementById("ajaxPopupBoxOriginalX").value-document.getElementById(nestedDivName).scrollLeft);
   document.getElementById('ajaxPopupBoxDiv').style.top = (findPosY(objPopupBoxAnchorElement)-document.getElementById("ajaxPopupBoxOriginalY").value+intAnchorHeight-document.getElementById(nestedDivName).scrollTop);
   document.getElementById('ajaxPopupBoxFrame').style.top = (findPosY(objPopupBoxAnchorElement)-document.getElementById("ajaxPopupBoxOriginalY").value+intAnchorHeight-document.getElementById(nestedDivName).scrollTop);
  }

  //Expand DIV
  document.getElementById('ajaxPopupBoxFrame').style.display = "block";
  document.getElementById('ajaxPopupBoxDiv').style.display = "block";
  expandPopupBox(1,1,intBoxWidth,intBoxHeight);

 }
 else{
  document.getElementById('ajaxPopupBoxFrame').style.left = findPosX(objPopupBoxAnchorElement);
  document.getElementById('ajaxPopupBoxFrame').style.top = findPosY(objPopupBoxAnchorElement)+intAnchorHeight;
  document.getElementById('ajaxPopupBoxDiv').style.left = findPosX(objPopupBoxAnchorElement);
  document.getElementById('ajaxPopupBoxDiv').style.top = findPosY(objPopupBoxAnchorElement)+intAnchorHeight;
  document.getElementById('ajaxPopupBoxDiv').style.display = "block";
  document.getElementById('ajaxPopupBoxFrame').style.display = "block";
  document.getElementById('ajaxPopupBoxDiv').style.width = intBoxWidth+"px";
  document.getElementById('ajaxPopupBoxFrame').style.width = intBoxWidth+"px";
  document.getElementById('ajaxPopupBoxDiv').style.height = intBoxHeight+"px";
  document.getElementById('ajaxPopupBoxFrame').style.height = intBoxHeight+"px";

  //Offest if within a DIV
  if(nestedDivName!=""){
   document.getElementById('ajaxPopupBoxDiv').style.left = (findPosX(objPopupBoxAnchorElement)-document.getElementById("ajaxPopupBoxOriginalX").value-document.getElementById(nestedDivName).scrollLeft);
   document.getElementById('ajaxPopupBoxFrame').style.left = (findPosX(objPopupBoxAnchorElement)-document.getElementById("ajaxPopupBoxOriginalX").value-document.getElementById(nestedDivName).scrollLeft);
   document.getElementById('ajaxPopupBoxDiv').style.top = (findPosY(objPopupBoxAnchorElement)-document.getElementById("ajaxPopupBoxOriginalY").value+intAnchorHeight-document.getElementById(nestedDivName).scrollTop);
   document.getElementById('ajaxPopupBoxFrame').style.top = (findPosY(objPopupBoxAnchorElement)-document.getElementById("ajaxPopupBoxOriginalY").value+intAnchorHeight-document.getElementById(nestedDivName).scrollTop);
  }
 }

 initiate_ajax(intsendHTTPID);

 document.getElementById('ajaxPopupBoxDiv').style.cursor = "wait";

 if(document.getElementById('ajaxPopupBoxDiv').innerHTML==""){
  document.getElementById('ajaxPopupBoxDiv').innerHTML="<font style='white-space:nowrap;'>Please&nbsp;Wait...</font>"
 }

 arrAjax[intsendHTTPID].open("POST",strURL,true);
 arrAjax[intsendHTTPID].setRequestHeader("Content-Type","application/x-www-form-urlencoded");
 arrAjax[intsendHTTPID].onreadystatechange = function() {
  if (arrAjax[intsendHTTPID].readyState==4) {
   if (arrAjax[intsendHTTPID].status==200) {

    document.getElementById('ajaxPopupBoxDiv').innerHTML=arrAjax[intsendHTTPID].responseText;

    //Resize underlying iFrame to new Div width
    if(document.getElementById('ajaxPopupBoxDiv').style.overflow==""){
     if(navigator.appName=="Microsoft Internet Explorer"){
      range = document.body.createTextRange();
      range.moveToElementText(document.getElementById('ajaxPopupBoxDiv'));
      document.getElementById('ajaxPopupBoxFrame').style.width = (range.boundingWidth + 4);
      document.getElementById('ajaxPopupBoxFrame').style.height = (range.boundingHeight + 4);
     }
     else{
      document.getElementById('ajaxPopupBoxDiv').style.width = "auto";
      document.getElementById('ajaxPopupBoxDiv').style.height = "auto";
      document.getElementById('ajaxPopupBoxFrame').style.width = (document.getElementById('ajaxPopupBoxDiv').offsetWidth + 4);
      document.getElementById('ajaxPopupBoxFrame').style.height = (document.getElementById('ajaxPopupBoxDiv').offsetHeight + 4);
     }
    }

    //Reset cursor
    document.getElementById('ajaxPopupBoxDiv').style.cursor = "default";

   }
   else {
    document.getElementById('ajaxPopupBoxDiv').innerHTML=arrAjax[intsendHTTPID].responseText;
   }
  }
 }
 strData = strData.replace(/ /g,"%20");
 arrAjax[intsendHTTPID].send(strData);
 return false ;

}

//'--------------------------------------------------------------------
//' expandPopupBox()
//'--------------------------------------------------------------------
function expandPopupBox(x,y,maxWidth,maxHeight){

 document.getElementById('ajaxPopupBoxFrame').style.filter="Alpha(Opacity=0)";
 document.getElementById('ajaxPopupBoxDiv').style.filter="Alpha(Opacity=0)";

 document.getElementById('ajaxPopupBoxDiv').style.overflow = "";
 document.getElementById('ajaxPopupBoxFrame').style.width = maxWidth+"px";
 document.getElementById('ajaxPopupBoxFrame').style.height = maxHeight+"px";
 document.getElementById('ajaxPopupBoxDiv').style.width = maxWidth+"px";
 document.getElementById('ajaxPopupBoxDiv').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('ajaxPopupBoxDiv'));
  document.getElementById('ajaxPopupBoxFrame').style.width = (range.boundingWidth + 4)+"px";
  document.getElementById('ajaxPopupBoxFrame').style.height = (range.boundingHeight + 4)+"px";
 }
 else{
  document.getElementById('ajaxPopupBoxDiv').style.width = "auto";
  document.getElementById('ajaxPopupBoxDiv').style.height = "auto";
  document.getElementById('ajaxPopupBoxFrame').style.width = (document.getElementById('ajaxPopupBoxDiv').offsetWidth);
  document.getElementById('ajaxPopupBoxFrame').style.height = (document.getElementById('ajaxPopupBoxDiv').offsetHeight);
 }

 self.setTimeout("document.getElementById('ajaxPopupBoxDiv').style.filter='Alpha(Opacity=25)';",50);
 self.setTimeout("document.getElementById('ajaxPopupBoxDiv').style.filter='Alpha(Opacity=50)';",100);
 self.setTimeout("document.getElementById('ajaxPopupBoxDiv').style.filter='Alpha(Opacity=75)';",150);
 self.setTimeout("document.getElementById('ajaxPopupBoxDiv').style.filter='Alpha(Opacity=100)';",200);

 /*
 if(x<maxWidth){
  document.getElementById('ajaxPopupBoxFrame').style.width = x+"px";
  document.getElementById('ajaxPopupBoxDiv').style.width = x+"px";
 }
 else{
  document.getElementById('ajaxPopupBoxFrame').style.width = maxWidth+"px";
  document.getElementById('ajaxPopupBoxDiv').style.width = maxWidth+"px";
  var widthReached = "true";
 }
 if(y<maxHeight){
  document.getElementById('ajaxPopupBoxFrame').style.height = x+"px";
  document.getElementById('ajaxPopupBoxDiv').style.height = x+"px";
 }
 else{
  document.getElementById('ajaxPopupBoxFrame').style.height = maxHeight+"px";
  document.getElementById('ajaxPopupBoxDiv').style.height = maxHeight+"px";
  var heightReached = "true";
 }
 if(widthReached=="true"&&heightReached=="true"){
  document.getElementById('ajaxPopupBoxDiv').style.overflow = "";
  //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('ajaxPopupBoxDiv'));
   document.getElementById('ajaxPopupBoxFrame').style.width = (range.boundingWidth + 4);
   document.getElementById('ajaxPopupBoxFrame').style.height = (range.boundingHeight + 4);
  }
  else{
   document.getElementById('ajaxPopupBoxDiv').style.width = "auto";
   document.getElementById('ajaxPopupBoxDiv').style.height = "auto";
   document.getElementById('ajaxPopupBoxFrame').style.width = (document.getElementById('ajaxPopupBoxDiv').offsetWidth);
   document.getElementById('ajaxPopupBoxFrame').style.height = (document.getElementById('ajaxPopupBoxDiv').offsetHeight);
  }
  return true;
 }
 else{
  self.setTimeout("expandPopupBox("+(x+15)+","+(y+15)+","+maxWidth+","+maxHeight+");",1);
 }
 */
}

//'--------------------------------------------------------------------
//' contractPopupBox()
//'--------------------------------------------------------------------
function contractPopupBox(x,y,intBoxWidth,intBoxHeight){

 //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('ajaxPopupBoxDiv'));
  document.getElementById('ajaxPopupBoxFrame').style.width = (range.boundingWidth + 4)+"px";
  document.getElementById('ajaxPopupBoxFrame').style.height = (range.boundingHeight + 4)+"px";
 }
 else{
  document.getElementById('ajaxPopupBoxDiv').style.width = "auto";
  document.getElementById('ajaxPopupBoxDiv').style.height = "auto";
  document.getElementById('ajaxPopupBoxFrame').style.width = (document.getElementById('ajaxPopupBoxDiv').offsetWidth);
  document.getElementById('ajaxPopupBoxFrame').style.height = (document.getElementById('ajaxPopupBoxDiv').offsetHeight);
 }

 self.setTimeout("document.getElementById('ajaxPopupBoxDiv').style.filter='Alpha(Opacity=75)';",50);
 self.setTimeout("document.getElementById('ajaxPopupBoxDiv').style.filter='Alpha(Opacity=50)';",100);
 self.setTimeout("document.getElementById('ajaxPopupBoxDiv').style.filter='Alpha(Opacity=25)';",150);
 self.setTimeout("document.getElementById('ajaxPopupBoxDiv').style.filter='Alpha(Opacity=0)';document.getElementById('ajaxPopupBoxDiv').style.display='none';document.getElementById('ajaxPopupBoxFrame').style.display='none';",200);

 /*
 if(x>1){
  document.getElementById('ajaxPopupBoxFrame').style.width = x+"px";
  document.getElementById('ajaxPopupBoxDiv').style.width = x+"px";
 }
 else{
  document.getElementById('ajaxPopupBoxFrame').style.width = "1px";
  document.getElementById('ajaxPopupBoxDiv').style.width = "1px";
  var widthReached = "true";
 }
 if(y>1){
  document.getElementById('ajaxPopupBoxFrame').style.height = y+"px";
  document.getElementById('ajaxPopupBoxDiv').style.height = y+"px";
 }
 else{
  document.getElementById('ajaxPopupBoxFrame').style.height = "1px";
  document.getElementById('ajaxPopupBoxDiv').style.height = "1px";
  var heightReached = "true";
 }
 if(widthReached=="true"&&heightReached=="true"){
  document.getElementById('ajaxPopupBoxFrame').style.display = "none";
  document.getElementById('ajaxPopupBoxDiv').style.display = "none";
  document.getElementById('ajaxPopupBoxFrame').style.width = intBoxWidth+"px";
  document.getElementById('ajaxPopupBoxDiv').style.width = intBoxWidth+"px";
  document.getElementById('ajaxPopupBoxFrame').style.height = intBoxHeight+"px";
  document.getElementById('ajaxPopupBoxDiv').style.height = intBoxHeight+"px";
  document.getElementById('ajaxPopupBoxDiv').innerHTML="";
  return true;
 }
 else{
  self.setTimeout("contractPopupBox("+(x-15)+","+(y-15)+","+intBoxWidth+","+intBoxHeight+");",1);
 }
 */
}

//--------------------------------------------------------------------
// hidePopupBox()
//--------------------------------------------------------------------
function hidePopupBox(){
 var intBoxWidth = document.getElementById('ajaxPopupBoxDiv').style.width.replace("px","");
 var intBoxHeight = document.getElementById('ajaxPopupBoxDiv').style.height.replace("px","");
 //document.getElementById('ajaxPopupBoxDiv').style.overflow = "hidden";
 contractPopupBox(intBoxWidth,intBoxHeight,intBoxWidth,intBoxHeight);
}


