var websearchpagenum;
var webquerytxt;
var websitesearch = "";
var webresultsize;
var pplsearchpagenum;
var pplquery;
var pplresultsize;
var pplsearchType;
var adminsectionopen = "";
var adminresultsize;
var adminsearchpagenum;
var adminAdminAlpha;
var depresultsize;
var depsearchpagenum;
var departmentvar;

WebPageClick = function(webpageclickednumber) {
	var querystring = "output=xml_no_dtd";
	websitesearch = websitesearch ? websitesearch : "";
	querystring += "&client=default_frontend";
	querystring += "&q=" + webquerytxt;
	querystring += "&sitesearch=" + websitesearch;
	querystring += "&start=" + ((+webresultsize * (webpageclickednumber - 1))); // the + unary forces a type conversion to number
	querystring += "&num=" + webresultsize;
	processouwebsearch(querystring);
	$("#webpager").pager({ pagenumber: webpageclickednumber, pagecount: websearchpagenum, buttonClickCallback: WebPageClick });
}
PplPageClick = function(pplpageclickednumber) {
	var querystring = "method=people";
	querystring += "&q=" + pplquery;
	querystring += "&start=" + (1 + (+pplresultsize * (pplpageclickednumber - 1))); // the + unary forces a type conversion to number
	querystring += "&num=" + pplresultsize;
	querystring += "&searchType=" + pplsearchType;
	processoupplsearch(querystring);
	$("#pplpager").pager({ pagenumber: pplpageclickednumber, pagecount: pplsearchpagenum, buttonClickCallback: PplPageClick });
}
AdminPageClick = function(adminpageclickednumber) {
	var querystring = "method=adminOffices";
	querystring += "&start=" + (1 + (+adminresultsize * (adminpageclickednumber - 1))); // the + unary forces a type conversion to number
	querystring += "&num=" + adminresultsize;
	querystring += "&adminAlpha=" + adminAdminAlpha;
	processouadminofficesearch(querystring);
	$("#pplpager").pager({ pagenumber: adminpageclickednumber, pagecount: adminsearchpagenum, buttonClickCallback: AdminPageClick });
}
DepPageClick = function(deppageclickednumber) {
	var querystring = "method=department";
	querystring += "&start=" + (1 + (+depresultsize * (deppageclickednumber - 1))); // the + unary forces a type conversion to number
	querystring += "&num=" + depresultsize;
	querystring += "&department=" + departmentvar;
	processoudepsearch(querystring);
	$("#pplpager").pager({ pagenumber: deppageclickednumber, pagecount: depsearchpagenum, buttonClickCallback: DepPageClick });
}
function processouwebsearch(querystring) {
	$("#webresultlist").empty();
	$("#webresultlist").append("<div id='searchresultinfo'><h2>Loading data...</h2></div>");
	$.ajax({
		url: "http://www.ou.edu/search",
		data: querystring, 
		dataType: "xml",
		error: function(){
			alert("This service is temporarily unavailable.");
		},
		success: function(xml){
			processouwebsearchXML(xml);
		},
		complete: function(){
			
		}
	});
}
function processouwebsearchXML(xmldata) {
	$("#webresultlist").empty();
	webquerytxt = $(xmldata).find("Q").text();
	$('#oupplsearch input:text[name=q]').val(webquerytxt);
	$(xmldata).find("PARAM").each(function(itemcount) {
		var paramtype = $(this).attr("name");
		if (paramtype == "num"){
			webresultsize =  $(this).attr("value");
		}
	});
	var requestedstartnumber = $(xmldata).find("start").text();
	var startnumber = $('RES', xmldata).attr('SN');
	var endnumber = $('RES', xmldata).attr('EN');
	var fullresultsize = $(xmldata).find("M").text();
	$("#webresultlist").append("<div id='searchresultinfo'><h2>OU Search Results</h2></div>");
	if (webquerytxt == ""){
		$("#webresultlist > div").append("No search term specified.");
	} else {
		$("#webresultlist > div").append("Results " + startnumber + " - " + endnumber + " of about " + fullresultsize + " for " + webquerytxt + ".");
	}
	$("#webresultlist").append("<ol></ol>");
	$(xmldata).find("R").each(function(itemcount) {
		var resultnum = $(this).attr('N');
		var title = $('T', this).text();
		var url = $('U', this).text();
		var urle = $('UE', this).text();
		var summary = $('S', this).text();
		$("#webresultlist ol").append("<li class'searchresult' id='result_num_" + resultnum + "'></li>");
		$("#webresultlist ol li#result_num_" + resultnum).append("<h3><a href='" + url + "'>" + title + "</a></h3>");
		$("#webresultlist ol li#result_num_" + resultnum).append("<div>" + summary + "<cite>" + urle + "</cite></div>");
	});
	if (startnumber < requestedstartnumber || ((endnumber - startnumber) + 1) < webresultsize){
		websearchpagenum =  Math.floor(((startnumber - 1) / webresultsize)) + 1;
		if (endnumber < fullresultsize){
			$("#webresultlist").append("<div id='webresultsexplanation'>In order to show you the most relevant results, we have omitted some entries very similar to the " + endnumber + " already displayed.</div>");
		}
	} else {
		websearchpagenum = Math.ceil(fullresultsize / webresultsize);
	}
	var presentpagenum = Math.floor(((startnumber - 1) / webresultsize)) + 1;
	$("#webpager").pager({ pagenumber: presentpagenum, pagecount: websearchpagenum, buttonClickCallback: WebPageClick });
}
function processoupplsearch(querystring) {
	$("#peoplelist").empty();
	$("#peoplelist").append("<div id='searchresultinfo'><h2>Loading data...</h2></div>");
	$("#pplpager").empty();
	// old access url http://129.15.7.216/common/services/searchServices.cfc
	$.ajax({
		url: "https://webapps.ou.edu/common/services/searchServices.cfc",
		data: querystring, 
		dataType: "jsonp",
		error: function(){
			$("#peoplelist").empty();
			$("#peoplelist").append("<div id='searchresultinfo'><h2>This service is temporarily unavailable.</h2></div>");
			alert("This service is temporarily unavailable.");
		},
		success: function(jsonData){
			$("#peoplelist").empty();
			var thismethod = jsonData.params[0].method;
			var thisstatus = jsonData.params[0].status;
			if (thismethod == "people" && thisstatus == "success") {
				var pplsearchTypename;
				pplsearchType = jsonData.params[0].searchType;
				if (pplsearchType == "") {
					pplsearchTypename = "All OU People";
				} else if (pplsearchType == "1,2,E,F,H") {
					pplsearchTypename = "OU Students";
				} else if (pplsearchType == "2,3,A,M,N,R,S") {
					pplsearchTypename = "OU Faculty and Staff";
				}
				var ppltotalRows = jsonData.params[0].totalRows;
				var pplstartnumber = jsonData.params[0].start;
				pplquery = jsonData.params[0].q;
				$("#ouwebsearch input:text[name=q]").val(pplquery);
				pplresultsize = jsonData.params[0].num;
				$("#peoplelist").append('<div id="searchresultinfo"><h2>' + pplsearchTypename + ' search Results for "<span class="personsearchterm">' + pplquery + '</span>"</h2></div>');
				$("#peoplelist").append("<div class='peoplecolumns' id='people_col_one'></div><div class='peoplecolumns' id='people_col_two'></div><div class='peoplecolumns' id='people_col_three'></div>");
				$.each( jsonData.people,
					function(itemcount, itemcontent) {
						if (itemcount >= 0 && itemcount < 15) {
							var personid = itemcontent.primaryid;
							$("#peoplelist #people_col_one").append("<div class='person' id='person_num_" + itemcount + "'><a href=''></a></div>");
							$("#peoplelist #people_col_one #person_num_" + itemcount + " a").append("<span class='personlname'>" + itemcontent.lastName + "</span>, ");
							$("#peoplelist #people_col_one #person_num_" + itemcount + " a").append("<span class='personfname'>" + itemcontent.firstName + "</span> ");
							$("#peoplelist #people_col_one #person_num_" + itemcount + " a").append("<span class='personmname'>" + itemcontent.middleName + "</span> ");
							$("#peoplelist #people_col_one #person_num_" + itemcount + " a").append("<span class='personsuffix'>" + itemcontent.gen + "</span>");
							$("#peoplelist #people_col_one #person_num_" + itemcount + " a").click(function () {
								var queryvars = "method=person";
								queryvars += "&primaryid=" + personid;
								processoupersonsearch(queryvars);
								return false;
							});
						} else if (itemcount >= 15 && itemcount < 30) {
							var personid = itemcontent.primaryid;
							$("#peoplelist #people_col_two").append("<div class='person' id='person_num_" + itemcount + "'><a href=''></a></div>");
							$("#peoplelist #people_col_two #person_num_" + itemcount + " a").append("<span class='personlname'>" + itemcontent.lastName + "</span>, ");
							$("#peoplelist #people_col_two #person_num_" + itemcount + " a").append("<span class='personfname'>" + itemcontent.firstName + "</span> ");
							$("#peoplelist #people_col_two #person_num_" + itemcount + " a").append("<span class='personmname'>" + itemcontent.middleName + "</span> ");
							$("#peoplelist #people_col_two #person_num_" + itemcount + " a").append("<span class='personsuffix'>" + itemcontent.gen + "</span>");
							$("#peoplelist #people_col_two #person_num_" + itemcount + " a").click(function () {
								var queryvars = "method=person";
								queryvars += "&primaryid=" + personid;
								processoupersonsearch(queryvars);
								return false;
							});
						} else if (itemcount >= 30 && itemcount < 45) {
							var personid = itemcontent.primaryid;
							$("#peoplelist #people_col_three").append("<div class='person' id='person_num_" + itemcount + "'><a href=''></a></div>");
							$("#peoplelist #people_col_three #person_num_" + itemcount + " a").append("<span class='personlname'>" + itemcontent.lastName + "</span>, ");
							$("#peoplelist #people_col_three #person_num_" + itemcount + " a").append("<span class='personfname'>" + itemcontent.firstName + "</span> ");
							$("#peoplelist #people_col_three #person_num_" + itemcount + " a").append("<span class='personmname'>" + itemcontent.middleName + "</span> ");
							$("#peoplelist #people_col_three #person_num_" + itemcount + " a").append("<span class='personsuffix'>" + itemcontent.gen + "</span>");
							$("#peoplelist #people_col_three #person_num_" + itemcount + " a").click(function () {
								var queryvars = "method=person";
								queryvars += "&primaryid=" + personid;
								processoupersonsearch(queryvars);
								return false;
							});
						}
					}
				)
				$("#people_col_one > div:odd").addClass("odd_people_row");
				$("#people_col_two > div:even").addClass("even_people_row");
				$("#people_col_three > div:odd").addClass("odd_people_row");
				pplsearchpagenum = Math.ceil(ppltotalRows / pplresultsize);
				var presentpagenum = Math.floor(((pplstartnumber - 1) / pplresultsize)) + 1;
				$("#pplpager").pager({ pagenumber: presentpagenum, pagecount: pplsearchpagenum, buttonClickCallback: PplPageClick });
			} else if (thismethod == "people" && thisstatus == "fail") {
				var thiserror = jsonData.params[0].errorMessage;
				$("#peoplelist").append("<div id='searchresultinfo'><h2>" + thiserror + "</h2></div>");
			} else if (thismethod != "people" && thisstatus == "fail") {
				$("#peoplelist").append("<div id='searchresultinfo'><h2>An invalid request has been made.</h2></div>");
			}
		},
		complete: function(){
		}
	});
}
function processoupersonsearch(querystring) {
	$("#peoplelist").empty();
	$("#peoplelist").append("<div id='searchresultinfo'><h2>Loading data...</h2></div>");
	$("#pplpager").empty();
	$.ajax({
		url: "https://webapps.ou.edu/common/services/searchServices.cfc",
		data: querystring,
		dataType: "jsonp",
		error: function(){
			$("#peoplelist").empty();
			$("#peoplelist").append("<div id='searchresultinfo'><h2>This service is temporarily unavailable.</h2></div>");
			alert("This service is temporarily unavailable.");
		},
		success: function(jsonData){
			$("#peoplelist").empty();
			var thismethod = jsonData.params[0].method;
			var thisstatus = jsonData.params[0].status;
			if (thismethod == "person" && thisstatus == "success") {
				$("#peoplelist").append('<div id="searchresultinfo"><h2>' + jsonData.person[0].fname + ' ' + jsonData.person[0].mname + ' ' + jsonData.person[0].lname + ' ' + jsonData.person[0].gen + '</h2></div>');
				$("#peoplelist").append("<p class='person' id='person_single'></p>");
				if (jsonData.person[0].title != "" && jsonData.person[0].title != " ") {
					$("#person_single").append("<span class='persontitle'><strong>Title:</strong> " + jsonData.person[0].title + "</span> ");
				}
				if (jsonData.person[0].deptTitle != "" && jsonData.person[0].deptTitle != " ") {
					$("#person_single").append("<span class='persontitle'><strong>Department Title:</strong> " + jsonData.person[0].deptTitle + "</span> ");
				}
				if (jsonData.person[0].alias != "" && jsonData.person[0].alias != " ") {
					$("#person_single").append("<span class='personalias'><strong>Email:</strong> " + jsonData.person[0].alias + " [at] ou [dot] edu</span> ");
				}
				if (jsonData.person[0].ophone != "" && jsonData.person[0].ophone != " ") {
					$("#person_single").append("<span class='personophone'><strong>Office Phone:</strong> " + jsonData.person[0].ophone + "</span> ");
				}
				if (jsonData.person[0].cphone != "" && jsonData.person[0].cphone != " ") {
					$("#person_single").append("<span class='personcphone'><strong>Campus Phone:</strong> " + jsonData.person[0].cphone + "</span> ");
				}
				if (jsonData.person[0].hphone != "" && jsonData.person[0].hphone != " ") {
					$("#person_single").append("<span class='personhphone'><strong>Home Phone:</strong> " + jsonData.person[0].hphone + "</span> ");
				}
				if (jsonData.person[0].dept != "" && jsonData.person[0].dept != " " && (jsonData.person[0].deptDept == "" || jsonData.person[0].deptDept == " ")) {
					$("#person_single").append("<span class='persondept'><strong>Department:</strong> " + jsonData.person[0].dept + "</span> ");
				}
				if (jsonData.person[0].dept != "" && jsonData.person[0].dept != " " && jsonData.person[0].deptDept != "" && jsonData.person[0].deptDept != " ") {
					$("#person_single").append("<span class='persondept'><a href=''><strong>Department:</strong> " + jsonData.person[0].dept + "</a></span> ");
				}
				if (jsonData.person[0].loc != "" && jsonData.person[0].loc != " ") {
					$("#person_single").append("<span class='personlocation'><strong>Location:</strong> " + jsonData.person[0].loc + "</span> ");
				}
				if (jsonData.person[0].stuclass != "" && jsonData.person[0].stuclass != " ") {
					$("#person_single").append("<span class='personclass'><strong>Student Classification:</strong> " + jsonData.person[0].stuclass + "</span> ");
				}
				if (jsonData.person[0].col != "" && jsonData.person[0].col != " ") {
					$("#person_single").append("<span class='personcollege'><strong>College:</strong> " + jsonData.person[0].col + "</span> ");
				}
				if (jsonData.person[0].haddr != "" && jsonData.person[0].haddr != " ") {
					$("#person_single").append("<span class='personhaddr'><strong>Home Address:</strong> " + jsonData.person[0].haddr + "</span> ");
				}
				if (jsonData.person[0].caddr != "" && jsonData.person[0].caddr != " ") {
					$("#person_single").append("<span class='personcaddr'><strong>Campus Address:</strong> " + jsonData.person[0].caddr + "</span> ");
				}
				if (jsonData.person[0].url1 != "" && jsonData.person[0].url1 != " ") {
					$("#person_single").append("<span class='personurl'><strong>URL:</strong> " + jsonData.person[0].url1 + "</span>");
				}
				if (jsonData.person[0].deptDept != "" && jsonData.person[0].deptDept != " ") {
					$("#person_single > .persondept > a").click(function () {
						$("#tabs").tabs('select', 2);
						var queryvars = "method=department";
						queryvars += "&start=1";
						queryvars += "&num=" + depresultsize;
						queryvars += "&department=" + escape(jsonData.person[0].deptDept);
						processoudepsearch(queryvars);
						return false;
					});
				}
			} else if (thismethod == "person" && thisstatus == "fail") {
				var thiserror = jsonData.params[0].errorMessage;
				$("#peoplelist").append("<div id='searchresultinfo'><h2>" + thiserror + "</h2></div>");
			} else if (thismethod != "person" && thisstatus == "fail") {
				$("#peoplelist").append("<div id='searchresultinfo'><h2>An invalid request has been made.</h2></div>");
			}
		},
		complete: function(){
		}
	});
}
function processoudepsearch(querystring) {
	$("#deplist").empty();
	$("#deplist").append("<div id='searchresultinfo'><h2>Loading data...</h2></div>");
	$("#deppager").empty();
	$.ajax({
		url: "https://webapps.ou.edu/common/services/searchServices.cfc",
		data: querystring,
		dataType: "jsonp",
		error: function(){
			$("#deplist").empty();
			$("#deplist").append("<div id='searchresultinfo'><h2>This service is temporarily unavailable.</h2></div>");
			alert("This service is temporarily unavailable.");
		},
		success: function(jsonData){
			$("#deplist").empty();
			var thismethod = jsonData.params[0].method;
			var thisstatus = jsonData.params[0].status;
			if (thismethod == "department" && thisstatus == "success") {
				var depstartnumber = jsonData.params[0].start;
				var deptotalRows = jsonData.params[0].totalRows;
				depresultsize = jsonData.params[0].num;
				departmentvar = jsonData.params[0].department;
				$("#deplist").append('<div id="searchresultinfo"><h2>Department Results for "<span class="personsearchterm">' + departmentvar + '</span>"</h2></div><table id="deptable"></table');
				$.each( jsonData.departments,
					function(itemcount, itemcontent) {
						$("#deptable").append("<tr class='department'><td class='departmentname'>" + itemcontent.department + "</td><td>&nbsp;</td></tr>");
						$.each( itemcontent.members,
							function(inneritemcount, inneritemcontent) {
								$("#deptable").append("<tr class='dep_person'></tr>");
								if (inneritemcontent.chair == "1") {
									$("#deptable .dep_person:last").append("<td class='personchair'></td> ");
									$("#deptable .dep_person:last .personchair").append("<span class='personlname'>" + inneritemcontent.lastName + "</span>, ");
									$("#deptable .dep_person:last .personchair").append("<span class='personfname'>" + inneritemcontent.firstName + "</span> ");
									$("#deptable .dep_person:last .personchair").append("<span class='personmname'>" + inneritemcontent.middleName + "</span>, ");
									$("#deptable .dep_person:last .personchair").append("<span class='persontitle'>" + inneritemcontent.title + "</span> ");
								}
								if (inneritemcontent.chair == "0") {
									$("#deptable .dep_person:last").append("<td class='personnotchair'></td> ");
									$("#deptable .dep_person:last .personnotchair").append("<span class='personlname'>" + inneritemcontent.lastName + "</span>, ");
									$("#deptable .dep_person:last .personnotchair").append("<span class='personfname'>" + inneritemcontent.firstName + "</span> ");
									$("#deptable .dep_person:last .personnotchair").append("<span class='personmname'>" + inneritemcontent.middleName + "</span>, ");
									$("#deptable .dep_person:last .personnotchair").append("<span class='persontitle'>" + inneritemcontent.title + "</span> ");
								}
								$("#deptable .dep_person:last").append("<td class='personphone'>" + inneritemcontent.phone + "</td> ");
							}
						);
					}
				);
				$("#deptable tr:odd").addClass("odd_dept_row");
				depsearchpagenum = Math.ceil(deptotalRows / depresultsize);
				var presentpagenum = Math.floor(((depstartnumber - 1) / depresultsize)) + 1;
				$("#deppager").pager({ pagenumber: presentpagenum, pagecount: depsearchpagenum, buttonClickCallback: DepPageClick });
			} else if (thismethod == "department" && thisstatus == "fail") {
				var thiserror = jsonData.params[0].errorMessage;
				$("#deplist").append("<div id='searchresultinfo'><h2>" + thiserror + "</h2></div>");
			} else if (thismethod != "department" && thisstatus == "fail") {
				$("#deplist").append("<div id='searchresultinfo'><h2>An invalid request has been made.</h2></div>");
			}
		},
		complete: function(){
		}
	});
}
function processouadminofficesearch(querystring) {
	$("#adminofficelist").empty();
	$("#adminofficelist").append("<div id='searchresultinfo'><h2>Loading data...</h2></div>");
	$("#adminpager").empty();
	$.ajax({
		url: "https://webapps.ou.edu/common/services/searchServices.cfc",
		data: querystring,
		dataType: "jsonp",
		error: function(){
			$("#adminofficelist").empty();
			$("#adminofficelist").append("<div id='searchresultinfo'><h2>This service is temporarily unavailable.</h2></div>");
			alert("This service is temporarily unavailable.");
		},
		success: function(jsonData){
			$("#adminofficelist").empty();
			var thismethod = jsonData.params[0].method;
			var thisstatus = jsonData.params[0].status;
			if (thismethod == "adminOffices" && thisstatus == "success") {
				var adminstartnumber = jsonData.params[0].start;
				var admintotalRows = jsonData.params[0].totalRows;
				adminresultsize = jsonData.params[0].num;
				$("#adminofficelist").append('<div id="searchresultinfo"><h2>Administrative Offices</h2></div>');
				$("#adminofficelist").append('<table class="people"><tr><th>Department Name</th><th>Phone Number*</th></tr></table>');
				$.each( jsonData.offices,
					function(itemcount, itemcontent) {
						var containssections = itemcontent.sections;
						$("#adminofficelist .people").append("<tr class='person' id='admin_office_" + itemcount + "'></tr>");
						if (containssections > 0) {
							$("#adminofficelist .people #admin_office_" + itemcount).append("<td class='officefieldone'><a href=''>" + itemcontent.OFFICE_NAME + "</a></td><td class='officefieldtwo'><a href=''>" + itemcontent.OFFICE_PHONE + "</a></td>");
							$("#adminofficelist .people #admin_office_" + itemcount + " a").click(function () {
								var adminsectionopencheck = "#admin_section_" + itemcount;
								if (adminsectionopen == adminsectionopencheck) {
									$("#adminofficelist .people #admin_section_" + itemcount).remove();
									adminsectionopen = "";
								} else if (adminsectionopen == "") {
									adminsectionopen = adminsectionopencheck;
									$("#adminofficelist .people #admin_office_" + itemcount).after("<tr class='person' id='admin_section_" + itemcount + "'><td class='officefieldone'></td><td class='officefieldtwo'></td></tr>");
									var queryvars = "method=adminSections";
									queryvars += "&OFFICE_KEY=" + itemcontent.OFFICE_KEY;
									var infotarget = "#adminofficelist .people #admin_section_" + itemcount;
									processouadminsectionsearch(queryvars, infotarget);
								} else if (adminsectionopen != adminsectionopencheck && adminsectionopen != "") {
									$(adminsectionopen).remove();
									adminsectionopen = adminsectionopencheck;
									$("#adminofficelist .people #admin_office_" + itemcount).after("<tr class='person' id='admin_section_" + itemcount + "'><td class='officefieldone'></td><td class='officefieldtwo'></td></tr>");
									var queryvars = "method=adminSections";
									queryvars += "&OFFICE_KEY=" + itemcontent.OFFICE_KEY;
									var infotarget = "#adminofficelist .people #admin_section_" + itemcount;
									processouadminsectionsearch(queryvars, infotarget);
								}
								return false;
							});
						} else if (containssections == 0) {
							$("#adminofficelist .people #admin_office_" + itemcount).append("<td class='officefieldone'>" + itemcontent.OFFICE_NAME + "</td><td class='officefieldtwo'>" + itemcontent.OFFICE_PHONE + "</td>");
						}
					}
				)
				$("#adminofficelist .people tr:odd").addClass("odd_dept_row");
				adminsearchpagenum = Math.ceil(admintotalRows / adminresultsize);
				var presentpagenum = Math.floor(((adminstartnumber - 1) / adminresultsize)) + 1;
				$("#adminpager").pager({ pagenumber: presentpagenum, pagecount: adminsearchpagenum, buttonClickCallback: AdminPageClick });
			} else if (thismethod == "adminOffices" && thisstatus == "fail") {
				var thiserror = jsonData.params[0].errorMessage;
				$("#adminofficelist").append("<div id='searchresultinfo'><h2>" + thiserror + "</h2></div>");
			} else if (thismethod != "adminOffices" && thisstatus == "fail") {
				$("#adminofficelist").append("<div id='searchresultinfo'><h2>An invalid request has been made.</h2></div>");
			}
		},
		complete: function(){
		}
	});
}
function processouadminsectionsearch(querystring, infotarget) {
	$.ajax({
		url: "https://webapps.ou.edu/common/services/searchServices.cfc",
		data: querystring,
		dataType: "jsonp",
		error: function(){
			$("#adminofficelist").empty();
			$("#adminofficelist").append("<div id='searchresultinfo'><h2>This service is temporarily unavailable.</h2></div>");
			alert("This service is temporarily unavailable.");
		},
		success: function(jsonData){
			var thismethod = jsonData.params[0].method;
			var thisstatus = jsonData.params[0].status;
			if (thismethod == "adminSections" && thisstatus == "success") {
				if (jsonData.sections.length == "0") {
					$(infotarget + " .officefieldone").append("<span class='sectionfieldone'>No additional information available.</span> ");
				}
				$.each( jsonData.sections,
					function(itemcount, itemcontent) {
						var personid = itemcontent.primaryid;
						var sec_name = itemcontent.SECTION_NAME;
						var sec_phone = itemcontent.SECTION_PHONE;
						if (itemcontent.SECTION_NAME == "" && itemcontent.SECTION_PHONE == "") {
							sec_name = "No additional information available."
						}
						$(infotarget + " .officefieldone").append("<span class='sectionfieldone'>" + sec_name + "&nbsp;</span> ");
						$(infotarget + " .officefieldtwo").append("<span class='sectionfieldtwo'>" + sec_phone + "&nbsp;</span> ");
					}
				)
			} else if (thismethod == "adminSections" && thisstatus == "fail") {
				var thiserror = jsonData.params[0].errorMessage;
				$("#adminofficelist").append("<div id='searchresultinfo'><h2>" + thiserror + "</h2></div>");
			} else if (thismethod != "adminSections" && thisstatus == "fail") {
				$("#adminofficelist").append("<div id='searchresultinfo'><h2>An invalid request has been made.</h2></div>");
			}
		},
		complete: function(){
		}
	});
}
function tagAdminOfficeAlphaList() {
	$("#adminofficealphalist li a").each(
		function(itemcount, itemcontent){
			$(itemcontent).click(function () {
				var queryvars = "method=adminOffices";
				adminAdminAlpha = $(itemcontent).text();
				queryvars += "&start=1";
				queryvars += "&num=" + adminresultsize;
				queryvars += "&adminAlpha=" + adminAdminAlpha;
				processouadminofficesearch(queryvars);
				return false;
			});
		}
	);
}
function tagDepAlphaList() {
	$("#depalphalist li a").each(
		function(itemcount, itemcontent){
			$(itemcontent).click(function () {
				var queryvars = "method=department";
				departmentvar = $(itemcontent).text();
				queryvars += "&start=1";
				queryvars += "&num=" + depresultsize;
				queryvars += "&department=" + departmentvar;
				processoudepsearch(queryvars);
				return false;
			});
		}
	);
}
function switchSearchTabs() {
	var $tabs = $('#tabs').tabs();
	var selectedtab = $tabs.tabs('option', 'selected');
	if (selectedtab == "0"){
		var querytxt = "";
		querytxt = $('#ouwebsearch input:text[name=q]').val();
		if (querytxt == ""){
			$("#webresultlist").empty();
			$("#webpager").empty();
		} else if (querytxt != ""){
			$('#ouwebsearch input:text[name=q]').css("backgroundImage","none");
			websitesearch = websitesearch ? websitesearch : "";
			querytxt = "&q=" + querytxt;
			querytxt += "&sitesearch=" + websitesearch;
			querytxt += "&client=default_frontend";
			querytxt += "&num=" + webresultsize;
			querytxt += "&output=xml_no_dtd";
			processouwebsearch(querytxt);
		}
	}
	if (selectedtab == "1"){
		var querytxt = "";
		querytxt = $('#oupplsearch input:text[name=q]').val();
		if (querytxt == ""){
			$("#peoplelist").empty();
			$("#pplpager").empty();
		} else if (querytxt != ""){
			$('#oupplsearch input:text[name=q]').css("backgroundImage","none");
			querytxt = "&q=" + querytxt;
			querytxt += "&method=people";
			querytxt += "&start=1";
			querytxt += "&num=" + pplresultsize;
			querytxt += "&searchtype=";
			processoupplsearch(querytxt);
		}
	}
	$("#deplist").empty();
	$("#deppager").empty();
	$("#adminofficelist").empty();
	$("#adminpager").empty();
}
function catchExternalParams() {
	var externaltype = jQuery.url.param("type");
	var externalsitesearch = jQuery.url.param("sitesearch");
	var externalq = jQuery.url.param("q");
	externalq = externalq ? externalq : "";
	if (externaltype == "web"){
		$("#tabs").tabs('select', 0);
		if (externalq != ""){
			websitesearch = externalsitesearch ? externalsitesearch : "";
			var querystring = "&q=" + externalq;
			querystring += "&sitesearch=" + websitesearch;
			querystring += "&client=default_frontend";
			querystring += "&num=" + webresultsize;
			querystring += "&output=xml_no_dtd";
			$('#oupplsearch input:text[name=q]').val(externalq);
			processouwebsearch(querystring);
		}
	} else if (externaltype == "people"){
		$("#tabs").tabs('select', 1);
		if (externalq != ""){
			var querystring = "&q=" + externalq;
			querystring += "&method=people";
			querystring += "&start=1";
			querystring += "&num=" + pplresultsize;
			querystring += "&searchtype=";
			$('#ouwebsearch input:text[name=q]').val(externalq);
			processoupplsearch(querystring);
		}
	} else if (externaltype == "dept"){
		$("#tabs").tabs('select', 2);
		if (externalq != ""){
			var queryvars = "method=department";
			departmentvar = externalq;
			queryvars += "&start=1";
			queryvars += "&num=" + depresultsize;
			queryvars += "&department=" + departmentvar;
			processoudepsearch(queryvars);
		}
	} else if (externaltype == "adminoffice"){
		$("#tabs").tabs('select', 3);
		if (externalq != ""){
			var queryvars = "method=adminOffices";
			adminAdminAlpha = externalq;
			queryvars += "&start=1";
			queryvars += "&num=" + adminresultsize;
			queryvars += "&adminAlpha=" + adminAdminAlpha;
			processouadminofficesearch(queryvars);
		}
	}
}
function setAppDefaults() {
	$.ajaxSetup({
		timeout: 2000,
		cache: true
	});
	if ($.client.os == "iPhone/iPod"){
		pplresultsize = 30;
		depresultsize = 12;
		adminresultsize = 15;
		webresultsize = 20;
	} else {
		pplresultsize = 45;
		depresultsize = 20;
		adminresultsize = 25;
		webresultsize = 20;
	}
}