
/* The following function creates an XMLHttpRequest object... */

function createRequestObject(){
	var request_o; //declare the variable to hold the object.
	var browser = navigator.appName; //find the browser name
	if(browser == "Microsoft Internet Explorer"){
		/* Create the object using MSIE's method */
		request_o = new ActiveXObject("Microsoft.XMLHTTP");
	}else{
		/* Create the object using other browser's method */
		request_o = new XMLHttpRequest();
	}
	return request_o; //return the object
}

/* You can get more specific with version information by using 
	parseInt(navigator.appVersion)
	Which will extract an integer value containing the version 
	of the browser being used.
*/
/* The variable http will hold our new XMLHttpRequest object. */
var http = createRequestObject(); 

function callAjax(url, param, div1){
	myRand=parseInt(Math.random()*99999999);  
	http.open('get', url + '?' + param + '&nocache='+ myRand);
	//Declare global variable to use in next function
	divChange = div1;
	http.onreadystatechange = changeDiv; 
	http.send(null);
}

function changeDiv(){
	/* Make sure that the transaction has finished. The XMLHttpRequest object 
		has a property called readyState with several states:
		0: Uninitialized
		1: Loading
		2: Loaded
		3: Interactive
		4: Finished */
	if(http.readyState == 4){ //Finished loading the response
		/* We have got the response from the server-side script,
			let's see just what it was. using the responseText property of 
			the XMLHttpRequest object. */
		var response = http.responseText;
		/* And now we want to change the product_categories <div> content.
			we do this using an ability to get/change the content of a page element 
			that we can find: innerHTML. */
		document.getElementById(divChange).innerHTML = response;
	}
}

function DeleteImage(img) {
	var agree=confirm("Are you sure you want to delete this image?");
	if (agree) {
		document.imgForm.submit();
		return true ;
	} else {
		document.imgForm.delImg[img].checked = false;
		return false ;
	}
}

function DeleteFile(fileId) {
	var agree=confirm("Are you sure you want to delete this project file?");
	if (agree) {
		document.fileForm.delFile.value = fileId;
		document.fileForm.submit();
		return true ;
	} else {
		document.fileForm.delFile.value = '';
		return false ;
	}
}

function DeleteProject() {
	var agree=confirm("Are you sure you want to delete this project AND all of its images AND files?");
	if (agree) {
		if(confirm("Are you sure you really want to do this?")) {
			document.form1.submit();
			return true ;
		} else {
			document.form1.delProj.checked = false;
			return false ;
		}
	} else {
		document.form1.delProj.checked = false;
		return false ;
	}
}

function DeleteOpsProject(projectName, projectId) {
	var agree=confirm("Are you sure you want to delete " + projectName + " from the Operations Map?");
	if (agree) {
		if(confirm("Are you sure you really want to do this?")) {
			document.opsForm.deleteTrigger.value = projectId;
			document.opsForm.submit();
			return true ;
		} else {
			return false ;
		}
	} else {
		return false ;
	}
}

function DeleteUser(user) {
	var agree=confirm("Are you sure you want to delete this user?");
	if (agree) {
		window.location = 'siteUsers.php?delUser='+user;
		return true ;
	}
}
	
