//------------------------------------------------------------------------------------------------------------------
//PIPELINE VALIDATOR
function val_check()
{
if (!document.layers)
{
if(document.login.user.value.length == 0 &&
document.login.userShow.value.length == 0 &&
document.login.userHide.value.length == 0)
{
alert('User ID required to login!');
if (document.login.userShow.style.display == 'block')
{
document.login.userShow.focus();
}
else
{
document.login.userHide.focus();
}
return false;
}
}
else
{
if(document.login.userShow.value.length == 0 && document.login.safe.value == '0')
{
alert('User ID required to login!');
document.login.userShow.focus();
return false;
}
}
if(document.login.pass_hide.value.length == 0)
{
alert('Password required to login!');
document.login.pass_hide.focus();
return false;
}
if(document.layers)
{
if(document.login.safe.value == '0')
{
document.login.user.value = document.login.userShow.value;
document.login.pass.value = document.login.pass_hide.value;
}
}
else
{
if(document.login.userShow.style.display != 'none')
{
document.login.user.value = document.login.userShow.value;
}
else if(document.login.userHide.style.display != 'none')
{
document.login.user.value = document.login.userHide.value;
}
document.login.pass.value = document.login.pass_hide.value;
}
return true;
}
//------------------------------------------------------------------------------------------------------------------
//TAKE ME TO MENU
function MM_jumpMenuGo(selName,targ,restore){ //v3.0
  var selObj = MM_findObj(selName); if (selObj) MM_jumpMenu(targ,selObj,restore);
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//------------------------------------------------------------------------------------------------------------------
//RELOAD PAGE FUNCTION - DREAMWEAVER THING
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);
//------------------------------------------------------------------------------------------------------------------
//PAGE PRINT FUNCTION
function printPage(){
	var pagecont = document.getElementById("info").innerHTML;
	document.getElementById("printcontpdf").value = "<head><link href='/templates/parts/css/main.css' rel='stylesheet' type='text/css'></head>" + pagecont;
}
//------------------------------------------------------------------------------------------------------------------
//PAGE PRINT SUBMIT FOR PDF PRINT
function printpdf(  )
{
  //document.printpdf.printpdfhidden.value = selectedtype ;
  document.printpdf.submit() ;
  return;
}
//---------------------------------------------------------------------------------------------------------------
//This is for fancy opening of a div
//---------------------------------------------------------------------------------------------------------------
var _maxheight = 0;

function divEffect(divid, speed) {
  var div = document.getElementById(divid);
  clearInterval(div._timeropenid);
  div._timerid = 0;  
  div._speed = speed;

  div.opened = true;
  
  if (speed > 0) {
  	div.style.height = "auto";
	div.style.height = div["offsetHeight"];
  }
  
  if (typeof div._startheight == "undefined") {
  	div._startheight = div["offsetHeight"];
	if (document.all) {
		<!-- Internet Explorer arrangements -->
		div._startheight = div["offsetHeight"] + 3 + "px";
	  }
  }
  
  if (document.all) {
	<!-- Internet Explorer arrangements -->
	div.maxheight = div["offsetHeight"] + 3;
  }
  else {
	  div.maxheight = div["offsetHeight"];
  }

  if (speed > 0) {
  		div.style.height = "1px";
  }

	div._timeropenid = window.setInterval("fancyDivInterval('" + divid + "')",25);
  div.style.visibility = "visible";  
  //div.style.display = "block";

}
function fancyDivInterval(divid) {
   var div = document.getElementById(divid);
	if (div._speed > 0) {
		div.style.height = (parseInt(div.style.height,10) + (div.maxheight - parseInt(div.style.height,10))/div._speed) + "px";
		
		if (parseInt(div.style.height,10) >= div.maxheight) {
			div.style.height = div.maxheight;
			clearInterval(div._timeropenid);
			div._timeropenid = -1;
		}
	}
	else {
		div.style.height = (parseInt(div.style.height,10) + (parseInt(div.style.height,10))/div._speed) + "px";
		
		
		if (parseInt(div.style.height,10) < 3) {
			div.style.height = "1px";
			div.style.visibility = "hidden";
			//div.style.display = "none";
			clearInterval(div._timeropenid);
			div._timeropenid = -1;
		}
	}
	
}
function hidediv(div) {
	if (!div) {
		alert("JavaScript Page Error, parameter not passed into hidediv().");
		return;
	}
	document.getElementById(div).style.display='none';
}
function showdiv(div) {
	if (!div) {
		alert("JavaScript Page Error, parameter not passed into showdiv().");
		return;
	}
	document.getElementById(div).style.display='block';
}
//---------------------------------------------------------------------------------------------------------------

//This function takes the current url including the current variables and just adds another variable to the
//end of it and reloads the page. Things are passed in like ("VARIABLE", "VALUE,...)
function addURLVariables() {
	//The reason this is complicated is because we have to search through the current variables in the URL
	//and make sure that this variable isn't already listed in the URL, because if it is, we want to replace it.
	if (arguments.length == 0) return;
	
	var isVariables = document.URL.split("?")[1];

	var URLsplit = document.URL.split("?");
	var URLString = URLsplit[0] + "?";
	
	var varfound = new Array(arguments.length/2);
	for (k = 0; k < arguments.length/2; k++) {
		varfound[k] = false;
	}
	if (typeof(isVariables) != "undefined") {
		var strvars = '' + URLsplit[1];
		strvar = strvars.split("&");
		
		for (i = 0; i < strvar.length;i++) {
			for (j = 0; j < arguments.length;j+=2) {
				if (strvar[i].split("=")[0] == arguments[j]) {
					
					varfound[j/2] = true;
					strvar[i] = arguments[j] + "=" + arguments[j+1];
					continue;
				}
			}
			if (i != 0) {
				URLString += "&" + strvar[i];
			}
			else URLString += strvar[i];
		}
	}
	for (j = 0; j < arguments.length;j+=2) {
		if (!varfound[j/2]) {
			if (isVariables || j != 0) {
				URLString += "&";
			}
			URLString += arguments[j] + "=" + arguments[j+1];
		}
	}
	document.location.assign(URLString);
	
}

// -------------------------------------------------------------------
// hasOptions(obj)
//  Utility function to determine if a select object has an options array
// -------------------------------------------------------------------
function hasOptions(obj) {
	if (obj!=null && obj.options!=null) { return true; }
	return false;
	}
	
/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure)
{
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name)
{
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1)
    {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    }
    else
    {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1)
    {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

function array_shift() {
  var A_s = 0;
  var response = this[0];
  for (A_s = 0; A_s < this.length-1; A_s++) {
     this[A_s] = this[A_s + 1];
  }
  this.length--;
  return response;
}

if (typeof Array.prototype.shift == "undefined") {
  Array_prototype.shift = array_shift;
}
/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

function storePageData() {
	//alert("Setting Page cookies");
	var title = document.title;
	var url = document.URL;
	
	var filled =true;
	var alreadyin = false;
	var i;
	
	var numh = 0; //THe number of history items.
	for (i = 0; i < titles.length; i++) {
		if (titles[i] == title) {
			alreadyin = true;
			break;
		}
		if (titles[i] == null) {
			filled = false;
			break;
		}
	}
	if (alreadyin) {
		//alert("Before Splicing: " + titles);
		titles.splice(i,1);
		urls.splice(i,1);
		var end = 1;
		for (var k = 0; k < titles.length; k++) {
			if (titles[k] == null) {
				titles[k] = title;
				urls[k] = url;
				end = 0;
				break;
			}
		}
		if (end) {
			titles.push(title);
			urls.push(url);
		}
		//alert("After Splicing: " + titles);
		
		for (i = 0; i < titles.length; i++) {
			if (titles[i] != null) {
				setCookie("bcc_titlestored[" + i + "]", titles[i], new Date("January 1, 2100"));
				setCookie("bcc_urlstored[" + i + "]", urls[i], new Date("January 1, 2100"));
				
			}
		}
	}
	else if (filled) {
		//alert("Cookies are filled, shifting. Before: " + titles);
		titles.shift();
		urls.shift();
		titles.push(title);
		urls.push(url);
		//alert("After: " + titles);
		
		for (i = 0; i < titles.length; i++) {
			setCookie("bcc_titlestored[" + i + "]", titles[i], new Date("January 1, 2100"));
			setCookie("bcc_urlstored[" + i + "]", urls[i], new Date("January 1, 2100"));
		}
	}
	else {
		//alert("Adding new cookie at titles[" + i +"]");
		setCookie("bcc_titlestored[" + i + "]", title, new Date("January 1, 2100"));
		setCookie("bcc_urlstored[" + i + "]", url, new Date("January 1, 2100"));
	}
	numh = 5;
	setCookie("bcc_history",numh, new Date("January 1, 2100"));
}

var titles = new Array();
var urls = new Array();
var numhistory = 0;
function getPageData() {
	//alert("Getting page data");
	numhistory = getCookie("bcc_history");
	//alert("Numhistory:" + numhistory);

	if (numhistory == null) {
		numhistory = 4; /* this controls how many links show up, just remember that 5 will show despite the variable being equal to 4, for example */
	}
	for (var i = 0; i < numhistory; i++) {
		//alert("Getting:" + i);
		titles.push(getCookie("bcc_titlestored[" + i + "]"));
		//alert(titles);
		urls.push(getCookie("bcc_urlstored[" + i + "]"));
	}
	
	writeHistory("history");

}
//function writeLink(div, title,href) {
//	var pull = "Butler Community College - "; // remove "Butler Community College - " to avoid repitition 
//	var pull2 = "Welcome to Butler - "; // remove "Welcome to Butler - " to avoid repitition 
//	title = title.replace( pull, "" );
//	title = title.replace( pull2, "" );
//var prev = div.innerHTML;
//	div.innerHTML = prev + "<a style='color:#cccccc; padding:1px; margin:3px; ' href='" + href + "'>" + title + "</a> ";
//}
//function writeHistory(d) {
//	//********alert("Writing the History to the div: " + d);
//	var div = document.getElementById(d);
////*******	alert(titles.length);
//	for (var i = titles.length-1; i > -1; i--) {
//		if (titles[i] != null) {
//			writeLink(div,titles[i], urls[i]);
//		}
//	}
//	//*********************alert("End");
//}
//if (!document.all) {
//	//FIREFOX IS BEING USED
//	window.addEventListener("load",getPageData, false);
//	window.addEventListener("load",storePageData, false);
//}
//else {
//	//INTERNET EXPLORER IS BEING USED
//	window.attachEvent("onload", storePageData);
//	window.attachEvent("onload", getPageData);
//}
function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

