﻿var clipNo;

$(document).ready(function(){
    if($('#clipNoLabel').text() == "81353941-e548-41bb") {
         $('#errorsDiv2').empty().append('<b>You are not allowed to use this portal.<br> You have invalid Clip Serial Number</b>');    
         $('input[type=submit]', this).attr('disabled', 'disabled');   
         $('#newAccount', this).attr('href', '#');                          
         $('#newAccount', this).attr('disabled', 'disabled');
         $('#forgotPasswordLink', this).attr('disabled', 'disabled');                                  
         $('#clipNoLabel').text('')
         $.blockUI({ message: $('#containerErrMsg'), css: { width: '390px',  border: '0px' }  ,overlayCSS: { backgroundColor: '#000', opacity: '0.6'} });                      
         
    }
    else {

        $('#forgotPasswordLink').click(function() {      
            clipNo = $("#clipNoLabel").text();
            $("#clipNoForgotLabel").text(clipNo);                    
            $.blockUI({ message: $('#container'), css: { width: '390px',  border: '0px' }  ,overlayCSS: { backgroundColor: '#000', opacity: '0.6'} });               
        }); 
        
        $('#newAccount').click(function() {              
            OpenNewCustomer();
        }); 
	}
	
	$("#userNameTextBox").keypress(function (e)  { 	  
	      if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57)) {	
	        return false;
          }	
	});
	
	$("#userNameForgotTextBox").keypress(function (e)  { 	  
	      if( e.which!=8 && e.which!=0 && (e.which<48 || e.which>57)) {	
	        return false;
          }	
	});	
	
	
	
    $('a[title=Close]').click(function() {
        $.unblockUI(); 
        return false;            
    });
});    
     
     
function SendMail() {
    $.ajax({        
        url: 'Handlers/ForgotPasswordHandler.ashx',
        type: "POST",
        data: "CustName=" + $("#userNameForgotTextBox").val() + "&ClipNo=" + clipNo,
        success: function(response) {           
            $.unblockUI(); 
            ShowMsg(response);            
        },
        error: function(xhr) {            
            $.unblockUI(); 
            ShowErrMsg(xhr.responseText);            
        }
    }); 
}

function ShowMsg(strtext){
    $('#msgDiv').empty().html(strtext);
    $.blockUI({ message: $('#containerMsg'), css: { width: '390px',  border: '0px' }  ,overlayCSS: { backgroundColor: '#000', opacity: '0.6'} });                  

}

function ShowErrMsg(strtext){    
    $('#errorsDiv2').empty().html(strtext);    
    $.blockUI({ message: $('#containerErrMsg'), css: { width: '390px',  border: '0px' }  ,overlayCSS: { backgroundColor: '#000', opacity: '0.6'} });                  

}

function OpenNewCustomer() {
    var newLocation = "NewCustomer.aspx" + "?ClipSerial=" + $("#clipNoLabel").text();
    window.location = newLocation;
}
