// JavaScript Document
/*
startList = function() {
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav")

		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i]
//			alert(node.nodeName)
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over"
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "")
				}
			}
		}
	}
}
window.onload=startList
*/
// ==============================================================================
//					TEXT SIZE
// ==============================================================================
function TextSize(s){
	document.getElementById("main_content").className = "main_content_"+s
}

// ==============================================================================
//					GET MOUSE POSITION
// ==============================================================================
mY = 0
mX = 0
document.onmousemove = getMouseXY;
IE = document.all?true:false
if (!IE) document.captureEvents(Event.MOUSEMOVE)

function getMouseXY(e){
	if (IE){
		mY = event.clientY + document.body.scrollTop
		mX = event.clientX + document.body.scrollLeft}
	else{
	mY = e.pageY
	mX = e.pageX}
}

// ==============================================================================
//					DROP DOWN MENUE
// ==============================================================================
lastName = ''
function navOver(name){
	document.getElementById(name).style.background = "url(/~jgcp/images/button_over.gif) no-repeat"
	menuPosY = document.getElementById("mainMenu").offsetTop
	bntPosY = document.getElementById(name).offsetTop
	menuPosX = document.getElementById("mainMenu").offsetLeft
	bntPosX = document.getElementById(name).offsetLeft

	if (name == lastName) return false
	if (lastName != '') navOut(lastName)

	if(document.getElementById(name+"_dd")){
		document.getElementById(name+"_dd").style.display = "block"
		document.getElementById(name+"_dd").style.top = (bntPosY + menuPosY + 0) + "px"
		document.getElementById(name+"_dd").style.left = (bntPosX + menuPosX + 135) + "px"
		}
	lastName = name
}

function navOut(name){
	if(name == 'all') name = lastName
	if(name == '') return
	document.getElementById(name).style.background = "url(/~jgcp/images/button.gif) no-repeat"

	if(document.getElementById(name+"_dd")) document.getElementById(name+"_dd").style.display = "none"
	lastName = ''
}

// ==============================================================================
//					FADE IN BANNER IMAGES
// ==============================================================================
c = 1 // set c (as in "count") to initial value{
d = 0 // set d (as in "degree" of fading) to initual value
function banner(){
	if(this.location == ("http://www2.ku.edu/~jgcp/") || this.location == ("http://www2.ku.edu/~jgcp/index.shtml")
	|| this.location == ("http://www.jgcp.ku.edu/~jgcp/") || this.location == ("http://www.jgcp.ku.edu/~jgcp/index.shtml")
	|| this.location == ("http://www.jgcp.ku.edu/") || this.location == ("http://www.jgcp.ku.edu/index.shtml")
	|| this.location == ("http://jgcp.ku.edu/") || this.location == ("http://jgcp.ku.edu/index.shtml")
	|| this.location == ("http://jgcp.ku.edu/~jgcp/") || this.location == ("http://jgcp.ku.edu/~jgcp/index.shtml")){
		if(c == 6){clearTimeout(p)}
		else p = setTimeout("fadein("+c+")",300)
	}
	else{
		for(i=1;i<6;i++){
			document.getElementById('img'+i).style.filter = 'alpha(opacity=100)'
			document.getElementById('img'+i).style.name = '-moz-opacity:99'
			document.getElementById('img'+i).style.opacity = '99'
			document.getElementById('img'+i).style.name = '-khtml-opacity:.99'
		}
		return
	}
}

function fadein(i){
	d += 10  //decrease fade by 10
	document.getElementById('img'+i).style.filter = 'alpha(opacity='+d+')'
	document.getElementById('img'+i).style.name = '-moz-opacity:.'+d
	document.getElementById('img'+i).style.opacity = '.'+d
	document.getElementById('img'+i).style.name = '-khtml-opacity:.'+d
	if(d > 80){
		clearTimeout(t)
		c++
		d = 0
		banner()
	}
	else t = setTimeout("fadein("+i+")",80)
}

// ===============================================================================
// UNIVERSAL VALIDATION SCRIPT
// Created by Randy Crook (12/06/2006)
// The University Of Kansas
// ===============================================================================

// ------------------------------------------------------------------------------
//						EMAIL
function checkEmail(v,n) {
error=""
if (v == "")return error

emailFilter=/^.+@.+\..{2,3}$/
    if (!(emailFilter.test(v))) {
       error = "Please enter a valid "+n+".\n"
    }
    else {
//test email for illegal characters
   illegalChars= /[\(\)\<\>\,\;\:\\\/\"\[\]]/
         if (v.match(illegalChars)) {
          error = "The "+n+" contains illegal characters.\n"
       }
    }
return error
}

// ------------------------------------------------------------------------------
//						NOT EMPTY
// non-empty textbox
function isEmpty(v, n) {
error = ""
  if (v.length == 0) {
     error = n+"here.\n"
  }
return error
}

// ------------------  STRIP PHONE   --------------------------------------------------
// phone number - strip out delimiters and check for 10 digits
function stripPhone (phone) {
	phone =  phone.replace(/[\(\)\.\-\ ]/g, '')
	return phone
}

// ------------------------------------------------------------------------------
//						PHONE NUMBER
function checkPhone (v,n) {
error = ""

stripped = v.replace(/[\(\)\.\-\ ]/g, '') //strip out acceptable non-numeric characters
    if (isNaN(parseInt(stripped))) {
       error = "The "+n+" number contains illegal characters.\n"

    }
    if (!(stripped.length == 10)) {
	error = "The "+n+" number is the wrong length. Make sure you included an area code.\n"
    }
return error
}

// ------------------  ZIP   --------------------------------------------------
// zip code - scheck for 5 or 9 digits
function checkZip (v,n) {
	var error = ""
    if (!v.match(/^(\d{5}-\d{4})|^(\d{5})|^(\d{9})$/)) {
       error = "The "+n+" contains illegal characters or is the wrong length.\n"
    }
	return error
}

// ------------------------------------------------------------------------------
//						DROP DOWN BOX
function checkDropdown(choice,n) {
error = ""
    if (choice == 0) {
    error = "Please choose an option from the "+n+" drop-down list.\n"
    }
return error
}

// ------------------------------------------------------------------------------
//						CHECKBOXES
function checkBox(v,n) {
	var error = ""
	var t=0
	for (i=0; i<v.length; i++){
		if(v[i].checked) t=1
	}
	if(t==0) error="Please select at least one " + n
	return error
}


// ==============================================================================
//					AJAX
// ==============================================================================
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) {

        xmlhttp = false;

      }

    }

  @else

  xmlhttp = false;

  @end @*/

  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {

    try {

      xmlhttp = new XMLHttpRequest();

    } catch (e) {

      xmlhttp = false;

    }

  }

  return xmlhttp;

}

var http = getHTTPObject(); // We create the HTTP Object


// ---------------------------------------------------------------------------------
// test AJAX
function ajaxObject(url) {        // This is the object constructor
   var that=this;                 // A workaround for some javascript idiosyncrocies
   this.updating = false;         // Set to true if this object is already working on a request
   this.callback = function () {}  // A post-processing call -- a stub you overwrite.

   this.update = function(passData) {    // Initiates the server call.
      if (that.updating==true) { return false; } // Abort if we're already processing a call.
      that.updating=true;                         // Set the updating flag.
      var AJAX = null;                            // Initialize the AJAX variable.
      if (window.XMLHttpRequest) {                // Are we working with mozilla?
         AJAX=new XMLHttpRequest();               //  Yes -- this is mozilla.
      } else {                                    // Not Mozilla, must be IE
         AJAX=new ActiveXObject("Microsoft.XMLHTTP");//  Wheee, ActiveX, how do we format c: again?
      }                                              // End setup Ajax.
      if (AJAX==null) {                              // If we couldn't initialize Ajax...
         return false;                               // Return false (WARNING - SAME AS ALREADY PROCESSING!)
      } else {
         AJAX.onreadystatechange = function() {      // When the browser has the request info..
            if (AJAX.readyState==4) {                //   see if the complete flag is set.
               that.updating=false;                  //   Set the updating flag to false so we can do a new request
               that.callback(AJAX.responseText,AJAX.status); //   Pass respons and status to callback.
               delete AJAX;                        //   delete the AJAX object since it's done.
            }                                      // End Ajax readystate check.
         }                                         // End create post-process fucntion block.
         var timestamp = new Date();               // Get a new date (this will make the url unique)
         var uri=urlCall+'?'+passData+'&timestamp='+(timestamp*1);   // Append date to url (so the browser doesn't cache the call)
         AJAX.open("GET", uri, true);                // Open the url this object was set-up with.
         AJAX.send(null);                           // Send the request.
         return true;                              // Everything went a-ok.
      }                                            // End Ajax setup aok if/else block
   }

   // This area set up on constructor calls.
   var urlCall = url;                        // Remember the url associated with this object.
}                                            // End AjaxObject