
// 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('cFirst_Name')){
    if (xlaAFPget('cFirst_Name').value==''){return cancelsubmit('Field \'cFirst Name\' is required','cFirst_Name')}
if (!isAlphabetic(xlaAFPget('cFirst_Name').value)){return cancelsubmit('Field \'cFirst Name\' can only contain alphabetic characters.','cFirst_Name')}

}

if (xlaAFPexists('cLast_Name')){
    if (xlaAFPget('cLast_Name').value==''){return cancelsubmit('Field \'cLast Name\' is required','cLast_Name')}
if (!isAlphabetic(xlaAFPget('cLast_Name').value)){return cancelsubmit('Field \'cLast Name\' can only contain alphabetic characters.','cLast_Name')}
if (!isAlphanumeric(xlaAFPget('cLast_Name').value)){return cancelsubmit('Field \'cLast Name\' can only contain alphanumeric characters.','cLast_Name')}

}

if (xlaAFPexists('cTelephone')){
    if (xlaAFPget('cTelephone').value==''){return cancelsubmit('Field \'cTelephone\' is required','cTelephone')}
if (xlaAFPeget('cTelephone').value.length<12){return cancelsubmit('Field \'cTelephone\' cannot contain less than 12 characters.','cTelephone')}

}

if (xlaAFPexists('cattached_file')){
    if (xlaAFPget('cattached_file').value==''){return cancelsubmit('Field \'cattached file\' is required','cattached_file')}

}

if (xlaAFPexists('cQuantity')){
    if (xlaAFPget('cQuantity').value==''){return cancelsubmit('Field \'cQuantity\' is required','cQuantity')}
if (!isNumeric(xlaAFPget('cQuantity').value)){return cancelsubmit('Field \'cQuantity\' is not numeric','cQuantity')}
if (!isInteger(xlaAFPget('cQuantity').value)){return cancelsubmit('Field \'cQuantity\' is not integer','cQuantity')}
if (!isNumeric(xlaAFPget('cQuantity').value)){return cancelsubmit('Field \'cQuantity\' is not numeric','cQuantity')} else {if (xlaAFPget('cQuantity').value<=49){return cancelsubmit('Field \'cQuantity\' should be greater than 49','cQuantity')}}
if (!noSpaces(xlaAFPget('cQuantity').value)){return cancelsubmit('Field \'cQuantity\' cannot contain spaces.','cQuantity')}

}


}

function xlaAFPget(what){
	return(document.getElementById(what));
}

function xlaAFPexists(what){
	if (document.getElementById(what))
		return true;
	else 
		return false;

}

