
function jobseeker() {
	getJalert();
	getResume();
    new dijit.Tooltip({
        connectId: ["submenu-active"],
        label: "value <b>change status</b>"
    });
}

function getJalert() {
	var divtext = dojo.byId("jalert");
	var buttontext = dojo.byId("status");
	dojo.xhrGet({
		url: "/action/action_return_jalert.jsp",
		//url: "/swe-v2/action/action_return_jalert.jsp",
		handleAs: "text",
		timeout: 10000,
		load: function(data) {
				if(data.match("Yes")) {
					divtext.innerHTML = "You have job alert <strong style=\"color:green;\">ENABLED</strong>";
					buttontext.innerHTML ="Disable now";
				}
				if(data.match("No")) {
					divtext.innerHTML = "You have job alert <strong style=\"color:red;\">DISABLED</strong>";
					buttontext.innerHTML ="Enable now";
				}
				return data;
			},
		error: function(error) {
					divtext.innerHTML = "Error: "+error;
					return data;
					buttontext.style.display="none";
			}
	});
	
}

function getResume() {
	
	var divtext = dojo.byId("getResume");
	dojo.xhrGet({
		url: "/resumeMgt",
		//url: "/swe-v2/resumeMgt",
		handleAs: "text",
		timeout: 10000,
		load: function(data) {
				divtext.innerHTML = data;
			},
		error: function(error) {
					divtext.innerHTML = "Error: "+data;
			}
	});
	
}

function getCompany() {
	
	var divtext = dojo.byId("getCompany");
	dojo.xhrGet({
		url: "/jobMgt?action=getCompany",
		handleAs: "text",
		timeout: 10000,
		load: function(data) {
				divtext.innerHTML = data;
			},
		error: function(error) {
					divtext.innerHTML = "Error: "+data;
			}
	});
	
}

function getJobs() {
	
	var divtext = dojo.byId("getJobs");
	dojo.xhrGet({
		url: "/jobMgt?action=getJobs",
		handleAs: "text",
		timeout: 10000,
		load: function(data) {
				divtext.innerHTML = data;
			},
		error: function(error) {
					divtext.innerHTML = "Error: "+data;
			}
	});
	
}
function removeResume(key) {
	var ans = window.confirm("Are you sure you want to delete this resume?");
	
	if(ans) {
		var divtext = dojo.byId("getResume");
		dojo.xhrGet({
			url: "/resumeMgt?key="+key,
			//url: "/swe-v2/resumeMgt?key="+key,
			handleAs: "text",
			timeout: 10000,
			load: function(data) {
			divtext.innerHTML = data;
		},
		error: function(error) {
			divtext.innerHTML = "Error: "+data;
		}
		});
	} 
}	
	
function updateStatus(key) {
	
	var ans = window.confirm("Are you sure you change the status of this resume?");
	
	if(ans) {
		var divtext = dojo.byId("getResume");
		console.log("Divtxt is :"+divtext);
		console.log("Key is :"+key);
		dojo.xhrGet({
			url: "/resumeMgt?status="+key,
			//url: "/swe-v2/resumeMgt?status="+key,
			handleAs: "text",
			timeout: 10000,
			load: function(data) {
			divtext.innerHTML = data;
		},
		error: function(error) {
			divtext.innerHTML = "Error: "+data;
		}
		});
	}
} 	

function toggleAlert() {
	
	var divtext = dojo.byId("jalert");
	var buttontext = dojo.byId("status");
	
	var result = dojo.xhrGet({
		url: "/action/action_toggle_jalert.jsp",
		//url: "/swe-v2/action/action_toggle_jalert.jsp",
		handleAs: "text",
		timeout: 10000,
		load: function(data) {
				if(data.match("Yes")) {
					alert("Job alert enabled");
					divtext.innerHTML = "Job alert is <strong style=\"color:green;\">ENABLED</strong> ";
					buttontext.innerHTML ="Disable now";
				}
				if(data.match("No")) {
					alert("Job alert disabled");
				divtext.innerHTML = "Job alert is <strong style=\"color:red;\">DISABLED</strong>";
					buttontext.innerHTML ="Enable now";
				}
			},
		error: function(error) {
					divtext.innerHTML = ""+error;
					buttontext.style.display="none";
			}
	});
	
}

function removeJob(key) {
	console.log("Key on remove is: "+key);
	var ans = window.confirm("Are you sure you want to delete this job?");
	if(ans) {
		location.href="/action/action_delete_job.jsp?key="+key;
	}
	
}

function changeJobStatus(key, status) {
	if(status == 0) {
		var ans = window.confirm("Are you sure you want to Activate this job?");
		if(ans) {
			location.href="/jobMgt?action=repost&key="+key;
		}
	}
	if(status == 1) {
		var ans = window.confirm("Are you sure you want to de-activate this job?");
		if(ans) {
			location.href="/jobMgt?action=deactivate&key="+key;
		}
	}
	
}

function getStateJobs() {
	
	var state = (window.location.pathname.split("/")[2]).split(".")[0];
	window.document.title = "Social Work Jobs, Social Service Jobs, Mental Health, Counselor, Human Service in "+state;
	
	var divtext = dojo.byId("stateJobs");
	
	dojo.xhrGet({
		url: "/search/"+state+"/_blank",
		handleAs: "text",
		timeout: 15000,
		load: function(data) {
				divtext.innerHTML = data;
			},
		error: function(error) {
					divtext.innerHTML = "Error: "+data;
			}
	});
}

function fixTitle() {
	window.document.title = "Social Work Jobs, Social Service Jobs, Mental Health, Counselor, Human Service in "+dojo.byId("search-form").state.value;	
}

