/**** REL = EXTERNAL ***/
addLoadEvent(function() { 
	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"; 
		}
	} 
})
/**** NAV MENU DROPDOWNS ***/
addLoadEvent(function() {
	var navLIs = document.getElementById("navWrap").getElementsByTagName("LI");
	for (var i=0; i<navLIs.length; i++) {
		navLIs[i].onmouseover = function() {
			this.className += " active";
		}
		navLIs[i].onmouseout = function() {
			this.className = this.className.replace(/active/g,"");
		}
	}
})
/**** BILLING CYCLE DROPDOWN FUNCTIONS ***/
addLoadEvent(function() {
	if (document.getElementById('billingCycle')) {
		document.getElementById('billingCycle').onchange = function() {
			billingCycleOnChange(this);
		}
		billingCycleOnChange(document.getElementById('billingCycle'));
	}
})

function billingCycleOnChange(obj) {
	var value;
	var planName = document.getElementById('planName').value;
	if (obj.value == "1" && planName == "Advisor Lite") {
		value = "$" + document.getElementById('liteMonthly').value + " monthly";
	} else if (obj.value == "12" && planName == "Advisor Lite") {
		value = "$" + document.getElementById('liteAnnually').value + " annually";
	} if (obj.value == "1" && planName == "Advisor Pro") {
		value = "$" + document.getElementById('proMonthly').value + " monthly / " + "$" + document.getElementById('proMonthlySetup').value + " setup fee";
	} else if (obj.value == "12" && planName == "Advisor Pro") {
		value = "$" + document.getElementById('proAnnually').value + " annually / " + "$" + document.getElementById('proAnnuallySetup').value + " setup fee";
	}
	obj.parentNode.getElementsByTagName('span')[0].innerHTML = value;
}

/**** LOGIN FORM LABELS ***/
addLoadEvent(function() {
	if (document.getElementById("loginWrap")) {
		var loginLabels = document.getElementById("loginWrap").getElementsByTagName('label');
		for (var i=0; i<loginLabels.length; i++) {
			var input = loginLabels[i].nextSibling.nextSibling;
			input.value = loginLabels[i].innerHTML;
			input.onfocus = function() {
				if (this.value == this.previousSibling.previousSibling.innerHTML) {
					this.value = "";
				}
			}
			input.onblur = function() {
				if (this.value == "") {
					this.value = this.previousSibling.previousSibling.innerHTML;
				}
			}
		}
	}
})
/**** FORM FIELD ACTIONS ***/
var tempFieldValue = "";
addLoadEvent(function() {
	document.getElementsByTagName("body")[0].focus();
	var form; //FORM OBJECT
	if (document.getElementsByTagName("form")[0]) {
		if (document.getElementsByTagName("form")[0].id == "loginForm") {
			form = document.getElementsByTagName("form")[1];
		} else {
			form = document.getElementsByTagName("form")[0];
		}
		form.onsubmit  = function() {
			return checkform(this);
		}
		var formDIVs = form.getElementsByTagName("div");
		for (var i=0; i<formDIVs.length; i++) {
			if (formDIVs[i].className.match("field") != null && formDIVs[i].className.match("change") == null) {
				if (formDIVs[i].getElementsByTagName("input")[0]) {
					var formObj = formDIVs[i].getElementsByTagName("input");
				} else if (formDIVs[i].getElementsByTagName("select")[0]) {
					var formObj = formDIVs[i].getElementsByTagName("select");
				} else if (formDIVs[i].getElementsByTagName("textarea")[0]) {
					var formObj = formDIVs[i].getElementsByTagName("textarea");
				}
				for (var f=0; f<formObj.length; f++) {
					formObj[f].onfocus = function() {
						this.parentNode.parentNode.className += " active";
						if (this.parentNode.parentNode.parentNode.className.match("edit") != null) {
							if (this.type == "checkbox") {
								tempFieldValue = this.checked;
							} else {
								tempFieldValue = this.value;
							}
						}
					}
					formObj[f].onblur = function() { 
						if (this.parentNode.parentNode.className.match("active") != null) {
							this.parentNode.parentNode.className = this.parentNode.parentNode.className.replace("active","");
							if (this.parentNode.className == "required") {
								checkField(this.parentNode.parentNode.parentNode.parentNode,this);
							}
							if (this.parentNode.parentNode.parentNode.className.match("edit") != null) {
								if (this.type == "checkbox") {
									if (this.checked != tempFieldValue && this.parentNode.parentNode.className.match("alert") == null) {
										var spans = this.parentNode.parentNode.getElementsByTagName('label')[0].getElementsByTagName('span');
										for (var s=0; s<spans.length; s++) {
											if (spans[s].className == "edit") {
												spans[s].parentNode.parentNode.className += " changed";
												spans[s].getElementsByTagName('span')[0].innerHTML = "changed";
											}
										}
									}
								} else {
									if (this.value != tempFieldValue && this.parentNode.parentNode.className.match("alert") == null) {
										var spans = this.parentNode.parentNode.getElementsByTagName('label')[0].getElementsByTagName('span');
										for (var s=0; s<spans.length; s++) {
											if (spans[s].className == "edit") {
												spans[s].parentNode.parentNode.className += " changed";
												spans[s].getElementsByTagName('span')[0].innerHTML = "changed";
											}
										}
									}
								}

							}
						}
					}
				}
			} else if (formDIVs[i].className.match("change") != null) {
				formDIVs[i].getElementsByTagName("label")[0].onmousedown = function() {
					var fields = this.getElementsByTagName("a")[0].rel.split(',');
					for (var f=0; f<fields.length; f++) {
						if (this.parentNode.className.match("cancel") == null) {
							document.getElementById(fields[f]).parentNode.parentNode.className = document.getElementById(fields[f]).parentNode.parentNode.className.replace("hidden","");
							if (document.getElementById(fields[f]).parentNode.className == "required") {
								document.getElementById('required').value = document.getElementById('required').value + "," + fields[f];
							}
						} else {
							document.getElementById(fields[f]).parentNode.parentNode.className += " hidden";
							if (document.getElementById(fields[f]).parentNode.className == "required") {
								document.getElementById('required').value = document.getElementById('required').value.replace("," + fields[f],"");
							}
						}
					}
				}
				formDIVs[i].getElementsByTagName("label")[0].onmouseup = function() { 
					if (this.parentNode.className.match("cancel") == null) {
						this.parentNode.className += " cancel";
						this.getElementsByTagName('span')[1].innerHTML = "Cancel Password Change";
					} else {
						this.parentNode.className = this.parentNode.className.replace("cancel","");
						this.getElementsByTagName('span')[1].innerHTML = "Change Password";
					}
				}
			}
		}
	}
})
/**** NAVIGATION - TARGET FORM FIELD SWAP ***/
addLoadEvent(function() {
	if (document.getElementById('advisorLite')) {
		if (document.getElementById('advisorPro').checked) {
			document.getElementById('domainName').parentNode.parentNode.className = document.getElementById('domainName').parentNode.parentNode.className.replace(/hidden/g,"");
		} else {
			document.getElementById('domainName').parentNode.parentNode.className += " hidden";
		}
		if (document.getElementById('advisorPro')) {
			document.getElementById('advisorPro').parentNode.parentNode.onclick = function() {
				targetFormFieldSwap(document.getElementById('advisorPro'), 'radio');
			}
		}
		if (document.getElementById('advisorLite')) {
			document.getElementById('advisorLite').parentNode.parentNode.onclick = function() {
				targetFormFieldSwap(document.getElementById('advisorLite'), 'radio');
			}
		}
		if (document.getElementById('freeTrial')) {
			document.getElementById('freeTrial').parentNode.parentNode.onclick = function() {
				targetFormFieldSwap(document.getElementById('freeTrial'), 'radio');
			}
		}
	}
})

addLoadEvent(function() {
	if (document.getElementById('domainName') && document.getElementById('domainName').value.length < 1) {
		domainChecked = false;
	}
})



addLoadEvent(function() {
	var agt=navigator.userAgent.toLowerCase();
	var appVer = navigator.appVersion.toLowerCase();
	var is_minor = parseFloat(appVer);
	var is_major = parseInt(is_minor);
	var iePos = appVer.indexOf('msie');
	if (iePos !=-1) {
		is_minor = parseFloat(appVer.substring(iePos+5,appVer.indexOf(';',iePos)))
		is_major = parseInt(is_minor);
	}
	var is_ie = ((iePos!=-1));
	var is_ie6 = (is_ie && is_major == 6);
	if (is_ie6) {
		document.getElementsByTagName('body')[0].className += " ie6";
	}
})