function clearMe(formfield){
  if (formfield.defaultValue==formfield.value)
   formfield.value = ""
 }

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_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}


/*this function will write out my address in such a way that should prevent
 * most spammers from finding it*/
function displayMail(mail) {
  var a='robfelty';
  var b='@';
  var c='gmail.com';
  //alert(mail);
  mail.title=a + b + c;
  mail.style.cursor='pointer';
}
function mailme() {
  var a='robfelty';
  var b='@';
  var c='gmail.com';
  document.location='mailto:' + a + b + c;
}
function addMail() {
  /*
  this function is called on the style sheet selector, instead of putting an
  onchange in the markup
  */
  if( document.getElementById && document.getElementsByTagName ) {
    if (document.getElementById('mail')) {
      var mail = document.getElementById('mail');
  //alert(mail);
      //styleSelector.onchange=alert('you clicked me');
      mail.onmouseover=function(){
        displayMail(mail);};
        //setActiveStyleSheet(styleSelector.options[styleSelector.selectedIndex].value);};
      mail.onclick=function(){
        mailme();};
    //      alert(styleSelector.onchange);
    }
  }
}

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      if (oldonload) {
        oldonload();
      }
      func();
    }
  }
}

addLoadEvent(function() {
  addMail(); 
  fontChange('init');
  changeFont();
  //changeStyle();
  /* more code to run on page load */
  //fontChange('init');
});

function fontChange(change) {
  cookieFontSize=readCookie('fontSize');
  //alert(cookieFontSize);
  if (cookieFontSize!=null) {
    currFontSize=cookieFontSize;
  } else {
    currFontSize='100%';
  }
  //  alert(currFontSize);
  var content=document.getElementById("content");
  //currFontSize=content.style.fontSize;
  var currFontNum =parseInt(currFontSize);
  if (change=='init') {
    content.style.fontSize=currFontSize;
    //content.style.fontSize='100%';
  }
  if (change=='default') {
    content.style.fontSize='100%';
    createCookie('fontSize', '100%', 7); 
  }
  if (change=='bigger') {
    biggerFont=currFontNum+6+'%';
    createCookie('fontSize', biggerFont, 7); 
    content.style.fontSize=biggerFont;
  }
  if (change=='smaller') {
    smallerFont=currFontNum-6+'%';
    createCookie('fontSize', smallerFont, 7); 
    content.style.fontSize=smallerFont;
  }
}
function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  } else {
    var expires = "";
  }
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') {
      c = c.substring(1,c.length);
    }
    if (c.indexOf(nameEQ) == 0) {
      return c.substring(nameEQ.length,c.length);
    }
  }
  return null;
}

function eraseCookie(name) {
  createCookie(name,"",-1);
}
function changeFont() {
  /* 
  this function is called on the font size selectors , instead of putting an
  onclick in the markup 
  */
  if( document.getElementById && document.getElementsByTagName ) {
    if (document.getElementsByTagName('input')) {
      var inputs = document.getElementsByTagName('input');
      for (var i=0; i < inputs.length; i++) {
        if (inputs[i].type=='button' && inputs[i].className.match('fontChange')) {
          if (inputs[i].className.match('smaller')) {
      inputs[i].onclick=function(){
        fontChange('smaller');};
          }
          if (inputs[i].className.match('bigger')) {
      inputs[i].onclick=function(){
        fontChange('bigger');};
          }
          if (inputs[i].className.match('default')) {
      inputs[i].onclick=function(){
        fontChange('default');};
          }
        }
      }
      //styleSelector.onchange=alert('you clicked me');
      //styleSelector.onchange=setActiveStyleSheet(styleSelector.options[styleSelector.selectedIndex].value);
    //      alert(styleSelector.onchange);

    }   
  }
}


function ajaxFunction(){
  var ajaxRequest;  // The variable that makes Ajax possible!
  
  try{
    // Opera 8.0+, Firefox, Safari
    ajaxRequest = new XMLHttpRequest();
  } catch (e){
    // Internet Explorer Browsers
    try{
      ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try{
        ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e){
        // Something went wrong
        alert("Your browser broke!");
        return false;
      }
    }
  }
  ajaxRequest.onreadystatechange = function(){
    if(ajaxRequest.readyState == 4){
      //var images=;
      // Get the data from the server's response
    }
  }
}

