function ClickContinue()
{
        $('#mask').hide();
	$('.window').hide();
}



$(document).ready(function() {	

	//select all the a tag with name equal to modal
	$('a[name=modal]').click(function(e) {
                //Check if member exists
                //if(IsMemberExists() == "true")
                //{
                //     alert("member exists");
                //}
                  
                IsMemberExists();

		//Cancel the link behavior
		e.preventDefault();
				
	
	});
	
	//if close button is clicked
	$('.window .close').click(function (e) {
		//Cancel the link behavior
		e.preventDefault();
		
		$('#mask').hide();
		$('.window').hide();
	});		
	
	//if mask is clicked
//	$('#mask').click(function () {
//		$(this).hide();
//		$('.window').hide();
//	});	

     
    // Define what happens when the textbox comes under focus
    // Remove the watermark class and clear the box
    $("#SearchByZip_4_zip").focus(function() {
        $(this).filter(function() {

            // We only want this to apply if there's not
            // something actually entered
            return $(this).val() == "" || $(this).val() == "enter zip code"

        }).removeClass("watermarkOn").val("");

    });
    
    // Add the watermark class and default text
    $("#SearchByZip_4_zip").blur(function() {
        $(this).filter(function() {

            // We only want this to apply if there's not
            // something actually entered
            return $(this).val() == ""

        }).addClass("watermarkOn").val("enter zip code");

    });
    
   //   $('#textBox1').bind('keypress', function(e) {
   //       if(e.keyCode==13){          
   //           gotoGoogle();
   //           return false;
   //              // Enter pressed... do anything here...
   //     }
   //});		
	
});

function IsMemberExists()
{
    var userName = $('.TextBoxUserName').val();
    var pw       = $('.TextBoxPassword').val();  
    if((userName == '') && (pw == ''))
    {
        return;
    }
          $.ajax(
            {
                type: "POST",
                url: "WebService.asmx/IsMemberExists",
                data: "{\"user\":\"" + userName + "\"" + ", \"pw\":\"" + pw + "\"}",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function(msg) {
                     
                     if(msg == "true")
                     {
                          ShowTerms();
                     }                                                            
                     else
                     {
                          alert("Invalid Usernmae or Password.");
                     }
                }
            });
    //}    
}

function LoginUser()
{
    var userName = $('.TextBoxUserName').val();
    var pw       = $('.TextBoxPassword').val();  
    $.ajax({
                type: "POST",
                url: "WebService.asmx/LoginUser",
                data: "{\"user\":\"" + userName + "\"" + ", \"pw\":\"" + pw + "\"}",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function(msg) {
                             window.location = "/home.aspx";                                        
                }
            });   
   
}

function ShowTerms()
{
    var userName = $('.TextBoxUserName').val();
    var pw       = $('.TextBoxPassword').val();  
    $.ajax(
            {
                type: "POST",
                url: "WebService.asmx/IsTermsAccepted",
                data: "{\"user\":\"" + userName + "\"" + ", \"pw\":\"" + pw + "\"}",
                dataType: "json",
                contentType: "application/json; charset=utf-8",
                success: function(msg) {
                     if(msg == "true")
                     {
                          LoginUser();
                     }                                                            
                     else
                     {
                          //Get the A tag
                           var id = $('#aLogin').attr('href');
	
                           //Get the screen height and width
                           var maskHeight = $(document).height();
                           var maskWidth = $(window).width();
	
                          //Set heigth and width to mask to fill up the whole screen
                          $('#mask').css({'width':maskWidth,'height':maskHeight});
		
    //transition effect		
    $('#mask').fadeIn(1000);	
    $('#mask').fadeTo("slow",0.8);	
	
    //Get the window height and width
    var winH = $(window).height();
    var winW = $(window).width();
             
    //Set the popup window to center
    $(id).css('top',  winH/2-$(id).height()/2);
    $(id).css('left', winW/2-$(id).width()/2);

    //transition effect
    $(id).fadeIn(2000); 
                     }
                }
            });
     
    
}