// JavaScript Document

function MM_reloadPage(init)
{  //reloads the window if Nav4 resized
	if (init==true) with (navigator)
	{
		if ((appName=="Netscape")&&(parseInt(appVersion)==4))
		{
			document.MM_pgW=innerWidth; document.MM_pgH=innerHeight; onresize=MM_reloadPage;
		}
	}
	else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) 
	{
		location.reload();
	}
}

MM_reloadPage(true);


function MM_openBrWindow(theURL,winName,features)
{ //v2.0
  window.open(theURL,winName,features);
}

function Split_URL(URL)
{
	var slash_separator = "/";
	var slash_arrayofStrings = URL.split(slash_separator);
	var dot_separator = ".";
	var dot_arrayofStrings = slash_arrayofStrings[2].split(dot_separator);
	
	if((slash_arrayofStrings[3] != "") && (slash_arrayofStrings[4] == ""))
	{
		var temp_dept = slash_arrayofStrings[3];
		
		if((temp_dept == "aero") || (temp_dept == "bsen") || (temp_dept == "chen") || (temp_dept == "civil") || (temp_dept == "comp") || (temp_dept == "csse") || (temp_dept == "ece") || (temp_dept == "elec") || (temp_dept == "ise") || (temp_dept == "insy") || (temp_dept == "matl") || (temp_dept == "mech") || (temp_dept == "pfen") || (temp_dept == "txen") || (temp_dept == "wireless"))
		{
			return "programs/"+slash_arrayofStrings[3];
		}
		else
		{/**/
			return slash_arrayofStrings[3];
		}
	}
		
	if((slash_arrayofStrings[3] != "") && (slash_arrayofStrings[4] != "programs") && (slash_arrayofStrings[4] != "centers"))
	{
		if(slash_arrayofStrings[3] == "programs")
		{
			return slash_arrayofStrings[3]+"/"+slash_arrayofStrings[4];
		}
		else
		{
			return slash_arrayofStrings[4];
		}
		
	}
	
	if((slash_arrayofStrings[3] == "") && (slash_arrayofStrings[4] == "programs"))
	{
		if(slash_arrayofStrings[4] == "programs")
		{
			return slash_arrayofStrings[4]+"/"+slash_arrayofStrings[5];
		}
		else
		{
			return slash_arrayofStrings[4];
		}
		
		//return slash_arrayofStrings[5];
	}

	if((slash_arrayofStrings[3] != "") && (slash_arrayofStrings[4] == "centers"))
	{
		return slash_arrayofStrings[4]+"/"+slash_arrayofStrings[5];
	}
	
	if((slash_arrayofStrings[3] == "") && (slash_arrayofStrings[4] == ""))
	{
		return dot_arrayofStrings[0];
	}
	
	if(slash_arrayofStrings[2] != "www.eng.auburn.edu")
	{
		return dot_arrayofStrings[1];
	}
	
	if((slash_arrayofStrings[2] != "www.eng.auburn.edu") && (slash_arrayofStrings[3] == "courses"))
	{
		return dot_arrayofStrings[1];
	}
	
	if((dot_arrayofStrings[1] == "engce"))
	{
		if((slash_arrayofStrings[3] == "courses"))
		{
			return dot_arrayofStrings[1];
		}
	}
}
	
function get_dept(path)
{
	var tempStr = Split_URL(locale);
	var splitStr = tempStr.split("/");
	var area = splitStr[0];
	var dept = splitStr[1];
	var fnldept = "";
	
	if(area == "programs")
	{
		if(dept == "comp")
		{
			fnldept = "csse";
		}
		else if(dept == "txen")
		{
			fnldept = "pfen";
		}
		else if(dept == "elec")
		{
			fnldept = "ece";
		}
                else
                {
                        fnldept = dept;
                }
	}
	else
	{
		fnldept = dept;
	}
	
	return fnldept;

}
function get_subDir(url)
{
	// Variable Declarations
	var firstdotIndex = 0;
	var subdomain = "";
	var firstsubDirIndex = 0;
	var firstsubDir = "";
	var firstsubDirLen = 0;
	var scndsubDirIndex = 0;
	var scndsubDir = "";
	var thirdSubDirIndex = 0;
	var thirdSubDir = "";
	var startIndex = 0;
	var subDir = "";
	
	/* Find the subdomain of the url.*/
	var firstdotIndex = url.indexOf(".", 0);
	var subdomain = url.substr(7, 3);
	var startIndex = 0;
	
	if(subdomain == "eng")
	{
		startIndex = 22;  // without www
	}
	else
	{
		startIndex = 26;  // with www
	}

	var firstsubDirIndex = url.indexOf("/", startIndex);
	var firstsubDir = url.substr(startIndex, (firstsubDirIndex-startIndex));
	var firstsubDirLen = firstsubDir.length;
	var subDir = "";
	
	/* If no child directory exists then we're at the root level of the directory structure. */
	if(firstsubDirIndex == -1)
	{
		/* If we're at the site's root level then return a NULL value.*/
		if(firstsubDirIndex == url.length)
		{
			var pgNm = url.substr(startIndex, url.length);
			if(pgNm == -1)
			{
				subDir = "";
			}
			else
			{
				subDir = "";
			}
		}
		else
		{
			subDir = "";
		}
		
	}
	else if((firstsubDirLen >= 5))
	{
		/* If the first child has a descendant then check its name to determine if its name is either
		   centers or programs. If the first child doesn't have a descendant then return the name of 
		   the parent. */
		   
		
		var scndsubDirIndex = url.indexOf("/", (firstsubDirIndex+1));
		var scndsubDir = url.substr((firstsubDirIndex+1), (scndsubDirIndex-1) - (firstsubDirIndex));
		
		if(scndsubDirIndex != -1)
		{
			/* If the first child has a descendant then check its name to determine if its name is either
			   is centers or programs. If it isn't then return name of the descandants parent. */
			if(scndsubDir == "centers")
			{
				/* If the descendant's name equals 'center' then determine if the descendant has a 
				   descendant of it's own. (great grandchild of the original parent)*/
				   
				var thirdSubDirIndex = url.indexOf("/", (scndsubDirIndex+1));
				var thirdSubDir = url.substr((scndsubDirIndex+1), (thirdSubDirIndex-1) - (scndsubDirIndex));
				
				/* If a great grandchild exists then set its name as the value of subDir. If not then
				   the value of subDir is set to the name of grand child.*/
				if(thirdSubDir != -1)
				{
					subDir = thirdSubDir;
				}
				else
				{
					subDir = scndsubDir;
				}
			}
			else
			{
				subDir = scndsubDir;
			}
		}
		else
		{
			subDir = firstsubDir;
		}
		
	}
	else
	{
		if(firstsubDir == "comp")
		{
			subDir = "csse";
		}
		else if(firstsubDir == "elec")
		{
			subDir = "ece";
		}
		else if(firstsubDir == "txen")
		{
			subDir = "pfen";
		}
		else
		{
			subDir = firstsubDir;
		}
	}
	
	return subDir;

}
/*function print_titleGraphic()
{
	var locale = new String(window.location);
	var tempStr = Split_URL(locale);
	var splitStr = tempStr.split("/");
	var area = splitStr[0];
	var dept = splitStr[1];
	var deptSplit = dept.split(".");
	var pageNm = deptSplit[0];
	var ext = deptSplit[1];
	var bckgrndImgURL = "";
	var width = "";
	var height = "";
	var tG = document.getElementById("titleGraphic");

	if(document.getElementById)
	{
		if(area == "programs")
		{
			if((dept == "grad-school") || (dept == "gei") || (ext == "html"))
			{
				bckgrndImgURL = "url(http://www.eng.auburn.edu/images/global/arch-headerimage.jpg)";
			}
			else
			{
				if(dept == "comp")
				{
					dept = "csse";
				}
				else if(dept == "txen")
				{
					dept = "pfen";
				}
				else if(dept == "elec")
				{
					dept = "ece";
				}
				
				bckgrndImgURL = "url(http://www.eng.auburn.edu/images/acad_depts/headers/"+ dept + ".jpg)";
			}
			width = "750px";
			height = "90px";
		}
		else if(area == "centers")
		{
			if(ext == "html")
			{
				bckgrndImgURL = "url(http://www.eng.auburn.edu/images/global/arch-headerimage.jpg)";
			}
			else
			{
				bckgrndImgURL = "url(http://www.eng.auburn.edu/images/centers/"+ dept + ".jpg)";	
			}
			width = "750px";
			height = "110px";
		}
		else
		{
			bckgrndImgURL = "url(http://www.eng.auburn.edu/images/global/arch-headerimage.jpg)";
			width = "750px";
			height = "110px"; 
		}
		
		tG.style.backgroundImage = bckgrndImgURL;
		tG.style.width = width;
		tG.style.height = height;
		tG.style.cssFloat = "right";
	}
}*/

function print_titleGraphic()
{
	//var locale = new String("http://www.eng.auburn.edu/programs/aero/");
	var locale = new String(window.location);
	
	var dept = get_subDir(locale);
	
	var parentfldr = 0; // possible values are 0, 1 and 2.  1 = academic program, 2 = centers
	var final_dept = "";
	var bckgrndImgURL = "";
	var width = "";
	var height = "";
	var tGt = document.getElementById("titleGraphicText");
	var tG = document.getElementById("titleGraphic");
	

	if(document.getElementById)
	{
		
		switch(dept)
		{
			case "aero":
				parentfldr = 1;
				final_dept = "aero";
				break;
			
			case "bsen":
				parentfldr = 1;
				final_dept = "bsen";
				break;
			
			case "chen":
				parentfldr = 1;
				final_dept = "chen";
				break;
			
			case "civil":
				parentfldr = 1;
				final_dept = "civil";
				break;
					
			case "csse":
				parentfldr = 1;
				final_dept = "csse";
				break;
			
			case "ece":
				parentfldr = 1;
				final_dept = "ece";
				break;
		
			case "insy":
				parentfldr = 1;
				final_dept = "insy";
				break;
			
			case "matl":
				parentfldr = 1;
				final_dept = "matl";
				break;
			
			case "mech":
				parentfldr = 1;
				final_dept = "mech";
				break;
			
			case "pfen":
				parentfldr = 1;
				final_dept = "pfen";
				break;
			
			case "wireless":
				parentfldr = 1;
				final_dept = "wireless";
				break;
			
			case "ac-pabe":
				parentfldr = 2;
				final_dept = "ac-pabe";
				break;
			
			case "audfs":
				parentfldr = 2;
				final_dept = "audfs";
				break;
			
			case "ose-ipp":
				parentfldr = 2;
				final_dept = "ose-ipp";
				break;
			
			case "mri":
				parentfldr = 2;
				final_dept = "mri";
				break;
			
			case "hrc":
				parentfldr = 2;
				final_dept = "hrc";
				break;
			
			case "iac":
				parentfldr = 2;
				final_dept = "iac";
				break;
			
			default:
				parentfldr = 0;
				final_dept = dept;
				break;
		}
		
		if(parentfldr == 1)
		{
			bckgrndImgURL = "url(http://www.eng.auburn.edu/images/acad_depts/headers/"+ final_dept + ".jpg)";
			width = "747px";
			height = "90px";
		}
		else if(parentfldr == 2)
		{
			bckgrndImgURL = "url(http://www.eng.auburn.edu/images/centers/"+ final_dept + ".jpg)";
			width = "747px";
			height = "110px";
		}
		else
		{
			bckgrndImgURL = "url(http://www.eng.auburn.edu/images/global/arch-headerimage.jpg)";
			width = "747px";
			height = "110px";
		}
		
		tG.style.backgroundImage = bckgrndImgURL;
		tG.style.backgroundRepeat = "no-repeat";
		tG.style.width = width;
		tG.style.height = height;
		tG.style.cssFloat = "left";		
	}
}


function print_phone_nums(locale)
{
	
	var dept = get_subDir(locale);
	
	switch (dept)
	{
		case "aero":
			document.write("334-844-4874");
			break;
		
		case "bsen":
			document.write("334-844-4180");
			break;
		
		case "chen":
			document.write("334-844-4827");
			break;
		
		case "civil":
			document.write("334-844-4320");
			break;
		
		case "comp":
			document.write("334-844-4330");
			break;

		case "csse":
			document.write("334-844-4330");
			break;
		
		case "ece":
			document.write("334-844-1800");
			break;
	
		case "elec":
			document.write("334-844-1800");
			break;
		
		case "insy":
			document.write("334-844-4340");
			break;
		
		case "matl":
			document.write("334-844-4822");
			break;
		
		case "mech":
			document.write("334-844-4820");
			break;
		
		case "pfen":
			document.write("334-844-4123");
			break;
		
		case "wireless":
			document.write("334-844-1800");
			break;
		
		case "attmep":
			document.write("334-844-2331");
			break;
		
		case "bo":
			document.write("334-844-4302");
			break;
		
		case "do":
			document.write("334-844-2308");
			break;
		
		case "ce":
			document.write("334-844-4370");
			break;
		
		case "development":
			document.write("334-844-2736");
			break;
		
		case "distance-learning":
			document.write("334-844-4370");
			break;
			
		case "ems":
			document.write("334-844-4804");
			break;
		
		case "ens":
			document.write("334-844-2280");
			break;
		
		case "engce":
			document.write("334-844-4370");
			break;
		
		case "erc":
			document.write("334-844-4370");
			break;

		case "ess":
			document.write("334-844-2309");
			break;
		
		case "edge":
			document.write("334-844-5300");
			break;
		
		case "marketing":
			document.write("334-844-2220");
			break;

		case "planning":
			document.write("334-844-3329");
			break;
		
		/* center phone numbers */
		
		case "audfs":
			document.write("334-844-3322");
			break;
		
		case "ac-pabe":
			document.write("344-844-2016");
			break;
		
		default:
			document.write("334-844-2308");
	}
}

function print_acad_toolbar(locale)
{
	var locale = new String(window.location);
	var dept = get_subDir(locale);
	/*var tempStr = Split_URL(locale);
	var splitStr = tempStr.split("/");
	var area = splitStr[0];
	var dept = splitStr[1];

	if(dept == "comp")
	{
		dept = "csse";
	}
	
	if(dept == "txen")
	{
		dept = "pfen";
	}

	if(dept == "elec")
	{
		dept = "ece";
	}*/
	document.write("<ul>\n");
	document.write("<li><a href=\"http://www.eng.auburn.edu/programs/" + dept + "/students/\">Students </a></li>\n");
	document.write("<li><a href=\"http://www.eng.auburn.edu/programs/" + dept + "/prospective/\">Prospective Students </a></li>\n");
	document.write("<li><a href=\"http://www.eng.auburn.edu/programs/" + dept + "/alumni/\">Alumni/Friends </a></li>\n");
	document.write("<li><a href=\"http://www.eng.auburn.edu/programs/" + dept + "/faculty/\">Faculty/Staff</a></li>\n");
	document.write("<li><a href=\"http://www.eng.auburn.edu/programs/" + dept + "/business/\">Business and Government </a></li>\n");
	document.write("<li><a href=\"http://www.eng.auburn.edu/visitors/index.html\">Visitors</a></li>\n");
	document.write("</ul>");

}


function print_quicklinks()
{
	var links = new Array(6);

	links[0] = "<a href=\"http://www.eng.auburn.edu/admin/ess/schfi/\">Scholarships</a>";
	links[1] = "<a title=\"Tigermail\" href=\"https://tigermail.auburn.edu/\" target=\"_blank\">Tigermail</a>";
	links[2] = "<a title=\"Student Services\" href=\"http://www.eng.auburn.edu/admin/ess/\">Student Services</a>";
	links[3] = "<a title=\"Webcams\"href=\"http://www.eng.auburn.edu/about/facilities/webcams.html\">Webcams</a>";
	links[4] = "<a title=\"Engineering Faculty Resources\" href=\"http://www.eng.auburn.edu/faculty/faculty-resources.html\">Faculty Resources</a>";
	links[5] = "<a title=\"AU Access\" href=\"http://auaccess.auburn.edu/\" target=\"_blank\">AU Access</a>";
	links[6] = "<a title=\"AU Blackboard\" href=\"http://blackboard.auburn.edu/\" target=\"_blank\">AU Blackboard</a>";

	document.write("<ul id=\"quickLinks\">");
	for(var i=0; i < links.length; i++)
	{
		document.write("<li>" + links[i] + "</li>");
	}
	document.write("</ul>");
}
function checkwords(ab)
{
	var maxlength = 175;
	if(document.images)
	{
		var temp = ab.Abstract.value.split(" ");
		if(temp.length > maxlength)
		{
			alert("Please restrict your abstract to 175 words or less. Thank You!");
			return false;
		}
	}
}

function autotab(original, destination)
{
	if (original.getAttribute && original.value.length == original.getAttribute("maxlength"))
	{
		destination.focus()
	}
}

if(window.addEventListener)
{
      window.addEventListener("load", print_titleGraphic, false);
}
else
{
      window.attachEvent("onload", print_titleGraphic, false);
}

/*function lrg_img_click()
{	
	$("#LrgImgContainer").html("<a href=\""+this.name+"\" target=\""+this.title+"\"><img alt=\""+this.alt+"\" src=\""+this.src+"\" width=\"750\" height=\"325\" border=\"0\" /></a>\n");
}

$(document).ready(function()
{
	$("#LrgImgsCntnr").cycle(
	{
		fx:     'fade',
		speed:  '3000',
		height: '325',
		timeout: 12000,
		next: '#LrgImgsCntnr',
		pause: 1,
		after: lrg_img_click
	});
});*/
$(document).ready(function()
{	
	// Civil grad pages slideshow code
	$(".slideshowWrapper").cycle(
	{
		fx:     'fade',
		speed:  '3000',
		height: '292',
		timeout: 12000
	});
	
	// student profile slideshows
	$('.profileImgs').cycle(
	{
		slideExpr: 'div',
		fx: 'fade',
		heigh: '292',
		speed: 1500,
		timeout: 12000
	});
	
	print_titleGraphic();
	
	$("#contents").html("<p>Click on a year to see the scholarships awarded.</p>")
	$("a").each(function(i)
	{
		var id = $(this).attr("id");
		var cntntcntrid = id.substr(0, id.length-1);
		
		if(id != "")
		{
			$("#"+cntntcntrid).css("display", "none");
		}
			
	});
	$("a").click(function()
	{
		var id = $(this).attr("id");
		var cntntcntrid = id.substr(0, id.length-1);
		
		if(id != "")
		{
			var newcontents = $("#"+cntntcntrid).html();		
			$("#contents").html(newcontents);
		}
	});
	
	//BET Image Gallery slideshow
	$(".gallery").after('<div class="galleryNav">').cycle(
	{
		fx:     'fade',
		speed:  '2000',
		height: '610',
		timeout: 1200,
		pager: '.galleryNav',
		pagerAnchorBuilder: function(idx, slide)
		{
			return "<a href=\"#\"><img src=\""+slide.src+"\" width=\"70\" height=\"70\" border=\"0\" /></a>";
		}
	});
});


