
// ---------- JAVASCRIPT ERROR REPORTING ----------

var errorString = "";				// leave alone
var numErrors = 0;				// leave alone
var displayingErrors = false;			// leave alone

maxErrorsToDisplay = 20;			// set to suit
var errorReporting = true;			// set to false to disable error reporting (note, this might be overridden in a script using this file)

domname = 'taichituition.co.uk';		// modify this, set to your email domain

function reportError( msg, url, line ) {

  if( ( errorReporting == true ) && ( numErrors < maxErrorsToDisplay ) ) {

    errorString += "Error: " + msg + " on line: " + line + "\nURL: " + url  + "\nWeb: " + navigator.appName + " " + navigator.appVersion + "\n";

    if( ++numErrors == maxErrorsToDisplay ) {
      errorString += "\nmax errors to display (" + maxErrorsToDisplay + ") reached\n";
    }

    if( displayingErrors )
      document.errform.errorDisplay.value = errorString;
  }
  return true;
}

window.onerror = reportError;

function showErrorReportBox()
{
  if( errorReporting == true ) {

    displayingErrors = true;

    document.write('<br><hr><center><p><form name=errform><span style="color: maroon; background-color: white; font-family: Verdana, Tahoma, Arial; font-size: x-small"><b>&nbsp;Javascript Error Report&nbsp;</b></span><br>');
    document.write('<textarea name=errorDisplay rows=20 cols=70></textarea><br><br>');
    document.write('<input type=button value="Cause Javascript Error" onClick="badScript()"><br><br>');
    document.write('</form></center>');

    document.errform.errorDisplay.value = errorString;
  }
}

// ---------- EMAIL FUNCTIONS ----------

function put_email( thePrefix )	// only one argument actually needed, (text before the '@')
{
// put_email( "thePrefix", "css_class", "theText" );
// if no class, but specifying text, specify the class as an empty string in function call
// i.e. put_email( "thePrefix", "", "theText" );

  var argv = put_email.arguments;
  var argc = put_email.arguments.length;

  var css_class = (argc > 1) ? argv[1] : null;
  var theText = (argc > 2) ? argv[2] : null;

  var addrComplete = thePrefix + '@' + domname;

  document.write( '<a href=\"ma' );
  document.write( 'ilto:' );
  document.write( addrComplete );
  document.write( '\"' );
  if( css_class != null ) {
    document.write( ' class=\"' );
    document.write( css_class );
    document.write( '\"' );
  }
  document.write('>');
  if( theText == null ){
    theText = addrComplete;
  }
  document.write( theText );
  document.write('<\/a>');
}

function validateEmail( emailAddress )
{
  var ok = 1;

  var exclude=/[^@\-\.\w]|^[_@\.\-]|[\._\-]{2}|[@\.]{2}|(@)[^@]*\1/;
  var check=/@[\w\-]+\./;
  var checkend=/\.[a-zA-Z]{2,4}$/;

  if( ( ( emailAddress.search( exclude ) != -1 ) || ( emailAddress.search( check ) ) == -1 ) || ( emailAddress.search( checkend ) == -1 ) )
    ok = 0;

  return ok;
}

// ---------- LINK IMAGE FUNCTIONS ----------

function MM_swapImgRestore() { //v3.0
  var i, x, a=document.MM_sr;
  for( i=0; a && i < a.length && ( x = a[i] ) && x.oSrc; i++ )
    x.src = x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document;
  if( d.images ) {
    if(!d.MM_p)
      d.MM_p = new Array();
    var i;
    var j = d.MM_p.length
    var a = MM_preloadImages.arguments;
    for( i=0; i < a.length; i++ ) {
      if ( a[i].indexOf("#") != 0 ) {
        d.MM_p[j]=new Image;
        d.MM_p[j++].src=a[i];
      }
    }
  }
}

function MM_findObj( n, d ) { //v4.01
  var p, i, x;

  if(!d)
    d=document;

  if( ( p=n.indexOf("?") ) > 0 && parent.frames.length ) {
    d=parent.frames[n.substring(p+1)].document;
    n=n.substring( 0, p );
  }

  if(!( x = d[n] ) && d.all )
    x = d.all[n];

  for ( i=0; !x && i < d.forms.length; i++ )
    x = d.forms[i][n];

  for( i=0; !x && d.layers && i < d.layers.length; i++ )
    x = MM_findObj( n, d.layers[i].document );

  if( !x && d.getElementById )
    x = d.getElementById(n);

  return x;
}

function MM_swapImage() { //v3.0
  var i, j=0, x, a=MM_swapImage.arguments;
  document.MM_sr=new Array;
  for( i=0; i < ( a.length - 2 ); i += 3 ) {
    if((x=MM_findObj(a[i]))!=null){
      document.MM_sr[j++]=x;
      if(!x.oSrc)
        x.oSrc=x.src;
      x.src=a[i+2];
    }
  }
}

// ---------- GENERAL FUNCTIONS ----------

function showLastModified()
{
  document.write("<center>\n<br>\n");
  document.write("This page last modified: <b>" + document.lastModified + "<\/b> &nbsp;");
  put_email( "john", "", "<b>Webmaster<\/b>" );
  document.write("\n<\/center>\n");
}
