
function calcHeight(iframeID) {
  var the_iframe = document.getElementById(iframeID);

  if(!the_iframe ){
      return;
  }
 
  //find the height of the internal page
  var the_height=the_iframe .contentWindow.document.body.scrollHeight; 

  //change the height of the iframe
  the_iframe.height=the_height;
}


function validate(oForm) {
    var r =true;
    var el, i = 0;
    while (el = oForm.elements[i++]) {
        if("true"==el.getAttribute("required")){

            if("email"==el.getAttribute("vType")){
                if(!looksLikeEmail(el.value)){
                    markError(el);
                    r=false;
                }else{
                    clearError(el);
                }
            }else if(el.type=='text'||el.type=='textarea'){
                if(trim(el.value)=='' || trim(el.value)==el.getAttribute('dflt')){
                    markError(el);
                    r=false;
                }else{
                    clearError(el);
                }
            }else if(el.type=='select-one'){
                var min = el.getAttribute('minIdx');
                var max = el.getAttribute('maxIdx');                    
                
                if(min && min>0 && el.selectedIndex <min){
                    markError(el);
                    r=false;
                }else if(max && el.selectedIndex >max){
                    markError(el);
                    r=false;
                }else{
                    clearError(el);
                }
            }
        }
    };
    return r;
}

function looksLikeEmail(v) {
       var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
       if(reg.test(v) == false) {
          return false;
       }
       return true;
}

function markError(e){
    e.style.borderColor='red';
    //if(e.className!=null && e.className.indexOf('error-input')!=-1){
    //    return;
    //}
    //e.className=(e.className==null?'': e.className)+' error-input';
}

function clearError(e){
    e.style.borderColor='#E7E0D6';
    //if(e.className!=null){
    //    e.className= e.className.replace('error-input','');
    //}
}

String.prototype.trim = function () {
    return trim(this);
}


function trim(s){
    if(s==null){
	return s;
    }
    return s.replace(/^\s*/, "").replace(/\s*$/, "");
}
String.prototype.startsWith = function(str)
{return (this.match("^"+str)==str)}

String.prototype.endsWith = function(str)
{return (this.match(str+"$")==str)}


/* open the print version popup window */
function openPrintVersion(printURL) {
	if(printURL!=null){
		window.open(printURL, "print", "width=730,height=750,dependent=yes,resizeable=yes,status=no,toolbar=no,location=no,scrollbars=yes");
		return;
	}
	var params = "print=true";
	if (document.location.search != "") {
		params = document.location.search + "&" + params;		
	} else {
		params = "?" + params;
	}
	window.open(document.location.pathname + params, "print", "width=730,height=750,dependent=yes,resizeable=yes,status=no,toolbar=no,location=no,scrollbars=yes");
}


function loadPage(fInfo){
  location.href = fInfo.options[fInfo.selectedIndex].value
}

function bookmark_us(url, title){
	if (window.sidebar) { // firefox
		window.sidebar.addPanel(title, url, "");
	}
	else if(window.opera && window.print) { // opera
		var elem = document.createElement('a');
		elem.setAttribute('href',url);
		elem.setAttribute('title',title);
		elem.setAttribute('rel','sidebar');
		elem.click();
	} 
	else if(document.all) { // ie
		window.external.AddFavorite(url, title);
	}
	else { //chrome for now, but have to find Safari soln
		alert("Press CTRL+D (Chrome) or Command+D (Safari) to bookmark thia page");
	}
			
}

function increaseFontSize() {
	
	
   var max = 14;
   var h2_max = 20
   
   // temp var to hold size
   var s = 11;
	
	//parse for all p tags, remove "px", increase size by 1 and replace px
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         s = 11;
      }
      if(s < max) {
         s++;
		 p[i].style.fontSize = s+"px";
      }      
   }
   
   var td = document.getElementsByTagName('td');
   for(i=0;i<td.length;i++) {
      if(td[i].style.fontSize) {
         s = parseInt(td[i].style.fontSize.replace("px",""));
      } else {
         var s = 11;
      }
      if(s < max) {
         s++;
      }
      td[i].style.fontSize = s+"px";
   }
   
   var su = document.getElementsByTagName('sup');
   for(i=0;i<su.length;i++) {
      if(su[i].style.fontSize) {
         var s = parseInt(su[i].style.fontSize.replace("px",""));
      } else {
         var s = 11;
      }
      if(s < max) {
         s++;
      }
      su[i].style.fontSize = s6+"px";
   }
   
   var h2 = document.getElementsByTagName('h2');
   for(i=0;i<h2.length;i++) {
      if(h2[i].style.fontSize) {
         var s5 = parseInt(h2[i].style.fontSize.replace("px",""));
      } else {
         var s5 = 16;
      }
      if(s5 <= h2_max) {
         s5 = s5 + 2;
		 h2[i].style.fontSize = s5+"px";
      }
      
   }      
}


function decreaseFontSize() {
	
   var min = 10;
   var h2_min = 14;
	
   var p = document.getElementsByTagName('p');
   for(i=0;i<p.length;i++) {
      if(p[i].style.fontSize) {
         var s1 = parseInt(p[i].style.fontSize.replace("px",""));
      } else {
         var s1 = 11;
      }
      if(s1 > min) {
         s1 = s1 - 1;
      }
      p[i].style.fontSize = s1+"px";
   }   
   

var td = document.getElementsByTagName('td');
   for(i=0;i<td.length;i++) {
      if(td[i].style.fontSize) {
         var s4 = parseInt(td[i].style.fontSize.replace("px",""));
      } else {
         var s4 = 11;
      }
      if(s4 > min) {
         s4--;
      }
      td[i].style.fontSize = s4+"px";
   }
   
   var su = document.getElementsByTagName('sup');
   for(i=0;i<su.length;i++) {
      if(su[i].style.fontSize) {
         var s6 = parseInt(su[i].style.fontSize.replace("px",""));
      } else {
         var s6 = 11;
      }
      if(s6 > min) {
         s6--;
      }
      su[i].style.fontSize = s6+"px";
   }
   
   var h2 = document.getElementsByTagName('h2');
   for(i=0;i<h2.length;i++) {
      if(h2[i].style.fontSize) {
         var s5 = parseInt(h2[i].style.fontSize.replace("px",""));
      } else {
         var s5= 16;
      }
      if(s5 >= h2_min) {
         s5 = s5 - 2;
      }
      h2[i].style.fontSize = s5+"px";
   }
         
}

function image_roll(img_swap, img_name)
{
	img_name.src = img_swap;
}
function image_rollout(img_return, img_name)
{
	img_name.src = img_return;
}

//Dreamweaver 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,j=d.MM_p.length,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];}
}

