// JavaScript Document
function initHighlight() {
    if (!document.getElementsByTagName){ return; }
    var textfields = document.getElementsByTagName("input");
    var textareafields = document.getElementsByTagName("textarea");

    // loop through all input tags and add events
    for (var i=0; i<textfields.length; i++){
        var textfield = textfields[i];
        if (textfield.getAttribute("type") == "text") {
            textfield.onfocus = function () {this.className = 'inputFocus'; if (this.defaultValue==this.value) this.value = ""; }
            textfield.onblur = function () {this.className = 'input'; if (this.value == "") this.value = this.defaultValue; }
       }
    }
    for (var i=0; i<textareafields.length; i++){
        var textareafield = textareafields[i];
            textareafield.onfocus = function () {this.className = 'inputFocus'; if (this.defaultValue==this.value) this.value = ""; }
            textareafield.onblur = function () {this.className = 'input'; if (this.value == "") this.value = this.defaultValue; }
    }
}
addEvent(window, 'load', function () { initHighlight(); });
// verify contact form
function submitContactForm() {
  var missing = '';
  var invalid = '';
  if (document.contactForm.Name.value == '' || document.contactForm.Name.value == document.contactForm.Name.defaultValue) {
	document.contactForm.Name.className = "inputInvalid";
    missing += (missing != '') ? 'Name \n' : 'Name \n';
  }
  
  if (document.contactForm.email == '' || document.contactForm.email.value == document.contactForm.email.defaultValue) {
	document.contactForm.email.className = "inputInvalid";
    missing += (missing != '') ? 'E-mail \n' : 'E-mail \n';
  }
          var emailFilter=/^.+@.+\..+$/;
  var illegalChars= /[\(\)\<\>\,\;\:\\\/\[\]]/;
  var addr = document.contactForm.email.value;
  if (!(emailFilter.test(addr)) || addr.match(illegalChars)) {
	document.contactForm.email.className = "inputInvalid";
	  
       invalid += "Invalid E-mail Address \n";
  }
    if (document.contactForm.Phone.value == '' || document.contactForm.Phone.value == document.contactForm.Phone.defaultValue) {
	document.contactForm.Phone.className = "inputInvalid";
    missing += (missing != '') ? 'Contact Phone \n' : 'Contact Phone \n';
  }
   if (document.contactForm.Message.value == document.contactForm.Message.defaultValue) {
   document.contactForm.Message.value = '';
   }
   if (document.contactForm.Website.value == document.contactForm.Website.defaultValue) {
   document.contactForm.Website.value = '';
   }
   if (document.contactForm.Referred.value == document.contactForm.Referred.defaultValue) {
   document.contactForm.Referred.value = '';
   }
  if (missing != '') {
   //alert("Required Fields Missing: \n" + missing);
    return false;
  } else if (invalid != '') {
    //alert("Form Error: \n" + invalid);
    return false;
 } else {
   // document.contactForm.action ;

    return true;
  }
  return false;
}

// verify contact form in sidebar
function submitsideContactForm() {
  var missing = '';
  var invalid = '';
  if (document.sideContactForm.Name.value == '' || document.sideContactForm.Name.value == document.sideContactForm.Name.defaultValue) {
	document.sideContactForm.Name.className = "inputInvalid";
    missing += (missing != '') ? 'Name \n' : 'Name \n';
  }
  
  if (document.sideContactForm.email == '' || document.sideContactForm.email.value == document.sideContactForm.email.defaultValue) {
	document.sideContactForm.email.className = "inputInvalid";
    missing += (missing != '') ? 'E-mail \n' : 'E-mail \n';
  }
          var emailFilter=/^.+@.+\..+$/;
  var illegalChars= /[\(\)\<\>\,\;\:\\\/\[\]]/;
  var addr = document.sideContactForm.email.value;
  if (!(emailFilter.test(addr)) || addr.match(illegalChars)) {
	document.sideContactForm.email.className = "inputInvalid";
       invalid += "Invalid E-mail Address \n";
  }
    if (document.sideContactForm.Phone.value == '' || document.sideContactForm.Phone.value == document.sideContactForm.Phone.defaultValue) {
	document.sideContactForm.Phone.className = "inputInvalid";
    missing += (missing != '') ? 'Contact Phone \n' : 'Contact Phone \n';
  }
     if (document.sideContactForm.Message.value == document.sideContactForm.Message.defaultValue) {
   document.sideContactForm.Message.value = '';
   }
   if (document.sideContactForm.Website.value == document.sideContactForm.Website.defaultValue) {
   document.sideContactForm.Website.value = '';
   }
   if (document.sideContactForm.Referred.value == document.sideContactForm.Referred.defaultValue) {
   document.sideContactForm.Referred.value = '';
   }

  if (missing != '') {
   //alert("Required Fields Missing: \n" + missing);
    return false;
  } else if (invalid != '') {
    //alert("Form Error: \n" + invalid);
    return false;
 } else {
    document.sideContactForm.action ;
    return true;
  }
  return false;
}
//menu functions
menuHover = function(nav) {
    var sfEls = document.getElementById(nav).getElementsByTagName("li");
    for (var i=0; i<sfEls.length; i++) {
      sfEls[i].onmouseover=function() {
        this.className+=" sfhover";
      }
      sfEls[i].onmouseout=function() {
        this.className=this.className.replace(new RegExp("\\s?sfhover\\b"), "");
      }
    }

    var listItem = document.getElementById(nav).getElementsByTagName('ul');
    for(var i=0;i<listItem.length;i++) {
      listItem[i].onmouseover=function() {
        var changeStyle = this.parentNode.getElementsByTagName('a');
        changeStyle[0].className+=" active";
      }

      listItem[i].onmouseout=function() {
        var changeStyle = this.parentNode.getElementsByTagName('a');
        changeStyle[0].className=this.className.replace(new RegExp("\\s?active\\b"), "");
      }
    }
  }

  function addEvent( obj, type, fn ) {
    if ( obj.attachEvent ) {
      obj['e'+type+fn] = fn;
      obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
      obj.attachEvent( 'on'+type, obj[type+fn] );
    } else
      obj.addEventListener( type, fn, false );
    }
  function removeEvent( obj, type, fn ) {
    if ( obj.detachEvent ) {
    obj.detachEvent( 'on'+type, obj[type+fn] );
    obj[type+fn] = null;
    } else
      obj.removeEventListener( type, fn, false );
    }

addEvent(window, 'load', function () { menuHover('menu'); });
  
// Testimonials
hexinput1=204 ; // Initial color value.
hexinput2=204 ; // Initial color value.
hexinput3=204;  // Initial color value.
var inc=-1; //increment variable

function fadingtext(){	         	
if(hexinput1>51 && hexinput2>51 && hexinput3>51) {	
hexinput1-=11; // increase color value
hexinput2-=11; // increase color value
hexinput3-=11; // increase color value
document.getElementById("faderClients").style.color="rgb("+hexinput1+","+hexinput2+","+hexinput3+")"; // Set color value.
setTimeout("fadingtext()",60);	
}
else
{
hexinput1=204 ; //reset hex value
hexinput2=204 ;//reset hex value
hexinput3=204 ; //reset hex value
}
}

function changetext()
{
	if (!document.getElementById) return
	inc++;
	if (inc==0)
	{
		document.getElementById("faderClients").innerHTML='<ul class="fader"><li>Our MegaSite is the lynchpin of our marketing campaign. Prospective clients are impressed by the artistic and content-filled design. The MegaHunter team is responsive to my suggestions and quick to respond to my concerns. I couldn\'t be happier. Check us out and tell me if you agree!</li></ul><strong>Nancy Adel</strong><br />Adel & Pollack<br />www.apinjurylaw.com';
	}
	else if (inc==1)
	{
		document.getElementById("faderClients").innerHTML='<ul class="fader"><li>...I would recommend your services to others without question. Thank you.</li></ul><strong>Edward L. Amaral, Jr.</strong><br />Amaral & Associates, P.C.<br />www.amarallaw.com';

	}
	else if (inc==2)
	{
		document.getElementById("faderClients").innerHTML='<ul class="fader"><li>We are very happy. We received rave reviews! It is really hard to start from scratch without any input or help. The content made it very easy. I still can\'t believe how fast you were able to get us the first draft. You were so nice to work with and patient with us. Thanks again for making us look good!</li></ul><strong>John L. Lowery & Associates</strong><br />www.jllowery.com';
	}
	else if (inc==3)
	{
		document.getElementById("faderClients").innerHTML='<ul class="fader"><li>I\'m very pleased with the site. The process was more intense than I anticipated due to my inexperience and lack of know how, but your thoughtful and timely assistance carried the day. Thanks.</li></ul><strong>James Wattigny</strong><br />Wattigny Law<br />www.wattignylaw.com';
	}
	else if (inc==4)
	{
		document.getElementById("faderClients").innerHTML='<ul class="fader"><li>Wow, I wish I had found MegaHunter five years earlier. We are bubbling with the the possibilites associated with our new site. It was easier than expected. Your staff was very reponsive, professional and easy to work with. We always knew what they were doing and were they were in the process. You did a great job at a great price. Thanks.</li></ul><strong>Mark Underwood</strong><br />Underwood Law Office, Inc.<br />www.underwoodlawoffice.com';
		inc=-1;
	}

fadingtext();
setTimeout("changetext()",11000);
}
addEvent(window, 'load', function () { changetext(); });

//window.onload=changetext;
//addLoadEvent(changetext);
// add multiple onload events
function addLoadEvent(func) {   
    var oldonload = window.onload;
    if (typeof window.onload != 'function'){
        window.onload = func;
    } else {
        window.onload = function(){
        oldonload();
        func();
        }
    }
}

