function sendMail(domainSuffix, user, CSSclass, domainPrefix, linkText) {
	F = user; 
	R = domainSuffix;
	L = domainPrefix;
	cls = CSSclass;
	if (cls == "") {
		if (linkText == "") {
			document.write("<a href=\"" + "m" + "a" + "i" + "l" + "t" + "o" + ":" + F + "@" + L + "." + R + "\">" + F + "@" + L + "." + R + "</a>");
		} else {
			document.write("<a href=\"" + "m" + "a" + "i" + "l" + "t" + "o" + ":" + F + "@" + L + "." + R + "\">" + linkText + "</a>");
		}
	} else {
		if (linkText == "") {
			document.write("<a href=\"" + "m" + "a" + "i" + "l" + "t" + "o" + ":" + F + "@" + L + "." + R + "\" class=\"" + cls + "\">" + F + "@" + L + "." + R + "</a>");
		} else {
			document.write("<a href=\"" + "m" + "a" + "i" + "l" + "t" + "o" + ":" + F + "@" + L + "." + R + "\" class=\"" + cls + "\">" + linkText + "</a>");
		}
	}
}

function TextMail(suffix1, user, suffix2, prefix, suffix3) {
	A = suffix2;
	F = user;
	R = suffix1;
	I = suffix3;
	L = prefix;
	return F + "@" + L + "." + R + A + I;
}

function EmailFormField(type, name, suffix, user, prefix) {
	F = user;
	R = suffix;
	L = prefix;
	document.write("<input type=\"" + type + "\" name=\"" + name + "\" value=\"" + F + "@" + L + "." + R + "\">");
}

function EmailSelectOption(display, suffix, user, prefix) {
	F = user;
	R = suffix;
	L = prefix;
	output = "<option value=\"" + F + "@" + L + "." + R + "\">" + display;
	if (document.URL.indexOf('SendFeedback.htm') != -1) {
		output = output + " (" + F + "@" + L + "." + R + ")";
	}
	output = output + "</option>";
	document.write(output);
}

function EnableFeedback() {
	document.getElementById("CCSDFeedback").Submit.disabled = false;
}

function SubmitFeedback() {
	GoToURL = "";

	if (document.URL.indexOf('/CCSDSP/') > 0) {
		NoFeedback = "No incluyó su retroalimentación.\nPor favor incluya algún comentario antes de volver a someter.";
		ValidEmail = "Por favor incluya una dirección de correo electrónico valida o borre su dirección\nde correo electrónico. No se requiere correo electrónico.";
		ReturnTo = "Haga clic aquí para volver a:";
		Return = "Haga clic aquí para regresar.";
		ThankYou = "Gracias por enviarnos su retroalimentación.";
	} else {
		NoFeedback = "You did not enter any feedback.\nPlease enter some feedback before submitting.";
		ValidEmail = "Please enter a valid e-mail address or delete your e-mail address.\nAn e-mail address is not required.";
		ReturnTo = "Click here to return to:";
		Return = "Click here to return.";
		ThankYou = "Thank you for sending us your feedback.";
	}
	
	if (document.getElementById("CCSDFeedback").Feedback.value == "") {
		alert(NoFeedback);
		return false;
	}
	else if (document.getElementById("CCSDFeedback").email.value != "" && !ValidEmailAddress(document.getElementById("CCSDFeedback").email.value)) {
		alert(ValidEmail);
		return false;
	}
	else {
		if (document.URL.indexOf('SendFeedback.htm') == -1) {
			GoToURL = document.URL;
			document.getElementById("CCSDFeedback").return_link_title.value = ReturnTo + " \"" + document.title + "\"";
			document.getElementById("CCSDFeedback").Submitted_From.value = "\"" + document.title + "\"";
			document.getElementById("CCSDFeedback").Submitted_From_URL.value = GoToURL;
		} else {
			if (document.referrer == "") {
				GoToURL = document.getElementById("CCSDFeedback").return_link_url.value;
				document.getElementById("CCSDFeedback").Submitted_From_URL.value = "";
			} else {
				GoToURL = document.referrer;
				document.getElementById("CCSDFeedback").Submitted_From_URL.value = GoToURL;
			}
			document.getElementById("CCSDFeedback").return_link_title.value = Return;
			document.getElementById("CCSDFeedback").Submitted_From.value = "";
		}
		document.getElementById("CCSDFeedback").return_link_url.value = GoToURL;
		document.getElementById("CCSDFeedback").redirect.value = GoToURL;
		alert(ThankYou);
		//document.getElementById("CCSDFeedback").Submit.value = "";
		return true;
	}
}

function ParseGetVars(VariableString) {
	var getVars = new Array();
	var qString = VariableString;
	var pairs = qString.split(/\&/);
	for (var i in pairs) {
		var nameVal = pairs[i].split(/\=/);
		getVars[decode(nameVal[0])] = decode(nameVal[1]);
	}	
	return getVars;
}

function decode(EncodedString) {
	return unescape(String(EncodedString).replace(/\+/g, " "));
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function MM_openBrWindow2(theURL,winName,features) { //v2.0
  var displayWindow = window.open(theURL,winName,features);
  displayWindow.focus;
  return false;
}

function externalLinks() {
	if (!document.getElementsByTagName) return;
	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++) {
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
			anchor.target = "_blank";
	}
}

function FormDisplay(user) {
	document.getElementById("EM").innerHTML = document.getElementById("EM").innerHTML + " (" + TextMail("c", user, "o", "calvarysd", "m") + ")";
	document.getElementById("WS").innerHTML = document.getElementById("WS").innerHTML + " (" + TextMail("c", "webservant", "o", "calvarysd", "m") + ")";
}

function ValidEmailAddress(EmailAddress) {
	var EmailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;

	if (EmailAddress.match(EmailRegEx)) {
		return true;
	}
	
	return false;
}

function SlideshowInit() {
	Shadowbox.init({
		overlayOpacity: 0.7,
		continuous: true,
		handleUnsupported: "remove",
		viewportPadding: -100
	});
}

function SlideshowInitHide() {
	Shadowbox.init({
		overlayOpacity: 0.7,
		continuous: true,
		handleUnsupported: "remove",
		viewportPadding: -100,
		onOpen: onSlidesOpen,
		onClose: onSlidesClose
	});
}

function onSlidesOpen() {
	ElementsToHide = document.getElementsByClass("SlideshowHide");
	for(var i=0; i<ElementsToHide.length; i++) {
		ElementsToHide[i].style.visibility = "hidden";
	}
}

function onSlidesClose() {
	ElementsToUnhide = document.getElementsByClass("SlideshowHide");
	for(var i=0; i<ElementsToUnhide.length; i++) {
		ElementsToUnhide[i].style.visibility = "";
	}
}

document.getElementsByClass = function(SearchClass) {
	var itemsfound = new Array;
	var elements = document.getElementsByTagName("*");
	for(var i=0; i<elements.length; i++){
		if(elements[i].className == SearchClass){
			itemsfound.push(elements[i]);
		}
	}
	return itemsfound;
}

window.onload = externalLinks;
