// JavaScript Document
function popWindow(page,content) {
pop_label = window.open(page + "?" + content, "pop_image", "fullscreen=no,toolbar=no,status=yes,menubar=no,scrollbars=no,resizable=yes,directories=no,location=no,width=600,height=640,left=0,top=0")
pop_label.focus();
}
function popWindowHome(page,content) {
pop_label = window.open(page + "?" + content, "pop_image", "fullscreen=no,toolbar=no,status=yes,menubar=no,scrollbars=no,resizable=yes,directories=no,location=no,width=600,height=580,left=0,top=0")
pop_label.focus();
}
function popWindowEdit(page,content) {
pop_label = window.open(page + "?" + content, "pop_image", "fullscreen=no,toolbar=no,status=yes,menubar=no,scrollbars=no,resizable=yes,directories=no,location=no,width=768,height=580,left=0,top=0")
pop_label.focus();
}
function closeandfocus() {
if (window.opener && !window.opener.closed) {
window.opener.focus();
//var URL = unescape('/clearimage/labels/index.php');
//window.opener.location.href(URL);
window.opener.location.href('../folio/index.php');
self.close();

}
else
{
window.open ("../folio/index.php","Main");
parent.close();
}
}
function CMAcloseandfocus(location) {
if (window.opener && !window.opener.closed) {
window.opener.focus();
window.opener.location.href(location);
self.close();
}
else
{
 window.open ("../folio/viewimages.php","Main");
 parent.close();
}
}
function closeWindow() {
window.close();
}
// FORM VALIDATION 
// validates that the field value string has one or more characters in it
function isNotEmpty(elem) {
	var str = elem.value;
	var fieldname = elem.id;
    var re = /.+/;
    if(!str.match(re)) {
        alert("Please fill in the " + fieldname + " field.");
        setTimeout("focusElement('" + elem.form.name + "', '" + elem.name + "')", 0);
        return false;
    } else {
        return true;
    }
}

//validates that the entry is a positive or negative number
function isNumber(elem) {
	var str = elem.value;
    var re = /^[-]?\d*\.?\d*$/;
    str = str.toString();
    if (!str.match(re)) {
        alert("Please enter only numbers into the " + elem.id +" field (without spaces).");
        setTimeout("focusElement('" + elem.form.name + "', '" + elem.name + "')", 0);
        return false;
    }
    return true;
}
// validates that the entry is 16 characters long
function isLen16(elem) {
	var str = elem.value;
    var re = /\b.{16}\b/;
    if (!str.match(re)) {
        alert("Entry does not contain the required 16 characters.");
        setTimeout("focusElement('" + elem.form.name + "', '" + elem.name + "')", 0);
        return false;
    } else {
        return true;
    }
}
// validates that the entry is formatted as an e-mail address
function isEMailAddr(elem) {
	var str = elem.value;
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) {
        alert("Please check your email address.");
        setTimeout("focusElement('" + elem.form.name + "', '" + elem.name + "')", 0);
        return false;
    } else {
        return true;
    }
}
// validate that the user made a selection other than default
function isChosen(select) {
	var fieldname = select.id;
    if (select.selectedIndex == 0) {
        alert("Please make a choice from the '" +fieldname+ "' list.");
        return false;
    } else {
        return true;
    }
}

// validate that the user has checked one of the radio buttons
function isValidRadio(radio) {
    var valid = false;
    for (var i = 0; i < radio.length; i++) {
		var fieldname = radio[i].id;
        if (radio[i].checked) {
            return true;
        }
    }
	
    alert("Make a choice for " + fieldname + ".");
    return false;
}

function focusElement(formName, elemName) {
    var elem = document.forms[formName].elements[elemName];
    elem.focus();
    elem.select();
}

