// Support for deleting records with Ajax

function v2(a) {
	// What we have to do to determine an array....
	if (typeof a.shift === 'function') {  
		while (flag = a.shift()) {
			switch (flag) {
			case 'J': 
				eval(a.shift()); 
				break;
			case 'JX': 
				if (eval(a.shift())) 
					eval(a.shift());
				else
					dumb = a.shift(); 
				break;
			case 'C': 
				divname = a.shift();
				elem = document.getElementById(divname);
				if (!elem) {
					dumb = a.shift();
					alert('Location not found on screen: ' + divname + " = " + dumb);
				} else {
					elem.innerHTML = a.shift();
				}
				break;
			}
		}
	} else {
		alert("Problem in v2: " + a);
	}
}

var currenturl = unescape(window.location.href);
function delete_result(x) {
	if (x.length == 0) {
		window.location = currenturl;
	} else {
		if (currenturl.indexOf("?") > 0)
			window.location = currenturl + '&infomsg=' + escape(x);
		else
			window.location = currenturl + '?infomsg=' + escape(x);
	}
}
function delete_record(clazz, pid) {
	ix = currenturl.indexOf("?");
	if (ix > 0)
		nurl = currenturl.substring(ix+1);
	else
		nurl = "";
	delete_record_go(clazz, pid, nurl);
}
function delete_record_go(clazz, pid, nurl) {
	delete_record_go_ex(clazz, pid, nurl, "");
}
function delete_record_go_ex(clazz, pid, nurl, filefield) {
	ix = currenturl.indexOf("?");
	if (ix > 0)
		currenturl = currenturl.substring(0,ix);
	if (nurl.length > 0)
		currenturl = currenturl + "?" + nurl;
	agent.call('ajax_functions.php','delete_record','delete_result', clazz, pid, filefield);
}

// Dialog control version 2
function makedialog(divid) { 
	scrollx = (document.all)?document.body.scrollLeft:window.pageXOffset;
	scrolly = (document.all)?document.body.scrollTop:window.pageYOffset;
	leftpadding = screen.availWidth / 10;
	// alert("x=" + x + " y=" + y + " scrollx=" + scrollx + " scrolly=" + scrolly);
	mb = document.getElementById(divid);
	if (mb) {
		mb.style.left = scrollx + leftpadding;
		mb.style.top = scrolly + 120;
		mb.className = 'pedialog';
	} else {
		alert("Error: Location not found on page: " + divid);
	}
}
function hidedialog(divid) {
	mb = document.getElementById(divid);
	if (mb) 
		mb.className = 'hidedialog';
}
function hidebyid(divid) {
	mb = document.getElementById(divid);
	if (mb) 
		mb.className = 'hidedialog';
}
function showbyid(divid) {
	mb = document.getElementById(divid);
	if (mb) 
		mb.className = 'showdialog';
}


