
// -------------------------
// Employee Photos JS code
// -------------------------

function loadImages(_IDs)
{
	// Pass in a CSV of IDs which then get split to 
	// pre-load the necessary images
	
	arrIDs = _IDs.split(",");
	images = new Array();
	var i = 0;
	for (i=0; i<=arrIDs.length; i++)
	{
		images[i] = "/res/images/people/" + arrIDs[i] + ".jpg";
	}
	
	// Pre-loading
	
    imageObj = new Image();
	for (i=0; i<=images.length; i++)
	{
		imageObj.src=images[i];  
	}		
}

function getPhotoContent(photoID)
{
	var baseLink = "/default.aspx?Section=page&p=/peopleandoffices/&f=uk";
	document.location.href = baseLink + "&employeeid=" + photoID;
}

function showEmployee(photoOrdinal, _Name, _Office, _Department, _Email, _Telephone, _EmployeeID)
{
	document.imgPhoto.src = images[photoOrdinal];

	document.getElementById("employeeName").textContent = _Name;	
	document.getElementById("employeeOffice").textContent = _Office;
	document.getElementById("employeeDepartment").textContent = _Department;	
	document.getElementById("employeeEmail").textContent = _Email;	
	document.getElementById("employeeEmail").href = "mailto:" + _Email;	
	document.getElementById("employeeTelephone").textContent = _Telephone;	
	document.getElementById("employeeVCard").href = "downloadVCard.aspx?employeeid=" + _EmployeeID;
	document.getElementById("employeeVCard").textContent = "Add this Contact to your Address book";
	
	document.getElementById("employeeName").innerText = _Name;	
	document.getElementById("employeeOffice").innerText = _Office;
	document.getElementById("employeeDepartment").innerText = _Department;	
	document.getElementById("employeeEmail").innerText = _Email;	
	document.getElementById("employeeEmail").href = "mailto:" + _Email;	
	document.getElementById("employeeTelephone").innerText = _Telephone;	
	document.getElementById("employeeVCard").href = "downloadVCard.aspx?employeeid=" + _EmployeeID;
	document.getElementById("employeeVCard").innerText = "Add this Contact to your Address book";

}

function hidephotoImage()
{
	document.getElementById("employeeName").textContent = " ";	
	document.getElementById("employeeOffice").textContent = " ";
	document.getElementById("employeeDepartment").textContent = " ";	
	document.getElementById("employeeEmail").textContent = " ";	
	document.getElementById("employeeTelephone").textContent = " ";	
	document.getElementById("employeeVCard").textContent = " ";

	document.getElementById("employeeName").innerText = " ";	
	document.getElementById("employeeOffice").innerText = " ";
	document.getElementById("employeeDepartment").innerText = " ";	
	document.getElementById("employeeEmail").innerText = " ";	
	document.getElementById("employeeTelephone").innerText = " ";	
	document.getElementById("employeeVCard").innerText = " ";
}

// -------------------------
//  Find Nearest JS Code
// -------------------------

var findNearest_showingContact;
var employeeList_populatingDropdown;

function findNearest_showContact(departmentname,obj)
{
	var aoeid;
		
	if(findNearest_showingContact==true)
	{
		// Don't do anything - we're programmatically changing
		// the dropdown selected value				
	}
	else
	{
		findNearest_showingContact = true;	

		switch (departmentname)
		{
		case "companycommercial":
			aoeid=1;
			break;
		case "commercialproperty":
			aoeid=2;
			break;
		case "commerciallitigation":
			aoeid=3;
			break;
		case "residentialconveyancing":
			aoeid=4;
			break;
		case "employment":
			aoeid=5;
			break;
		case "disputes":
			aoeid=6;
			break;
		case "familychildren":
			aoeid=7;
			break;
		case "crime":
			aoeid=8;
			break;
		case "licensingmatters":
			aoeid=9;
			break;
		case "willstax":
			aoeid=10;
			break;
		case "probate":
			aoeid=11;
			break;
		case "notarialservices":
			aoeid=12;
			break;
		}

		var selectedValue;
		var selectedOffice;
		selectedValue = Number(obj.value);
		selectedOffice = obj.options[obj.selectedIndex].text.toLowerCase()
		
		findNearest_showingContact == false;
		obj.value = 0;
		obj.selectedIndex = 0;
		document.location.href = "/?section=page&p=/peopleandoffices/&f=people" + selectedOffice + "&aoeid=" + aoeid;
		
		/*									
		var selectedValue;
		var selectedOffice;
		selectedValue = Number(obj.value);
		selectedOffice = obj.options[obj.selectedIndex].text.toLowerCase()
	
		// Set dropdown back to 'choose office' so back button
		// doesn't fire off a redirect again!
		obj.value = 0;
		*/
		
		//document.location.href = "/?section=page&p=/peopleandoffices/&f=people" + selectedOffice + "&employeeid=" + selectedValue;				
	}
}

// -------------------------
// Find Lawyer JS code
// -------------------------

var findLawyer_populatingDropdown = false;

function findLawyer_criteriaChanged()
{
	var ddlOffice = document.getElementById("office");
	var ddlAOE = document.getElementById("service");
	var officeid = -1;
	var aoeid = -1;
	
	if (ddlOffice.value == 0)
	{
		officeid = -1;
	}
	else
	{
		officeid = ddlOffice.value;
	}
	if (ddlAOE.value == 0)
	{
		aoeid = -1;
	}
	else
	{
		aoeid = ddlAOE.value;				
	}				
	_default.findLawyer_populateLawyers(officeid,aoeid,findLawyer_populateLawyersCallBack);					
}		

function findLawyer_populateLawyersCallBack(res)
{
	findLawyer_populatingDropdown = true;
	var res2string = res.value;
	var splitout = new Array();
	splitout = res2string.split("|");
	ddlLawyers = document.getElementById("lawyer");
	ddlLawyers.options.length = 0;
	
	var i=0;
	for (i=0; i<splitout.length;i+=3)
	{
		newoption = document.createElement("option");
		newoption.text = splitout[i + 1];
		newoption.value = splitout[i] + "," + splitout[i+2];

		try 
		{
		    ddlLawyers.add(newoption, null); // standards compliant; doesn't work in IE
		}
		catch (ex) 
		{
		    ddlLawyers.add(newoption); // IE only
		}		
    }
	findLawyer_populatingDropdown = false;
}

function findLawyer_showSelectedLawyer(obj)
{
	if (!findLawyer_populatingDropdown)
	{
		// Browse to selected Employee profile
	
		findLawyer_populatingDropdown = true;										
		var selectedValue;
		var selectedOffice;
		splitout = obj.value.split(",");
		selectedValue = splitout[0];
		selectedOffice = splitout[1];
			
		// Set dropdown back to 'choose office' so back button
		// doesn't fire off a redirect again!
		
		obj.value = 0;
	
		findLawyer_populatingDropdown == false;
		document.location.href = "/?section=page&p=/peopleandoffices/&f=people" + selectedOffice + "&employeeid=" + selectedValue;							
	}
}

// Employee List

function employeeList_selectPerson(obj)
{
	var employeeId;
	employeeId = obj.value;	
	_default.employeeList_getPersonDetails(employeeId,employeeList_selectPersonCallBack);
}

function employeeList_selectPersonCallBack(res)
{
	var res2string = res.value;
	var splitout = new Array();
	splitout = res2string.split("|");
	document.getElementById("employeeName").textContent = splitout[0];	
	document.getElementById("employeeOffice").textContent = splitout[1];
	document.getElementById("employeeDepartment").textContent = splitout[2];	
	document.getElementById("employeeEmail").textContent = splitout[3];	
	document.getElementById("employeeEmail").href = "mailto:" + splitout[3];	
	document.getElementById("employeeTelephone").textContent = splitout[4];	
	document.getElementById("employeeVcard").href = "downloadVCard.aspx?employeeid=" + splitout[5];
	document.getElementById("employeeVcard").textContent = "Add this Contact to your Address book";
	document.getElementById("employeeProfile").textContent = splitout[7];
	document.getElementById("profileCaption").textContent = "Profile for " + splitout[0];
	
	document.getElementById("employeeName").innerText = splitout[0];	
	document.getElementById("employeeOffice").innerText = splitout[1];
	document.getElementById("employeeDepartment").innerText = splitout[2];	
	document.getElementById("employeeEmail").innerText = splitout[3];	
	document.getElementById("employeeEmail").href = "mailto:" + splitout[3];	
	document.getElementById("employeeTelephone").innerText = splitout[4];	
	document.getElementById("employeeVcard").href = "downloadVCard.aspx?employeeid=" + splitout[5];
	document.getElementById("employeeVcard").innerText = "Add this Contact to your Address book";		
	document.getElementById("employeeProfile").innerText = splitout[7];
	document.getElementById("profileCaption").innerText = "Profile for " + splitout[0];

	document.imgPhoto.src = splitout[6];	
}

// -------------------------
// People Search JS code
// -------------------------

function peopleSearch_criteriaChanged()
{
	var ddlOffice = document.getElementById("peopleoffice");
	var ddlAOE = document.getElementById("peopleservice");
	var officeid = -1;
	var aoeid = -1;
	
	if (ddlOffice.value == 0)
	{
		officeid = -1;
	}
	else
	{
		officeid = ddlOffice.value;
	}
	if (ddlAOE.value == 0)
	{
		aoeid = -1;
	}
	else
	{
		aoeid = ddlAOE.value;				
	}				
		
	if ((officeid != -1) && (aoeid == -1))
	{
		// If just an office selected then just browse to appropriate page - jobs a good un	
		document.location.href = "/?section=page&p=/peopleandoffices/&f=people" + ddlOffice.options[ddlOffice.selectedIndex].text.toLowerCase();
	}
	else if ((officeid == -1) && (aoeid != -1))
	{
		// If just an AOEID selected then browse to page filtered by service
		document.location.href = "/?section=page&p=/peopleandoffices/&f=peopleletchworth&aoeid=" + aoeid + "&alloffices=1";
	}
	else if ((officeid != -1) && (aoeid != -1))
	{
		// Both an office and an service selected - go to office page PLUS filter
		document.location.href = "/?section=page&p=/peopleandoffices/&f=people" + ddlOffice.options[ddlOffice.selectedIndex].text.toLowerCase() + "&aoeid=" + aoeid;	
	}
}

// --------------------------------------------
// Select or Upload a File (res/img/CMSGallery)
// --------------------------------------------

function SelectPicture()
{	
	var url = "/res/cms/cmsImages.aspx";
	// display popup window allowing user to select from an image list, or upload their own
	flist = "dialogHeight:520px;dialogWidth:800px;resizable:yes;";

	var myObject = new Object();
	myObject.cancel = true;
	myObject.imagePath = "";
	myObject.testString = "Hello";

	var dialog = window.showModalDialog(url, myObject, flist);

	if (myObject.cancel) return;
	document.getElementById("txtPicture").value = myObject.imagePath;			
}

// --------------------------------------------
// Select or Upload a Photo (res/images/people)
// --------------------------------------------

function SelectPhoto()
{	
	var url = "/res/cms/cmsEmployeeImages.aspx";
	// display popup window allowing user to select from an image list, or upload their own
	flist = "dialogHeight:520px;dialogWidth:800px;resizable:yes;";

	var myObject = new Object();
	myObject.cancel = true;
	myObject.imagePath = "";
	myObject.testString = "Hello";

	var dialog = window.showModalDialog(url, myObject, flist);

	if (myObject.cancel) return;
	document.getElementById("txtPhoto").value = myObject.imagePath;			
}
