var $j = jQuery.noConflict();
var sitePath = (document.domain == "localhost") ? '/paperround' : '';

$j(document).ready(function(){
    $j('.bt-next').click(function(){
        if(checkFields1()){
            $j('.bt-next').hide();
            $j('.next-step').show();
            $j('.submit-button').show();
        }
    });
    $j('#enquire_form').submit(function(){
        if(checkallFields()){
            
        
        $j.ajax({
            type: "GET",
            cache : true,
            data: $j("#enquire_form").serialize(),
            async: false,
            url: sitePath+"/includes/ajax-form.asp",
            success: function(data)
            {
                if (data)
                {

                    $j('#error-msg').html(data);
                    $j('#error-msg').fadeIn('slow');


                }
                else
                {

                    document.location.href = sitePath+'/thank-you-enquire.shtml';
                }
            }
        });
        }
        return false;
    });
    
});
function checkFields1(){
    if ($j('#name') && trimAll($j('#name').val()) == ''){
        alert('Name is missing');
        $j('#name').focus();
        return false;
    }
    if ($j('#email') && $j('#email').val().indexOf('@')==-1){
       alert('Invalid email address');
       $j('email').focus();
       return false;
    }
    if ($j('#phone') && trimAll($j('#phone').val())==''){
        alert('Phone number is missing');
        $j('#phone').focus();
        return false;
    }

    if ($j('#company') && trimAll($j('#company').val())==''){
        alert('Company name is missing');
        $j('#company').focus();
        return false;
    }
    if ($j('#postcode') && trimAll($j('#postcode').val())==''){
        alert('Postcode is missing');
        $j('#postcode').focus();
        return false;
    }
return true;

}
function checkallFields(){
    if ($j('#name') && trimAll($j('#name').val())==''){
        alert('Name is missing');
        $j('#name').focus();
        return false;
    }
    if ($j('#email') && $j('#email').val().indexOf('@')==-1){
       alert('Invalid email address');
       $j('email').focus();
       return false;
    }

    if ($j('#company') && trimAll($j('#company').val())==''){
        alert('Company name is missing');
        $j('#company').focus();
        return false;
    }
    if ($j('#postcode') && trimAll($j('#postcode').val())==''){
        alert('Postcode is missing');
        $j('#postcode').focus();
        return false;
    }
    if ($j('#employees') && $j('#employees').val()==''){
        alert('No. of Employees is missing');
        $j('#employees').focus();
        return false;
    }
    if ($j('#area') && trimAll($j('#area').val())==''){
        alert('Area of Interest is missing');
        $j('#area').focus();
        return false;
    }
    return true;

}
function trimAll(sString)
{
    while (sString.substring(0,1) == ' ')
    {
       sString = sString.substring(1, sString.length);
    }
    while (sString.substring(sString.length-1, sString.length) == ' ')
    {
       sString = sString.substring(0,sString.length-1);
    }
    return sString;
}

