$(function() {
  
  $('#wholesales_pass .error').hide();
  $('#wholesales_login .error').hide();
  
  $('#wholesales_pass input.text-input').css({backgroundColor:"#FFFFFF"});
  $('#wholesales_login input.text-input').css({backgroundColor:"#FFFFFF"});
  
  $('#wholesales_pass input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  $('#wholesales_login input.text-input').focus(function(){
    $(this).css({backgroundColor:"#FFDDAA"});
  });
  
  $('#wholesales_pass input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });
  $('#wholesales_login input.text-input').blur(function(){
    $(this).css({backgroundColor:"#FFFFFF"});
  });  

  $("#wholesales_pass input#RequestPass_btn").click(function() {
		// validate and process form
		// first hide any error messages
    $('#wholesales_pass .error').hide();
		
	var name = $("#wholesales_pass input#name").val();
	if (name == "") {
      $("#wholesales_pass label#name_error").show();
      $("#wholesales_pass input#name").focus();
      return false;
    }
	var email = $("#wholesales_pass input#email").val();
	if (email == "") {
      $("#wholesales_pass label#email_error").show();
      $("#wholesales_pass input#email").focus();
      return false;
    }
		
		var dataString = 'name='+ name + '&email=' + email;
		//alert (dataString);return false;
		
	$.ajax({
      type: "POST",
      url: "sendWholesaleEmail.php",
      data: dataString,
      success: function() {
        $('#wholesales_pass_msg').html("<b>Your request Submitted! We will be in touch soon!</b>")
        .hide()
        .fadeIn(1500, function() {
          $('#wholesales_pass_msg').append("<img id='checkmark' src='includes/css/images/check.png' width='20'/><br/>");
        });
      }
     });
    return false;
	});

 $("#wholesales_login input#Login_btn").click(function() {
		// validate and process form
		// first hide any error messages
    $('#wholesales_login .error').hide();
		
	var name = $("#wholesales_login input#username").val();
	if (name == "") {
      $("#wholesales_login label#username_error").show();
      $("#wholesales_login input#username").focus();
      return false;
    }
	var password = $("#wholesales_login input#password").val();
	if (password == "") {
      $("#wholesales_login label#password_error").show();
      $("#wholesales_login input#password").focus();
      return false;
    }
	
	if (name != "wholesale" && password != "12345") {
      $('#wholesales_login_msg').html("<img id='cancelmark' src='includes/css/images/cancel.png'/>")
	  .append("<font color='red'>Wrong username or password</font>");
      $("#wholesales_login input#username").focus();
      return false;
    }else{	
		/*
      $('#wholesales_login_msg').html("<b>Correct username or password</b>")
	  .append("<img id='checkmark' src='includes/css/images/check.png' width='20'/>");
      $("#wholesales_login input#username").focus();
      return false;*/
	  window.open("promotion/catalog.htm", "_blank", ""); return false;
	}//end if
	
    return false;
	});	
});
runOnLoad(function(){
  $("#wholesales_pass input#name").select().focus();
  $("#wholesales_login input#username").select().focus();
});
