// JavaScript Document

function reloadAttachments() {
  // for some reason I can't call the Ajax directly, but by adding the 30 millisec timeout, it works fine...
  window.setTimeout('attachmentAjax('+arguments[0]+','+arguments[1]+')', 30);   
}

function attachmentAjax() {
  new Ajax.Updater('attachments'+arguments[1], 'student.php', {parameters:'action=updateAttachments&conductID='+arguments[0]+'&conductDiv='+arguments[1], evalScripts:true, asynchronous:true});	
}

function reloadLog() {
  // for some reason I can't call the Ajax directly, but by adding the 30 millisec timeout, it works fine...
  window.setTimeout('reloadLogAjax(\''+arguments[0]+'\')', 30);   
}

function reloadLogAjax() {
  maskScreen();
  new Ajax.Updater('logArea', 'logs.php', {parameters:'action='+arguments[0], evalScripts:true, asynchronous:true});	
}

function deleteConduct() {
  $check = confirm("        This action can not be undone!\nAre you sure you wish to delete this record?");
  if($check) {
    if(arguments[0] != 'null') {
      $('deleteConductIcon'+arguments[0]).src='assets/graphics/loadingSmall.gif';
      new Ajax.Updater('conduct'+arguments[0],'student.php', {parameters:'recID='+arguments[1]+'&action=deleteConduct', evalScripts:true, asynchronous:true});
    }
  }
}

function updateMenuButtons () {
  $buttons = new Array('generalButton','conductsButton','lettersButton','smsButton','emailButton','chartButton');
  for($i=0; $i<$buttons.length; $i++) { 
    if(updateMenuButtons.arguments[0] == $buttons[$i]) {
	  $($buttons[$i]).className='selectedTab';
	  $($buttons[$i]+'Image').src = "assets/graphics/menu/tabSelected.jpg"; }
	else {
	  $($buttons[$i]+'Image').src = "assets/graphics/menu/tab.jpg";
	  document.getElementById($buttons[$i]).className='tabNav'; }
	}
}

function updateChart() {
  new Ajax.Updater('chart', 'student.php', {parameters:'action=updateChart&studentID='+updateChart.arguments[0]+'&chartType='+document.getElementById('chartType').value+'&recordType='+document.getElementById('recordType').value+'&pieYscale='+document.getElementById('pieYscale').value+'&pieDepth='+document.getElementById('pieDepth').value+'&pieRadius='+document.getElementById('pieRadius').value+'&chartColour='+document.getElementById('chartColour').value+'&chartView='+$('chartView').value, evalScripts:true, asynchronous:true});
}

function updateConductChart() {
  new Ajax.Updater('chart', 'conduct.php', {parameters:'action=updateChart&type='+arguments[0]+'&chartType='+document.getElementById('chartType').value+'&pieYscale='+document.getElementById('pieYscale').value+'&pieDepth='+document.getElementById('pieDepth').value+'&pieRadius='+document.getElementById('pieRadius').value+'&chartColour='+document.getElementById('chartColour').value+'&cat='+$('cat').value+'&studentSearch='+$('studentSearch').value, evalScripts:true, asynchronous:true});
}

function editCheck() {
  $args = editCheck.arguments;
  if($args[0].options[$args[0].selectedIndex].text == 'Edit list...')
    alert('This facility will be added shortly. In the interim please contact your\n           system administrator to have values added here.'); 
  if($args[0].options[$args[0].selectedIndex].text == 'New conduct') {
	maskScreen(); positionMessage('newConductType', 350, 300); $field = $args[0].id; }
  if($args[0].options[$args[0].selectedIndex].text == 'New action') {
	maskScreen(); positionMessage('newActionTaken', 350, 140); $field = $args[0].id; }
  if($args[0].options[$args[0].selectedIndex].text == 'New letter') {
	maskScreen(); positionMessage('newDefaultLetter', 350, 180); $field = $args[0].id; }
  if($args[0].options[$args[0].selectedIndex].text == 'New message') {
	maskScreen(); positionMessage('newIndicatorMessage', 350, 180); $field = $args[0].id; }	
  if($args[0].options[$args[0].selectedIndex].text == 'New') {
	maskScreen(); positionMessage('newPointsValue', 350, 140); $field = $args[0].id; }
}

function colourThis() {
  if(arguments[0].options[arguments[0].selectedIndex].value < 0)
    arguments[0].style.backgroundColor = 'red';
  if(arguments[0].options[arguments[0].selectedIndex].value > 0)
    arguments[0].style.backgroundColor = 'green';
}

function saveForm() {
  // call as saveForm(div to update, page to use, action to append to arguments, field with field infoList);
  maskScreen(); $die = false;
  $args = saveForm.arguments; $fieldList = new Array(); $selectList = new Array(); $checkList = new Array();
  
  if($args[2] != 'deleteConduct') {
  	$infoList = document.getElementById($args[3]).value.split('|');
 	  if($infoList[0].length > 0) {
    	if(document.getElementById($infoList[0]).value.indexOf('|') != -1) $fieldList = document.getElementById($infoList[0]).value.split('|');
	  else $fieldList[0] = document.getElementById($infoList[0]).value; }
	  if($infoList[1].length > 0) {
	    if(document.getElementById($infoList[1]).value.indexOf('|') != -1) $selectList = document.getElementById($infoList[1]).value.split('|');
		else $selectList[0] = document.getElementById($infoList[1]).value; }
 	 if($infoList[2].length > 0) {
 	   if(document.getElementById($infoList[2]).value.indexOf('|') != -1) $checkList = document.getElementById($infoList[2]).value.split('|');
		else $checkList[0] = document.getElementById($infoList[2]).value; }
	  var $arguments ='';
	  for($i=0; $i<$fieldList.length; $i++) {
		if($args[4]) { if(document.getElementById($fieldList[$i]).value == '') $die = true; }
	    $arguments += document.getElementById($fieldList[$i]).name +'='+ document.getElementById($fieldList[$i]).value +'&'; }
	  for($i=0; $i<$selectList.length; $i++) { 
		if($args[4]) { if(document.getElementById($selectList[$i]).options[document.getElementById($selectList[$i]).selectedIndex].value == '') $die = true;  }
	    $arguments += document.getElementById($selectList[$i]).name +'='+ document.getElementById($selectList[$i]).options[document.getElementById($selectList[$i]).selectedIndex].value +'&'; }
	  for($i=0; $i<$checkList.length; $i++) {
		$arguments += document.getElementById($checkList[$i]).name +'=';
		if(document.getElementById($checkList[$i]).checked) $arguments += document.getElementById($checkList[$i]).value +'&';
		else $arguments += '0&';
	}
  if($args[2] == 'newConductFromList' && $studentCount <= 0) $die = true;
  
   // alert($arguments);
  if(!$die) {
	if($args[2] == 'newConductType') {	$arguments += 'destinationField='+$field+'&'; showLoading('formButtons'); }
    
    new Ajax.Updater($args[0], $args[1]+'.php', {parameters:$arguments+'action='+$args[2], evalScripts:true, asynchronous:true});
    
    if(($args[2] == 'newConduct' || $args[2] == 'updateConduct') && $args[1] == 'student') {
      new Ajax.Updater('thumbnailGraph','student.php', {parameters:'action=updateChartThumb', evalScripts:true, asynchronous:true});
	  new Ajax.Updater('studentConductSummary','assets/includes/studentDataSummary.php', {parameters:'action=newConduct', evalScripts:true, asynchronous:true}); }
  } else {
	alert('Please complete all fields'); 
	unmaskScreen();
	}
  }
  else {
	
  }
}

function sendForm() { // form containing the data, div for content, page to call
  $data = $(arguments[0]).serialize()
  new Ajax.Updater(arguments[1],arguments[2]+'.php', {parameters:''+$data, evalScripts:true, asynchronous:true});
  return false;	
}

function saveSimpleForm() {
  maskScreen();
  if(arguments[2] == 'newPointsValue') showLoading('pointsButtons'); 
  if(arguments[2] == 'newActionTaken') showLoading('actionButtons'); 
  new Ajax.Updater(arguments[0], arguments[1]+'.php', {parameters:arguments[3]+'&action='+arguments[2], evalScripts:true, asynchronous:true});	
}


function saveList() {
  var $arguments ='';
  for($i=0; $i<$('fieldCount').value; $i++) { $thisItem = 'listItem'+$i; $thisID = 'listRecID'+$i;
	if($($thisItem)) {
	  $arguments += 'recID[]='; if($($thisID)) $arguments += $($thisID).value; $arguments +='&listValue[]='+$($thisItem).value+'&'; } }
  new Ajax.Updater(arguments[0], arguments[1]+'.php', {parameters:$arguments+'action='+arguments[2]+'&list='+arguments[3], evalScripts:true, asynchronous:true});	
}

function saveConductList() {
  var $arguments ='';
  for($i=0; $i<$('fieldCount').value; $i++) { 
    $thisItem = 'listItem'+$i; $thisID = 'listRecID'+$i; $thisPositive = 'positive'+$i; $thisAction = 'defaultAction'+$i; $thisPoints = 'defaultPoints'+$i; $thisLetter = 'defaultLetter'+$i; $thisMessage = 'indicatorMessage'+$i;
	if($($thisItem)) {
	  $arguments += 'recID[]='; if($($thisID)) $arguments += $($thisID).value; $arguments +='&listValue[]='+$($thisItem).value+'&defaultAction[]='+$($thisAction).options[$($thisAction).selectedIndex].value+'&defaultPoints[]='+$($thisPoints).options[$($thisPoints).selectedIndex].value+'&defaultLetter[]='+$($thisLetter).options[$($thisLetter).selectedIndex].value+'&indicatorMessage[]='+$($thisMessage).options[$($thisMessage).selectedIndex].value+'&positive[]'; }
	  if($($thisPositive).checked) $arguments+='=1&'; else $arguments+='=0&';}
    //alert($arguments);
  new Ajax.Updater(arguments[0], arguments[1]+'.php', {parameters:$arguments+'action='+arguments[2]+'&list='+arguments[3], evalScripts:true, asynchronous:true});	
}

function saveStaffList() {
  var $arguments ='';
  for($i=0; $i<$('fieldCount').value; $i++) { 
    $thisID = 'tutorRecID'+$i; $thisTitle = 'tutorNameTitle'+$i; $thisNameFirst = 'tutorNameFirst'+$i; $thisNameLast = 'tutorNameLast'+$i; $thisForm = 'tutorFormClass'+$i; $thisEmail = 'tutorEmail'+$i; $thisMobileNumber = 'tutorMobileNumber'+$i; $thisAccessName = 'tutorAccessName'+$i; $thisAccessPassword = 'tutorAccessPassword'+$i; $thisAdmin = 'positive'+$i; 
	if($($thisNameLast) && $($thisNameLast).value != '') {
	  $arguments += 'recID[]='; if($($thisID)) $arguments += $($thisID).value; $arguments +='&tutorNameTitle[]='+$($thisTitle).value+'&tutorNameFirst[]='+$($thisNameFirst).value+'&tutorNameLast[]='+$($thisNameLast).value+'&tutorFormClass[]='+$($thisForm).options[$($thisForm).selectedIndex].value+'&tutorEmail[]='+$($thisEmail).value+'&tutorMobileNumber[]='+$($thisMobileNumber).value+'&tutorAccessName[]='+$($thisAccessName).value+'&tutorAccessPassword[]='+$($thisAccessPassword).value+'&tutorIsAdministrator[]='; }
	  if($($thisAdmin).checked) $arguments+='yes&'; else $arguments+='no&';}
  new Ajax.Updater(arguments[0], arguments[1]+'.php', {parameters:$arguments+'action='+arguments[2], evalScripts:true, asynchronous:true});	
}

function processDate() {
  // expects that the field given in arguments[0] will be of the form dateXXX
  var $dayNames = new Array("Sun", "Mon", "Tue","Wed", "Thurs", "Fri","Sat");
  var $thisDate = ''; if(arguments[2] < 10) $thisDate += '0'; 
      $thisDate += arguments[2]+'/';  if(arguments[3] < 10) $thisDate += '0'; 
	  $thisDate += arguments[3]+'/'+arguments[1];
  document.getElementById(arguments[0]).value = $thisDate;
  var $displayDate = new Date(); $displayDate.setFullYear(arguments[1],arguments[2]-1,arguments[3]);
  document.getElementById(arguments[0].substr(0,4)+'Display'+arguments[0].substr(4,arguments[0].length-4)).value = 
    $dayNames[$displayDate.getDay()]+'. '+arguments[3]+'/'+arguments[2]+'/'+arguments[1];
}

function showHide() {
  $div = document.getElementById(arguments[0]);
  if($div.style.display == 'block') {
  	$div.style.display = 'none';
  	unmaskScreen();
  }
  else {$div.style.display = 'block'; $div.focus(); }
}

function showHideConduct() {
  if($(arguments[0]).style.display == 'block') {
	  $(arguments[0]).style.display = 'none';
	  $('staffInvolved0').selectedIndex = 0; $('location0').selectedIndex = 0; $('period0').selectedIndex = 0;
	  $('conductType0').selectedIndex = 0; $('actionTaken0').selectedIndex = 0; $('points0').selectedIndex = 0; }
  else {$(arguments[0]).style.display = 'block'; $(arguments[0]).focus(); }
}


function hide() {
  $(arguments[0]).style.display = 'none';
}

function show() {
  $(arguments[0]).style.display = 'block';
}

function showLoading() {
  $(arguments[0]).innerHTML = '<p style="margin-left:140px"><img src="assets/graphics/loadingSmall.gif" /></p>';
}

function doNewConductAjax() {
	if(navigator.appVersion.indexOf('Mac')!=-1 && navigator.userAgent.indexOf('Safari')!=-1) 
	  $path = '';
	else
	  $path = 'assets/includes/conduct/'
	
	new Ajax.Updater('studentNameList', $path+'conductNewGroup.php', {parameters:'listFor=conduct', evalScripts:true, asynchronous:true});
	$('newConduct').style.display = 'block';
	unmaskScreen();
}

function updateAction() {
 if(arguments[0].value != '') {
  $thisRecord = arguments[0].id.substr(11,arguments[0].id.length-11);
  for(i=0; i<document.getElementById('actionTaken'+$thisRecord).length; i++) {
    if(document.getElementById('actionTaken'+$thisRecord).options[i].text.toLowerCase() == $conducts[arguments[0].value]['defaultAction'].toLowerCase()) {
      document.getElementById('actionTaken'+$thisRecord).selectedIndex = i;
	  var $foundAction = true;
      break; } }
  if(!$foundAction) document.getElementById('actionTaken'+$thisRecord).selectedIndex = 0;
  for($j=0; $j<document.getElementById('points'+$thisRecord).length; $j++) {
    if(document.getElementById('points'+$thisRecord).options[$j].text == $conducts[arguments[0].value]['defaultPoints']) {
      document.getElementById('points'+$thisRecord).selectedIndex = $j;
	  var $foundPoints = true;
      break; } }
  if(!$foundPoints) document.getElementById('points'+$thisRecord).selectedIndex = 0;
 }
}

function updateSelector() {
  $thisRecord = arguments[0].id.substr(11,arguments[0].id.length-11);
  $('conductTypeSelector'+$thisRecord).selectedIndex = 0;
}

function openWindow() {
  $args=openWindow.arguments;
  // 0 = window name, 1 = file to load, 2 = width, 3 = height, 4 = scrollbars
  thisWindow = window.open($args[1],$args[0],'width='+$args[2]+',height='+$args[3]+',scrollbars='+$args[4]);
  $leftPosition = (screen.width-$args[2])/2; $topPosition=(screen.height-$args[3]-40)/2;
  thisWindow.moveTo($leftPosition,$topPosition);
  thisWindow.focus();
  }

function inputList() {
  var $fieldList =''; var $selectList = '';
  for($i=0; $i<document.getElementsByTagName('input').length; $i++)
	$fieldList  += document.getElementsByTagName('input')[$i].id + '|'; 
  for($i=0; $i<document.getElementsByTagName('select').length; $i++)
	$selectList  += document.getElementsByTagName('select')[$i].id + '|';
  document.write('<p> fields '+$fieldList+'</p>');
  document.write('<p> selects '+$selectList+'</p>');
}

function hideShowPie() {
  $chartType = document.getElementById('chartType').value; 
  $pieTypes = new Array(5,6,8,9);
  if ($pieTypes.indexOf($chartType)!==-1) document.getElementById('pieSettings').style.display = 'block';
  else document.getElementById('pieSettings').style.display = 'none';
}

function deleteStudent () {
  if(confirm('Are you sure you wish to delete this student record? It can\'t be retrieved once you have done this!')) {
  maskScreen();
  document.location.href = 'student.php?studentNumber='+arguments[0]+'&action=deleteStudent'; }
}


function addItemDiv() {
  var ni = $('itemX');
  var numi = $('fieldCount');
  var num = parseInt($('fieldCount').value); numi.value = num +1; 
  var divIdName = "item"+num;
  var newdiv = document.createElement('div');
  newdiv.setAttribute("id",divIdName);
  newdiv.innerHTML = '<div id="item'+num+'" class="valueListEditing">'+
  					 '  <input type="text" id="listItem'+num+'" name="listItem[]" value="" />'+
					 '  <a href="javascript:removeItemDiv('+num+')"><img src="assets/graphics/iconDeleteMedium.png" alt="X" title="Delete item" /></a>'+
					 '</div>';
  ni.appendChild(newdiv);
  $('listItem'+num).focus();
}

function removeItemDiv() {
  $('itemX').removeChild($('item'+arguments[0]));
}

function insertText() {
  var $field = arguments[0]; var $value = arguments[1];
  if (document.selection) { 
    $field.focus();
	$sel = document.selection.createRange();
	$sel.text = $value; }
  else if ($field.selectionStart || $field.selectionStart == '0') {
	var $startPos = $field.selectionStart;
	var $endPos = $field.selectionEnd;
	var $currentScroll = $field.scrollTop;
	$field.value = $field.value.substring(0, $startPos)+ $value+ $field.value.substring($endPos, $field.value.length);
	$field.focus();
	$field.selectionStart = $endPos + $value.length;
	$field.selectionEnd = $endPos + $value.length;
	$field.scrollTop = $currentScroll;
	} else {
	  $field.value += $value;
	}
} 

function positionMessage() {
  // provide div, width and height (in that order) as called paramters
  var pagesize = maskGetPageSize();
  var arrayPageScroll = maskGetPageScrollTop();
  $(arguments[0]).setStyle({left: ((pagesize[0] - arguments[1])/2)+"px", top: (arrayPageScroll[1] + ((pagesize[1]-arguments[2])/2))+"px" })
  $(arguments[0]).setStyle({display:"block"});
}

function stripslashes(str) {
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
return str;
}

function createOption() {
  $(arguments[0]).options[($(arguments[0]).length)]=new Option(stripslashes(arguments[1]), stripslashes(arguments[1]), false, false); 
  $(arguments[0]).selectedIndex = ($(arguments[0]).length)-1;
  if(arguments[2]) { 
    $(arguments[2]).setStyle({display:"none"});
    unmaskScreen(); }
}

function openLetter() {
  if(arguments[0] == 'list')
	letterWindow = window.open('assets/includes/conduct/studentList.php?listFor=letter','letterWindow','width=350,height=560,scrollbars=no');
  else
    letterWindow = window.open('assets/includes/studentLetter.php?upn='+arguments[1]+'&amp;action=select','letterWindow','width=400,height=230,scrollbars=no');
  $leftPosition = (screen.width-400)/2; $topPosition=(screen.height-190)/2;
  letterWindow.moveTo($leftPosition,$topPosition);
  letterWindow.focus();
  $studentID = arguments[1];
  $destination = arguments[0];
}

function printParentLetter() {
  letterWindow = window.open('assets/includes/parentLetter.php?action='+arguments[0],'letterWindow','width=400,height=500,scrollbars=yes');
  $leftPosition = (screen.width-400)/2; $topPosition=(screen.height-500)/2;
  letterWindow.moveTo($leftPosition,$topPosition);
  letterWindow.focus();
  $destination = 'close';
  setWatch();
}

function setWatch() {
  $watch = setInterval(letterOpen, 500);
}


function letterOpen() {
  if (letterWindow.closed) {
   clearTimeout($watch);
   maskScreen();
   if($destination == 'student')
     new Ajax.Updater('content', 'student.php', {parameters:'studentNumber='+$studentID+'&action=showLetter', evalScripts:true, asynchronous:true});
   else {
     if($destination == 'close')
        unmaskScreen();
	 else
	 	window.location.reload(true); 
   }
  }
}

function isMacSafari() {
  if(navigator.appVersion.indexOf('Mac')!=-1) {
	if(navigator.userAgent.indexOf('Safari')!=-1)
	  document.write('<link rel="stylesheet" type="text\/css" href = "assets/css/macSafari.css" />');
	else
	  document.write('<link rel="stylesheet" type="text\/css" href = "assets/css/macFirefox.css" />');
  }	
}

function editWatch() {
  switch(arguments[0]) {
    case 'New':
    case 'Self':
       if($('formTeacher'+arguments[0]).getValue() == '') alert('You must select a staff member to add to the watch list');
       else
         if($('sms'+arguments[0]).getValue() != 1 && $('email'+arguments[0]).getValue() != 1) alert('You must select at least one watch type');
         else
       		new Ajax.Updater('studentWatchList', 'assets/includes/studentWatchList.php', {parameters:'action=addWatch&tutorID='+$('formTeacher'+arguments[0]).getValue()+'&sms='+$('sms'+arguments[0]).getValue()+'&email='+$('email'+arguments[0]).getValue(), evalScripts:true, asynchronous:true});
    break;
    case 'change':
       new Ajax.Updater('studentWatchList', 'assets/includes/studentWatchList.php', {parameters:'action=changeWatch&tutorID='+$('tutorID'+arguments[1]).getValue()+'&sms='+$('sms'+arguments[1]).getValue()+'&email='+$('email'+arguments[1]).getValue(), evalScripts:true, asynchronous:true});
    break;
    case 'remove':
      new Ajax.Updater('studentWatchList', 'assets/includes/studentWatchList.php', {parameters:'action=removeWatch&tutorID='+$('tutorID'+arguments[1]).getValue()+'&sms='+$('sms'+arguments[1]).getValue()+'&email='+$('email'+arguments[1]).getValue(), evalScripts:true, asynchronous:true});    
    break;
  }
}

function reloadAdmin() {
	new Ajax.Updater('studentWatchAdmin', 'assets/includes/studentWatchAdmin.php', {parameters:'action=reload', evalScripts:true, asynchronous:true});    
}

function debug() {
	new Ajax.Updater('studentConduct', 'assets/includes/watchAlert.php', {parameters:'action=reload', evalScripts:true, asynchronous:true});    	
}

function promoteCheck() {
	if(confirm('This process can not be reversed!\nAre you sure that you have checked all new form groups carefully?\n\nSelect OK when you are ready to proceed')) {
		return true;
	} else {
		return false;
	}
}

function promoteYear() {
	new Ajax.Updater('eoyUpdates', 'admin.php', {parameters:'action=eoyProcess&method=promoteNext', evalScripts:true, asynchronous:true});    	
}

function rssSubscribe() {
	maskScreen();
	positionMessage('rssSubscribe', 350, 250);
	show('rssSubscribe');
}

function saveRSS() {
	if($('rssName').getValue() == '') {
		alert('You must provide a name for this RSS feed');
	} else {
		$param = '';
		if(arguments[0]) {
			switch(arguments[0]) {
				case 'force':
					$param = '&params=force';
				break;
				case 'remind':
					$param = '&params=remind';
				break;
			}
		}
		new Ajax.Updater('rssSubscribe', 'admin.php', {parameters:'action=rssSave&name='+$('rssName').getValue()+$param, evalScripts:true, asynchronous:true});    	
	}
}

function rssDelete() {
	$('deleteFeed'+arguments[0]).src='assets/graphics/loadingSmall.gif';
	new Ajax.Updater('rssFeedTable', 'admin.php', {parameters:'action=rssManage&type=delete&feedID='+arguments[0], evalScripts:true, asynchronous:true});    	
	
}

function exportExcel() {
	openWindow('export','conduct.php?action=exportExcel&type='+arguments[0], 350, 180, 0);
}

function mergeFile() {
	maskScreen();
	if(!$('mergeDiv')) { 
		appendElement(document.body,'div','mergeDiv','');
	}
	new Ajax.Request('conduct.php', {
		method: 'post',
		parameters:'action=exportMerge&type='+arguments[0]+'&output='+arguments[1],
		onSuccess: function(transport) {
			$('mergeDiv').update(transport.responseText);
			centerDiv('mergeDiv',300,180);
		}
	});	
}

function appendElement(node,tag,id,htm) {
	var ne = document.createElement(tag);
	if(id) ne.id = id;
	if(htm) ne.innerHTML = htm;
	node.appendChild(ne);  
}

/*
Event.observe(document, 'keypress', 
function(event) { 
  var thisKey = event.charCode ? event.charCode : event.keyCode;
  if(event.ctrlKey) {
    switch(thisKey) {
	  case 78:
	  case 110: 
	    document.location.href = 'student.php?action=new';
	  break;
	  case 70:
	  case 102:
	    document.location.href = 'student.php?action=search';
	  break;
	}}
  return false;});
*/