function validate_callback(formid)
{
    var theform = document.getElementById(formid);
    var errors = 0;
    var blankemail = theform.email.value;
    if(theform.email)
        {
            if (blankemail.length == 0)
                {
                    //do not valdiate
                } else {
                if (vemail(theform.email.value, formid) === false)
                    {
                        errors++;
                    }
                }
        }

    if(theform.name)
        {
            if (stringnotempty(theform.name.value, formid) === false)
                {
                    errors++;
                }
        }

    if(theform.company)
        {
            if (compnotempty(theform.company.value, formid) === false)
                {
                    errors++;
                }
        }

    if(theform.tel)
        {
            if (checkNum(theform.tel.value, formid) === false)
                {
                    errors++;
                }
        }

    if(errors == 0){
        theform.submit();
    } else {

    }
}

function validate(formid)
{
    var theform = document.getElementById(formid);
    var errors = 0;
    if(theform.email)
        {
            if (vemail(theform.email.value, formid) === false)
                {
                    errors++;
                }
        }

    if(theform.name)
        {
            if (stringnotempty(theform.name.value, formid) === false)
                {
                    errors++;
                }
        }

    if(theform.company)
        {
            if (compnotempty(theform.company.value, formid) === false)
                {
                    errors++;
                }
        }

    if(theform.tel)
        {
            if (checkNum(theform.tel.value, formid) === false)
                {
                    errors++;
                }
        }

    if(errors == 0){
        theform.submit();
    } else {

    }
}

function vemail(emailv, formid)
{
    var theform = document.getElementById(formid);
    if(checkMail(emailv))
        {
            theform.email.style.border = '1px solid red';
            theform.email.style.background = 'url(images/cross.png) no-repeat right #FFF'
            return false;
        } else {
            theform.email.style.border = '1px solid green';
            theform.email.style.background = 'url(images/tick.png) no-repeat right #FFF';
            return true;
        }
}
function vemailba(emailv, formid)
{
    var theform = document.getElementById(formid);
    if (emailv.length == 0)
        {
            theform.email.style.border = '1px solid green';
            theform.email.style.background = 'url(images/tick.png) no-repeat right #FFF';
            return true;
        } else {
    if(checkMail(emailv))
        {
            theform.email.style.border = '1px solid red';
            theform.email.style.background = 'url(images/cross.png) no-repeat right #FFF'
            return false;
        } else {
            theform.email.style.border = '1px solid green';
            theform.email.style.background = 'url(images/tick.png) no-repeat right #FFF';
            return true;
        }
       }
}
function stringnotempty(stringv, formid)
{
    var theform = document.getElementById(formid);
    if (!notempty(stringv))
        {
            theform.name.style.border = '1px solid red';
            theform.name.style.background = 'url(images/cross.png) no-repeat right #FFF';
            return false;
        } else {
            theform.name.style.border = '1px solid green';
            theform.name.style.background = 'url(images/tick.png) no-repeat right #FFF';
            return true;
        }
}

function compnotempty(stringv, formid)
{
    var theform = document.getElementById(formid);
    if (!notempty(stringv))
        {
            theform.company.style.border = '1px solid red';
            theform.company.style.background = 'url(images/cross.png) no-repeat right #FFF';
            return false;
        } else {
            theform.company.style.border = '1px solid green';
            theform.company.style.background = 'url(images/tick.png) no-repeat right #FFF';
            return true;
        }
}

function checkNum(number, formid)
{
    var theform = document.getElementById(formid);
    if (number.length >=7 && IsNumeric(number))
        {
            theform.tel.style.border = '1px solid green';
            theform.tel.style.background = 'url(images/tick.png) no-repeat right #FFF';
            return true;
        } else {
            theform.tel.style.border = '1px solid red';
            theform.tel.style.background = 'url(images/cross.png) no-repeat right #FFF';
            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 checkMail(value)
{
    var x = value;
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (filter.test(x))
        {
            return false;
        } else {
            return true;
        }
}

function notempty(val)
{
    if (val == '')
        {
            return false;
        } else {
            return true;
        }
}