/**
 * @author Preetham
 * I will take care of reading in the sign up login details
 * Modifying the signup information
 */
function getLoginDetailsFromSignUpForm(){
	
	var loginDetail = null;
	
	$("#createLoginMesg").text("");
	
	var myElements=new Array("email","password1","password2","fName","lName");
	
	var firstElem = validateFields(myElements);
	
	if(firstElem) {
		$(firstElem).focus();
	}else {
		//all fields are valid
		loginDetail = {firstName:$("#fName").val(),
			lastName:$("#lName").val(),
			email:$("#email").val(),
			password:$("#password1").val()};
		
		
//		JOPTDWRGateway.createLogin(loginDetail,function(data){
//			$("#createLoginMesg").text("").text("Successfully created id");
//
//			//clear the elements
//			$.each (myElements, function(i, n){
//				$(("#" + n)).val("")
//			});
//			
//			
//						
//		});
	}
	
	return loginDetail;
}

/**
 * @author Preetham
 */
 

function modifyLoginInfo(myCallBackFunction){
	
	var validForm;
	
	$("#modifyLoginMesg").text("");
	
	var myElements=new Array("email","oldPassword", "password1","password2","fName","lName");
	
	var firstElem = validateFields(myElements);
	
	if(firstElem) {
		$(firstElem).focus();
	}else {
		//all fields are valid
		var loginDetail = {
			candidateId:$("#candidateId").val(),
			firstName:$("#fName").val(),
			lastName:$("#lName").val(),
			email:$("#email").val(),
			oldPassword:$("#oldPassword").val(),
			password:$("#password1").val()};
		
		JOPTDWRGateway.modifyLogin(loginDetail,function(data){
			if(data){
				$("#modifyLoginMesg").text("").text("Successfully modified login details");	
				//clear the elements
				$.each (myElements, function(i, n){
					$(("#" + n)).val("")
				});
				checkLogin(myCallBackFunction);			
				
			}else {
				alert("Please enter your correct old password.")
			}

		});
	}
	
}




function validateFields(myElements){

	var firstElem;
	for(var i=0; i< myElements.length ;i++){
		var elem = "#" + myElements[i]
		if(!checkRequired($(elem))){
			firstElem = !firstElem ? elem : firstElem;
		}
	}
	
	if(!firstElem) {
		//all elements are filled, check the email is valid
		var elem = "#email";
		if(!checkEmail(elem)) {
			firstElem = elem;
		}
	}
	
	if(!firstElem) {
		if(!checkPasswords()){
			//if passwords are not identical, focus on firstElem
			firstElem = "#password1";
		}
	}
	
	return firstElem;
}
