   var popupReturn=null;	

   function showPopup(url){
		var title = arguments[1];
		if (title!=null){setPopupTitle(title);}
		initializeAJAXReq();
		REQ.onreadystatechange=captureContent;
        url = randURL(url);
    	url += "&ipu=true";
        if(popupReturn!=null){
        	url += "&rurl="+popupReturn;
        }
       
		REQ.open("GET",url);
		REQ.send(null);
	}

	function captureContent(){
		var html = "";
		if(REQ.readyState==4){
			if (REQ.status == 200) {
				html = REQ.responseText;
			}
		}
		displayPopup(html);
	}

    var popupTitle = "";
	function setPopupTitle(title){this.popupTitle = title;}

	function displayPopup(html){
		var clearInnerValues = 0;
		bodyWriteResize();

		var popupDiv = document.getElementById("popupDiv");
		var popupData = document.getElementById("popupData");
   		var popupTitle = document.getElementById("popupTitle");
		popupTitle.innerHTML = this.popupTitle;

    	popupData.style.height = "auto";
		popupData.innerHTML = html;
		popupDiv.style.display = 'block';
		popupDiv.style.zindex = '10';

		sizePopup();
		positionPopup();
		sizeBackground();
	}

	function setInnerValues(){
		if (window.innerHeight == null){
			window.innerHeight = document.body.clientHeight;
			window.innerWidth = document.body.clientWidth;
			clearInnerValues = 1;
		} else {clearInnerValues = 0;}
	}

	function checkInnerValues(){
		if (clearInnerValues == 1){
			window.innerHeight = null;
			window.innerWidth = null;
			clearInnerValues = 0;
		}
	}

	function sizePopup(){
		setInnerValues();
		if (popupData.scrollHeight > (window.innerHeight * 0.76)){
			var popupDataHeight = (window.innerHeight * 0.75);
			popupData.style.height = Math.round(popupDataHeight) + "px";
		}
		if (popupData.offsetWidth > 750){
			popupData.style.width = 710 + "px";
		}
		checkInnerValues();
	}

	function sizeBackground(){
		if (document.body.clientWidth < 800){
			popupDiv.style.width = 800 + "px";
		} else popupDiv.style.width = document.body.clientWidth + "px";

		if (document.body.offsetHeight < document.body.scrollHeight){
			popupDiv.style.height = document.body.scrollHeight + "px";
		} else popupDiv.style.height = document.body.offsetHeight + "px";
	}

	function positionPopup(){
		setInnerValues();
		if (window.innerWidth < popupShell.offsetWidth){
			if (document.body.scrollWidth - document.body.scrollLeft <= popupShell.offsetWidth) {
				var popupShellLeft = (document.body.scrollWidth - popupShell.offsetWidth);
			} else {
				var popupShellLeft = (0 + document.body.scrollLeft);
			}
		} else {
			var popupShellLeft = (((document.body.clientWidth - popupShell.offsetWidth) / 2) + document.body.scrollLeft);
		}
		if (window.innerHeight < popupShell.offsetHeight){
			if (document.body.scrollHeight - document.body.scrollTop <= popupShell.offsetHeight) {
				var popupShellTop = (document.body.scrollHeight - popupShell.offsetHeight);
			} else {
				var popupShellTop = (0 + document.body.scrollTop);
			}
		} else {
			var popupShellTop = (((window.innerHeight - popupShell.offsetHeight) / 2) + document.body.scrollTop);
		}
		popupShell.style.left = Math.round(popupShellLeft) + "px";
		popupShell.style.top = Math.round(popupShellTop) + "px";
		checkInnerValues();
	}

	function bodyWriteResize(){
		document.body.setAttribute("onresize", "repositionPopup();");
		window.onresize = repositionPopup;
		document.body.setAttribute("onscroll", "repositionPopup();");
		window.onscroll = repositionPopup;
	}

	function repositionPopup(){
		sizePopup();
		positionPopup();
		sizeBackground();
	}

	function hidePopup(){
		var popupDiv = document.getElementById("popupDiv");
		var popupData = document.getElementById("popupData");

		popupDiv.style.display = 'none';
    	popupDiv.style.height = "0px";

	}

	function displayInline(html,parentDiv){
 		var inlineDiv = document.getElementById(parentDiv);
		inlineDiv.innerHTML = html;
	}


   var callDisplayDiv;
   var waitHTML = "";
   function callForDisplay(url,parentDiv){
	 if (arguments.length ==3){
        waitHTML = arguments[2];
      }else{
         waitHTML = "<div class=\"loading\"><span>Loading...</span></div>";
      }
      var html = waitHTML;
      callDisplayDiv = parentDiv;
      initializeAJAXReq();
      displayInline(html,callDisplayDiv);
      REQ.onreadystatechange=displayCallForDisplay;
      url = randURL(url);
      REQ.open("POST",url);
      REQ.send(null);
    }

   function displayCallForDisplay(){
    var html = waitHTML;
      if(REQ.readyState==4){
          if (REQ.status == 200) {
            html = REQ.responseText;
          }
      }
       displayInline(html,callDisplayDiv);
    }

   function getFormFieldsAsUrlParms(addForm){
      var parms = "";
      for(i=0; i<addForm.elements.length; i++){
        var frmEl = addForm.elements[i];
        parms +=getFormFieldParm(frmEl);
      }
     return parms;
    }

   function getFormFieldParm(frmEl){
      var parms = "";
      if(frmEl.name != ""){
        if(frmEl.type == 'checkbox'){
          if(frmEl.checked){parms +="&"+frmEl.name + "=" + frmEl.value ;}
      }else{
          if(frmEl.type == 'select-one'){
            parms +="&"+frmEl.name + "=" + frmEl[frmEl.selectedIndex].value ;
          }else{
            parms +="&"+frmEl.name + "=" + escape(frmEl.value) ;
          }
        }
      }
     return parms;
    }

    function randURL(url){
      var s = "?";
      if(url.indexOf("?")>0){s = "&";}
      var dt = new Date();
      var nmbr = dt.getTime();
      var nme = Math.round((Math.random() * 1000));
      url = url + s + nme + "=" + nmbr;
      return url;
     }
