signupError = 0;

function changePasswordBox (ip, blur) 
{
	if (blur == 0)
	{
		if (ip.type == "password")
			return;
		var np			= ip.cloneNode(true);
		np.type			= 'password';
		np.value	= '';
		ip.parentNode.replaceChild(np,ip);
		np.focus();
	}
	else if (ip.value == "")
	{
		var np			= ip.cloneNode(true);
		np.type			= 'text';
		np.value		= 'Password';
		ip.parentNode.replaceChild(np,ip);
	}
}

function checkEmpty(id)
{
	if ($(id).value != "")
		$(id+"e").innerHTML = '<img class="validation" src="/images/validation_tick.gif" alt="" />';
	else
		$(id+"e").innerHTML = '<img class="validation" src="/images/validation_cross.gif" alt="" />';
}

function checkUsername(id)
{
	if ($(id).value == "" || $(id).value.match(/^[a-zA-Z_][a-zA-Z0-9_-]{0,7}$/) == null)
	{
		$(id+"e").innerHTML = '<img class="validation" src="/images/validation_cross.gif" alt="This field has been entered incorrectly" /> &nbsp;&nbsp;Invalid username';
	}
	else
	{
		new Ajax.Request ('/ajax.php', {
				method: 'post',
			parameters: {
				action: 'checkUsername',
				username: $(id).value
			},
			onSuccess: function (response) {
				if (response.responseText == "good")
					$(id+"e").innerHTML = '<img class="validation" src="/images/validation_tick.gif" alt="This field has been entered correctly" />';
				else
					$(id+"e").innerHTML = '<img class="validation" src="/images/validation_cross.gif" alt="This field has been entered incorrectly" /> &nbsp;&nbsp;Username taken';
			}
		});
	}
}

function checkEmail(id)
{
	if ($(id).value.match(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i))
	{
		new Ajax.Request ('/ajax.php', {
				method: 'post',
			parameters: {
				action: 'checkEmail',
				email: $(id).value
			},
			onSuccess: function (response) {
				if (response.responseText == "good")
					$(id+"e").innerHTML = '<img class="validation" src="/images/validation_tick.gif" alt="This field has been entered correctly" />';
				else
					$(id+"e").innerHTML = '<img class="validation" src="/images/validation_cross.gif" alt="This field has been entered incorrectly" /> &nbsp;&nbsp;Email already has been used';
			}
		});
	}
	else
		$(id+"e").innerHTML = '<img class="validation" src="/images/validation_cross.gif" alt="This field has been entered incorrectly" />';
}

function checkNumber(id)
{
	if ($(id).value.match(/[0-9]{10}/))
		$(id+"e").innerHTML = '<img class="validation" src="/images/validation_tick.gif" alt="This field has been entered correctly" />';
	else
		$(id+"e").innerHTML = '<img class="validation" src="/images/validation_cross.gif" alt="This field has been entered incorrectly" />';
}

function checkCountries(id)
{
	if ($(id).value != "")
		$(id+"e").innerHTML = '<img class="validation" src="/images/validation_tick.gif" alt="" />';
	else
		$(id+"e").innerHTML = '<img class="validation" src="/images/validation_cross.gif" alt="" />';
	if ($(id).value == '1')
	{
		$('address_us_state').style.display = 'inline';
		$('address_state').style.display = 'none';
	}
	else
	{
		$('address_us_state').style.display = 'none';
		$('address_state').style.display = 'inline';
	}
}

show_cc = 0;
show_ccb = 0;

function ccInfo() {
	$('creditcard_details').appear({duration:.2});
}

function hideCcInfo() {
	$('creditcard_details').fade({duration:.2});
}

function ccBillingInfo() {
	Effect.toggle('cc_billing_address', 'blind', {duration: .2})
}

function selectPackage (input) {
	el = input.parentNode.parentNode.parentNode.getElementsByTagName('tr');
	for (i = 0; i < el.length; i++)
		el[i].className = '';
	input.parentNode.parentNode.className = input.parentNode.parentNode.className + 'selectedPackage';
}

dialog = {
	action: '',
	id: '',
	open: function (id, value) {
		if (this.action != '' && this.action != null)
			closeDialog();
		new Ajax.Request ('/ajax.php', {
			method: 'post',
			parameters: {
				action: 'dialog',
				command: value,
				id: id
			},
			onSuccess: function (response) {
				 $('dialogContent').innerHTML = response.responseText;
			}
		});
		
		this.action = value;
		this.id = id;
		$('dialog').style.display = 'block';
	},
	updateGraph: function () {
		if (this.action == 'bandwidth')
		{
			new Ajax.Request ('/ajax.php', {
				method: 'post',
				parameters: {
					action: 'bwgraph',
					serverid: this.id,
					dateto: $('dateto').value,
					datefrom: $('datefrom').value
				},
				onSuccess: function (response) {
					 $('bwgraph').src = response.responseText;
				}
			});
		}
	},
	close: function () {
		$('dialog').style.display = 'none';
		this.action = '';
	}
}
//function openDialog (id, select) 

function updateGraph () {
	new Ajax.Request ('/ajax.php', {
		method: 'post',
		parameters: {
			action: 'bwgraph',
			serverid: currentHostname,
			dateto: $('dateto').value,
			datefrom: $('datefrom').value
		},
		onSuccess: function (response) {
			 $('bwgraph').src = response.responseText;
		}
	});
}

function confirmOrder () {
	if ($('payMethod').value != "paypal")
	{
		$('preOrder1').fade({duration:0});
		$('preOrder2').fade({duration:0});
		$('gotOrder1').appear();
		$('gotOrder2').appear();
		$('gotOrder3').appear();
		$('gotOrder4').appear();
		scroll(0,0);
	}
	new Ajax.Request ('/ajax.php', {
		method: 'post',
		parameters: {
			action: 'register'
		},
		onSuccess: function (r) {r.responseText.evalScripts();}
	});
	return false;
}

function submitSupportTicket (form) {
	new Ajax.Request ('/ajax.php', {
		method: 'post',
		parameters: {
			action: 'support',
			subject: form.ticket_subject.value,
			message: form.ticket_message.value
		},
		onSuccess: function (r) {
			$('supportTicket').fade({duration:.3});
			$('supportNum').innerHTML = r.responseText;
			setTimeout("$('supportTicketInfo').appear();",310);
		}
	});
	return false;
}

function newSupportReply (form) {
	new Ajax.Request ('/ajax.php', {
		method: 'post',
		parameters: {
			action: 'supportReply',
			reply: form.reply.value,
			id: form.ticket_id.value
		},
		onSuccess: function (r) {
			div = form.parentNode.getElementsByTagName("ul")[0];
			el = document.createElement("li");
			el.className = "right";
			el.innerHTML = "<strong class=\"responder\">You: </strong>"+form.reply.value;
			div.appendChild(el);
			form.reply.value = '';
		}
	});
	return false;
}

function closeTicket (form) {
	new Ajax.Request ('/ajax.php', {
		method: 'post',
		parameters: {
			action: 'supportClose',
			reply: form.reply.value,
			id: form.ticket_id.value
		},
		onSuccess: function (r) {
			form.parentNode.parentNode.parentNode.removeChild(form.parentNode.parentNode);
		}
	});
}

function modifyAccount () {
	new Ajax.Request ('/ajax.php', {
		method: 'post',
		parameters: {
			action:		'modifyAccount',
			email:		$('email').value,
			password:	$('newpass1').value,
			cpassword:	$('newpass2').value,
			first: 		$('first_name').value,
			last:		$('last_name').value,
			address:	$('address').value,
			city:		$('address_city').value,
			state:		$('address_state').value,
			country:	$('address_country').value,
			zip:		$('address_zip').value
		},
		evalScripts: true,
		onSuccess: function (r) { r.responseText.evalScripts(); }
	});
}

function addMoney () {
	formPayMethod = "false";
	for (i = 0; i < $('addFundsForm').payMethod.length; i++)
		if ($('addFundsForm').payMethod[i].checked == true)
			formPayMethod = $('addFundsForm').payMethod[i].value;
	if (formPayMethod == "false") {
		alert("You must select a payment option!");
		return;
	}
	new Ajax.Request ('/ajax.php', {
		method: 'post',
		parameters: {
			action:		'addMoney',
			amount:		$('addFundsForm').amount.value,
			payMethod:	formPayMethod,
			updateCC:	$('updateCC').checked,
			ccnum: 		$('ccnum').value,
			ccexpir:	$('cc_exp').value,
			cvc:		$('cc_cvc').value,
			ccname:		$('cc_name').value,
			cc_street:	$('cc_street').value,
			cc_city:	$('cc_city').value,
			cc_state:	$('cc_state').value,
			cc_country:	$('cc_country').value,
			cc_zip:		$('cc_zip').value
		},
		evalScripts: true,
		onSuccess: function (r) { r.responseText.evalScripts(); }
	});
}

function Tip ()
{
}

function UnTip ()
{
}
