// Function to open up a window with a list of sub specialties.
function openSubSpecs(specialtyCategoryId) {
	var ps = new proxyService();
	
	// Setup ajaxproxy to get the count of the specialty area selected.
	ps.setHTTPMethod("post");
	ps.setCallbackHandler(retrieveJobCount);
	ps.setErrorHandler(myErrorHandler);
	try {
		ps.GetJobSpecialtyCount(specialtyCategoryId);
	}
	catch(err){
		window.alert(err);
		window.alert("An unknown error prevented the GetJobSpecialtyCount request from being processed.");
	}
		
	return false;
}

// Resizes cfwindow cfWinName to the size of cfWinDIVName, constrained by the min/max set inside function
function resizeToFit(cfWinName, cfWinDIVName){
	var maxWidth = 820, maxHeight = 600;
	var minWidth = 450, minHeight = 100;
	var displayDiv, displayHeight, displayWidth;
	var win = ColdFusion.Window.getWindowObject(cfWinName);
	win.resizeTo(minWidth,minHeight);

	displayDiv = document.getElementById(cfWinDIVName);
	if (displayDiv) {
		displayHeight = displayDiv.offsetHeight + 50;
		displayHeight = Math.min(maxHeight,Math.max(minHeight,displayHeight));

		displayWidth = displayDiv.scrollWidth + 50;
		displayWidth = Math.min(maxWidth,Math.max(minWidth,displayWidth));
		/*alert("offsetHeight: " + displayDiv.offsetHeight + "\n" +
		 "scrollWidth: " + displayDiv.scrollWidth + "\n" +
		 "offsetWidth: " + displayDiv.offsetWidth + "\n" +
		 "minWidth: " + minWidth + "\n" +
		 "minHeight: " + minHeight + "\n" +
		 "displayWidth: " + displayWidth + "\n" +
		 "displayHeight: " + displayHeight
		 );*/

		win.resizeTo(displayWidth,displayHeight);
	}
}

// Function to show the full quote of the testimonial in a modal window.
function showTestimonial() {
	resizeToFit("testimonialWindow", "testimonialCfWindow");
	ColdFusion.Window.show("testimonialWindow");
	return false;
	
}

//Function to create a graphical mouse rollover.
function swapImage(imageName, graphicSource) {
	document.getElementById(imageName).src = graphicSource;
}


// Handlers
function cleanup() {
    ColdFusion.Window.destroy("showSpecialties", true);
}

retrieveJobCount = function(result) { // result[0] is the SpecialtyCategoryID, result[1] is the record count, and result[2] is the Specialty.
	if (result[1] == 1) { // Go directly to career center.
		location.href="/CareerCenter/FindSpecialty/" + result[2];
	} else { // Display window.
		try {
			ColdFusion.Window.destroy("showSpecialties", true);
		} catch(e) { }
		
		ColdFusion.Window.create("showSpecialties", "Select a Specific Specialty", "_jobs.cfm?specCatId=" + result[0],
			{callbackHandler:specialtyBreakdownCreated,center:true,draggable:false,modal:true,resizable:false,width:815,destroyOnClose:true});
		ColdFusion.Window.onHide("showSpecialties", cleanup);
	}
}

//Error handler for the asynchronous functions.
myErrorHandler = function(statusCode, statusMsg) {
	window.alert('Status: ' + statusCode + ', ' + statusMsg);
}

specialtyBreakdownCreated = function() {
	resizeToFit("showSpecialties", "specialtyBreakdown");
}
