$(document).ready(function() {
	
	$("#nav1").hover(function() { $(this).attr('src','/img/nav/over_03.gif'); },function() { $(this).attr('src','/img/nav/nav_up_03.gif');});
	$("#nav2").hover(function() { $(this).attr('src','/img/nav/over_04.gif'); },function() { $(this).attr('src','/img/nav/nav_up_04.gif');});
	$("#nav3").hover(function() { $(this).attr('src','/img/nav/over_05.gif'); },function() { $(this).attr('src','/img/nav/nav_up_05.gif');});
	$("#nav4").hover(function() { $(this).attr('src','/img/nav/over_06.gif'); },function() { $(this).attr('src','/img/nav/nav_up_06.gif');});
	$("#nav5").hover(function() { $(this).attr('src','/img/nav/over_07.gif'); },function() { $(this).attr('src','/img/nav/nav_up_07.gif');});
	$("#nav6").hover(function() { $(this).attr('src','/img/nav/over_08.gif'); },function() { $(this).attr('src','/img/nav/nav_up_08.gif');});
	$("#nav7").hover(function() { $(this).attr('src','/img/nav/over_09.gif'); },function() { $(this).attr('src','/img/nav/nav_up_09.gif');});
	$("#nav8").hover(function() { $(this).attr('src','/img/nav/over_account.gif'); },function() { $(this).attr('src','/img/nav/nav_up_account.gif');});
	$("#nav9").hover(function() { $(this).attr('src','/img/nav/over_myRegistryAdvisor.gif'); },function() { $(this).attr('src','/img/nav/nav_up_myRegistryAdvisor.gif');});

	$("#nav10").hover(function() { $(this).attr('src','/img/nav/over_10.gif'); },function() { $(this).attr('src','/img/nav/nav_up_10.gif');});
	$("#nav11").hover(function() { $(this).attr('src','/img/nav/over_11.gif'); },function() { $(this).attr('src','/img/nav/nav_up_11.gif');});

	$("#why1").hover(function() { $(this).attr('src','/img/why/whyNav1_over.gif'); },function() { $(this).attr('src','/img/why/whyNav1_down.gif');});
	$("#why2").hover(function() { $(this).attr('src','/img/why/whyNav2_over2.gif'); },function() { $(this).attr('src','/img/why/whyNav2_down.gif');});
	$("#why3").hover(function() { $(this).attr('src','/img/why/whyNav3_over.gif'); },function() { $(this).attr('src','/img/why/whyNav3_down.gif');});

	$("#vnav1").hover(function() { $(this).attr('src','/img/why/v-nav1_over.gif'); },function() { $(this).attr('src','/img/why/v-nav1.gif');});
	$("#vnav2").hover(function() { $(this).attr('src','/img/why/v-nav2_over.gif'); },function() { $(this).attr('src','/img/why/v-nav2.gif');});
	$("#vnav3").hover(function() { $(this).attr('src','/img/why/v-nav3_over.gif'); },function() { $(this).attr('src','/img/why/v-nav3.gif');});
	$("#vnav4").hover(function() { $(this).attr('src','/img/why/v-nav4_over.gif'); },function() { $(this).attr('src','/img/why/v-nav4.gif');});

		
	/*
	Focuser tool
	*/
	$("input.focuser").bind("focus", function(e) {
		if($(this).val() == $(this).attr('title')) {
			$(this).val('');
		}
	});
	
	$("input.focuser").bind("blur", function(e) {
		if($(this).val() == '') {
			$(this).val($(this).attr('title'));
		}
	})
	
    jQuery.validator.addMethod("isEmail", function( value, element ) {
	    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
        var address = value;
        if(reg.test(address) == false) 
        {
            $('#workingImg').hide();
            $('#okImg').hide();
            $('#notokImg').show();
            return false;
        }
        else
        {
            $('#workingImg').hide();
            $('#okImg').show();
            $('#notokImg').hide();
            return true;
        }
	}, "Must be a valid email address");
	
	jQuery.validator.addMethod("isTaken", function( value, element ) {
		var ajaxTestResult = false;
		
		var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
        var address = value;
        if(reg.test(address) == false)
            return false;
        
        $('#workingImg').show();
        $('#okImg').hide();
        $('#notokImg').hide();
        $.ajax(
		{
		    async:false,
			type:"POST",
			url:"/Users/CheckEmailAvailable",
			data:"email="+value,
			dataType:'html',
			success:function(data)
			{
				if(data=='true')
				{
				    $('#workingImg').hide();
                    $('#okImg').show();
                    $('#notokImg').hide();
				    ajaxTestResult = true;
				}
				else
				{
				    $('#workingImg').hide();
                    $('#okImg').hide();
                    $('#notokImg').show();
				    ajaxTestResult = false;
				}
			}
			,
			error:function()
			{
				ajaxTestResult = false;
			}
		});
        return ajaxTestResult;
	}, "This email address already exists in our system.");
	
	jQuery.validator.addMethod("passwordEight", function( value, element ) {
		var result = this.optional(element) || value.length >= 8;
		if(result)
		{
		    $('#pworkingImg').hide();
            $('#pokImg').show();
            $('#pnotokImg').hide();
        }
        else
        {
            $('#pworkingImg').hide();
            $('#pokImg').hide();
            $('#pnotokImg').show();
        }
                    
		return result;
	}, "Must be 8 characters minimum, with 1 cap and 1 number.");
	
	jQuery.validator.addMethod("passwordLetter", function( value, element ) {
		var result = /\d/.test(value) && /[A-Z]/.test(value);
		return result;
	}, "Must be 8 characters minimum, with 1 cap and 1 number.");
	
	jQuery.validator.addMethod("StateOrProvince", function( value, element ) {
	    if(($('#UserCountry').val()=='US' || $('#UserCountry').val()=='CA') && value=='')
	    {
	        return false;
	    }
		return true;
	}, "This field is required.");
	
	$("#usersCreateForm").validate({
	  rules: {
		"data[User][confirm_email]": { equalTo:"#UserEmail"},
		"data[User][confirm_password]": {equalTo:"#UserPassword"}
	  },
	  messages: {
		  "data[User][confirm_email]": {
			  	equalTo:"Please enter the same email as above."
		  },
		  "data[User][confirm_password]": {
				equalTo:"Please enter the same password as above."  
		  }
	  }
	});
	$("a#quickSearch").click(function() { 
			var firstname = $("input#registryFirstname").val();
			var lastname  = $("input#registryLastname").val();
			$.ajax({
				type:"POST",
				url:"/registries/quickSearch",
				data: "firstname="+firstname+"&lastname="+lastname,
				success: function(html) {
					$("#quickSearchResults").html(html);	
				}
			});
	});
	
	$("#rebateTip").tooltip({
			extraClass:"small_horiz",
			top:-27
		});
	
	var imagelist= new Array();
	imagelist[0] = '/img/searchfnamebg.jpg';
	imagelist[1] = '/img/searchfnamebg-active.jpg';
	imagelist[2] = '/img/searchlnamebg.jpg';
	imagelist[3] = '/img/searchlnamebg-active.jpg';
	imagelist[4] = '/img/loginemailbg.gif';
	imagelist[5] = '/img/loginemailbg-active.gif';
	imagelist[6] = '/img/loginpwbg.gif';
	imagelist[7] = '/img/loginpwbg-active.gif';
	for(var i = 0; i<imagelist.length; i++)
	{
		jQuery("<img>").attr("src", imagelist[i]);
	}
});

	function clearDefault(el) {
  		if (el.defaultValue==el.value) el.value = ""
	}


function inputfocus(id,imageurl)
{
    if(imageurl)
       $('#'+id).css('backgroundImage','url('+imageurl+')');
}
function openPopup(link,width,height)
{
	$.showAkModal(link,'',width,height, true)
	return false;
}
function roundCorners()
{
	$('.ak_modal_inner').corner();
	$('#ak_modal_div').corner("cc:#FFFFFF");
}

