//::Min/Max Function
function MinMax(id){
	if (document.getElementById('t'+id).style.display == "none"){
		document.getElementById('t'+id).style.display = "";
		document.getElementById('i'+id).src = "images/ICO_Minus.gif";
	}
	else{
		document.getElementById('t'+id).style.display = "none";
		document.getElementById('i'+id).src = "images/ICO_Plus.gif";
	}
}

//::Event Min/Max Function
function EventMinMax(id){
	if (document.getElementById('ta'+id).style.display == "none"){
		document.getElementById('ta'+id).style.display = "";
		document.getElementById('tb'+id).style.display = "";
		document.getElementById('tc'+id).style.display = "";
		document.getElementById('i'+id).src = "images/ICO_Minus.gif";
	}
	else{
		document.getElementById('ta'+id).style.display = "none";
		document.getElementById('tb'+id).style.display = "none";
		document.getElementById('tc'+id).style.display = "none";
		document.getElementById('i'+id).src = "images/ICO_Plus.gif";
	}
}

//::Show/Hide Function
function ShowHide(submenu){
	if (document.getElementById(submenu).style.display == "none"){
		document.getElementById(submenu).style.display = "";
	}
	else{
		document.getElementById(submenu).style.display = "none";
	}
}

//::Search Articles
function SubmitSearch(){
	document.location.href='?q='+document.frm.keyword.value+'&o='+document.frm.order.value;
}

//::Numeric Mask Function
//ex. onKeyDown="javascript:return NumericMask(this,'(###) ###-####');"
function NumericMask(objText,strMask) {
	key = event.keyCode;
	FilterNum = FilterStrip(objText.value,strMask);
	if (key==9)	{
		return true;
	}
	else if (key==8&&FilterNum.length!=0) {
		FilterNum = FilterNum.substring(0,FilterNum.length-1);
	}
	else if (((key>47 && key<58)||(key>95 && key<106)) && FilterNum.length<FilterMax(strMask)) {
		if (key>95 && key<106) {
			key = (key-48);
		}
		FilterNum=FilterNum+String.fromCharCode(key);
	}
	var FilterFinal='';
	for (FilterStep = 0; FilterStep < strMask.length; FilterStep++) {
		if (strMask.charAt(FilterStep)=='#') {
			if (FilterNum.length!=0) {
				FilterFinal = FilterFinal + FilterNum.charAt(0);
				FilterNum = FilterNum.substring(1,FilterNum.length);
			}
			else {
				FilterFinal = FilterFinal + "";
			}
		}
		else if (strMask.charAt(FilterStep)!='#') {
			FilterFinal = FilterFinal + strMask.charAt(FilterStep);
		}
	}
	objText.value = FilterFinal;
	return false;
}
function FilterStrip(FilterTemp,strMask) {
	strMask = ReplaceAll(strMask,'#','');
	for (FilterStep = 0; FilterStep < strMask.length++; FilterStep++) {
		FilterTemp = ReplaceAll(FilterTemp,strMask.substring(FilterStep,FilterStep+1),'');
	}
	return FilterTemp;
}
function FilterMax(strMask) {
	FilterTemp = strMask;
	for (FilterStep = 0; FilterStep < (strMask.length+1); FilterStep++) {
		if (strMask.charAt(FilterStep)!='#') {
			FilterTemp = ReplaceAll(FilterTemp,strMask.charAt(FilterStep),'');
		}
	}
	return FilterTemp.length;
}

//::Replace All Function
function ReplaceAll(strFull,strOld,strNew) {
	var strLength = strFull.length, txtLength = strOld.length;
	if ((strLength == 0) || (txtLength == 0)) return strFull;
	var i = strFull.indexOf(strOld);
	if ((!i) && (strOld != strFull.substring(0,txtLength))) return strFull;
	if (i == -1) return strFull;
	var strReplace = strFull.substring(0,i) + strNew;
	if (i+txtLength < strLength) strReplace += ReplaceAll(strFull.substring(i+txtLength,strLength),strOld,strNew);
	return strReplace;
}

//::Trim String Function
function Trim(str){
	str = str.replace(/\s+/,'');
	str = str.replace(/\s+$/,'');
	return str;
}

//::IsNumeric Function
function IsNumeric(val){
	for (i=0; i<val.length; i++){
		if (isNaN(val.charAt(i))){
			return false;
		}
	}
	return true;
}

//::Valid Number
function ValidNumber(num){
	str = Trim(num);
	if (str != "" && IsNumeric(str) && str.indexOf(" ") < 0){
		return true
	}else{return false}
}

//::Valid Currency
function ValidCurrency(num){
	str = Trim(num);
	str = str.replace("$","");
	str = str.replace(",","");
	str = str.replace(".","");
	if (str != "" && IsNumeric(str)){
		return true
	}else{return false}
}

//::Valid Credit Card Number
function ValidCreditCard(s){
	var i, n, c, r, t;
	r = "";
	for (i = 0; i < s.length; i++) {
		c = parseInt(s.charAt(i), 10);
		if (c >= 0 && c <= 9)
			r = c + r;
	}
	if (r.length <= 12)
		return false;
	t = "";
	for (i = 0; i < r.length; i++) {
		c = parseInt(r.charAt(i), 10);
		if (i % 2 != 0)
			c *= 2;
			t = t + c;
	}
	n = 0;
	for (i = 0; i < t.length; i++) {
		c = parseInt(t.charAt(i), 10);
		n = n + c;
	}
	if (n != 0 && n % 10 == 0)
		return true;
	else
		return false;
}

//::Valid E-Mail
function ValidEmail(str){
	AccPos = str.indexOf('@');
	AccStr = str.substr(0,AccPos);
	AccLen = AccStr.length;
	DomPos = str.lastIndexOf('.');
	DomStr = str.substr(AccPos+1,(DomPos-AccPos)-1);
	DomLen = DomStr.length;
	ExtPos = DomPos + 1;
	ExtLen = str.length - ExtPos;
	ExtStr = str.substr(ExtPos,ExtLen);
	if(	   (AccPos != -1)
		&& (DomPos != -1)
		&& (AccLen >= 2)
		&& (DomLen >= 2)
		&& (ExtLen >= 2)
		&& (ExtLen <= 3)){
		return true;
	}
	else{return false}
}

//::Valid Phone
function ValidPhone(PhoneArea,PhonePre,PhoneSuf){
	if ((Trim(PhoneArea) == "") ||
		(Trim(PhonePre) == "") ||
		(Trim(PhoneSuf) == "") ||
		(PhoneArea.length != 3) ||
		(PhonePre.length != 3) ||
		(PhoneSuf.length != 4)){
		return false;
	}else{
		if (IsNumeric(PhoneArea) &&
			IsNumeric(PhonePre) &&
			IsNumeric(PhoneSuf) &&
			(PhoneArea.length == 3) &&
			(PhonePre.length == 3) &&
			(PhoneSuf.length == 4)){
			return true;
		}
	}
}

//::Valid Telephone
function ValidTelephone(str){
	str = Trim(str);
	str = str.replace("(","");
	str = str.replace(")","");
	str = str.replace(".","");
	str = str.replace(".","");
	str = str.replace("-","");
	str = str.replace("-","");
	str = str.replace(" ","");
	strLen = str.length;
	if((strLen == 10 || strLen == 7) && IsNumeric(str)){
		return true;
	}
	else{
		return false;
	}
}

//::Validate Donations
function ValidateDonations() {
	missinginfo = "";
	var objForm = document.frm;

	if (objForm.title.value == "") {
	missinginfo += "\n     »  Title";
	}
	if (objForm.firstname.value == "") {
	missinginfo += "\n     »  First Name";
	}
	if (objForm.lastname.value == "") {
	missinginfo += "\n     »  Last Name";
	}
	if (objForm.address.value == "") {
	missinginfo += "\n     »  Address";
	}
	if (objForm.city.value == "") {
	missinginfo += "\n     »  City";
	}
	if (objForm.state.value == "") {
	missinginfo += "\n     »  State / Province";
	}
	if (objForm.zip.value == "") {
	missinginfo += "\n     »  Zip / Postal Code";
	}
	if (!ValidEmail(objForm.email.value)) {
	missinginfo += "\n     »  E-Mail";
	}

	if (objForm.creditcard.value == "") {
	missinginfo += "\n     »  Credit Card";
	}
	if (!ValidCreditCard(objForm.cardnumber.value)) {
	missinginfo += "\n     »  Card Number";
	}
	if (!ValidNumber(objForm.cardexpmo.value)) {
	missinginfo += "\n     »  Expiration Month";
	}
	if (!ValidNumber(objForm.cardexpyr.value)) {
	missinginfo += "\n     »  Expiration Year";
	}

	if (!ValidCurrency(objForm.amount.value)) {
	missinginfo += "\n     »  Amount";
	}

	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	alert(missinginfo);
	return false;
	}
	else return true;
}

//::Validate Newsletter
function ValidateNewsletter() {
	missinginfo = "";
	var objForm = document.frm;

	if (objForm.title.value == "") {
	missinginfo += "\n     »  Title";
	}
	if (objForm.firstname.value == "") {
	missinginfo += "\n     »  First Name";
	}
	if (objForm.lastname.value == "") {
	missinginfo += "\n     »  Last Name";
	}
	if (objForm.address.value == "") {
	missinginfo += "\n     »  Address";
	}
	if (objForm.city.value == "") {
	missinginfo += "\n     »  City";
	}
	if (objForm.state.value == "") {
	missinginfo += "\n     »  State / Province";
	}
	if (objForm.zip.value == "") {
	missinginfo += "\n     »  Zip / Postal Code";
	}
	if (!ValidEmail(objForm.email.value)) {
	missinginfo += "\n     »  E-Mail";
	}

	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	alert(missinginfo);
	return false;
	}
	else return true;
}

//::Validate Schedule Event
function ValidateScheduleEvent() {
	missinginfo = "";
	var objForm = document.frm;

	if (objForm.title.value == "") {
	missinginfo += "\n     »  Title";
	}
	if (objForm.firstname.value == "") {
	missinginfo += "\n     »  First Name";
	}
	if (objForm.lastname.value == "") {
	missinginfo += "\n     »  Last Name";
	}
	if (objForm.address.value == "") {
	missinginfo += "\n     »  Address";
	}
	if (objForm.city.value == "") {
	missinginfo += "\n     »  City";
	}
	if (objForm.state.value == "") {
	missinginfo += "\n     »  State / Province";
	}
	if (objForm.zip.value == "") {
	missinginfo += "\n     »  Zip / Postal Code";
	}
	if (!ValidEmail(objForm.email.value)) {
	missinginfo += "\n     »  E-Mail";
	}

	if (missinginfo != "") {
	missinginfo = "The following information was entered incorrectly:\n" +
	missinginfo + "\n\nPlease re-enter the information and try again...";
	alert(missinginfo);
	return false;
	}
	else return true;
}