var imageArray = [
	['image1.bmp', 'GRTC'],
	['image2.bmp', '8F2H'],
	['image3.bmp', 'N9RZ'],
	['image4.bmp', 'SCA2'],
	['image5.bmp', 'UCQ4'],
	['image6.bmp', 'ZQEK'],
	['image7.bmp', 'VJ8W'],
	['image8.bmp', '73PS'],
	['image9.bmp', '9MTV'],
	['image10.bmp', 'YFF3'],
	['image11.bmp', 'M8KH'],
	['image12.bmp', 'RYCA'],
	['image13.bmp', 'T49K'],
	['image14.bmp', 'Q7XQ'],
	['image15.bmp', 'QZTB'],
	['image16.bmp', 'YZL7'],
	['image17.bmp', 'MRAV'],
	['image18.bmp', 'QZPU'],
	['image19.bmp', 'AJ7K'],
	['image20.bmp', '7CC4']
]

var IMAGEDIR = "images/CAPTCHA/";

function isValidEmail(email) {
    reg = /^([A-Za-z0-9])+([_.\-\\&][A-Za-z0-9]+)*\@([A-Za-z0-9])+([_.-][A-Za-z0-9]+)*\.([A-Za-z]{2,4})$/;
    if(reg.test(email) == false)
	return false;
    else
	return true;
}

function checkcode(f) {
    var i = f.sdx.value;
    if(f.code.value == imageArray[i][1])
	return true;
    else
	return false;
}

function validate(f) {
    if(f.email.value == "") {
        alert("Please enter your Email Address");
        return false;
    }
    else
    if(!isValidEmail(f.email.value)) {
        alert("You have entered an invalid email address");
        return false;
    }
    else
    if(!checkcode(f)) {
        alert("You entered an invalid security code.\nForm not submitted.");
        return false;
    }
    else
        return true;
}

/***********************************************************************
*                                                                      *
* The purpose of the following Javascript function is to block email   *
* spam by building an email address with a mailto link and subject.    *
* To use this function, you make a Javascript call from the location   *
* within the HTML body where you want to insert the email link. You    *
* must supply the following 3 arguments:                               *
*                                                                      *
* end: (required) This is the domain of the email address after the    *
*      '@' excluding the trailing '.' plus extension such as .com or   *
*      .net. IMPORTANT: You must append an index number to this domain *
*      to indicate an extension as follows:                            *
*                                                                      *
*      0 = .com                                                        *
*      1 = .net                                                        *
*      2 = .org                                                        *
*      3 = .gov                                                        *
*      4 = .biz                                                        *
*                                                                      *
*      For example, 'nexteon0' for this parameter will translate to    *
*      nexteon.com; 'nexteon1' translates to nexteon.net.              *
*                                                                      *
* front:  (required) This is the part of the email address before      *
*         the '@' character.                                           *
*                                                                      *
* subj:  (optional) This is the subject of the mailto email address.   *
*        If omitted, the subject is set to spaces.                     *
*                                                                      *
* NOTE:  To write the email link into the body of your HTML, you must  *
* make a call to the Javascript document.write function as in the      *
* following example:                                                   *
*                                                                      *
* <script>                                                             *
* document.write(buildem('nexteon0', 'somename', 'Hello'));            *
* </script>                                                            *
*                                                                      *
* Written by Steve Carey at Next Eon on 1/9/2009                       *
*                                                                      *
************************************************************************/
function buildem(end, front, subj) {
    var domArray = [
	[0, 'com'],
	[1, 'net'],
	[2, 'org'],
	[3, 'gov'],
	[4, 'biz']
    ]
    var s = (typeof subj == "undefined") ? '' : subj;
    var em = front + '@' + end.substring(0, end.length - 1) + '.' + domArray[end.slice(-1)][1];
    return "<a href='mailto:" + em + "?subject=" + s + "'>" + em + "</a>";
}

