var mid = "";
var left = 0;
var height = 0;
var width = 0;
var expanddelay = 1;
var expandpx = 10;
var loaded;
var expanded;
var data;
var docwidth;

if (self.innerWidth) { 
	// all except Explorer
    docwidth = self.innerWidth;
} else {
    if (document.documentElement && document.documentElement.clientWidth) {
    	// Explorer 6 Strict Mode
    	docwidth = document.documentElement.clientWidth;
    } else {
        if (document.body) {
            // other Explorers
        	docwidth = document.body.clientWidth;
        }
    }
}


function getAjaxConnection() {
    var xmlHttp;
    try {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    } catch (e) {
        // Internet Explorer  
        try {
            // IE 6+
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                // IE 5
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {
                alert("Your browser does not support AJAX.");
                xmlHttp = false;
            }
        }
    }
    return xmlHttp;
}


function updatebox() {
    document.getElementById("specialbox").style.left = left+"px";
    document.getElementById("specialbox").style.width = width+"px";
    document.getElementById("specialbox").style.height = height+"px";
}

function expandleft() {
    left = left - expandpx;
    width = width + expandpx;
    updatebox();
    if (width<250) {
        setTimeout("expandleft()",expanddelay);    
    }
}

function expanddown() {
    height = height + expandpx;
    updatebox();
    if (height<300) {
        setTimeout("expanddown()",expanddelay);    
    } else {
        expanded = true;
        if (loaded) {
            displayMessage(data);
        }
    }
}

function contractup() {
    height = height - expandpx;
    updatebox();
    if (height>18) {
        setTimeout("contractup()",expanddelay);
    }
}

function contractright(dir) {
    left = left + expandpx;
    width = width - expandpx;
    updatebox();
    if (width>1) {
        setTimeout("contractright('"+dir+"')",expanddelay);
    } else {
        document.getElementById("specialbox").style.display = "none";
        document.getElementById("specialbox").style.visibility = "hidden";
        loadnetprofile(dir)
    }
}

function showbox() {

    left = docwidth-100;
    width = 1;
    height = 18;

    updatebox();
    document.getElementById("specialbox").style.top = "110px";
    document.getElementById("specialbox").style.display = "inline";
    document.getElementById("specialbox").style.visibility = "visible";
    
    setTimeout("expandleft()",expanddelay);    
    setTimeout("expanddown()",350);
}

function close(dir) {
    displayMessage("");
    setTimeout("contractup()",expanddelay);
    setTimeout("contractright('"+dir+"')",350);
}

function displayMessage(txt) {
    document.getElementById("specialbox").innerHTML = txt;
}

function displayMessage2(txt) {
    document.getElementById("profiledisplay").innerHTML = txt;
}

function netselect(dir) {
    loaded = false;
    expanded = false;
    loadnetselect(dir);
    showbox();
}

function merselect(dir) {
    loaded = false;
    expanded = false;
    loadmerselect(dir);
    showbox();
}


function loadnetselect(dir) {
    xmlHttp = getAjaxConnection();
    if (xmlHttp.readyState==0) {
        xmlHttp.onreadystatechange = netselstate;
        var url = dir+mid+"loadnetselect.php";
        xmlHttp.open("GET",url,true);
        xmlHttp.send(null);
    } else {
        displayMessage("Error, cannot load network profile data");
    }
}

function loadmerselect(dir) {
    xmlHttp = getAjaxConnection();
    if (xmlHttp.readyState==0) {
        xmlHttp.onreadystatechange = merselstate;
        var url = dir+mid+"loadmerselect.php";
        xmlHttp.open("GET",url,true);
        xmlHttp.send(null);
    } else {
        displayMessage("Error, cannot load merchant profile data");
    }
}

function loadnetprofile(dir) {
    xmlHttp = getAjaxConnection();
    if (xmlHttp.readyState==0) {
        xmlHttp.onreadystatechange = netloadstate;
        var url = dir+mid+"loadnetprofile.php";
        xmlHttp.open("GET",url,true);
        xmlHttp.send(null);
    } else {
        displayMessage2("Error, cannot load network profile data");
    }
}


function netselstate() {
    if (xmlHttp.readyState==2) { 
        displayMessage("LOADING...");
    }
    if (xmlHttp.readyState==4) {
        data = xmlHttp.responseText;
        loaded = true;
        if (expanded) {
            displayMessage(data);
        } 
    }
}

function merselstate() {
    if (xmlHttp.readyState==2) { 
        displayMessage("LOADING...");
    }
    if (xmlHttp.readyState==4) {
        data = xmlHttp.responseText;
        loaded = true;
        if (expanded) {
            displayMessage(data);
        } 
    }
}

function netloadstate() {
    if (xmlHttp.readyState==2) { 
        displayMessage2("LOADING...");
    }
    if (xmlHttp.readyState==4) {
        data = xmlHttp.responseText;
        displayMessage2(data);
    }
}


function updatenet(str,dir) {
    document.getElementById("networkprofile").innerHTML = str;
//    setTimeout("",500);
    close(dir);
}

function updatemer(str,dir) {
    document.getElementById("merchantprofile").innerHTML = str;
    close(dir);
}
