/**
 *  This script will validate the inputs, all functions will return either a true
 *  or a false boolean value.
 */



/**
 *  @desc   Method to validate a url
 *  @param  string  url
 *  @return boolean
 */
function isValidUrl(url)
{
    if(url.match(/^(http|ftp)\:\/\/\w+([\.\-]\w+)*\.\w{2,4}(\:\d+)*([\/\.\-\?\&\%\#\=]\w+)*\/?$/i) ||
    url.match(/^mailto\:\w+([\.\-]\w+)*\@\w+([\.\-]\w+)*\.\w{2,4}$/i))
    { return true; } else return false;
}

/**
 *  @desc   Method to check if the extention of a file is in fact an image.
 *  @param  string  fileName
 *  @return boolean
 */
function isValidImage(fileName)
{
    // Lower the case.
    fileName = fileName.toLowerCase();

    // Check if the extention is ok.
    if (!fileName.match(/(\.jpg|\.gif|\.png|\.JPG|\.GIF|\.PNG|\.jpeg|\.JPEG)$/)) return false;
    return true;
}

/**
 *  @desc   Method to check if the given e-mailaddress is valid.
 *  @param  string  emailAddress
 *  @return boolean
 */
function isValidEmail(emailAddress)
{
    if (emailAddress.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1) return true;
    else return false;
}

/**
 *  @desc   Method to check if the given date is valid.
 *  @param  string  $date
 *  @param  string  $notation
 *  @return boolean
 */
function isValidDate(givenDate, notation)
{
    if(notation == 'YYYY-MM-DD')
    {
        trim(givenDate);
        var data = givenDate.split('-');
        return verifyDate(data[2], data[1], data[0]);
    }

    return false;
}

function isNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

   for (i = 0; i < sText.length && IsNumber == true; i++) 
   { 
	   Char = sText.charAt(i); 
       if (ValidChars.indexOf(Char) == -1) 
       {
    	   IsNumber = false;
       }
   }
   
   return IsNumber;
}

function verifyDate(day,month,year)
{
    dteDate=new Date(year,month,day);
    return ((day==dteDate.getDate()) && (month==dteDate.getMonth()) && (year==dteDate.getFullYear()));
}

function trim(value)
{
    return value.replace(/^\s+|\s+$/,'');
}