//#########################################################################################
//# Copyright (C) 2006 StopDog, Inc. All Rights Reserved.
//# Author        : Scott Wilfong (swilfong@exodusweb.com)
//# Inception     : January 14, 2008
//# Contributers  : ???
//#////////////////////////////////////////////////////////////////////////////////////////
//# Change Log
//#    2006-10-02 > by Scott Wilfong
//#               >  
//#########################################################################################

	var names = new Array();
	var texts = new Array();

	function makeCaptcha(name, width, height){
		var its_random = new Date().getTime();
		var text = "";
		
		//make six character captcha string
		for(i=0; i<6; i++){
			var random = Math.floor(Math.random()*26);
			text += String.fromCharCode(random + 64);
		}
		
		//check for name and put text in correct spot
		var found = false;
		for(var i=0; i<names.length; i++){
			if(names[i] == name){
				texts[i] = text;
				found = true;
				break;
			}
		}
		if(!found){
			texts[names.length] = text;
			names[names.length] = name;
		}
		
		//replace image source to display captcha
		document.$(name).setAttribute('src', "/captcha.aspx?random=" + its_random + "&text=" + text + "&width=" + width + "&height=" + height);
	}

	//validate the captcha entry
	function validate(form){
		//get name of captcha from form
		var name = form.captcha_name.value;
		
		//get value in image for this form
		var text = "";
		for(var i=0; i<names.length; i++){
			if(names[i] == name){
				text = texts[i];
				break;
			}
		}
		
		//is the captcha entry field empty?
		if(form.captcha.value == ""){
			alert("You must enter the validation code.");
			return false;
		}
		
		//does the value entered match the value in the image?
		if(form.captcha.value.toLowerCase() != text.toLowerCase()){ //form.captcha_text.value.toLowerCase()){
			alert("Validation Codes Do Not Match.");
			return false;
		}
		
		return true;
	}
