var http = createRequest();

function deleteCustomer(id) {
	check = confirm("Do you really want to delete this customer and all their lightboxes?");
	if(check) {
		sendRequest("customer_remove.php",id);
	}
}

function deleteBuilder(id) {
	check = confirm("Do you really want to delete this builder?");
	if(check) {
		sendRequest("builder_remove.php",id);
	}
}

function deleteLight(id) {
	check = confirm("Do you really want to delete this light?");
	if(check) {
		sendRequest("light_remove.php",id);
	}
}

function deleteLocation(id) {
	check = confirm("Do you really want to delete this location?");
	if(check) {
		sendRequest("location_remove.php",id);
	}
}

function deletePackage(id) {
	check = confirm("Do you really want to delete this package?");
	if(check) {
		sendRequest("package_remove.php",id);
	}
}

function deleteDefaultLocation(id) {
	check = confirm("Do you really want to delete this default location?");
	if(check) {
		sendRequest("location_default_remove.php",id);
	}
}

function addDefaultLocations(id) {
	check = confirm("Do you really want to add all default locations to this builder?");
	if(check) {
		sendRequest("location_add_default.php",id);
	}
}

function deleteCategory(id) {
	check = confirm("Do you really want to delete this Light Category?");
	if(check) {
		sendRequest("category_remove.php",id);
	}
}

function activateLight(id) {
	check = confirm("Do you really want to activate this Light?");
	if(check) {
		sendRequest("light_activate.php",id);
	}
}

function deactivateLight(id) {
	check = confirm("Do you really want to deactivate this Light?");
	if(check) {
		sendRequest("light_deactivate.php",id);
	}
}

function activatePackageLight(id,bp) {
	http.open('get','package_light_activate.php?id='+id+'&package='+bp);
	http.onreadystatechange = handleResponse;
    http.send(null);
}

function deactivatePackageLight(id,bp) {
	http.open('get','package_light_deactivate.php?id='+id+'&package='+bp);
	http.onreadystatechange = handleResponse;
    http.send(null);
}

function activateBuilderLight(id,builder) {
	http.open('get','builder_light_activate.php?id='+id+'&builder='+builder);
	http.onreadystatechange = handleResponse;
    http.send(null);
}

function deactivateBuilderLight(id,builder) {
	http.open('get','builder_light_deactivate.php?id='+id+'&builder='+builder);
	http.onreadystatechange = handleResponse;
    http.send(null);
}

function allBuilderLights(cat,builder,mode) {
	if(mode==1) {
		check = confirm("Do you really want to add all lights in this category to this builder?");
	}
	if(mode==0) {
		check = confirm("Do you really want to remove all lights in this category from this builder?");
	}
	if(check) {
		http.open('get','builder_light_all.php?cat='+cat+'&builder='+builder+'&mode='+mode);
		http.onreadystatechange = handleResponse;
    	http.send(null);
	}
}

function createRequest() {
	var obj;
	var browser = navigator.appName;
	if(browser == "Microsoft Internet Explorer"){
        obj = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        obj = new XMLHttpRequest();
    }
    return obj;
}

function sendRequest(page, id) {
	http.open('get', page+'?id='+id);
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function handleResponse() {
	if(http.readyState == 4){
		// this is the content of the called page
        var response = http.responseText;
        //(response);
        var update = new Array();

       	//process the response
       	window.location.reload();
    }
}

function addUserAccess(builder) {
	var s = document.getElementById("user").selectedIndex;
	var id = document.getElementById("user").options[s].value;
	//alert(id);
	http.open('get','builder_access.php?b='+builder+'&u='+id+'&o=i');
	http.onreadystatechange = handleResponse;
    http.send(null);
}

function removeUserAccess(builder, user) {
	http.open('get','builder_access.php?s='+builder+'&u='+user+'&o=d');
	http.onreadystatechange = handleResponse;
    http.send(null);
}
