function disableBox(id) {
	document.getElementById(id).disabled = true;
}

function echeck(str) {
	var at="@"; var dot="."; var lat=str.indexOf(at); var lstr=str.length; var ldot=str.indexOf(dot);
	if (str.indexOf(at)==-1) return false;
	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr) return false;
	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr) return false;
	if (str.indexOf(at,(lat+1))!=-1) return false;
	if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot) return false;
	if (str.indexOf(dot,(lat+2))==-1) return false;
	if (str.indexOf(" ")!=-1) return false;
	return true;				
}

function textareaLen(field,maxlimit) {
	if (field.value.length > maxlimit) {
		field.value = field.value.substring(0, maxlimit);
		alert('You may enter up to ' + maxlimit + ' characters.');
	}
}

function textareaWords(field,maxlimit) {
	var testStr = ' .,?!<>{}[];:=+_()!&"';
	var words = 0;
	var loopDie = 0;
	var str;
	var punctuate = false;
	if (field.value.length > 0) {
		for(i=0; i < field.value.length+1; i++){
			str = field.value.substr(i,1);
			if (testStr.indexOf(str) != -1) {
				punctuate = true;
			} else {
				if (punctuate) {words++;}
				punctuate = false;
			}
			if (words > maxlimit) {
				loopDie = i;
				break;
			}
		}
		if (words > maxlimit) {
			field.value = field.value.substring(0, loopDie);
			alert("Your description contains more than " + (words-1) + " words.\n\nYou must shorten your description before proceeding.");
		}
	}
}

//checking credit card

function CheckNum(cardnum) {
	if (isNaN(cardnum)) 	{return 1;}
	if (CheckLUHN(cardnum))	{return 0;}
	else					{return 1;}
}
function Reverse(strToReverse) {
	var strRev = new String;
	var i = strToReverse.length;
	while (i--) {
		strRev += strToReverse.charAt(i);
	}
	return strRev;
}
function CheckLUHN(cardnum) {
	var RevNum = new String(cardnum);
	RevNum = Reverse(RevNum);
	var total = new Number(0);
	for ( var i = 0; i < RevNum.length; i += 1 ) {
		var temp = 0;
		if (i % 2) {
			temp = RevNum.substr(i, 1) * 2;
			if (temp >= 10) {
				var splitstring = new String(temp);
				temp = parseInt(splitstring.substr(0, 1)) + parseInt(splitstring.substr(1, 1));
			}
		} else {
			temp = RevNum.substr(i, 1);
			total += parseInt(temp); 
		}
	}
	// if there's no remainder, we return 1 (true)
	return (total % 10) ? 0 : 1;
}

function maxChoices(obj,id,max_choices) {
	var total_choices = 0;
	if (document.all[id].length) {
		for (counter = 0; counter < document.all[id].length; counter++) {
			if (document.all[id][counter].checked) {total_choices++};
		}
	}
	if (total_choices > max_choices) {
		obj.checked = false;
		alert("You are allowed up to " + max_choices + " selections");
	}
}
choices = {};
function maxChoicesCount(obj,id,max_choices) {
	if (!choices[id]) {choices[id] = 0;}
	if (obj.checked) {
		choices[id] += 1;
	} else {
		choices[id] -= 1;
	}
	if (choices[id] > max_choices) {
		obj.checked = false;
		alert("You are allowed up to " + max_choices + " selections");
		choices[id] -= 1;
	}
}

function radioValue(field) {
	var field_value = "";
	if (field.length == undefined) {
		if (field.checked) {
			field_value = field.value;
		}
	} else {
		for (counter = 0; counter < field.length; counter++) {
			if (field[counter].checked) {
				field_value = field[counter].value;
			}
		}
	}
	return field_value;
}

