var host = "http://www.oeh.com/intranet/";
// == Implementations ===========================================================
function ajaxGetCountriesInRegion(regionId) {
	makeHttpRequest(host + "ajax/getcountry.asp?regionid=" + regionId, "ajaxShowCountriesInRegion",false);
}
function ajaxShowCountriesInRegion(str){
	document.getElementById("countrydiv").innerHTML = str;
}
function ajaxGetBuByType(typeid) {
	makeHttpRequest(host + "ajax/getbu.asp?typeid=" + typeid, "ajaxShowBuByType",false);
}
function ajaxShowBuByType(str){
	document.getElementById("budiv").innerHTML = str;
}
function ajaxGetSubUnits(buid) {
	makeHttpRequest(host + "ajax/getsu.asp?buid=" + buid, "ajaxShowSubUnits",false);
}
function ajaxShowSubUnits(str){
	document.getElementById("subunit").style.display = "";
	document.getElementById("subunitdiv").style.display = "inline";
	document.getElementById("suhelp").style.display = "inline";
	document.getElementById("subunitdiv").innerHTML =  str;
	//show master unit's details - master unit should always be 1st in the dropdown
	//ajaxGetSubUnitDetails(document.getElementById("suid").value);
	ajaxGetSubUnitDetails(document.search.suid[document.search.suid.selectedIndex].value);
	//[document.search.country.selectedIndex].value
}
function ajaxGetReportSubUnits(buid) {
	makeHttpRequest(host + "ajax/getreportsu.asp?buid=" + buid, "ajaxShowReportSubUnits",false);
}
function ajaxShowReportSubUnits(str){
	document.getElementById("subunit").style.display = ""
	document.getElementById("subunitdiv").innerHTML =  str;
}
function ajaxGetSubUnitDetails(suid) {
	makeHttpRequest(host + "ajax/getsudetails.asp?suid=" + suid, "ajaxShowSubUnitDetails",false);
}
function ajaxShowSubUnitDetails(str){
	document.getElementById("budetailsdiv").innerHTML = str;
}
function ajaxAssignUnits(suid, pid) {
	//alert("Add: " + suid + "--" + pid);
	var d = new Date();
	var uid = d.getTime();
	makeHttpRequest(host + "ajax/assignunits.asp?suid=" + suid + "&pid=" + pid + "&uid=" + uid, "ajaxShowAssignedUnits",false);
}
function ajaxShowAssignedUnits(str){
	document.getElementById("assigned").innerHTML = str;
}
function ajaxRemoveUnits(suid, pid) {
	//alert("Remove: " + suid + "--" + pid);
	var d = new Date();
	var uid = d.getTime();
	makeHttpRequest(host + "ajax/removeunits.asp?suid=" + suid + "&pid=" + pid + "&uid=" + uid, "ajaxShowAssignedUnits",false);
}
function ajaxUnAssignUnits(pid) {
	var d = new Date();
	var uid = d.getTime();
	makeHttpRequest(host + "ajax/unassignedunits.asp?pid=" + pid + "&uid=" + uid, "ajaxShowUnAssignedUnits",false);
}
function ajaxShowUnAssignedUnits(str){
	document.getElementById("allunits").innerHTML = str;
}

function ajaxGetGroupPerms(group_id) {
	makeHttpRequest(host + "ajax/getGroups.asp?groupid=" + group_id, "ajaxShowGroupPerms",false);
}
function ajaxShowGroupPerms(str){
	document.getElementById("viewGroup").style.display = "block";
	document.getElementById("viewGroup").innerHTML = str;
}

function ajaxGetGroupPermsNew(group_id) {
	makeHttpRequest(host + "ajax/getGroupsNew.asp?groupid=" + group_id, "ajaxShowGroupPermsNew",false);
}
function ajaxShowGroupPermsNew(str){
	document.getElementById("perm_boxes").innerHTML = str;
}


// == Main HTTP request function ===========================================================
// =========================================================================================
function makeHttpRequest(url, callback_function, return_xml) { 

   var http_request = false; 
   if (window.XMLHttpRequest) { // Mozilla, Safari,... 
       http_request = new XMLHttpRequest(); 
       if (http_request.overrideMimeType) { 
           http_request.overrideMimeType('text/xml'); 
       } 
   } else if (window.ActiveXObject) { // IE 
       try { 
           http_request = new ActiveXObject("Msxml2.XMLHTTP"); 
       } catch (e) { 
           try { 
               http_request = new ActiveXObject("Microsoft.XMLHTTP"); 
           } catch (e) {} 
       } 
   } 
   if (!http_request) { 
       alert('Unfortunatelly your browser doesn\'t support this feature.'); 
       return false; 
   } 
   http_request.onreadystatechange = function() { 
       if (http_request.readyState == 4) { 
           if (http_request.status == 200) { 
               if (return_xml) { 
                   eval(callback_function + '(http_request.responseXML)'); 
               } else { 
                   eval(callback_function + '(http_request.responseText)'); 
               } 
           } else { 
               alert('There was a problem with the request.(Code: ' + http_request.status + ')'); 
           } 
       } 
   } 
   http_request.open('GET', url, true); 
   http_request.send(null); 
}
// =========================================================================================
// =========================================================================================




