// a list of variables, parameters, and functions using in the pages
// contact Geer Shuang via e-mail at geershuang@yahoo.com for more information
var svr = "http://" + window.location.hostname + "/ENGINEER/ME/";

function breadcrumb(url) {
	// generate the breadcrumb according to URL of the page
	// NOTE: 
	//		- there must be a page for each folder
	// 		- name of the page must be foldername.htm
	//		- the page must be one level higher than the pages within the folder 
	//		- code need to be modified, if index.htm of the website is not in the root of the web server
	//		- avoid using special characters for name of folder or page
	//		- don't use index.htm for the page name if it is not the home page of the entire website
	// style was defined in css/site.css
	
	//url = "http://www.alipro.com/services/training.htm"
	//if (url.indexOf("?") != -1) {
	//	url = url.substring(0,url.indexOf("?"));
	//}
	// simbol between two breadcrumbs
	var simbol = "&nbsp;&raquo;&raquo;&nbsp;";
	if (url.indexOf("#") != -1) {
		url = url.substring(0,url.indexOf("#"));
	}
	// endwith = 1 if last char of url is "/", =0 otherwise.
	var endwith = (url.charAt(url.length-1) == "/" ) ? 1 : 0;
	// endwith = 1 if last segment of url is "index.htm", =0 otherwise.
	var endwith2 = (url.substring(url.length-9, url.length).toLowerCase() == "index.htm") ? 1 : 0;
	var temp = url.split('/');
	var str = "";
	var i = 0;
	// 
	var depth = 5;
	var url = "";
	
	// if url has no more than 2 "/" (3 items in array temp[]) in it, the url could be wrong
	// i.e. http://www.asdf.com has 2 "/", 3 items should be in array temp[]
	if (temp.length == depth) {
		for (i = 0; i<depth; i++) {
			url += temp[i] + "/";
		}
		//url = temp[0] + "//" + temp[2] + "/" + temp[3] + "/" + temp[4];
		str = "<a href='" + url + "'>Home</a>";
		document.write(str);
	}	
	else if ((temp.length == depth + 1) && ((endwith == 1) || (endwith2 == 1))) {
		for (i = 0; i<depth; i++) {
			url += temp[i] + "/";
		}
		//url = temp[0] + "//" + temp[2] + "/" + temp[3] + "/" + temp[4];
		str = "<a href='" + url + "'>Home</a>";
		document.write(str);
	}	
	else if ((temp.length > depth)) {
		for (i = 0; i<depth; i++) {
			url += temp[i] + "/";
		}
		//temp[1] should be null
		//url = temp[0] + "//" + temp[2] + "/" + temp[3] + "/" + temp[4];
		str = "<a href='" + url + "'>Home</a>";
		var description = "";
		url = url.substring(0,url.length-1);
		
		for (i=depth; i<temp.length ; i++) {
			// if temp[i] is the end of the array, don't need to add ".htm" to it
			// if not, need ".htm"		
			
			if (i == temp.length - 1) {
				url += "/" + temp[i];
				//capitalize the first character of description (name of the folder or page)
				temp[i] = temp[i].replace(".htm","");
				var temp2 = temp[i].split("_");
				description = "";
				for (var j = 0; j < temp2.length; j++) {
					description += temp2[j].replace(temp2[j].substring(0,1), temp2[j].substring(0,1).toUpperCase()) + "&nbsp;";
				}
				//description = temp[i].replace("_","&nbsp;").replace("%20","&nbsp;").replace(".htm","");
				//description = description.replace(description.substring(0,1), description.substring(0,1).toUpperCase());
				// if file name or folder name has "_", replace it by " " when display in the breadcrumb
				str += simbol + "<a href='" + url + "'>" + description + "</a>";
			}
			else {
				url += "/" + temp[i];
				temp[i] = temp[i].replace(".htm","");
				var temp2 = temp[i].split("_");
				description = "";
				for (var j = 0; j < temp2.length; j++) {
					description += temp2[j].replace(temp2[j].substring(0,1), temp2[j].substring(0,1).toUpperCase()) + "&nbsp;";
				}
				//description = temp[i].replace("_","&nbsp;").replace("%20","&nbsp;").replace(".htm","");
				//description = description.replace(description.substring(0,1), description.substring(0,1).toUpperCase());
				str += simbol + "<a href='" + url + ".htm'>" + description + "</a>";
			}
		}		
		document.write(str);
	}
	else {
		alert("Breadcrumb URL error. ");
	}
}

function title(url) {
	// use the last segment of page URL as title
	// replace "_" in the filename to " "
	// capitalize the first charater of title
	if (url.indexOf("#") != -1) {
		url = url.substring(0,url.indexOf("#"));
	}
	var depth = 5;
	var temp = url.split('/');
	var title = "";
	if ((temp.length > depth) && (temp[temp.length-1] != "index.htm") && (temp[temp.length-1] != "")) {
		temp[temp.length-1] = temp[temp.length-1].replace(".htm","");		
		var temp2 = temp[temp.length-1].split("_");
		for (var i = 0; i < temp2.length; i++) {
			title += temp2[i].replace(temp2[i].substring(0,1), temp2[i].substring(0,1).toUpperCase()) + "&nbsp;";
		}
		document.write(title);
	}
	else {
		document.write("Welcome");
	}
}

var popUpWin=0;
function popup(URLStr, left, top, width)
{
	if(popUpWin)
	{
		if(!popUpWin.closed) popUpWin.close();
	}
	popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width='+width+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}


function showhide(hight)
{
	document.getElementById("tb_details").style.display = "";
	document.getElementById("p_btn").style.display = "none";
	document.getElementById("tb_main").style.height = hight + "px";
	location.href = "#start";
}