//    This function is called when
//    Submit button is pressed
//    Output : true if all input are correct, false otherwise

function checkForm()
{
    // the variables below are assigned to each
    // form input
    var gname, gphone, gemail, gad;
    with(window.document.adsform)
    {
        gname    = name;
        gphone   = phone;
        gemail     = email;
	gad	= ad;
 
    }

    // if name is empty alert the visitor
    if(trim(gname.value) == '')
    {
        alert('No name is provided. Please enter your name.');
        gname.focus();
        return false;
    }
 
    // alert the visitor if message is empty
    else if(trim(gphone.value) == '')
    {
        alert('No phone number is provided. Please enter your number.');
        gphone.focus();
        return false;
    }

   // alert the visitor if message is empty
    else if(trim(gemail.value) == '')
    {
        alert('No e-mail is provided. Please enter your e-mail address.');
        gemail.focus();
        return false;
    }

    else if(trim(gad.value) == '')
    {
        alert('No ad is provided. Please enter your ad.');
        gemail.focus();
        return false;
    }
    else
    {
        // when all input are correct
        // return true so the form will submit
        return true;
    }
}

/*
Strip whitespace from the beginning and end of a string
Input  : a string
Output : the trimmed string
*/
function trim(str)
{
    return str.replace(/^\s+|\s+$/g,'');
}


