//Script that handles the validation of a wrong customer account or password submission.

$(document).ready(function()
{			
	if ($('#login_form').length > 0) {
	  document.login_form.affiliateID.focus();
	}
	
	$("#login_form").submit(function()
	{		
		 if ($('#affiliateID').val() == "") {
            alert( "The affiliateID is required." );
            document.login_form.affiliateID.focus();
            return false ;
         }
         
         if ($('#password').val() == "") {
            alert( "The password is required." );
            document.login_form.password.focus();
            return false ;
         }
		 
		 //$("#msgbox").removeClass().addClass('messagebox').text('').fadeOut(0);
		
		//remove all the class add the messagebox classes and start fading
		$("#msgbox").removeClass().addClass('messagebox').text('Validating....').fadeIn(0);		
		//check the affiliateID exists or not from ajax
		$.post("http://affiliates.wagerweb.com/shared/content/login_validation.cfm",{ affiliateID:$('#affiliateID').val(),password:$('#password').val(),rand:Math.random() } ,function(data)
        { 		
		  document.login_form.affiliateID.disabled=true;
	      document.login_form.password.disabled=true;
		  		  		  		  		  		  
		  if(data==1) //if correct login detail
		  {			
		    $("#msgbox").fadeIn(0,function()  //start fading the messagebox	   
			{ 
			  //add message and change the class of the box and start fading			 
			  $(this).html('Logging in.....').addClass('messageboxok').fadeIn(0,
              function()
			  { 
			  	 //redirect to secure page
				 document.location=$('#internalpage').val();				 								
			  });
			  
			});
		  }
		  
		  if(data==2) 
		  {		  	
			$("#msgbox").fadeIn(0,function() //start fading the messagebox		   
			{ 
			  document.login_form.affiliateID.disabled=false;			
		      document.login_form.password.disabled=false;			 
			  document.login_form.affiliateID.focus();
			  //add message and change the class of the box and start fading
			  $(this).html('<a style="cursor:pointer;" onclick="parent.location.href=\'http://affiliates.wagerweb.com/content/forgotpassword\';">Forgot password? CLICK HERE</a>').addClass('messageboxerror').fadeIn(0);		  
			});			
			
          }
		  
		  if(data==3) 
		  {		  	
			$("#msgbox").fadeIn(0,function() //start fading the messagebox		   
			{ 
			  document.login_form.affiliateID.disabled=false;			
		      document.login_form.password.disabled=false;			 
			  document.login_form.affiliateID.focus();
			  //add message and change the class of the box and start fading
			  $(this).html('Account has been suspended.<br>Please contact our Customer Service for further assistance.').addClass('messageboxsuspended').fadeIn(0);		  
			});			
			
          }
				
        });
 		return false; //not to post the form physically
	});
	//now call the ajax also focus move from 
	$("#password").blur(function()
	{
		//$("#login_form").trigger('submit');
	});
});


//Script that handles the validation of a wrong customer account or password submission.

$(document).ready(function(){
		
	$("#login_form_internal").submit(function()
	{		
		 if ($('#affiliateID_internal').val() == "") {
            alert( "The affiliateID is required." );
            document.login_form_internal.affiliateID_internal.focus();
            
            return false ;
         }
         
         if ($('#password_internal').val() == "") {
            alert( "The password is required." );
            document.login_form_internal.password_internal.focus();
            return false ;
         }
		 
		 //$("#msgbox_internal").removeClass().addClass('messagebox').text('').fadeOut(0);
		
		//remove all the class add the messagebox classes and start fading
		$("#msgbox_internal").removeClass().addClass('messagebox_internal').text('Validating....').fadeIn(0);		
		//check the username exists or not from ajax
		$.post("http://affiliates.wagerweb.com/shared/content/login_validation.cfm",{ affiliateID:$('#affiliateID_internal').val(),password:$('#password_internal').val(),rand:Math.random() } ,function(data)
        { 		
		  document.login_form_internal.affiliateID_internal.disabled=true;
	      document.login_form_internal.password_internal.disabled=true;      

		  if(data==1) //if correct login detail
		  {		  	
			$("#msgbox_internal").fadeIn(0,function() //start fading the messagebox	   
			{ 
			  //add message and change the class of the box and start fading			  
			  $(this).html('Logging in.....').addClass('messageboxok_internal').fadeIn(0,
              function()
			  { 
			  	 //redirect to secure page			  	 
				 document.location=$('#internalpage_internal').val();				 								
			  });
			  
			});
		  }
		  
		  if(data==2) 
		  {		  	
			$("#msgbox_internal").fadeIn(0,function() //start fading the messagebox													
			{ 
			  document.login_form_internal.affiliateID_internal.disabled=false;			
		      document.login_form_internal.password_internal.disabled=false;			 
			  document.login_form_internal.affiliateID_internal.focus();
			  //add message and change the class of the box and start fading
			  $(this).html('<a style="cursor:pointer;" onclick="parent.location.href=\'http://affiliates.wagerweb.com/content/forgotpassword\';">Forgot password? CLICK HERE</a>').addClass('messageboxerror_internal').fadeIn(0);		  
			});			
			
          }
		  
		  if(data==3) 
		  {		  	
			$("#msgbox_internal").fadeIn(0,function() //start fading the messagebox													
			{ 
			  document.login_form_internal.affiliateID_internal.disabled=false;			
		      document.login_form_internal.password_internal.disabled=false;			 
			  document.login_form_internal.affiliateID_internal.focus();
			  //add message and change the class of the box and start fading
			  $(this).html('Account has been suspended.<br>Please contact our Customer Service for further assistance.').addClass('messageboxsuspended_internal').fadeIn(0);		  
			});			
			
          }
				
        });
 		return false; //not to post the form physically
	});
	//now call the ajax also focus move from 
	$("#password_internal").blur(function()
	{
		//$("#login_form_landing").trigger('submit_landing');
	});
});
