
// 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('Contact_Name')){
    if (xlaAFPget('Contact_Name').value==''){return cancelsubmit('Field \'Contact Name\' is required','Contact_Name')}
if (!isAlphabetic(xlaAFPget('Contact_Name').value)){return cancelsubmit('Field \'Contact Name\' can only contain alphabetic characters.','Contact_Name')}
if (xlaAFPget('Contact_Name').value.length>50){return cancelsubmit('Field \'Contact Name\' cannot contain more than 50 characters.','Contact_Name')}
if (xlaAFPeget('Contact_Name').value.length<4){return cancelsubmit('Field \'Contact Name\' cannot contain less than 4 characters.','Contact_Name')}

}

if (xlaAFPexists('Contact_Company')){
    if (xlaAFPget('Contact_Company').value==''){return cancelsubmit('Field \'Contact Company\' is required','Contact_Company')}
if (!isAlphanumeric(xlaAFPget('Contact_Company').value)){return cancelsubmit('Field \'Contact Company\' can only contain alphanumeric characters.','Contact_Company')}
if (xlaAFPget('Contact_Company').value.length>60){return cancelsubmit('Field \'Contact Company\' cannot contain more than 60 characters.','Contact_Company')}
if (xlaAFPeget('Contact_Company').value.length<2){return cancelsubmit('Field \'Contact Company\' cannot contain less than 2 characters.','Contact_Company')}

}

if (xlaAFPexists('Contact_Email')){
    if (xlaAFPget('Contact_Email').value==''){return cancelsubmit('Field \'Contact Email\' is required','Contact_Email')}
if (!isEmail(xlaAFPget('Contact_Email').value)){return cancelsubmit('Field \'Contact Email\' does not contain a valid e-mail address.','Contact_Email')}
if (xlaAFPget('Contact_Email').value.length>60){return cancelsubmit('Field \'Contact Email\' cannot contain more than 60 characters.','Contact_Email')}
if (xlaAFPeget('Contact_Email').value.length<5){return cancelsubmit('Field \'Contact Email\' cannot contain less than 5 characters.','Contact_Email')}
if (!noSpaces(xlaAFPget('Contact_Email').value)){return cancelsubmit('Field \'Contact Email\' cannot contain spaces.','Contact_Email')}

}

if (xlaAFPexists('country')){
    if (xlaAFPget('country').value==''){return cancelsubmit('Field \'country\' is required','country')}
if (!isAlphanumeric(xlaAFPget('country').value)){return cancelsubmit('Field \'country\' can only contain alphanumeric characters.','country')}
if (xlaAFPget('country').value.length>60){return cancelsubmit('Field \'country\' cannot contain more than 60 characters.','country')}
if (xlaAFPeget('country').value.length<3){return cancelsubmit('Field \'country\' cannot contain less than 3 characters.','country')}

}


}

function xlaAFPget(what){
	return(document.getElementById(what));
}

function xlaAFPexists(what){
	if (document.getElementById(what))
		return true;
	else 
		return false;

}


