function updateFranchiseList(franchiseID,franchiseName,add){
	if(add) addToFranchiseList(franchiseID,franchiseName);
	else removeFranchiseList(franchiseID);
}
function addToFranchiseList(franchiseID, franchiseName){
	if(franchiseListTotalCount < franchiseSelectionLimit){

	   //build list of parameters
		var querystring_variables = new Array();
		querystring_variables["franchiseID"] = franchiseID;
		querystring_variables["franchiseName"] = franchiseName;

		//make asynchoronous call to get_franchises_json.php
		var bindArgs = {
			url: 'addFranchiseToCart.php',
			type: 'text/javascript',
			content: querystring_variables,
			handler: displayFranchiseListResults
		};
		dojo.io.bind(bindArgs);
		/*if(document.getElementById("check"+franchiseID)) {
			document.getElementById("check"+franchiseID).checked = true;
			document.getElementById("franchise"+franchiseID).style.backgroundColor = "#eeeeee";
		}*/
	} else {
		alert("You have reached the maximum of " + franchiseSelectionLimit + " selections. To add more franchises, please uncheck selections in your request list.");
	}

}

function removeFranchiseList(franchiseID){
   //build list of parameters
	var querystring_variables = new Array();
	querystring_variables["deleteFranchise"] = franchiseID;

	//make asynchoronous call to get_franchises_json.php
	var bindArgs = {
		url: 'delete_from_cart.php',
		type: 'text/json',
		content: querystring_variables,
		handler: displayFranchiseListResults
	};
	dojo.io.bind(bindArgs);
	if(document.getElementById("check"+franchiseID)) {
		document.getElementById("check"+franchiseID).checked = false;
		document.getElementById("franchise"+franchiseID).style.backgroundColor = "rgb(255, 255, 255)";
	}
}

function displayFranchiseListResults(type, data, evt) {
	franchiseListResults = data.parseJSON();
	oFranchiseList = document.getElementById("franchiseList");
	oFranchiseList.innerHTML = "";

	franchiseListTotalCount = franchiseListResults.count;

	if(franchiseListResults.count > 0){
				dojo.byId('franchiseList').innerHTML += "<form name='frm' method='post' action='request_form.php'><input type=\"submit\" id=\"submit2\" value=\"Request Information Now\" style=\"width:160px;\" /><hr>";

		oFranchiseList.innerHTML += "<div><strong>Selection Count</strong>: " + franchiseListResults.count + "</div>";
		for (var i=0; i<franchiseListResults.count; i++) {
			var franchiseID = franchiseListResults[i].id;
			var franchiseName = franchiseListResults[i].name.replace(/\'/g, "&#39;");
			//oFranchiseList.innerHTML += franchiseID + franchiseName + "<br>";

			//Create list for submission
			if (document.all) {
				var typeArray = document.createElement("<input type=\"checkbox\" name=\"franchises[]\" \"value=\"" + franchiseID +  "\" onclick=removeFranchiseList(" + franchiseID +") checked=\"checked\">");
				dojo.byId('franchiseList').appendChild(typeArray);
			} else {

				var typeArray = document.createElement('input');
				typeArray.setAttribute("name", "franchises[]");
				typeArray.setAttribute("type", "checkbox");
				typeArray.setAttribute("value", franchiseID);
				dojo.byId('franchiseList').appendChild(typeArray);
				typeArray.setAttribute("checked", true);
				typeArray.setAttribute("onclick", "removeFranchiseList(" + franchiseID +");");
			}

			dojo.byId('franchiseList').innerHTML += " " + franchiseName + "<br>";
		}

		dojo.byId('franchiseList').innerHTML += "<br><br></form>";

	} else {
		dojo.byId('franchiseList').innerHTML = "<div style=\"padding:10px;\">Franchise List is empty</div>";
	}
}


//var previousSpot = 109;
function movepanel(){
	var franchiseListObj = document.getElementById("franchiseListContainer");
	franchiseListObj.style.display = "block";

	//var franchiseListContentObj = document.getElementById("franchiseList");
	//var previousSpotArray = findPosition(franchiseListObj)
	var scrollArray = getScrollXY();

	if(scrollArray[1] < 75){
		//franchiseListContentObj.innerHTML = previousSpot + " " + scrollArray[1];
		franchiseListObj.style.top =375+ "px";
		previousSpot = 375;
	} else {
		//alert(scrollArray[1]);
		//franchiseListContentObj.innerHTML = previousSpot + " " + scrollArray[1];
		franchiseListObj.style.top = (scrollArray[1] +30) + "px";
		previousSpot = scrollArray[1];
		//t1 = new Tween(franchiseListObj.style,'top',Tween.regularEaseIn,previousSpot,(scrollArray[1]),1,'px');
		//t1.start();
		//previousSpot = scrollArray[1];
	}
}

function jumpToSubCategory(){
	var oSubCategorySelection = document.getElementById("subCategoryDropdown");
	if(oSubCategorySelection.options[oSubCategorySelection.selectedIndex].value != ""){
		window.location.href = "/industry.php?html_id=" + oSubCategorySelection.options[oSubCategorySelection.selectedIndex].value;
	}

}

function jumpToProfile(url,fid,box){
	if(box.checked){
		box.checked = false;
		window.location = url;
	}else{
		removeFranchiseList(fid);
	}
}

