/**************************************************************
** Itomic Script
**
** (c) Itomic pty. ltd. [itomic.com]
**************************************************************/
// Things to trigger on DOM load
window.addEvent('domready', function() {
	var Glossary = new Tips($$('acronym'), {
		initialize:function(){
			this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
		},
		onShow: function(toolTip) {
			this.fx.start(1);
		},
		onHide: function(toolTip) {
			this.fx.start(0);
		}
	});
});


function iframeHeight(obj)
{
  //find the height of the internal page
  var the_height = obj.document.body.scrollHeight;

  //change the height of the iframe
  obj.height= the_height;
}


Itomic = {
	domainSearch: function(frm) {
		var popup = new Nucleus.Popup.HTMLLoad({close:false,timeout:false});

		var loading = document.createElement('p');
		var img = document.createElement('img');
		img.src = '/clientlib/cms/images/icons/itomic_loader_small.gif';
		img.width = '30';
		img.height = '30';
		img.alt = "Loading...";
		loading.className = 'loading';
		loading.appendChild(img);
		loading.appendChild(document.createTextNode("Checking Domain Name availability now. This could take as long as a few minutes so thanks for your patience!"));
		popup.box.appendChild(loading);
		popup.getHTML(frm.action, "domain="+escape(frm.domain.value), { method: 'post', onSuccess:function(respText, respXML) { 
				var domain = respXML.getElementsByTagName('domain')[0];
				if (!domain) alert("No Domain");
				var name = respXML.getElementsByTagName('name')[0];
				var raw = respXML.getElementsByTagName('raw')[0];
				var title = document.createElement('h3');
				var dom = document.createElement('a');
				var p = document.createElement('p');
				var rawout = document.createElement('pre');
				var div = document.createElement('div');
				var isAvailable = (domain.getAttribute('available') == 'true');
				
				// Clean what's in there (popup-box)
				popup.cleanBox();
				popup.settings.close = true;  // now add in the close button
				
				// Put the domain name in a strong tag
				dom.appendChild(document.createTextNode(Nucleus.Elements.xmlText(name)));
				dom.href = "http://" + name.textContent;
				dom.setAttribute('target', '_blank');
				
				if (isAvailable) {
					title.appendChild(document.createTextNode(Nucleus.Elements.xmlText(name) + ' is Available'));
					p.appendChild(document.createTextNode('It appears that the domain '));
					p.appendChild(dom);
					p.appendChild(document.createTextNode(' is available. '));
					div.className = 'domain-available';
				} else {
					title.appendChild(document.createTextNode('Sorry, the domain '+ Nucleus.Elements.xmlText(name) + ' is Unavailable'));
					p.appendChild(document.createTextNode('It appears that the domain '));
					p.appendChild(dom);
					p.appendChild(document.createTextNode(' has been taken. '));
					div.className = 'domain-taken';
					
					// Only add the raw content if we had some
					if (Nucleus.Elements.xmlText(raw)) {
						var txt = Nucleus.Elements.xmlText(raw);
						if (document.all) {
							// IE7 does not seem to obay the white-space:pre CSS rule, so we will put in the line breaks ourselves.
							txt = txt.split(/\n/gi);
							var index = 0;
							for(index=0;index<txt.length;index++) {
								rawout.appendChild(document.createTextNode(txt[index]));
								rawout.appendChild(document.createElement('br'));
							}
						} else rawout.appendChild(document.createTextNode(txt));
					} else { isAvailable = true; }
				}
				
				div.appendChild(title);
				div.appendChild(p);
				if (!isAvailable) div.appendChild(rawout);
				popup.box.appendChild(div);
				popup.show();
				return true; 
			}});
		popup.show();	
		
		return true;
	},
	
	scrollToContactTabs: function() {
		jQuery.scrollTo(jQuery('#contact_tabs').get(0), 800);
	}
}
window.addEvent('domready', function() {
	if (document.getElementById("form_paybillForm")) {
		//switcher for repaid/pay bills on payment form
		
		var form = document.getElementById("form_paybillForm");
	
		
		switchForm = function() {
			if ($("form_paybillType2").checked) { //prepaid
				$("form_paybillInvoice_numbersRow").style.display = "none"
				//document.getElementById("form_paybillPayment_amount").style.display = "none"
				this.form.invoice_numbers.value = "PREPAID PAYMENT";
		
				if (!document.getElementById("prepaidradios")) {
					/*$("form_paybillPayment_amountRow").getElementsByTagName("td")[0].innerHTML += "<span id='prepaidradios'></span>";
					$("prepaidradios").innerHTML += "<label class='block'><input type='radio' class='radio' id='pp10' name='prepaid' value='1425'  />10 Hours</label>";
					$("prepaidradios").innerHTML += "<label class='block'><input type='radio' class='radio' id='pp30' name='prepaid' value='4050' />30 Hours</label>";
					$("prepaidradios").innerHTML += "<label class='block'><input type='radio' class='radio' id='pp50' name='prepaid' value='6375' />50 Hours</label>";
					$("prepaidradios").innerHTML += "<label class='block'><input type='radio' class='radio' id='pp100' name='prepaid' value='12750' />100 Hours</label>";
					for (var i=0, els = $("prepaidradios").getElementsByTagName("input"); i<els.length; i++) {
						if (els[i].value == $("form_paybillPayment_amount").value) els[i].checked = true; //populate it if the user is coming back from the confirm page or it is refreshed etc
						els[i].onclick = function() { 
							this.form.invoice_numbers.value =  this.getAttribute("id").replace(/pp/, "PREPAID ")
							this.form.payment_amount.value = this.value
							
						}
					}*/
					
				}
				else $("prepaidradios").style.display = ""
			
			}
			
			
			else if ($("form_paybillType1").checked) { //bill
				$("form_paybillInvoice_numbersRow").style.display = ""
				$("form_paybillPayment_amount").style.display = ""
				
				if ($("form_paybillInvoice_numbers").value.indexOf("PREPAID") != -1) {
					$("form_paybillPayment_amount").value = ""
					$("form_paybillInvoice_numbers").value = ""
				}
				
				//$("prepaidradios").style.display = "none"
				if ($("prepaidradios")) $("prepaidradios").remove();
				
			} 
	
		}
		
		$("form_paybillType1").onclick = switchForm
		$("form_paybillType2").onclick = switchForm
		
		switchForm()
		
	}
})
