
// Absolute Form Processor XE V1.0 : Form Validation System
// Copyright(c)2000 - 2003 XIGLA SOFTWARE
// http://www.xigla.com

function cancelsubmit(msg,element){
	alert(msg);
	element.focus();
	return false
}



function isNumeric(what){
    if (what.search(/^[-+]?\d+(\.\d+)?$/) != -1)
        return true;
    else
        return false;
}

function isInteger(what){
	if (what.search(/^[-+]?[1-9]\d*.?[0]*$/) != -1)
        return true;
    else
        return false;
}


function isEmail(what) {
	// Works
    if (what.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}

function isAlphanumeric(what){
	// ANY alphanumeric string with spaces, commas, dashes.
    if (what.search(/^[a-zA-Z0-9\s.\-]+$/) != -1)
        return true;
    else
        return false;
}

function isAlphabetic(what){
    if (what.search(/^[a-zA-Z\s]+$/) != -1)
        return true;
    else
        return false;
}

function noSpaces(what){
    if (what.search(/\s/) != -1)
        return false;
    else
        return true;
}

function isCC(what){
    if (what.search(/^((4\d{3})|(5[1-5]\d{2})|(6011))-?\d{4}-?\d{4}-?\d{4}|3[4,7]\d{13}$/) != -1)
        return true;
    else
        return false;
}


function xlaAFPvalidate(xlaAFPform){
if (xlaAFPform.companyname){if (xlaAFPform.companyname.value==''){return cancelsubmit('Field \'companyname\' is required',xlaAFPform.companyname)}if (!isAlphanumeric(xlaAFPform.companyname.value)){return cancelsubmit('Field \'companyname\' can only contain alphanumeric characters.',xlaAFPform.companyname)}if (xlaAFPform.companyname.value.length>40){return cancelsubmit('Field \'companyname\' cannot contain more than 40 characters.',xlaAFPform.companyname)}if (xlaAFPform.companyname.value.length<1){return cancelsubmit('Field \'companyname\' cannot contain less than 1 characters.',xlaAFPform.companyname)}}
if (xlaAFPform.phone1){if (xlaAFPform.phone1.value==''){return cancelsubmit('Field \'phone1\' is required',xlaAFPform.phone1)}if (!isAlphanumeric(xlaAFPform.phone1.value)){return cancelsubmit('Field \'phone1\' can only contain alphanumeric characters.',xlaAFPform.phone1)}if (xlaAFPform.phone1.value.length>20){return cancelsubmit('Field \'phone1\' cannot contain more than 20 characters.',xlaAFPform.phone1)}if (xlaAFPform.phone1.value.length<10){return cancelsubmit('Field \'phone1\' cannot contain less than 10 characters.',xlaAFPform.phone1)}}
if (xlaAFPform.contactname){if (xlaAFPform.contactname.value==''){return cancelsubmit('Field \'contactname\' is required',xlaAFPform.contactname)}if (!isAlphabetic(xlaAFPform.contactname.value)){return cancelsubmit('Field \'contactname\' can only contain alphabetic characters.',xlaAFPform.contactname)}if (xlaAFPform.contactname.value.length>45){return cancelsubmit('Field \'contactname\' cannot contain more than 45 characters.',xlaAFPform.contactname)}if (xlaAFPform.contactname.value.length<3){return cancelsubmit('Field \'contactname\' cannot contain less than 3 characters.',xlaAFPform.contactname)}}
if (xlaAFPform.contacttitle){if (xlaAFPform.contacttitle.value==''){return cancelsubmit('Field \'contacttitle\' is required',xlaAFPform.contacttitle)}if (!isAlphanumeric(xlaAFPform.contacttitle.value)){return cancelsubmit('Field \'contacttitle\' can only contain alphanumeric characters.',xlaAFPform.contacttitle)}if (xlaAFPform.contacttitle.value.length>40){return cancelsubmit('Field \'contacttitle\' cannot contain more than 40 characters.',xlaAFPform.contacttitle)}if (xlaAFPform.contacttitle.value.length<3){return cancelsubmit('Field \'contacttitle\' cannot contain less than 3 characters.',xlaAFPform.contacttitle)}}
if (xlaAFPform.email){if (xlaAFPform.email.value==''){return cancelsubmit('Field \'email\' is required',xlaAFPform.email)}if (!isEmail(xlaAFPform.email.value)){return cancelsubmit('Field \'email\' does not contain a valid e-mail address.',xlaAFPform.email)}if (!noSpaces(xlaAFPform.email.value)){return cancelsubmit('Field \'email\' cannot contain spaces.',xlaAFPform.email)}}
if (xlaAFPform.maincategory){if (xlaAFPform.maincategory.value==''){return cancelsubmit('Field \'maincategory\' is required',xlaAFPform.maincategory)}if (!isAlphabetic(xlaAFPform.maincategory.value)){return cancelsubmit('Field \'maincategory\' can only contain alphabetic characters.',xlaAFPform.maincategory)}}

}

