$(document).ready(function() {
	// validate signup form on keyup and submit
	var validator = $("#LoginForm").validate({
		rules: {
			username: {
				required: true
			},
			password: {
				required: true
			}
		},
		messages: {
			username: {
				required: "Required"
			},
			password: {
				required: "Required"
			}
		},
		// ecifying a submitHandler prevents the default submit, good for the demo
		submitHandler: function() {
			$('#LoginForm').ajaxSubmit({ 
				success:function(responseText) 
				{
										//var data = eval('(' + reponseText + ')');
					if (responseText == 0) {
						$('#login_message').text('Invalid Username and Passwordssssss');
						//validator.showErrors({"password": "Invalid"});
					} else if (responseText == 1) {
/*						if (responseText.next != '') {
							window.location.href = responseText.next;
						} else {
							window.location.href = base_url + 'users/account';
						}	*/	
						//window.location.href = base_url + 'admin';
					} else {
						alert('hello');
						$('#Message').html(responseText);
					}
				},
				dataType:'json'
			});			
		},
		// set this class to error-labels to indicate valid fields
		success: function(label) {
			// set &nbsp; as text for IE
			label.html("&nbsp;").addClass("checked");
		}	
	});
});


$(document).ready(function() {
	// validate signup form on keyup and submit
	var validator = $("#EmployeeCustomerLoginForm").validate({
		rules: {
			username: {
				required: true
			},
			password: {
				required: true
			}
		},
		messages: {
			username: {
				required: "Required"
			},
			password: {
				required: "Required"
			}
		},
		// ecifying a submitHandler prevents the default submit, good for the demo
		submitHandler: function() {
			$('#EmployeeCustomerLoginForm').ajaxSubmit({ 
				success:function(responseText) 
				{
					//var data = eval('(' + reponseText + ')');
					if (responseText == 1) {
						window.location.href = base_url + 'customer';
					} else if (responseText == 2) {
						window.location.href = base_url + 'employee';
					} else if (responseText == 3) {
						window.location.href = base_url + 'admin';
					} else if (responseText== 5) {
						$('#Message').text('Invalid Username or Password');
						
					} else {
						$('#Message').text('Please select option');
					}
				},
				dataType:'json'
			});			
		},
		// set this class to error-labels to indicate valid fields
		success: function(label) {
			// set &nbsp; as text for IE
			label.html("&nbsp;").addClass("checked");
		}	
	});
});

function signUp(company_id)
{
	$("#canvassCompanyLogin").hide();
	$("#canvassSignUp").show();
	$.post(base_url + 'index/_load_company_signup_form',{company_id:company_id},
	  function(o){
	   $('#canvassSignUp').html(o);
	});
}

function showCompanyLogin(company_id) {
	$('#canvassCompany').hide();
	$('#canvassCompanyLogin').show();
	$('#company_id').val(company_id);
	
}

function backToCompany() {
	$('#canvassCompany').show();
	$('#canvassCompanyLogin').hide();
}

function loadActiveCompanyDT() {
	$("#canvassCompanyLogin").hide();
	var action = function(elCell, oRecord, oColumn, oData) { 
				var id = oRecord.getData("id");
					elCell.innerHTML = "<a href=\"javascript: showCompanyLogin("+ id +")\"><font color=\"blue\">Login</font></a>"; 
			};	
			
		var columns = 	[{key:"id",label:"id",width:30,resizeable:true,sortable:true},
						 {key:"name",label:"Vendor Name",width:120,resizeable:true,sortable:true},
  					     {key:"Action",label:"Action",width:120,resizeable:true,sortable:true, formatter:action}];
						 //{key:"action",label:"Action",width:60,resizeable:true,sortable:true, formatter:action}];
		var fields =	['id','name','action'];
		var height = 	'200px'; //optional
		var width = 	'400px'; //optional
		var path = 'index/_load_active_company';
	
		var DataTable = new createDataTable('canvassCompany',path, columns, fields, height, width);
		DataTable.rowPerPage(15);
		DataTable.pageLinkLabel('first','previous','next','last');
		DataTable.show();		
}

