function showHide(show, hide) {
  document.getElementById(show).style.display = "block";
  document.getElementById(hide).style.display = "none";

  if (show == "tab1") { 
     document.getElementById("tabHeader").style.backgroundImage  = "url(media/quoteHeader.gif)"; 
	 }
  if (show == "tab2") { 
     document.getElementById("tabHeader").style.backgroundImage  = "url(media/quoteHeader2.gif)"; 
	 }
}
/*********************
*  Form Validation -- Katinka Dixon www.winkshelp.com 
* In HTML use following for form fields:
* onChange="checkForError(document.getElementById('Email_Address'),'isEmail')"  
* always include value=""
* have a <p id="Email_AddressText" class="errorMessage"></p> for each field checked
* example css for errorMessage and dropThanks:
*.errorMessage { color:red; font-size:110%; display:inline;}
*
*#dropThanks {
*position:absolute; font-size:120%; font-weight:bold;
*visibility:hidden; padding:10px;
*left:200px; top:-200px;display:block;
*border: 1px inset blue;
*background-color:#ffffe1;
*}
* errors checked isPhoneNumber, isEmail, isEntered, isNumeric
* also include this dropThanks div anywhere HTML after body tag
*  <div id="dropThanks">
*    <div align="right"><a href="#" onClick="dropBox['dropThanks'].dismissBox();return false">[Close Box] </a></div>
*      <br /><br /><br /><br />
*      Thank you for your interest! <br /><br />A representative of TMG will be in touch with you shortly. 
*      <br /><br /><br /><br />
*     </div>
**********************/
 
 var submitted = 0;
 var stopSubmit = false;
 var numErrors = 0;
/***************
*  Validate on hit of submit
*  take submit type off button, let js do submit
***************/
function formvalidation (form, type1, type2, type3, isEnteredFieldNames) {
 var errorStatus = "false";
 stopSubmit = "false";
 if (submitted == 1) {
  alert("Form already submitted, please be patient");
  return false;}

 // field validations go here
  if ((type1 == "isPhoneNumber") || (type2 == "isPhoneNumber")  || (type3 == "isPhoneNumber")) {
     checkForError(document.getElementById('Phone_Number'),'isPhoneNumber');
     PhoneNumberOkay = errorStatus;
  }
  
  if ((type1 == "isEmail") || (type2 == "isEmail")  || (type3 == "isEmail")) {
     checkForError(document.getElementById('Email_Address'),'isEmail');
	 // if have valid phone don't need valid email
     if ((PhoneNumberOkay == "true") && (errorStatus == "true")) stopSubmit = "false";
  }
  
  if ((type1 == "isEntered") || (type2 == "isEntered")  || (type3 == "isEntered")) {
     fieldNames = isEnteredFieldNames.split(",");
	 for (var i = 1; i < fieldNames.length; i++) {
	     checkForError(document.getElementById(fieldNames[i]),'isEntered');
     }
  }
 
 if (stopSubmit == "true") {
    if (numErrors > 2) {
	   alert ("Please enter your name, phone number, and email address in their correct form before pressing the submit button");
    }
    numErrors = numErrors + 1;
	return false;
 }
 
 if (submitted == 0)  {
  submitted = 1;
  new dropBox('dropThanks',0,300);
  submitForm(form);
  return true;
  }
}

function submitForm(form) {
  formName = form.name
  document.getElementById(formName).submit();
}

function checkForError(elem, typeCheck) {

 //assume true

 if (!elem) {return;}

 elemName = elem.id;
 helperMsg = " ";
 elem.style.backgroundColor = "#FFF";
 var errorStatus = "false"; 
 elem.value=removeSpaces(elem.value)
 
 //check for not
 if (typeCheck == "isEntered") {
    stringCheck = trim(elem.value);
   
	if (stringCheck.length == 0) {
		helperMsg = "* required";
		errorStatus = "true";
    	elem.style.backgroundColor = "#ffffee";
  	    elem.focus();
	}	
 }
 if (typeCheck == "isNumeric") {
 	var numericExpression = /^[0-9]+$/;
	if((!elem.value.match(numericExpression)) || (elem.value.length == 0)){   
	    helperMsg = "* enter number";
    	elem.style.backgroundColor = "#ffffee";
		errorStatus = "true";
  	    elem.focus();
    }
 }

 if (typeCheck == "isEmail") {  
     var emailFilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i;
	 if (elem.value.length == 0) {
	    helperMsg = "* enter as name@domain.com";
		errorStatus = "true";
    	elem.style.backgroundColor = "#ffffee";
  	    elem.focus();
	 }
	 if (!elem.value.match( emailFilter)) {
		helperMsg = "* as name@domain.com";
		errorStatus = "true";
    	elem.style.backgroundColor = "#ffffee";
  	    elem.focus();
     } 
 }		
 if (typeCheck == "isPhoneNumber") {  
    var phoneRegex = /^\(\d\d\d\)\d\d\d-\d\d\d\d$/;
    if((!elem.value.match( phoneRegex )) || (elem.value.length == 0)) {
	    helperMsg = "* as (XXX) XXX-XXXX";
		errorStatus = "true";
    	elem.style.backgroundColor = "#ffffee";
  	    elem.focus();
    }
  }
  	    
  setReply(elemName, errorStatus, helperMsg);
}

function removeSpaces(string) {
	var tstring = "";
	string = '' + string;
	splitstring = string.split(" ");
	for(i = 0; i < splitstring.length; i++)
	tstring += splitstring[i];
	return tstring;
}

function setReply(elemName, errorStatus, helperMsg){
	var errorDivID = elemName + "Text"; 
	if(errorStatus == "false"){
   	  document.getElementById(errorDivID).innerHTML = " ";
	}
	else {
      stopSubmit = "true"
	  document.getElementById(errorDivID).innerHTML = helperMsg;
	}	
}

function dropBox(id, bounceLimit, finalTop){
if (!document.getElementById)
return
dropBox[id]=this;
this.finalTop=typeof finalTop=='number'? finalTop : document.getElementById(id).offsetTop;
this.bounceLimit=typeof bounceLimit=='number'? bounceLimit-bounceLimit%8 : 32;
this.obj=document.getElementById(id).style;
this.obj.zIndex=dropBox.zIndex++;
this.scrollTop=typeof window.pageYOffset=='number'? window.pageYOffset : this.trueBody().scrollTop;
this.obj.top=this.scrollTop-250+'px';
this.obj.visibility='visible';
this.dropStart=setInterval(function(){dropBox[id].dropIn();},50);
}

dropBox.prototype.dropIn=function(){
this.scrollTop=typeof window.pageYOffset=='number'? window.pageYOffset : this.trueBody().scrollTop;
if (parseInt(this.obj.top)<this.finalTop+this.scrollTop)
this.obj.top=Math.min(this.finalTop+this.scrollTop ,parseInt(this.obj.top)+40)+'px';
else{
var dropper=this;
clearInterval(this.dropStart);
this.bounceStart=setInterval(function(){dropper.bounceIn();},50);
}
}

dropBox.prototype.bounceIn=function(){
this.obj.top=parseInt(this.obj.top)-this.bounceLimit+'px';
if (this.bounceLimit<0)
this.bounceLimit+=8;
this.bounceLimit=this.bounceLimit*-1;
if (this.bounceLimit==0)
clearInterval(this.bounceStart);
}

dropBox.prototype.dismissBox=function(){
clearInterval(this.bounceStart);
this.obj.visibility='hidden';
}

dropBox.prototype.trueBody=function(){
return (document.compatMode && document.compatMode!='BackCompat')? document.documentElement : document.body;
}

function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
} 
