var displayRow = (navigator.appName=='Microsoft Internet Explorer' ? 'block' : 'table-row');

function highlightLine(line) {
	var line_id = 'line_'+line;
	document.getElementById(line_id).className = 'inputrequired';
}
function confirmdelete(record,field,script) {
	if(confirm("Delete record ?")) {
		var hasQMark = script.indexOf('?');
		var qsChar = (hasQMark==-1 ? '?' : '&');
		window.location=script+qsChar+"delete=y&"+field+"="+record
	} else {
		window.location=script
	}
	return false;
}
function imagedelete(record,script) {
	if(confirm("Delete image ?")) {
		window.location=script+"&deleteimage=y&"+record+"#amend"
	} else {
		window.location=script
	}
	return false;
}
function docdelete(record,script) {
	if(confirm("Delete document ?")) {
		window.location=script+"&deletedoc=y&"+record+"#amend"
	} else {
		window.location=script
	}
	return false;
}
function img_resize(pic_id,min_height,max_height) {
	if(document[pic_id].height==min_height) {
		document[pic_id].height=max_height
	} else {
		document[pic_id].height=min_height
	}
}
var calWin = null;
function opencalWin(field,date,e) {
    e = e || window.event;
	x = e.screenX;
	y = e.screenY;
	calWin = window.open("../classes/calendar.php?field="+field+"&d="+date, "sWin", "width=180,height=150,left="+x+",top="+y+",scrollbars=0");
	calWin.focus();
}
var DAPopUpWin = null;
function openDAPopUpWin(script,height,width) {
	DAPopUpWin = window.open(script, "daWin", "height="+height+",width="+width+",scrollbars=auto");	
	DAPopUpWin.focus();
}

// Popup Link Menu Activator
function gotoPopUpLink(form, field) {
	var url = eval("form."+field+".options[form."+field+".selectedIndex].value");
	if (url != "") location.href = url;
	return false;
}
function selectPage(script,displayPerPage,sortString) {
	var page = document.getElementById('pageSelector').options[document.getElementById('pageSelector').selectedIndex].value;
	var startAt = (page-1)*displayPerPage;
	var url = script+'?start_at='+startAt+sortString;
	if (url != "") location.href = url;
	return false;
}
function setAllChecked(field,number) {
	for($i=0; $i<number; $i++) {
		var obj = field+$i;
		if (document.getElementById(obj).checked == false) document.getElementById(obj).checked = true;
	}
}
function setAllUnChecked(field,number) {
	for($i=0; $i<number; $i++) {
		var obj = field+$i;
		if (document.getElementById(obj).checked == true) document.getElementById(obj).checked = false;
	}
}
function formatDecimal(originalNumber, decPlaces){
	if(isNaN(originalNumber)) {
		return '0.00'; 
	}
	originalNumber += 0.00001;
	originalNumber = originalNumber.toString();
	var decimalIndex = originalNumber.search(/\./);
	if (decimalIndex >= -1) {
		var formatted = originalNumber.substring(0, decimalIndex + 1 + decPlaces);
	} else {
		var formatted = originalNumber;
	}
	return(formatted);
}
function checkFiletype(theField,validTypes) {
	var fileSplit = theField.value.split(".");
	var fileType = fileSplit[1];
	var typeSplit = validTypes.split(":");
	var valid = 0;
	for(var i=0; i<typeSplit.length; i++) {
		if(typeSplit[i].toUpperCase()==fileType.toUpperCase()) {
			valid = 1;
		}
	}
	if(!valid) {
		alert('Incorrect file type detected: '+theField.value);
		theField.focus();
	}
}
function closeWindow() {	
	top.window.opener.location.reload();
	top.window.opener = top;
	top.window.open('','_parent','');
	setTimeout('top.window.close()',500);
}
function delay(millisecs){
	var then,now; 
	then=new Date().getTime();
	now=then;
	while((now-then)<millisecs) {
		now=new Date().getTime();
	}
}