function edit_list(igoto, val)
{
    if (val == 'edit') {
        if (confirm('Changes on this page will be lost. Please ensure changes are saved before proceeding.') == false)
            return false;

        location.href = igoto;
    }
}

function edit_multilist(igoto, select)
{
    for(var i=0; i < select.options.length; i++) {
        if(select.options[i].selected && select.options[i].value == 'edit') { 
        
            if (confirm('Changes on this page will be lost. Please ensure changes are saved before proceeding.') == false)
                return false;

            location.href = igoto;
        }
    }
}

function docategory(options, index) {
    if (options[index].value == 'edit') return '_category.php';
    else if (!isNaN(index) && index > 0) return '.php/set_category/' + options[index].value;
    else return '.php/set_category';
}

function docategory2(options, index, from, to) {
    if (options[index].value == 'edit') return to+'.php';
    else if (!isNaN(index) && index > 0) return from+'.php/set_category/' + options[index].value;
    else return from+'.php/set_category';
}

function catmenu(phpself,val,manager,retquery,itemid) {

        if(itemid != null && val == 'edit') {
          if(confirm('Changes on this page will be lost. Please ensure changes are saved before proceeding') == false) {
	    return false;
          }
          
        }

	if(val == 'edit') {
		location.href='/manager/category/' + manager +  '?' + retquery;
	} else if(itemid == null){
		location.href=phpself + val;
	}
 
}

function check_selected(formid) {
	var e = document.forms[formid].elements;
	var allchecked = true;

	for (var i=0; i<e.length; i++) {
		if (e[i].type == "checkbox") {
			if (!e[i].checked) {
				allchecked = false;
			}
		}
	}
}

function hilite_row(formid, chkbox,docheck) {
	var e = chkbox;

    while (e && e.tagName != "TR") {
		e = e.parentNode;
	}

	if (chkbox.checked) e.className = "tr_hilighted";
	else e.className = "tr_normal";

	if (docheck) check_selected(formid);
}

function selectallcheckboxes(formid,val) {
	var e = document.forms[formid].elements;
	for (var i=0; i<e.length; i++) {
		if (e[i].type == "checkbox") {
			e[i].checked = val;
			hilite_row(formid, e[i],false);
		}
	}

	check_selected(formid);
}

function opensmallwin(url) {
	if(navigator.appVersion.substring(0,1) <3) return false ;

	remote = window.open(url,"small","toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=200,height=150");

	self.name = "mainwin";
	remote.focus();

	return true;
}

function openlargewin(url) {
	if(navigator.appVersion.substring(0,1) <3) return false ;

	remote = window.open(url,"large","toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=760,height=560");

	self.name = "mainwin";
	remote.focus();

	return true;
}


function manage_attachments(parentformid) {
	document.getElementById(parentformid).add_attachment.value = 1;

	submitform(parentformid);

}


function deletewarning(msg) {
	return(confirm("Are you sure you want to delete " + msg + "?"));
}

function do_stuff(url) {
 	remote = window.open(url,"mgrsubwin","toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=700,height=400");
	remote.focus();
}

function submitform(parentformid) {
	document.getElementById(parentformid).submit();
	return true;
}

function openmgrsubwin(url) {
	remote = window.open(url,"mgrsubwin","toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=525,height=525");
	remote.focus();
	return true;
}

function submitform2(e) {
    var frm = document.forms[e];

    if (frm) frm.submit();
}

function sizedwindow(url,ww,wh) { 

var fw = ww;
var fh = wh;

curr_window = window.open(url,'remotewindow','toolbar=yes,location=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width='+fw+',height='+fh+''); 
curr_window.focus();

}

function max_size(e,size) {
    if(e.description.textLength > size) {
        alert("Description Size can only be " + size + " characters, but you've entered " + e.description.textLength + " characters");
        return false;
    }
    return true;
}
