/**
 * @author Preetham
 */


 
 function getCandidateProfileDetailsFromForm(){
 	
	
	
// 	var myElements = new Array("#profileCandidateId", "#candidateFName", "#candidateLName",
//	 		 "#phone", "#city", "#state", "#university", "#degree", "#subject", "#programName",
//			 "#gradYear", "#gradMon", "#optStartYear", "#optStartMon","#skill1", "#prof1",
//			 "#skill2", "#prof2","#locPre", "#aboutTxt");
	
//	alert($("#state").val()); 
//	alert($("#qual").val()); 
//	alert($(":radio").filter("[name='prof1']").filter(":checked").val());
//	alert($(":radio").filter("[name='prof2']").filter(":checked").val());
//	alert($("#locPre").val());
	
	var candidate = {
		candidateId:$("#profileCandidateId").val(),
		firstName:$("#candidateFName").val(),
		lastName:$("#candidateLName").val()		
	};
	
	var candidateSkill1 = {
		skillName:$("#skill1").val(),
		levelId:$(":radio").filter("[name='prof1']").filter(":checked").val()
	};

	var candidateSkill2 = {
		skillName:$("#skill2").val(),
		levelId:$(":radio").filter("[name='prof2']").filter(":checked").val()
	};
	
	var candidateSkill = new Array();
	if($("#skill1").val()) {
		candidateSkill.push(candidateSkill1);	
	}
	if($("#skill2").val()) {
		candidateSkill.push(candidateSkill2);	
	}
	var gradDate = null;	
	if($("#gradYear").val()) {
		gradDate = $("#gradYear").val();
		if($("#gradMon").val()){
			gradDate = gradDate + "-" + $("#gradMon").val() + "-00";
		}else {
			gradDate = gradDate + "-00-00";
		}
	}

	var optStartDate = null;	
	if($("#optStartYear").val()) {
		optStartDate = $("#optStartYear").val();
		if($("#optStartMon").val()){
			optStartDate = optStartDate + "-" + $("#optStartMon").val() + "-00";
		}else {
			optStartDate = optStartDate + "-00-00";
		}
	}

	//to begin set to an empty array
	var locPreArr = locPreArr = new Array();
	
	if($("#locPre").val()) {
		locPreArr = $("#locPre").val();
		if(locPreArr.length > 0) {
			if(locPreArr[0] == "") {
				//since it implies no preference, setting to empty array
				locPreArr = new Array();
				//alert("Setting to empty array");
			}
		}
	}
	   
 	var candidateProfile = {
		candidate:candidate,
		phone:$("#phone").val(),
		city:$("#city").val(),
		stateCode:$("#state").val(),
		
		university:$("#university").val(),
		degreeId:$("#degree").val(),
		subjectId:$("#subject").val(),
		programName:$("#programName").val(),
		graduationDate:gradDate,
		optStartDate:optStartDate,
		
		jobLocationPrefStateCode:locPreArr,
		about:$("#aboutTxtArea").val(),
		skillSet:candidateSkill
				
	};
	
	return candidateProfile;
	
 }
 //pass candidateProfile that we need to load in the form
 function populateFormWithCandiateProfDetail(cp){
		
		$("#phone").val(cp.phone);
		$("#city").val(cp.city);
		$("#state").val(cp.stateCode);
//		
		$("#university").val(cp.university);
		$("#degree").val(cp.degreeId);
		$("#subject").val(cp.subjectId);
		$("#programName").val(cp.programName);
		console.log("grad date " + cp.graduationDate);
		if(cp.graduationDate) {
			$("#gradYear option[value='" + cp.graduationDate.split("-")[0] +"']").attr("selected","selected");	
			console.log("GRAD MON " + cp.graduationDate.split("-")[1]);
			$("#gradMon option[value='" + cp.graduationDate.split("-")[1] +"']").attr("selected","selected");
		}
		
		if(cp.optStartDate) {
			$("#optStartYear option[value='" + cp.optStartDate.split("-")[0] +"']").attr("selected","selected");
			$("#optStartMon option[value='" + cp.optStartDate.split("-")[1] +"']").attr("selected","selected");
		}

		
	if(cp.skillSet && cp.skillSet.length > 0) {
	 	$("#skill1").val(cp.skillSet[0].skillName);
		
		$("input.prof1").filter("[value='" + cp.skillSet[0].levelId + "']").attr('checked', 'checked');
		//$("form#candProfileForm :radio").filter("[name='prof1']").filter("[value='2']").attr('checked','checked');
	}
	
	if (cp.skillSet && cp.skillSet.length > 1) {
		$("#skill2").val(cp.skillSet[1].skillName);
		$("input.prof2").filter("[value='" + cp.skillSet[1].levelId + "']").attr('checked', 'checked');
		
//		$("#candProfileForm :radio").filter("[name='prof2']").filter("[value='" +
//			cp.skillSet[1].levelId + "']").attr('checked', 'checked');
	}
	
	$.each(cp.jobLocationPrefStateCode, function(i,n){
		$("#locPre option[value='" + n +"']").attr("selected","selected");
	});
	
	//NOT USING THIS TO REFRESH THIS TEXT AFTER A RESUME UPDATE IS ANOTHER CALL AND ANYWAY I NEED TO GO THE BACKEND TO GET
	// THE DETAILED RESUME
	//set brief about in the table and the rest in the hiddent dialog
//	if(cp.about && cp.about.length > 150) {
//		//starting from 0 to first index of space after 150
//		$("#aboutTxt").html(cp.about.substring(0,(cp.about.indexOf(" ", 150))));	
//	}else {
//		$("#aboutTxt").html(cp.about);	
//	}
	$("span#resumeText pre").html("").html(cp.about); 
	
	
 }
