function totaltop(ele) {
	var total = ele.offsetTop;
	var parent = ele;
	while ((parent = parent.offsetParent) != null) {
		total += parent.offsetTop;
	}
	return total;
}
function totalleft(ele) {
	var total = ele.offsetLeft;
	var parent = ele;
	while ((parent = parent.offsetParent) != null) {
		total += parent.offsetLeft;
	}
	return total;
}

function initplans() {
	if (document.getElementById) {
		setTimeout(function() {
			var tab = document.getElementsByTagName('table');
			var x;
			var popupele;

			popupele = document.createElement('div');
			popupele.style.position="absolute";
			popupele.style.top="0px";
			popupele.style.left="0px";
			popupele.style.textAlign="left";
			popupele.style.background="white";
			popupele.style.border="1px solid black";
			popupele.style.width="200px";
			popupele.style.padding="10px";
			popupele.style.visibility="hidden";
			document.body.appendChild(popupele);

			function popup() {
				if (this.popupele.style.visibility == 'hidden') {
					this.popupele.innerHTML=this.getAttribute('information');
					this.popupele.style.top = (totaltop(this) - this.popupele.offsetHeight - 10) + 'px';
					this.popupele.style.left = (totalleft(this) - 20) + 'px';
					this.popupele.style.visibility='visible';
				}
			}

			function hide(e) {
				var e1, e2;
				if (document.all) {
					e = window.event;
					e1 = e.fromElement;
					e2 = e.toElement;
				} else {
					e1 = e.target;
					e2 = e.relatedTarget;
				}
				if (!((e1.parentNode == e2) || (e1 == e2.parentNode))) {
					this.popupele.style.visibility='hidden';
				}
			}

			function click() {
				window.open(this.getAttribute('link'));
			}

			for (x = 0; x < tab.length; x ++) {
				if (tab[x].className == 'plans') {
					var tbody = tab[x].getElementsByTagName('tbody');
					if (tbody.length) {
						var tr = tbody[0].getElementsByTagName('tr');
						var y;
						for (y = 0; y < tr.length; y++) {
							var td = tr[y].getElementsByTagName('td');
							if (td[0].getAttribute('information')) {
								td[0].onmouseover = popup;
								td[0].onmouseout = hide;
								td[0].popupele = popupele;
							}
							if (td[0].getAttribute('link')) {
								td[0].onclick = click;
							}
						}
					}
				}
			}
		}, 100);
	}
}
function mllogin(cc) {
	var f=document.loginform,acc=[{u:'user',p:'pass',l:'http://www.yourhub.com.au:2095/login/',x:'<input type="hidden" name="goto_uri" value="/"/><input type="hidden" name="login_theme" value="cpanel"/>'},{u:'member[username]',p:'member[password]',l:'http://www.yourhub.com.au/custdata/'},{u:'member[username]',p:'member[password]',l:'http://www.yourhub.com.au/custdata/'}];
	if(typeof(f.mlsel)=='undefined') {
		f.mlsel=0;
	}
	if(typeof(acc[f.mlsel])=='undefined') {
		alert("Sorry, an error occured while logging you in. Please try again later.");
		if(typeof(cc)=='boolean') {
			return;
		} else {
			return false;
		}
	}
	$('<form method="post" action="'+acc[f.mlsel].l+'" target="_blank">'+(typeof(acc[f.mlsel].x)!='undefined'?acc[f.mlsel].x:'')+'<input type="hidden" name="'+acc[f.mlsel].u+'" value="'+f.username.value+'"/><input type="hidden" name="'+acc[f.mlsel].p+'" value="'+f.password.value+'"/></form>').appendTo('body').get(0).submit();

	//document.loginform.submit();

	return false;
}
function mlselect(ind,ele) {
	document.loginform.mlsel=ind;
	$("div.forminner a").removeClass('c');
	$(ele).addClass('c');
	return false;
}
function hosting() {
	var f=document.loginform;
	f.action='http://www.'+f.domain.value.replace(/^(http:\/\/)?(www\.)?/,'')+':2082/login/';
	return true;
}
function updatepostal(e) {
	var ee=false;
	if (e.checked) {
		ee=true;
		e.form['residentialadslapply[postal_street_address]'].value=e.form['residentialadslapply[street_address]'].value;
		e.form[e.form['residentialadslapply[postal_suburb]'].getAttribute('foc')].value=e.form[e.form['residentialadslapply[suburb]'].getAttribute('foc')].value;
		e.form['residentialadslapply[postal_suburb]'].value=e.form['residentialadslapply[suburb]'].value;
	}
	e.form['residentialadslapply[postal_street_address]'].disabled=ee;
	e.form[e.form['residentialadslapply[postal_suburb]'].getAttribute('foc')].disabled=ee;
}
function updateservice(a,s,sn,e) {
	var ee=false;
	if (e.checked) {
		ee=true;
		e.form['residentialadslapply[service_street_address]'].value=a;
		e.form[e.form['residentialadslapply[service_suburb]'].getAttribute('foc')].value=sn;
		e.form['residentialadslapply[service_suburb]'].value=s
	}
	e.form['residentialadslapply[service_street_address]'].disabled=ee;
	e.form[e.form['residentialadslapply[service_suburb]'].getAttribute('foc')].disabled=ee;
}
function v2updatepostal(e) {
	var ee=false;
	if (e.checked) {
		ee=true;
		e.form['residentialadslapply[postal_floor_number]'].value=e.form['residentialadslapply[floor_number]'].value;
		e.form['residentialadslapply[postal_street_number]'].value=e.form['residentialadslapply[street_number]'].value;
		e.form['residentialadslapply[postal_street_name]'].value=e.form['residentialadslapply[street_name]'].value;
		e.form[e.form['residentialadslapply[postal_suburb]'].getAttribute('foc')].value=e.form[e.form['residentialadslapply[suburb]'].getAttribute('foc')].value;
		e.form['residentialadslapply[postal_suburb]'].value=e.form['residentialadslapply[suburb]'].value;
	}
	e.form['residentialadslapply[postal_floor_number]'].disabled=ee;
	e.form['residentialadslapply[postal_street_number]'].disabled=ee;
	e.form['residentialadslapply[postal_street_name]'].disabled=ee;
	e.form[e.form['residentialadslapply[postal_suburb]'].getAttribute('foc')].disabled=ee;
}
function v2updateservice(fn,n,sa,s,sn,e) {
	var ee=false;
	if (e.checked) {
		ee=true;
		e.form['residentialadslapply[service_floor_number]'].value=fn;
		e.form['residentialadslapply[service_street_number]'].value=n;
		e.form['residentialadslapply[service_street_name]'].value=sa;
		e.form[e.form['residentialadslapply[service_suburb]'].getAttribute('foc')].value=sn;
		e.form['residentialadslapply[service_suburb]'].value=s
	}
	e.form['residentialadslapply[service_floor_number]'].disabled=ee;
	e.form['residentialadslapply[service_street_number]'].disabled=ee;
	e.form['residentialadslapply[service_street_name]'].disabled=ee;
	e.form[e.form['residentialadslapply[service_suburb]'].getAttribute('foc')].disabled=ee;
}
function updatehardware(e) {
	$.each(e.form.hardware,function(i) {
		$(this.parentNode).toggleClass('selected',this.checked);
	});
}
function updateconnectiontype(e) {
	if(e.selectedIndex==0) {
		e.form['residentialadslapply[adsl_phone_number]'].removeAttribute('compulsory');
	} else {
		e.form['residentialadslapply[adsl_phone_number]'].setAttribute('compulsory','true');
	}
}
function updateconnectiontype2(e) {
	if(e.selectedIndex==0) {
		e.form['residentialadslapply[adsl_phone_number]'].removeAttribute('compulsory');
	} else {
		e.form['residentialadslapply[adsl_phone_number]'].setAttribute('compulsory','true');
	}
	if(e.selectedIndex==2) {
		e.form['residentialadslapply[current_carrier]'].setAttribute('compulsory','true');
		e.form['residentialadslapply[current_carrier_account_name]'].setAttribute('compulsory','true');
		e.form['residentialadslapply[current_wholesale_account_number]'].setAttribute('compulsory','true');
	} else {
		e.form['residentialadslapply[current_carrier]'].removeAttribute('compulsory');
		e.form['residentialadslapply[current_carrier_account_name]'].removeAttribute('compulsory');
		e.form['residentialadslapply[current_wholesale_account_number]'].removeAttribute('compulsory');
	}
}
function updatepayment(e) {
	if (e.selectedIndex==0) {
		e.form['residentialadslapply[_card_number]'].setAttribute('compulsory','true');
		e.form['residentialadslapply[_name_on_card]'].setAttribute('compulsory','true');
	} else {
		e.form['residentialadslapply[_card_number]'].removeAttribute('compulsory');
		e.form['residentialadslapply[_name_on_card]'].removeAttribute('compulsory');
	}
}

