var process_counter=0;
var xmlHttp=new Array();
var targetId=new Array();
var command=new Array();

function closePopup(id)
{
   p=document.getElementById(id);
   if (p) {
    p.style.visibility="hidden";
    p.style.display="none";
   }
}


function popup(url,w,h)
{
    window.open(url,'popup','width='+w+',height='+h+',scrollbars=no,menubar=0');
}














function createXmlHttpRequestObject()
{
    var xmlHttp;
    try {
        xmlHttp = new XMLHttpRequest();
    }
    catch(e)
    {
        // IE 6 oder älter
        try {
            xmlHttp= new ActiveXObject("Microsoft.XMLHttp");
        }
        catch(e) {
        }
    }
    if (!xmlHttp) {
        alert("Your are using Internet Explorer V6 or V5. Please activate ActiveX or update your browser or use firefox/mozilla!");
        return;

    }
    return xmlHttp;
}

// Datei vom Server lesen
function process(url,tId)
{
    xmlHttp[process_counter]=createXmlHttpRequestObject();
    targetId[process_counter]=tId;
    command[process_counter]="replaceHTML";
    var targetObj=document.getElementById(targetId);
    if (targetObj) targetObj.innerHTML="<p>...</p>";
    if (xmlHttp[process_counter]) {
        try {
            xmlHttp[process_counter].open("GET",url,true);
            xmlHttp[process_counter].onreadystatechange = handleRequestStateChange;
            xmlHttp[process_counter].send(" ");
            process_counter++;
        }
        catch(e)
        {
            //alert("Couldnt connect to server:\n" + e.toString()+"\n"+url+"\n"+tId);
        }
    }
}

function processHTMLAreaV1(url,tId)
{
    xmlHttp[process_counter]=createXmlHttpRequestObject();
    targetId[process_counter]=tId;
    command[process_counter]="insertHTML_V1";
    if (xmlHttp[process_counter]) {
        try {
            xmlHttp[process_counter].open("GET",url,true);
            xmlHttp[process_counter].onreadystatechange = handleRequestStateChange;
            xmlHttp[process_counter].send(" ");
            process_counter++;
        }
        catch(e)
        {
            //alert("Couldnt connect to server:\n" + e.toString()+"\n"+url+"\n"+tId);
        }
    }
}


function handleRequestStateChange()
{
    for (var i=0;i<process_counter;i++) if (targetId[i]!="") {
        var targetObj=document.getElementById(targetId[i]);
        if (targetObj) {
            if (xmlHttp[i].readyState.toString() == 4) {
                // Status OK
                if (xmlHttp[i].status == 200 ) {
                    try {
                       response=xmlHttp[i].responseText;
                        switch(command[i]) {
                            case 'replaceHTML':
                                targetObj.innerHTML=response;
                                targetId[i]="";
                            break;
                            case 'insertHTML_V1':
                                editor_insertHTML(targetId[i],response);
                                targetId[i]="";
                            break;
                        }
                    }
                    catch(e){
                        //alert("Error reading the response: "+e.toString() );
                    }
                } else {
                    //alert("There was a problem retrieving the data:\n"+xmlHttp[i].statusText);
                }
            }
        } else alert("Error getting targetID : "+targetId[i]);
   }
}
