var kbtreesections = [];
var kbtreec=0;
var kbtreeeffects = [];
function ondomready() {
	if (typeof cursection != 'undefined') { 
		for (c=0; c<kbtreec; c++) {
			if (kbtreesections[c]!=cursection) { 
				$('tree-'+kbtreesections[c]).style.display='none';
			}	
		}
		if ($('bullet-'+cursection)) { 
			$('bullet-'+cursection).src='/images/saffron-bullet-down.gif';
		}
	}
	var as = document.getElementsByTagName('a');
	for (var i = 0; i < as.length; i++) {
		if (!eval('as[i].onmouseover')) { 
			as[i].onmouseover = function () { link_over(this); }
		}
	}
	
}
function link_over (obj) {
	obj.style.color='#e7d0f4';
	new Effect.Morph(obj,{style: { color: '#6b5594'}, duration: 0.4});
}
function expandcollapsekbtree(c) {
	if (kbtreeeffects[c]) {
		return;
	}
	if ($('tree-'+c).style.display != 'none') { 
		$('bullet-'+c).src='/images/saffron-bullet.gif';
		kbtreeeffects[c]=new Effect.BlindUp('tree-'+c, {afterFinish: function() { kbtreeeffects[c]=null; } });
	} else {
		$('bullet-'+c).src='/images/saffron-bullet-down.gif';
		kbtreeeffects[c]=new Effect.BlindDown('tree-'+c, {afterFinish: function() { kbtreeeffects[c]=null; } });

	}
}
function fixButton(x) {
    window.setTimeout(function(){document.getElementById(x).blur();},50);
}

var donedomains = new Array();
function done(domain) {
	for(d in donedomains){
		if(d==domain) return true;
	}
	return false;
}
function checkDomain (domain,prechecked) {
	handler=function() {
		donedomains[domain]=true;	
	}
	new Ajax.Updater(domain, "/ajax/checkdomain.php", {
		asynchronous:true,
		method:"post",
		postBody:"domain="+domain+"&prechecked="+prechecked,
		onSuccess:handler,
		onFailure:handler
	});
	return false;
}
function diskUsage () {
//	alert('Foo');
	new Ajax.Updater(results, "/ajax/diskusage.php", {
		asynchronous:true,
		method:"get"
	});
	return false;
}
function updateTotal (div,n) {
	var years = 0;
	for(var i=0;i<n;i++){
		years += parseInt($('years'+i.toString()).value);
	}
	new Ajax.Updater(div, "/ajax/priceofdomain.php", {
		asynchronous:true,
		method:"post",
		postBody:"years="+years+"istotal=true",
		onComplete:updateGrandTotal
	});
	return true;
}
function updateHostingPrice (div,account,years) {
	new Ajax.Updater(div, "/ajax/priceofhosting.php", {
		asynchronous:true,
		method:"post",
		postBody:"account="+account+"&years="+years,
		onComplete:updateGrandTotal
	});
	return true;
}
function updatePrice (div,domain,years,istotal) {
	if(istotal==null) istotal='false';
	new Ajax.Updater(div, "/ajax/priceofdomain.php", {
		asynchronous:true,
		method:"post",
		postBody:"domain="+domain+"&years="+years+"&istotal="+istotal
	});
	return true;
}
function updateGrandTotal () {
	alltotals = document.getElementsByClassName("totalvalues");
	var total=0;
	for (i = 0; i < alltotals.length; i++) {
		currency = alltotals[i].firstChild.nodeValue.substr(0,1);
		value = alltotals[i].firstChild.nodeValue.substr(1);
		total += parseFloat(value);
	}
	Element.update('grandtotal',currency+total.toFixed(2));
}
function saveSession() {
	var domains = Form.serialize('domainsform');
	postStr = '';
	if(domains.length>0) {
		postStr = domains+'&';
	}
	if($('accounttype').value.length>0) {
		postStr = postStr+"package="+$('accounttype').value+"&type="+type+"&years="+$('hostingyears').value;
	}
        new Ajax.Updater ("saveresult", "/ajax/savesession.php", {
                asynchronous:true,
                method:"post",
                postBody:postStr
        });
}
function checkUsername(username) {
        new Ajax.Updater ("usernamestatus", "/ajax/checkusername.php", {
                asynchronous:true,
                method:"post",
                postBody:"username="+username,
		onComplete:handler
        });
	function handler() {
		if ($('result').value == 'true') {
			$('forward').disabled=false;
		} else {
			$('forward').disabled=true;
		}
	}
}

