
jQuery(document).ready(function() {

  //search bar watermark
  jQuery(function(jQuery){
    jQuery('#ctl00_txtProduct_Name_Search').Watermark('Search for a reward by name or brand');
  });
 
  //reward border 
  jQuery('#reward-listing div.item').mouseover(function() {
	if (jQuery(this).is('.feat')) {
	  jQuery(this).css({'width':'398px','border':'solid 1px #a6a4bf','cursor':'pointer'});
	  jQuery('.feat-tag',this).css({'background-position':'-1px -1px','height':'99px','width':'99px'});
	} else {
	  jQuery(this).css({'width':'158px','border':'solid 1px #a6a4bf','cursor':'pointer'});
	}
	jQuery('.img-container', this).css({'padding':'2px 2px 3px 2px'});
	jQuery('.item-desc', this).css({'padding':'5px 4px 4px 4px'});
	jQuery('.item-pts', this).css({'padding':'5px 5px 5px 4px'});
  }).mouseout(function() {
	if (jQuery(this).is('.feat')) {
	  jQuery(this).css({'width':'400px','border':'none'});
	  jQuery('.feat-tag',this).css({'background-position':'0 0','height':'100px','width':'100px'}); 
	} else {
	  jQuery(this).css({'width':'160px','border':'none'});
	}
    jQuery('.img-container', this).css({'padding':'3px'});
    jQuery('.item-desc', this).css({'padding':'5px'});
    jQuery('.item-pts', this).css({'padding':'5px'});
	
  });
  
  	//signin pop-out
	var $div = $('#loginBox');
	var height = $div.height();
	$div.hide().css({'height':'0','top':'200px'});
	
	$('.sign-in').click(function () {																	
		overlayOn();
		$div.show().animate({ height : height }, { duration: 700 });
		return false;
	});
	
	$('.sign-in-close-btn').click(function () {																	
		overlayOff();
		$div.hide().animate({'height':'0'}, { duration: 700, complete: function() {$div.hide().css({height:0});}});
		return false;
	});
	
	setSignInPos();
	$(window).resize(function() {
		setSignInPos();
	});
	
	function setSignInPos() {
		leftpx = ($(window).width()-342)/2;
		$('#loginBox').css('left',leftpx+'px');
	};

  
  	//add-remove page overlay
	function overlayOn() {
	    // Added by Jason on Jun.18/2010 START: disable validators if found (e.g. when the login form is visible,
	    // want any validators of form fields (e.g. joinnow.aspx, etc.) to be disabled.
        if (document.getElementById("ctl00_ContentPlaceHolder1_rfvCustomer_FirstName") != null) {
            var rfvCustomer_FirstName = document.getElementById('ctl00_ContentPlaceHolder1_rfvCustomer_FirstName');
            ValidatorEnable(rfvCustomer_FirstName, false);
        }
        if (document.getElementById("ctl00_ContentPlaceHolder1_rfvCustomer_LastName") != null) {
            var rfvCustomer_LastName = document.getElementById('ctl00_ContentPlaceHolder1_rfvCustomer_LastName');
            ValidatorEnable(rfvCustomer_LastName, false);
        }
        if (document.getElementById("ctl00_ContentPlaceHolder1_rfvCustomer_Email") != null) {
            var rfvCustomer_Email = document.getElementById('ctl00_ContentPlaceHolder1_rfvCustomer_Email');
            ValidatorEnable(rfvCustomer_Email, false);
        }
        if (document.getElementById("ctl00_ContentPlaceHolder1_regCustomer_Email") != null) {
            var regCustomer_Email = document.getElementById('ctl00_ContentPlaceHolder1_regCustomer_Email');
            ValidatorEnable(regCustomer_Email, false);
        } 
        if (document.getElementById("ctl00_ContentPlaceHolder1_rfvCustomer_Password") != null) {
            var rfvCustomer_Password = document.getElementById('ctl00_ContentPlaceHolder1_rfvCustomer_Password');
            ValidatorEnable(rfvCustomer_Password, false);
        } 
        if (document.getElementById("ctl00_ContentPlaceHolder1_regCustomer_Password") != null) {
            var regCustomer_Password = document.getElementById('ctl00_ContentPlaceHolder1_regCustomer_Password');
            ValidatorEnable(regCustomer_Password, false);
        }
        // Added by Jason on Jun.18/2010 END: disable validators if found (e.g. when the login form is visible,
	    // want any validators of form fields (e.g. joinnow.aspx, etc.) to be disabled.

		$('#overlayDiv').css({'filter':'alpha(opacity=0)','width':'100%','height':'100%'});
		$('#overlayDiv').animate({'opacity': .8},800);
	}
	
	function overlayOff() {					
		$('#overlayDiv').animate({'opacity': 0}, { duration: 800, complete: function () {
			$('#overlayDiv').css({'filter':'alpha(opacity=0)','width':'0','height':'0'});
		}});
	}
	
	//join now form validation
	$('#sign-up_container #first-name-input input').blur(function () {
		if ($(this).val() == "") {																   
			$('#sign-up_container #first-name .false').fadeIn(500);
			$('#sign-up_container #first-name .true').fadeOut(200);
		} else {
			$('#sign-up_container #first-name .true').fadeIn(500);
			$('#sign-up_container #first-name .false').fadeOut(200);
		}
	});
	
	$('#sign-up_container #last-name-input input').blur(function () {
		if ($(this).val() == "") {																   
			$('#sign-up_container #last-name .false').fadeIn(500);
			$('#sign-up_container #last-name .true').fadeOut(200);
		} else {
			$('#sign-up_container #last-name .true').fadeIn(500);
			$('#sign-up_container #last-name .false').fadeOut(200);
		}
	});
		
	$('#sign-up_container #email-input input').blur(function () {															  
		if ($(this).val().indexOf(".") > 2 && $(this).val().indexOf("@") > 0) {																   
			$('#sign-up_container #email .true').fadeIn(500);
			$('#sign-up_container #email .false').fadeOut(200);			
		} else {
			$('#sign-up_container #email .false').fadeIn(500);
			$('#sign-up_container #email .true').fadeOut(200);
		}
	});
			
	$('#sign-up_container #pass-input input').blur(function () {
		if ($(this).val().length >= 6) {																   
			$('#sign-up_container #pass .true').fadeIn(500);
			$('#sign-up_container #pass .false').fadeOut(200);
		} else {
			$('#sign-up_container #pass .false').fadeIn(500);
			$('#sign-up_container #pass .true').fadeOut(200);
		}
	});
	
	//shipping info popup
	$('#primary-shipping_check').live("click", function() {
		$('#account-info #shipping').slideToggle("fast");
	});

	//forgot password
	$('#ctl00_ContentPlaceHolder1_btnSubmit').click(function () {
		if ($('#ctl00_ContentPlaceHolder1_txtCustomer_Email').val() == "") {
			document.getElementById('error-txt').innerHTML = "Please enter your email address.";
		} else {
			var regEmail = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{1,4})$/;
			var strEmail = $('#ctl00_ContentPlaceHolder1_txtCustomer_Email').val();
			if (strEmail.search(regEmail) == -1) {
				document.getElementById('error-txt').innerHTML = "Please enter a valid email address.";
			}
		}
	});

}); 
