/*
* CCM Popup Layer
* 
* Copyright(c) 2006 by CCM - Customer Communication Management GmbH
* All Rights reserved
* http://www.ccm-solutions.de
* e-mail: info@ccm-solutions.de
* 
* Copying and any kind of unauthorized use is prohibited.
*/



//-----------------------------------------------------------------------
// XMLHTTP Request
//-----------------------------------------------------------------------

_xhRequest = XHRequest.prototype;
function XHRequest(){}
_xhRequest.getObject = function() {
	if (window.XMLHttpRequest) {
		return new XMLHttpRequest();
	}
	else if (window.ActiveXObject) {
		return new ActiveXObject("Microsoft.XMLHTTP");
	}
	else {
		alert("XML HTTP Request support cannot be found!");
		return null;
	}
}
//-----------------------------------------------------------------------



//-----------------------------------------------------------------------
// The popup object
//-----------------------------------------------------------------------

var g_objPopup = new JPopup();

function JPopup() {}
_jPopup = JPopup.prototype;

_jPopup.initialize = function(szUrlFrame) 
{
    /*open an HTTP request to the url*/
	var pageRequest = new XHRequest().getObject();
	pageRequest.open("GET",szUrlFrame, false);

    //This is for asynchronus call only
//    pageRequest.onreadystatechange=function() 
//    {
//        if (pageRequest.readyState==4) 
//        {
//            embedpage(pageRequest.responseText);
//        }
//    }	

	pageRequest.send(null);
	
	if (pageRequest.readyState==4)
	{
	    embedPopupFrame(pageRequest.responseText);
	    this.close();
	}
}

_jPopup.close = function()
{
    var ns4=document.layers;
    var ie4=document.all;
    var ns6=document.getElementById&&!document.all;
    var oPopupLayer;
    
    oPopupLayer = document.getElementById("PopupMasterContainer");
    
    
    if (ie4||ns6)
    {
        oPopupLayer.style.visibility="hidden"
    }
    else if (ns4)
    {
        oPopupLayer.visibility="hide"
    }
}


_jPopup.open = function(szUrlContent, szCaption, szWidth)
{
    var ns4=document.layers;
    var ie4=document.all;
    var ns6=document.getElementById&&!document.all;
    var oPopupLayer;
    var oMoverLayer;
    var oCaption;
    
    
    embedNewContent(szUrlContent);
    
    
    oPopupLayer = document.getElementById("PopupMasterContainer");
    oMoverLayer = document.getElementById("mover");
    oCaption = document.getElementById("PopupTopTitle");
    oCaption.innerHTML = szCaption;
    
    if (ie4||ns6)
    {
        oPopupLayer.style.visibility="visible"
        oPopupLayer.style.width = szWidth;
        oPopupLayer.style.height = "auto";
        oMoverLayer.style.width = szWidth;
    }
    else if (ns4)
    {
        oPopupLayer.visibility="show"
    }

    dd.elements.mover.resizeTo(parseInt(szWidth),dd.elements.mover.h);
    
}


onPopupAction = function() {}

//-----------------------------------------------------------------------



//
function embedPopupFrame(reqText){
        
    var htmlInclude;
    var posStart = reqText.search(/<body.+?>/);
    var posEnd = reqText.search(/<\/body>/);
    
    htmlInclude = reqText.substring(posStart, posEnd);
    htmlInclude = htmlInclude.replace(/<body.+?>/, "");
    
    //alert(posStart + " " + posEnd);    
    //alert(htmlInclude);

    document.write(htmlInclude);
}


function embedNewContent(szUrlContent)
{
    var htmlPage;
    var htmlInclude;
    var posStart;
    var posEnd;
    var objContentArea;
    

	var pageRequest = new XHRequest().getObject();
	pageRequest.open("GET",szUrlContent, false);

	pageRequest.send(null);
	
	if (pageRequest.readyState==4)
	{
	    htmlPage = pageRequest.responseText;
	    
        posStart = htmlPage.search(/<\!\-\-\#contentAreaStart\#\-\->/);
        posEnd = htmlPage.search(/<\!\-\-\#contentAreaEnd\#\-\->/);
        
        htmlInclude = htmlPage.substring(posStart, posEnd);
        htmlInclude = htmlInclude.replace(/<\!\-\-\#contentAreaEnd\#\-\->/, "");
	    
	    objContentArea = document.getElementById("PopupContent");
	    objContentArea.innerHTML = htmlInclude;
	}
}
