function jah(url, indexarg, target) {
    // native XMLHttpRequest object
        var url = url+"?param=";
    document.getElementById(target).innerHTML = 'sending...';
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = function() {jahDone(target);};
        var indexid = document.getElementById(indexarg).value;
        req.open("GET", url + escape(indexid), true);
        req.send(null);
    // IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = function() {jahDone(target);};
            var indexid = document.getElementById(indexarg).value;
            req.open("GET", url + escape(indexid), true);
            req.send();
        }
    }
}    

function jah_new(url, indexarg, target) {
    // native XMLHttpRequest object
        var url = url+"?param=";
    document.getElementById(target).innerHTML = 'sending...';
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = function() {jahDone(target);};
        var indexid = document.getElementById(indexarg).value;
        req.open("GET", url + escape(indexid), true);
        req.send(null);
    // IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = function() {jahDone(target);};
            var indexid = document.getElementById(indexarg).value;
            req.open("GET", url + escape(indexid), true);
            req.send();
        }
    }
} 

function jah_design() {
    // native XMLHttpRequest object
        var url = "design_current.php";
    document.getElementById('output').innerHTML = 'sending...';
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = function() {jahDone('output');};
        req.open("POST", url, true);
        req.send(null);
    // IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = function() {jahDone('output');};
            req.open("POST", url, true);
            req.send();
            }
    }
     var jah_timeout= setTimeout('jah_design();',60000);   
}    

function jah_photo() {
    // native XMLHttpRequest object
        var url = "randomphoto.php";
      if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = function() {jahDone('imagespace');};
        req.open("POST", url, true);
        req.send(null);
    // IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = function() {jahDone('imagespace');};
            req.open("POST", url, true);
            req.send();
            }
    }
     var jah_timeout= setTimeout('jah_photo();',5039);   
}    


function jahDone(target) {
    // only if req is "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            results = req.responseText;
            document.getElementById(target).innerHTML = results;
        } else {
            document.getElementById(target).innerHTML="jah error:\n" +
                req.statusText;
        }
    }
}

function start_the_engines() {
			var dummy = jah_design();
			var dummy2 = writeTime();
}

function submitForm(formname) { 
		var sbmtform='document.'+formname+'.submit()';
		eval(sbmtform); 
	}
function calendar(target) {
	var url='tfcalendar.php?param='+target;
	window.open(url,'Calendar','toolbar=no,width=225,height=250')
	}

function handleHttpResponse(fieldid) {
  if (http.readyState == 4) {
    if (http.responseText.indexOf('invalid') == -1) {
      // Split the comma delimited response into an array
      results = http.responseText.split(",");
     
     document.getElementById(fieldid).value = results[1];
     isWorking = false;
    }
  }
}
var isWorking = false;

function updatefield(phpfile, searchid, fieldid) 
	{
  if (!isWorking && http) 
  	{
  	var fields=fieldid;
  	var url=phpfile+"?param=";
    var indexid = document.getElementById(searchid).value;
    http.open("GET", url + escape(indexid), true);
    http.onreadystatechange = function() {handleHttpResponse(fieldid);};
    isWorking = true;
    http.send(null);
  	}
	}

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

function javahtml(source, target) {
		document.getElementById(target).innerHTML = document.getElementById(source).value;
		document.getElementById('Div3').innerHTML = document.getElementById(source).value;
		document.getElementById('Div4').innerHTML = document.getElementById(source).value;
		document.getElementById('Div5').innerHTML = document.getElementById(source).value;
		}
function javaadd(mcgill) {
		switch (document.getElementById(mcgill).value)
		{
		case "+":
  	document.getElementById('results').value = (document.getElementById('operand1').value-0)+(document.getElementById('operand2').value-0)
  	break
  	case "-":
  	document.getElementById('results').value = document.getElementById('operand1').value-document.getElementById('operand2').value
  	break
  	case "*":
  	document.getElementById('results').value = document.getElementById('operand1').value*document.getElementById('operand2').value
  	break
  	case "/":
  	document.getElementById('results').value = document.getElementById('operand1').value/document.getElementById('operand2').value
  	break
		default:
  	document.getElementById('results').value = 0
		}	
	}
	
function writeTime() {
  
  // get a date object
  var today = new Date();

  // ask the object for some information
  var hours = today.getHours();
  var minutes = today.getMinutes();
  var seconds = today.getSeconds();
  var day = today.getDate();
	var month = today.getMonth() + 1;
	var year = today.getFullYear();
	
  // fixTime makes the minutes and seconds look right
  // it just sticks a zero in front of numbers less than 10
  minutes = fixTime(minutes);
  seconds = fixTime(seconds);

  // put together the time string and write it out
  var the_time = year + "/" + month + "/" + day + "  -  " + hours + ":" + minutes + ":" + seconds;
  document.getElementById('timing').innerHTML = the_time;
  
  // run this function again in half a second
  var the_timeout= setTimeout('writeTime();',1000);

}


function fixTime(the_time) {

	if (the_time <10) 
	{
		the_time = "0" + the_time;
	}
	return the_time;
}
