function isNotEmpty(elem) {
    var str = elem.value;
	var re = /.+/;
    if(!str.match(re)) {
        alert("Please fill in the required field!");
		elem.focus();
        return false;
    } else {
        return true;
    }
}

// Check retype password
function checkrepass(elem1,elem2) {
    if(elem1.value != elem2.value) {
        alert("Password not match! Please retype password!");
		elem2.focus();
        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("Enter only numbers into the field!");
		elem.focus();
        return false;
    }
    return true;
}
function isPositive(elem) {
    if (elem.value<0) {
        alert("Enter only positve numbers into the field!");
		elem.focus();
        return false;
    }
    return true;
}
function isBetween(elem,a,b) {
    if ((elem.value<a) || (elem.value>b)){
		str="This number must be from " + a + " to " + b;
        alert(str);
		elem.focus();
        return false;
    }
    return true;
}
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!");
		elem.focus();
        return false;
    } else {
        return true;
    }
}
   
// validates that the entry is formatted as an email address
function isEmailAddr(elem) {

    var str = elem.value;
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) {
        alert("Verify the email address format!");
		elem.focus();
        return false;
    } else {
        return true;
    }
}

///////////////////////////////////////
function view(act,id){
 var arg= "width =350, height=300,";
 arg+="resizable=no,scrollbars=yes,";
 arg+="status=0,top=0,left=450";
 window.open("popup.php?act="+act+"&id="+id,"a",arg);
 }
function check(){
if (confirm("Are you sure?")) return true;
return false;
}
function navigate(t,choice) {
    var url = t+choice.options[choice.selectedIndex].value;
    if (url) {
        location.href = url;
    }
}
function view_larg(id){
 var arg= "width =450, height=400,";
 arg+="resizable=yes,scrollbars=yes,";
 arg+="status=0,top=0,left=5x50";
 window.open(id,"a",arg);
 }
 
 /*
Strip whitespace from the beginning and end of a string
Input : a string
*/
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,'');
}

/*
Make sure that textBox only contain number
*/
function checkNumber(textBox)
{
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	textBox.value = trim(textBox.value);
/*	if (textBox.value.length == 0) {
		textBox.value = 0;		
	} else {
		textBox.value = parseInt(textBox.value);
	}*/
}

/*
	Check if a form element is empty.
	If it is display an alert box and focus
	on the element
*/
function isEmpty(formElement, message) {
	formElement.value = trim(formElement.value);
	
	_isEmpty = false;
	if (formElement.value == '') {
		_isEmpty = true;
		alert(message);
		formElement.focus();
	}
	
	return _isEmpty;
}

/*
	Set one value in combo box as the selected value
*/
function setSelect(listElement, listValue)
{
	for (i=0; i < listElement.options.length; i++) {
		if (listElement.options[i].value == listValue)	{
			listElement.selectedIndex = i;
		}
	}	
}