
// Absolute Form Processor .NET : Form Validation System
// Copyright(c)XIGLA SOFTWARE
// http://www.xigla.com

function cancelsubmit(msg,element){
	alert(msg);
	document.getElementById(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 (xlaAFPexists('Topic')){
    if (xlaAFPget('Topic').value==''){return cancelsubmit('Field \'Topic\' is required','Topic')}

}

if (xlaAFPexists('Name')){
    if (xlaAFPget('Name').value==''){return cancelsubmit('Field \'Name\' is required','Name')}
if (!isAlphabetic(xlaAFPget('Name').value)){return cancelsubmit('Field \'Name\' can only contain alphabetic characters.','Name')}
if (xlaAFPget('Name').value.length>50){return cancelsubmit('Field \'Name\' cannot contain more than 50 characters.','Name')}
if (xlaAFPeget('Name').value.length<3){return cancelsubmit('Field \'Name\' cannot contain less than 3 characters.','Name')}

}

if (xlaAFPexists('Email')){
    if (xlaAFPget('Email').value==''){return cancelsubmit('Field \'Email\' is required','Email')}
if (!isEmail(xlaAFPget('Email').value)){return cancelsubmit('Field \'Email\' does not contain a valid e-mail address.','Email')}

}

if (xlaAFPexists('Company')){
    if (xlaAFPget('Company').value==''){return cancelsubmit('Field \'Company\' is required','Company')}
if (!isAlphanumeric(xlaAFPget('Company').value)){return cancelsubmit('Field \'Company\' can only contain alphanumeric characters.','Company')}
if (xlaAFPget('Company').value.length>50){return cancelsubmit('Field \'Company\' cannot contain more than 50 characters.','Company')}
if (xlaAFPeget('Company').value.length<3){return cancelsubmit('Field \'Company\' cannot contain less than 3 characters.','Company')}

}

if (xlaAFPexists('Comments')){
    if (xlaAFPget('Comments').value==''){return cancelsubmit('Field \'Comments\' is required','Comments')}
if (xlaAFPget('Comments').value.length>1000){return cancelsubmit('Field \'Comments\' cannot contain more than 1000 characters.','Comments')}
if (xlaAFPeget('Comments').value.length<3){return cancelsubmit('Field \'Comments\' cannot contain less than 3 characters.','Comments')}

}


}

function xlaAFPget(what){
	return(document.getElementById(what));
}

function xlaAFPexists(what){
	if (document.getElementById(what))
		return true;
	else 
		return false;

}

