
/* -------------------------- */
/* LOGIN                      */
/* -------------------------- */
/* Required: var nocache is a random number to add to request. This value solve an Internet Explorer cache issue */

var nocache = 0;

function front_login() {
	
	$('#message').removeClass().empty().html('<div><img src="/iqr/images/loader.gif" width="220" height="19" border="0" /></div>').fadeIn(500);
	
	var username = $('#username').val();
	var password = $('#password').val();
	
	$('#status').val('true');
	
	$.ajax({
		type: "POST",
		url: "/includes/eventHandler.php",
		data: 'username='+username+'&password='+password+'&mode=login',
	   success: function(data){
		   
		   var result = data.split('|',2);
			
			if(result[0] == 0){
				
				// FAILED	
				window.location = 'http://iqr.hy-bon.com/login?msg=Please verify username and password';
			
			} else if (result[0] == 1) {
				
				// SUCCESS
				window.location = 'http://iqr.hy-bon.com/?action=approved-company-records&login=true&k='+result[1];
			
			} else if (result[0] == 2) {
				
				// SUCCESS
				window.location = 'http://iqr.hy-bon.com/?action=company-records&login=true&k='+result[1];
			
			}
				
	   },
		error : function(XMLHttpRequest, textStatus, errorThrown) {
			$('#message').removeClass().addClass('error').text('There was an error. Please try again.').hide().fadeIn(500);
			setTimeout(function() {
				$('#message').fadeOut(800)
			}, 3000);
		}
	 });
	
}

