var dirtyFlag=false; //Flag if input data has not been saved

//Hilite table row under mouse
function bg(obj,on) {
	if (on) {
		obj.className = 'row_hilite';
	} else {
		obj.className = 'row_unhilite';
	}
}

function setDirtyFlag(field) {
	if (field==undefined) {
		dirtyFlag=true;
		try {document.getElementById('saved_status').src=root_path+"admin/furniture/icon_error.gif";} catch(e) {}
	} else if (field.value!=field.defaultValue) {
		dirtyFlag=true;
		try {document.getElementById('saved_status').src=root_path+"admin/furniture/icon_error.gif";} catch(e) {}
	}
}

function clearDirtyFlag() {
	dirtyFlag=false;
}

//Check dirty flag before attempting to load a page
function loadPage(new_url) {
	if (dirtyFlag) {
		var conf=confirm("You have unsaved changes on this page.\nDo you wish to proceed WITHOUT saving?");
		if (conf) {
			document.location.href=new_url;
		}
	} else {
		document.location.href=new_url;
	}
}

		
function tab_hilite(t) {
	for (var tab=1;tab<5;tab++) {
		tb='top_tab'+tab;
		bt='top_btn'+tab;
		if (t==tab) {
			document.getElementById(tb).className='opt'+tab+'Active';
			document.getElementById(bt).className='top_button_hilite';
		} else {
			document.getElementById(tb).className='opt'+tab;
			document.getElementById(bt).className='';
		}
	}
}

function tab_unhilite(t) {
		bt='top_btn'+t;
		document.getElementById(bt).className='';
}


function SetAllCheckBoxes(FormName, FieldName, CheckValue) {
	for (i=0; i<document.forms[FormName].elements.length; i++) {
        if (document.forms[FormName].elements[i].name.indexOf(FieldName)==0)
            document.forms[FormName].elements[i].checked = CheckValue;
    }
}

function submitenter(myfield,e) {
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	else if (e) keycode = e.which;
	else return true;
	
	if (keycode == 13) {
	   myfield.form.submit();
	   return false;
	} else {
	   return true;
	}
}

function init() {
	
	try {page_init();} catch (e) {}
	
	try {
		for (i=0; i<document.forms[0].getElementsByTagName("input").length; i++) {
			if (document.forms[0].getElementsByTagName("input")[i].type == "text") {
				document.forms[0].elements[i].focus();
				break;
			}
		}
	}
	catch (e) {}
}
