function expandCollapse(parent) {
	var oChild = document.getElementById(parent);
	if(oChild.title == 'collapse'){
		oChild.style.display = '' ;
		oChild.title = 'expand';
	}else {
		if(oChild.title == 'expand'){
			oChild.style.display = 'none' ;
			oChild.title = 'collapse';
		}
	}
}

function diplaySub(url, id, parent){

	if(!parent){
	   var oChild = document.getElementById(id);
    }else{
        var oChild = document.getElementById(parent);
        oChild.title = 'Collapse';
        //oChild.innerHTML = 'test';
        loadSubordinate(url, id, parent);
    }
	if (oChild.getElementsByTagName("div")[0].innerHTML.startsWith("Please wait, loading...")) {
		oChild.style.display = '' ;
		oChild.title = 'Expand';
		loadSubordinate(url, id);
	}else {
		if(oChild.title == 'Expand'){
			oChild.style.display = 'none' ;
			oChild.title = 'Collapse';
		}else {
			oChild.style.display = '' ;
			oChild.title = 'Expand';
		}
	}
}


function AjaxCall(url, id, parent){

	if(!parent){
	   var oChild = document.getElementById(id);
    }else{
        var oChild = document.getElementById(parent);
        oChild.title = 'Collapse';
        //oChild.innerHTML = 'test';
        
        loadEIR(url, id, parent);
    
    }
}

function loadEIR(url,userId, parent) {
	//var url = 'http://localhost/Cratos/src/Employee.php';
    if(!parent){
	   var params = 'userId=' + userId; 
    }else{
         var params = '&userId=' + userId;
         params += '&parent=' + parent;

    }
    //alert (url + ' ' + userId + ' ' + parent);
	new AJAXInteraction(
			url, 
			params, 
			xhttp.HTTP_METHOD_GET, 
			function(xmlHttpReq) {
				// returned xml document
				var xmlDoc = xmlHttpReq.responseXML.documentElement;
				//alert ('xmldoc ' + xmlDoc);
                if(!parent){
				    var oChild = document.getElementById(userId);
				    
                }else {
                    var oChild = document.getElementById(parent);
                }
				var dataNode = ParseDataNode(xmlDoc);
				oChild.innerHTML = dataNode.firstChild.data;
				//oChild.innerHTML = 'test';
			}, 
			function(xmlHttpReq, httpReqError) { 
				if (httpReqError == xhttp.ERROR_CAN_NOT_CREATE) {
					alert('Your browser does not support XMLHttpRequest.');				
				} else if (httpReqError == xhttp.ERROR_CAN_NOT_COMMUNICATE) {
					alert('A networking error has occurred. Please check your network connection.');
				} else {
					alert('An error has occurred. Please contact your system administrator.');
					var errorMsg = 'Error fetching data!';
					try {
						errorMsg += '\n\nreadyState:' + xmlHttpReq.readyState;
					} catch(e){}
					try {
						errorMsg += '\nstatus: ' + xmlHttpReq.status;
					} catch(e){}
					try {
						errorMsg += '\nheaders: ' + xmlHttpReq.getAllResponseHeaders();
					} catch(e){}
					alert(errorMsg);
				}
			}
	);
}



function loadSubordinate(url,userId, parent) {
	//var url = 'http://localhost/Cratos/src/Employee.php';
    if(!parent){
	   var params = 'userId=' + userId; 
    }else{
         var params = 'userId=' + userId;
         params += '&parent=' + parent;

    }
	new AJAXInteraction(
			url, 
			params, 
			xhttp.HTTP_METHOD_GET, 
			function(xmlHttpReq) {
				// returned xml document
				var xmlDoc = xmlHttpReq.responseXML.documentElement;
                if(!parent){
				    var oChild = document.getElementById(userId);
				    
                }else {
                    var oChild = document.getElementById(parent);
                }
				var dataNode = ParseDataNode(xmlDoc);
				oChild.innerHTML = dataNode.firstChild.data;
				//oChild.innerHTML = 'test';
			}, 
			function(xmlHttpReq, httpReqError) { 
				if (httpReqError == xhttp.ERROR_CAN_NOT_CREATE) {
					alert('Your browser does not support XMLHttpRequest.');				
				} else if (httpReqError == xhttp.ERROR_CAN_NOT_COMMUNICATE) {
					alert('A networking error has occurred. Please check your network connection.');
				} else {
					alert('An error has occurred. Please contact your system administrator.');
					var errorMsg = 'Error fetching data!';
					try {
						errorMsg += '\n\nreadyState:' + xmlHttpReq.readyState;
					} catch(e){}
					try {
						errorMsg += '\nstatus: ' + xmlHttpReq.status;
					} catch(e){}
					try {
						errorMsg += '\nheaders: ' + xmlHttpReq.getAllResponseHeaders();
					} catch(e){}
					alert(errorMsg);
				}
			}
	);
}