$(document).ready(function(){
	
	$('a[@rel=ext]').each(function(){
		 if($.browser.msie)
		 {
		 	$(this).attr('target','_blank');
		 }
		 else
		 {
		 	$(this).attr('onclick','window.open(\''+ $(this).attr('href') +'\'); return false; ');
		 }
	});
	
	if(navigator.userAgent.indexOf('MSIE 6') > -1)
	{
		$('input[@type=image]').addClass('pngfix');
		$('img[@src:contains(.png)]').addClass('pngfix');
	}
	else
	{
		$('div.yellow-container').append('<div class="yellow-tl"></div><div class="yellow-bl"></div><div class="yellow-tr"></div><div class="yellow-br"></div>')
		$('div.white-container').append('<div class="white-tl"></div><div class="white-bl"></div><div class="white-tr"></div><div class="white-br"></div>')
		$('div.grey-container').append('<div class="grey-tl"></div><div class="grey-bl"></div><div class="grey-tr"></div><div class="grey-br"></div>')
		$('div.red-container').append('<div class="red-tl"></div><div class="red-bl"></div><div class="red-tr"></div><div class="red-br"></div>')
		$('div.green-container').append('<div class="green-tl"></div><div class="green-bl"></div><div class="green-tr"></div><div class="green-br"></div>')
		$('div.blue-container').append('<div class="blue-tl"></div><div class="blue-bl"></div><div class="blue-tr"></div><div class="blue-br"></div>')
	}
	

	var highestCol = Math.max($('#content').height(),$('#suggest').height());
	if (highestCol>610) { setTimeout("$('#suggest').animate({height:'"+(highestCol+10)+"px'});",500) }
	
	
});

function flash_basket()
{
	$('#basket_link').css('background-image', 'url(img/basket-active.png)');
	setTimeout('$(\'#basket_link\').css(\'background-image\', \'url(img/basket-bg.png)\')', 1000);
	setTimeout('$(\'#basket_link\').css(\'background-image\', \'url(img/basket-active.png)\')', 2000);
	setTimeout('$(\'#basket_link\').css(\'background-image\', \'url(img/basket-bg.png)\')', 3000);
}

function expand_tr(rowid)
{
	if(navigator.appName == 'Microsoft Internet Explorer') { 
		display = 'block';
	} else {
		display = 'table-row';
	}
	if($('tr#extras-' + rowid).css('display') == 'none')
	{
		$('tr#extras-' + rowid).css('display', display);
		$('img#row-expander-' + rowid).attr('src', 'img/small-expand.png');
	}
	else
	{
		$('tr#extras-' + rowid).css('display', 'none');
		$('img#row-expander-' + rowid).attr('src', 'img/small-cross.png');
	}
}

function collapse_all_tr()
{
	var i = 0;
	while($('tr#extras-' + i).css('display') != undefined)
	{
		$('tr#extras-' + i).css('display', 'none');
		$('img#row-expander-' + i).attr('src', 'img/small-cross.png');
		i++;
	}
}

function ShowPaymentMethod(method, upgrade)
{
	if(method == 'pp') {
		$('#pp-billing').slideDown('slow');
		$('#cc-billing').slideUp('slow');
		$('#aof-billing').slideUp('slow');
	} else if(method == 'cc') {
		$('#cc-billing').slideDown('slow');
		$('#pp-billing').slideUp('slow');
		$('#aof-billing').slideUp('slow');
	} else {
		$('#aof-billing').slideDown('slow');
		$('#pp-billing').slideUp('slow');
		$('#cc-billing').slideUp('slow');
	}
}

function ValidateTransfer()
{
	var errors = new Array();
	var domain_parts = $('#transfer_name').val().split(".");
	if($('#transfer_name').val().length < 6) errors.push('transfer_name');
	if(domain_parts.length == 1) errors.push('transfer_name');
	if($('#epp_code').val().length < 6) errors.push('epp_code');
	
	$('#transfer_form label').removeClass('error');
	if(errors.length > 0)
	{
		$.each(errors,function(key){
			$('label[@for='+ errors[key] +']').addClass('error');
		});
	} else {
		return true;
	}
	return false;
}
	
function RunWhois(ext,domain,check)
{
	var tldid = 1;
	var ContinueButton = 0;
	$.ajax({
		type:"GET",
		dataType:"json",
		timeout:4000,
		url:'domain-whois.php?domain=' + domain + '&ext=' + ext,
		success:function(data){
			if(ContinueButton < 1)
			{
			$.each(data,function(entryKey, entry){
				if(entryKey == 'availability')
				{
					if(entry == 'taken')
					{
						//taken
						html = '<img src="img/small-no.png" style="margin: 2px 2px 0px 2px; " />';
					}
					else
					{
						//available
						html = '<input type="checkbox" style="float: left; margin: 3px 5px 0px 2px; *margin: 0px; "';
						if(check == true) {
							html = html + ' checked="checked"';
						}					
						html = html + ' name="ext_' + ext.replace('.', '_') + '" value="1" />';
					}
				}
			});
			if(data['terms'].length < 1)
			{
				//taken
				html = '<img src="img/small-no.png" style="margin: 2px 2px 0px 2px; " />';
			}
			else
			{
				if(data['availability'] == 'available') {
					//available
					html = '<input type="checkbox" style="float: left; margin: 3px 5px 0px 2px; *margin: 0px; "';
					if(check == true) {
						html = html + ' checked="checked"';
					}					
					html = html + ' name="ext_' + ext.replace('.', '_') + '" value="1" />';
				} else {
					//taken
					html = '<img src="img/small-no.png" style="margin: 2px 2px 0px 2px; " />';
				}
			}
			$('#avail_' + ext.replace('.', '_')).html(html);
		}
	}
	});
}
