function linkOn(id){
  id='span'+id;
  document.all[id].style.color='#ffffcc';
}

function linkOff(id){
  id='span'+id;
  document.all[id].style.color='#cccc99';
}

///////////////////////////////////////////////////////////////////////////////
// changes cell color on mouseover
///////////////////////////////////////////////////////////////////////////////
function ovr(id){
	tdname=id+'Td';
	spanname=id+'Span';
	document.getElementById(tdname).style.background='#ffffff';
	document.getElementById(spanname).style.color='#000000';
}
///////////////////////////////////////////////////////////////////////////////
// changes back cell color on mousout
///////////////////////////////////////////////////////////////////////////////
function out(id){
	tdname=id+'Td';
	spanname=id+'Span';
	document.getElementById(tdname).style.background='#ff6600';
	document.getElementById(spanname).style.color='#ffffff';
}
////////////////////////////////////////////////////////////////////////////////
// display new section, hide old section
///////////////////////////////////////////////////////////////////////////////
function toggle(id,v){
	// hide encounter //
	if(v=='v1'){
		toggle(id,'v2');
		document.getElementById('v2').value='';
	}
	// close current //
	if(id==document.getElementById(v).value){
		document.getElementById(id).style.display='none';
		document.getElementById(v).value='';
	}else{
		oldid=document.getElementById(v).value
		if(oldid != ''){
			document.getElementById(oldid).style.display='none';
		}
		// show id block //
		document.getElementById(v).value=id
		document.getElementById(id).style.display='block';
	}
}
///////////////////////////////////////////////////////////////////////////////
// submit page for SQL action
///////////////////////////////////////////////////////////////////////////////
function submitpage(sql,table,field,flag,id,returnpage){
	document.getElementById('sql').value=sql;
	document.getElementById('table').value=table;
	document.getElementById('field').value=field;
	document.getElementById('flag').value=flag;
	document.getElementById('id').value=id;
	document.getElementById('returnpage').value=returnpage;
	document.form.submit();
}
///////////////////////////////////////////////////////////////////////////////
// submit page with 2 tables for SQL action
///////////////////////////////////////////////////////////////////////////////
function submitpage2(sql,table,table2,field,field2,flag,flag2,id,id2,returnpage){
	document.getElementById('sql').value=sql;
	document.getElementById('table').value=table;
	document.getElementById('table2').value=table2;
	document.getElementById('field').value=field;
	document.getElementById('field2').value=field2;
	document.getElementById('flag').value=flag;
	document.getElementById('flag2').value=flag2;
	document.getElementById('id').value=id;
	document.getElementById('id2').value=id2;
	document.getElementById('returnpage').value=returnpage;
	document.form.submit();
}
///////////////////////////////////////////////////////////////////////////////
// refresh page passing value
///////////////////////////////////////////////////////////////////////////////
function rf(a,b){
	document.getElementById(a).value=b;
	document.form.action=window.location;
	document.form.submit();
}
///////////////////////////////////////////////////////////////////////////////
// drop-down refreshes page. Note: this syntax requires from to be named "form"
///////////////////////////////////////////////////////////////////////////////
function dd(a,b){
	document.getElementById(a).value=document.getElementById(b).value;
	document.form.action=window.location;
	document.form.submit();
}
///////////////////////////////////////////////////////////////////////////////
function dd2(a,b,a2,b2){
	document.getElementById(a).value=document.getElementById(b).value;
	document.getElementById(a2).value=document.getElementById(b2).value;
	document.form.action=window.location;
	document.form.submit();
}
///////////////////////////////////////////////////////////////////////////////
function sendemail(to,subj,body,hdr){
	document.getElementById('to').value=to;
	document.getElementById('subj').value=subj;
	document.getElementById('body').value=document.getElementById(body).value;
	document.getElementById('hdr').value=hdr;
	document.form.action=window.location;
	document.form.submit();
}
///////////////////////////////////////////////////////////////////////////////
// SUBMIT A FORM, CAUSING PAGE TO PROCEED
// actionPage = page to proceed, newPage = 1/new window, 0/same window
///////////////////////////////////////////////////////////////////////////////
function submit(page,popup){
 document.form.action=page;
 if(popup==1){
  document.form.target="_blank";
 }else{
  document.form.target="_self";
 }
 document.location.href=page;
}
///////////////////////////////////////////////////////////////////////////////
// SUBMIT A FORM, CAUSING PAGE TO PROCEED
// actionPage = page to proceed, newPage = 1/new window, 0/same window
///////////////////////////////////////////////////////////////////////////////
function submitButton(actionPage,newPage){
 document.form.action=actionPage;
 if(newPage==1){
  document.form.target="_blank";
 }
 else{
  document.form.target="_self";
 }
}
///////////////////////////////////////////////////////////////////////////////
// LOW-LEVEL FUNCTIONS
///////////////////////////////////////////////////////////////////////////////
function isnum(v1){
 if(v1=="") return false;
 for(i=0;i<v1.length;i++){
  if(v1.charAt(i)<"0"){return false;}
  if(v1.charAt(i)>"9"){return false;}
 }
 return true;
}
///////////////////////////////////////////////////////////////////////////////
// VERIFY THE FORM
// Call this function by: <form method=post onsumbit="return verify(this)">
// error-checking: <input type=hidden id=x_r name=x_r value="Enter X">
///////////////////////////////////////////////////////////////////////////////
function verify(form){
	for (var i=0;i<form.elements.length;i++){
		var flagfield=form.elements[i];
		var flagfieldname=form.elements[i].name;

		// REQUIRED FIELDS //
		if(/_r$/.test(flagfieldname)){
			var datafield=document.getElementById(flagfieldname.substr(0,flagfieldname.length-2));
			var datafieldname=datafield.name;
			if(datafield.value==''||datafield==null){
				alert(flagfield.value);
				datafield.focus();
				return false;
			}
		}
	}
	return true;
}
///////////////////////////////////////////////////////////////////////////////
// see if expression is numeric
///////////////////////////////////////////////////////////////////////////////
function testNumeric(inp){
 var valid = "-.0123456789";
 var temp;
 for (var i=0; i<inp.length; i++) {
  temp = "" + inp.substring(i, i+1);
  if (valid.indexOf(temp) == "-1") return false;
 }
 return true;
}
/*****************************************************************************/
/*/ VAIDATE REGISTRATION
/*****************************************************************************/
function register(form,sql,table,field,flag,id,returnpage){
	if(document.getElementById('password_1').value!=document.getElementById('password').value){
		alert('Passwords do not match.');
		document.getElementById('password_1').focus();
		return false;
	}
	
	document.getElementById('email_1').value=trimAll(document.getElementById('email_1').value);
	if(validateEmail(document.getElementById('email_1').value)==false){
		alert('Please enter a valid email address. ');
		return false;
	}
	
	var a1=verify(form);
	if(a1==true){
		submitpage(sql,table,field,flag,id,returnpage);
		return true;
	}else{
		return false;
	}
}
/****************************************************************************/
// TRIM ALL WHITE SPACE (EMAIL)
/****************************************************************************/
function trimAll($s) {
 if (typeof $s != "string") { return $s; }
 var $sout = $s;
 var $s1="";
 for(var i=0;i<$sout.length;i++){
  var $ch=$sout.substring(i,i+1);
  if($ch==" "){
   $s1=$sout.substring(0,i);
   $s2=$sout.substring(i+1,$sout.length);
   $sout=$s1+$s2;      
  }
 }  
 return $sout; // Return the trimmed string back to the user
}
/****************************************************************************/
// VALIDATE EMAIL ADDRESS
/****************************************************************************/
function validateEmail(a){
	// ASSUME EMAIL IS VALID
	var emailValid=1; 

	// ENSURE THAT THERE IS AN @ SIGN
	if(a.indexOf('@')<=0) emailValid=0;
	
	// ENSURE THERE IS ONLY ONE @ SIGN
	if(a.indexOf('@')!=a.lastIndexOf('@')) emailValid=0;

	// ENSURE THAT . DOESN'T FOLLOW @
	if(a.indexOf('.')-a.indexOf('@')==1) emailValid=0;
	
	// ENSURE SUFFIX IS .COM, .ORG OR .NET
	if((/\.com$/.test(a)==false) && (/\.net$/.test(a)==false) && (/\.org$/.test(a)==false) && (/\.tv$/.test(a)==false) ) emailValid=0;

	return(emailValid==1)?true:false;
}