var tempTarget;
var tempTargetScan;
var multiArray;
var baseURL = "/";
//var baseURL = "http://pdi.acro123.com/";
//var workingLawyerID = 39;
var thisID = 0;

/*---------------------+
| Load Children
- Initiates the JS App.
- calls AJAX request for the lawyer xml
*/
function loadChildren(categoryID, selectID){
	var url = baseURL + 'searchCategories.php';
	var param = "categoryID=";

	thisID = selectID;

	param += categoryID;
	var myAjax = new Ajax.Request( url, {method: 'get', parameters: param, onSuccess: loadData, onFailure: showMessage} );
	
	document.getElementById("selectedCategory").value = categoryID;
	
	//theParentID = categoryID;
	//alert(url +"?"+ param);
}

/*---------------------+
| Load Data
- Loads the initial root element instance on AJAX Request success 
*/
function loadData(originalRequest){
	var divText = originalRequest.responseText;
//	var temp = "selects";
	var splitCat = "";
	var temp = "catVal";
	var i = 0;

	if(thisID > 0){
		//temp = "select";
		temp += thisID;
	}
	//var theDiv = document.getElementById(temp);
	var theList = document.getElementById(temp);

	// clear the options first so they don't pile up.
	theList.options.length = 0;

	// if there is something add, then add it.
	if(divText != ""){

		// split the individual categories
		var splitText = divText.split('|');
		
		// add a default
		if(thisID == 1)
			theList[0] = new Option("--- Please Select a Sub-Specialty ---");
		else if(thisID == 2)
			theList[0] = new Option("--- Narrow your search further ---");
		else
			theList[0] = new Option("--- Please Select a Specialty ---");
		
		// for each category, split it to get the ID and the name, then add the name/value to the list.
		for(i=0; i<splitText.length; i++){
			splitCat = splitText[i].split('::');
			theList[i+1] = new Option(splitCat[1]);
			theList[i+1].value=splitCat[0];
		}
		theList.style.display = "block";

		thisID++;
		temp = "catVal" + thisID;
		theList = document.getElementById(temp);
		if(theList != null){
			theList.style.display = "none";
		}		
	}
	else{
		theList.style.display = "none";
		thisID++;
		temp = "catVal" + thisID;
		theList = document.getElementById(temp);
		if(theList != null){
			theList.style.display = "none";
		}
			
	}

}

/*---------------------+
| show Message
+ ---------------------
- shows message box, scrolls to it
- decides if error or success
- if error with xml pastes default message
- if error with submission pastes ordered list
- if success just pastes success message.
*/
function showMessage(message, type, notXML){
	alert("showMessage");
	$('messageBox').style.display = "block";
	window.scrollTo(0, 200);
	$('messageBox').className = type + "Message";
	if(!notXML && type == "errorMessage"){
		$('messaseBox').getElementsByTagName('div')[0].innerHTML = "<p>There was a problem communicating with the server, if problem continues contact us!</p>";
	}
	else{
		$('messageBox').getElementsByTagName('div')[0].innerHTML = message.responseText;
	}
}

//onload initiates the application
//window.onload = loadChildren(0,-1);

function pageShift(){
	return;
}

window.onLoad = loadChildren(0, 0);
