////////////////////////////////////////////////////////////////////
//					  Validation Functions						  //
//							ver. 1.1							  //
//						Author: Alex Kvak						  //
////////////////////////////////////////////////////////////////////

//validates that the entry is a float
function aks_checkFloat(field,field_name)
{
    str = aks_getElement(field).value;
    var re = /^[-]?\d*\.?\d*$/;
    str = str.toString();
    if (!str.match(re)) 
	{
		if (field.indexOf('__') != -1)
		{
			field_ = field.substring(0,field.indexOf('__'));
			field_ = field_.toUpperCase();
		}
		else
			field_ = field.toUpperCase();
		
		if ((typeof field_name != "undefined") && (field_name != ""))
			field_ = field_name;
		
		alert(error_in_field+" "+field_+"!");
		aks_getElement(field).focus();
		return false;
	}
	return true;
}

//validates that the entry is a positive or negative number
function aks_checkInteger(field,field_name)
{
    str = aks_getElement(field).value;
    var re = /^[-]?\d*\.?\d*$/;
    str = str.toString( );
    if (!str.match(re)) 
	{
		if (field.indexOf('__') != -1)
		{
			field_ = field.substring(0,field.indexOf('__'));
			field_ = field_.toUpperCase();
		}
		else
			field_ = field.toUpperCase();

		if ((typeof field_name != "undefined") && (field_name != ""))
			field_ = field_name;

        alert(error_in_field+" "+field_+"!");
		aks_getElement(field).focus();
        return false;
    }
	return true;
}

// validates that the entry is formatted as an email address
function aks_is_email(str) {
    var re = /^[\w-]+(\.[\w-]+)*@([\w-]+\.)+[a-zA-Z]{2,7}$/;
    if (!str.match(re)) 
        return false;
    else
        return true;
}

// check for an empty field 
function aks_checkMenu(field)
{
    return (aks_getElement(field).value!='');
}

// validates that the entry is formatted as an URL
function aks_is_url(str)
{
    var re = /^[\w-]+(\/)*(\.){1,4}/i;
    if (!str.match(re)) 
        return false;
    else
        return true;
}

// check for an empty field 
function aks_checkLogin()
{
    return (($('email').value!='') && ($('pwd').value!=''));
}

