// Configures a href links to open in new window via rel=external
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")) {
     		if (anchor.getAttribute("rel").match("external") == "external") {
				anchor.onclick = function() {
					newWindow(this.getAttribute("href"));
					return false;
				}
			} else if(anchor.getAttribute("rel").match("livehelp") == "livehelp") {
				anchor.onclick = function() {
					livehelp(this.getAttribute("href"));
					return false;
				}
			} else if(anchor.getAttribute("rel").match("popup") == "popup") {
				anchor.onclick = function() {
					popupWindow(this.getAttribute("href"),this.getAttribute("rel"));
					return false;
				}
			}
		}
 	}
	
	var forms = document.getElementsByTagName("form");
	for (var i=0; i<forms.length; i++) {  
   		var form = forms[i];
		if(form.getAttribute("rel")){
			if(form.getAttribute("rel").match("external") == "external") {
				form.target = "_blank";	
			}
		}
	}
}  

addLoadEvent(externalLinks);


// JS to open resized pop up for live chat.
function livehelp(liveChatURL) {
	window.open(liveChatURL,'32RedLiveChat', config='height=425,width=450, toolbar=no, menubar=no, scrollbars=no,location=no, directories=no, status=yes, resizable=1');
	return false;
}

function newWindow(href) {
	window.open(href,'_blank');
	return false;
}


// JS to handle resized pop ups
// needs work done on it
function popupWindow(href,rel) {
	var dimensions = rel.split(" ")[1];
	var popupWidth = dimensions.split("x")[0];
	var popupHeight = dimensions.split("x")[1];
	window.open(href,'_blank', config='height='+popupHeight+',width='+popupWidth+', toolbar=no, menubar=no, scrollbars=yes,location=no, directories=no, status=yes, resizable=1');
	return false;
}


