// Supress errors
//window.onerror = new Function("return true;");
//**********************************************


// ***** Main Nav Rollover *****
function roll(imgName,imgState) {
	document.images[imgName].src = "/images/nav/" + imgName + "_" + imgState + ".gif";
}
// ***********************************************************************

function swapImage(imgName, src1, src2) {
    var curImg = "" + document.images[imgName].src;
    if( curImg.indexOf(src1) >= 0 ) {
        document.images[imgName].src = src2;
    } else {
        document.images[imgName].src = src1;
    }
}


// ***** Preload Rollover Images ***************************************
if (document.images) {
	image1 = new Image(); image1.src = "/images/nav/main_career_tools_ON.gif";
	image2 = new Image(); image2.src = "/images/nav/main_continuing_education_ON.gif";
	image3 = new Image(); image3.src = "/images/nav/main_create_profile_ON.gif";
	image4 = new Image(); image4.src = "/images/nav/main_teaching_central_ON.gif";
	image5 = new Image(); image5.src = "/images/nav/main_admin_tools_ON.gif";
	image6 = new Image(); image6.src = "/images/nav/main_create_position_ON.gif";
	image7 = new Image(); image7.src = "/images/nav/main_professional_development_ON.gif";
	image8 = new Image(); image8.src = "/images/nav/main_recruiting_central_ON.gif";
	image9 = new Image(); image9.src = "/images/nav/main_reports_nclb_ON.gif";
	image10 = new Image(); image10.src = "/images/nav/main_statistics_ON.gif";
	image11 = new Image(); image11.src = "/images/nav/main_my_profile_ON.gif";
	
	
	image100 = new Image(); image100.src = "/images/spacer.gif";
}
// *********************************************************************


// ***** Date Setup ***************************************
dayName = new Array("Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday");
monthName = new Array("January","February","March","April","May","June","July","August","September","October","November","December");
now = new Date();
// *********************************************************************


// *********************************************************************
// Function to create pop-up windows at a custom size.
// w = width
// h = height
// d = directories
// l = location
// m = menubar
// r = resizeable
// sc = scrollbars
// st = status
// t = toolbar
// EXAMPLE CALL: <a href="javascript:popUp('[URL]','[WINDOW NAME]',400,300,1,1,0,0,0,0,0);">LINK</a>
// *********************************************************************
function popUp(URL,name,w,h,d,l,m,r,sc,st,t) {
	var featureStr = "";
	featureStr = "width=" + w + ",height=" + h + ",directories=" + d + ",location=" + l + ",menubar=" + m + ",resizable=" + r + ",scrollbars=" + sc + ",status=" + st + ",toolbar=" + t;
	window.open(URL,name,featureStr);
}
// *********************************************************************


// ***** Mac work-around for Printable Page functionality **************
var mac = (navigator.userAgent.indexOf("Mac") != -1); 

function printPage() {
	if (mac) {
		alert("Sorry, your browser doesn't support this feature. Please use your browser's print functionality.");
  	} else {
		window.print();
	}
}
// *********************************************************************


/* Disables any form fields. These should be passed in as
 * extra arguments to the function
 */
function disableFields(curForm) {
    var i;
    for( i=1; i<arguments.length; i++ ) {
        curForm.elements[ arguments[i] ].disabled = true;
    }
}

/* Enables any form fields. These should be passed in as
 * extra arguments to the function
 */
function enableFields(curForm) {
    var i;
    for( i=1; i<arguments.length; i++ ) {
        curForm.elements[ arguments[i] ].disabled = false;
    }
}

/*
 * Function to format a phone number
 */
function formatPhone(field) {
    var newValue = "";
    newValue = field.value.replace(/\D/g,"");
    if (newValue.length == 10) {
        var area = newValue.substring(0,3);
        var prefix = newValue.substring(3,6);
        var suffix = newValue.substring(6,10);
        newValue = area + "-" + prefix + "-" + suffix;
        field.value = newValue;
    } else {
        // do nothing!
    }
}

/* Sets the designated form field to the given value.  */
function setField(curFormField, val) {
    curFormField.value = val;
}

/* Sets the designated form field to the given value.  */
function setFieldAndSubmit(curForm, curFormField, val) {
    if (curForm && curFormField && val) {
		document.forms[curForm].elements[curFormField].value = val;
	}
    document.forms[curForm].submit();
}

/* CLEARS all checkboxes in a set of results */
function clearAll(formName,elementName){
	var checkElements = document.forms[formName].elements;

	for( i = 0 ; i < checkElements.length ; i++ ){
    	if( checkElements[i].name == elementName ){
        	checkElements[i].checked = false;
      	}
   	}
}

/* SELECTS all checkboxes in a set of results */
function selectAll(formName,elementName){
	var checkElements = document.forms[formName].elements;

	for( i = 0 ; i < checkElements.length ; i++ ){
    	if( checkElements[i].name == elementName ){
        	checkElements[i].checked = true;
      	}
   	}
}

/* Only allows form to be submitted once. Upon submission the button is then automatically disabled to prevent accidental second submission. */
var submitted = false; 
function doSubmit(form) {
	if (!submitted) {
		submitted = true;
		form.submit();
	}
}

/* Passes login information to the parent window and submits the login form from that parent page. */
function handleLoginFromPopup(formName) {
	opener.document.forms['LoginForm'].userName.value = document.forms[formName].userName.value;
	opener.document.forms['LoginForm'].userPassword.value = document.forms[formName].userPassword.value;
	opener.document.forms['LoginForm'].submit();
	window.close();
}

function selectUser( url,  val ) {
    var newUrl = url + "?id=" + val.value;
    window.location =  newUrl ;
}



function closePopIn( popInID ) {
    document.getElementById( popInID ).style.display="none";
}

/* Used in TSN Admin to toggle a section on and off depending on a select-box (selectedIndex) */
function checkValue( index ) {
    if (index != 0) {
		document.getElementById("toggleContainer").style.display="block";
	} else {
		document.getElementById("toggleContainer").style.display="none";
	}
}

var xmlHttpRequestErrorPage = "/SysError.do";


function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
  @if (@_jscript_version >= 5)
    try {
      xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (E) {
        window.location.replace(xmlHttpRequestErrorPage);
        xmlhttp = false;
      }
    }
  @else
  xmlhttp = false;
  @end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
    } catch (e) {
      xmlhttp = false;
      window.location.replace(xmlHttpRequestErrorPage);
    }
  }
  return xmlhttp;
}

function Cookie(document, name, expiration, path, domain, secure)
{
	this._document = document;
	this._name = name;

	if(expiration)
		this._expiration = expiration
	else this._expiration = null;
	
	if(path) this._path = path;
	else this._path = null;
	
	if(domain) this._domain = domain;
	else this._domain = null;
	
	if(secure) this._secure = secure;
	else this._secure = false;
}

function _Cookie_store()
{
	this._document.cookie = this.toString();
} // _Cookie_store()

function _Cookie_load()
{
	var ok = false;
	
	var cookieStr = this._document.cookie;
	//alert(unescape(cookieStr));
	if (cookieStr && cookieStr != "")
	{
		var start = cookieStr.indexOf(this._name + '=');
		if(start != -1)
		{
			start += this._name.length + 1;
			var end = cookieStr.indexOf(';', start);
			if (end == -1) end = cookieStr.length;
			var cookieVal = cookieStr.substring(start, end);
			
			var a = cookieVal.split('&');
			for(var i = 0; i < a.length; i++)
				a[i] = a[i].split(':');
				
			for(var i = 0; i < a.length; i++)
				this[a[i][0]] = unescape(a[i][1]);

			ok = true;
		}
		/*else
			alert("cookie " + this._name + " not found");*/
	}
	return ok;
} // _Cookie_load()

function _Cookie_remove()
{
	var cookie = this._name + '=';
	if (this._path) cookie += '; path=' + this._path;
	if (this._domain) cookie += '; domain=' + this._domain;
	cookie += '; expires=Fri, 02-Jan-1970 00:00:00 GMT';
	
	this._document.cookie = cookie;
}

function _Cookie_toString()
{
	var cookieval = "";
	for(var prop in this)
	{
		if ((prop.charAt(0) != '_') && (typeof this[prop] != 'function'))
		{
			if (cookieval != "") cookieval += '&';
			cookieval += prop + ':' + escape(this[prop].toString());
		}
	}
	var cookieStr = this._name + '=' + cookieval;
	
	if(this._expiration) cookieStr += '; expires=' + this._expiration.toString();
	if(this._path) cookieStr += '; path=' + this._path;
	if(this._domain) cookieStr += '; domain=' + this._domain;
	if(this._secure) cookieStr += '; secure=' + secure;
	
	return cookieStr;
}

Cookie.prototype.store = _Cookie_store;
Cookie.prototype.load = _Cookie_load;
Cookie.prototype.remove = _Cookie_remove;
Cookie.prototype.toString = _Cookie_toString;

function getkey(e)
{
if (window.event)
   return window.event.keyCode;
else if (e)
   return e.which;
else
   return null;
}

function checkChars(e, validChars)
{
var key, keychar;
key = getkey(e);
if (key == null) return true;

keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();
checks = validChars.toLowerCase();

if (checks.indexOf(keychar) != -1)
	return true;

if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
   return true;

return false;
}

function checkNumeric(e){
   return checkChars(e,'01234567890');
}
