$(document).ready(function()
{
	$('a[@rel=external]').bind('click', function()
	{
		$(this).attr('target', '_blank');
	});

	$('ul.currency li a').click(function(){
		$('.curr').hide();
		$('#curr_' + $(this).attr('rel')).show();	
		$('ul.currency li').removeClass('sel');
		$(this).parent().addClass('sel');
	});




	$('#newsletter').click(function(){
		if ($(this).val() == 'Enter your email')
		{
			$(this).val('');
		}
	});

	$('#newsletter').keypress(function(data){
		if (data['keyCode'] == 13)
			$('#add_email').trigger('click');
	});

	$('#add_email').click(function(){
		$.ajax({
			type: "POST",
			url: '/addEmail.php',
			data: '&email=' + $('#newsletter').val(),
			success: function (data){
				var code = parseInt(data);
				if (code == -1 || code == 5)
				{
					$('#subscribe').fadeOut();
					$('#subscribe_ok').fadeIn();					
				}
				else
				{
					$('#newsletter').css({'border-color': 'red'});
				}
			}
		});
	});

	$('#subdomain').keyup(function(){
		var $field = $(this).parent();

		$.ajax({
			url: '/check.php?subdomain='+$(this).val(),
			success: function (data){
				var code = parseInt(data);
				if (code)
				{
					$field.addClass('error');
					$('.yes').hide();
					$('.no').show();					
				}
				else
				{
					$field.removeClass();
					$('.yes').show();
					$('.no').hide();	
				}
			}
		});
	});

});

$( document ).click( function( event, ui ) {
   
    var $parentClass = $( event.target ).parents('.international');

       if ( !$parentClass.length ) {
           $( '#international_select').hide();
       } else {
    
     $( '#international_select').show();
    }
   
   
   } );

function zIndexWorkaround()
{
    // If the browser is IE,
    if(isIE())
    {
        /*
        ** For each div with class menu (i.e.,
        ** the thing we want to be on top),
        */
        $("#international_select").parents().each(function() {
            var p = $(this);
            var pos = p.css("position");
 
            // If it's positioned,
            if(pos == "relative" ||
               pos == "absolute" ||
               pos == "fixed")
            {
                /*
                ** Add the "on-top" class name when the
                ** mouse is hovering over it, and remove
                ** it when the mouse leaves.
                */
                p.hover(function() {
                        $(this).addClass("on-top");
                    },
                    function() {
                        $(this).removeClass("on-top");
                    });
            }
        });
    }
}
