// Example: obj = findObj("image1");
function findObj(theObj, theDoc)
{
  var p, i, foundObj;
  
  if(!theDoc) theDoc = document;
  if( (p = theObj.indexOf("?")) > 0 && parent.frames.length)
  {
    theDoc = parent.frames[theObj.substring(p+1)].document;
    theObj = theObj.substring(0,p);
  }
  if(!(foundObj = theDoc[theObj]) && theDoc.all) foundObj = theDoc.all[theObj];
  for (i=0; !foundObj && i < theDoc.forms.length; i++) 
    foundObj = theDoc.forms[i][theObj];
  for(i=0; !foundObj && theDoc.layers && i < theDoc.layers.length; i++) 
    foundObj = findObj(theObj,theDoc.layers[i].document);
  if(!foundObj && document.getElementById) foundObj = document.getElementById(theObj);
  
  return foundObj;
}

// * Dependencies * 
// this function requires the following snippets: (above)findObj, (ff: below)timeoutLayer
//
// Accepts a variable number of arguments, in triplets as follows:
// arg 1: simple name of a layer object, such as "Layer1"
// arg 2: ignored (for backward compatibility)
// arg 3: 'hide' or 'show'
// repeat...
//
// Example: showHideLayers(Layer1,'','show',Layer2,'','hide');

//  ::FF:: Now includes a time out function using timeoutLayer
var timedHide

function showHideLayers(){ 
  var i, visStr, obj, args = showHideLayers.arguments;
  if(timedHide != null) clearTimeout(timedHide);
  for (i=0; i<(args.length-2); i+=3)
  {
    if ((obj = findObj(args[i])) != null)
    {
      visStr = args[i+2];
      if (obj.style)
      {
        obj = obj.style;
        if(visStr == 'show') {
                  visStr = 'visible';
                } else if(visStr == 'hide') {
                  visStr = 'hidden';
                }
      }
      obj.visibility = visStr;
    }
  }
}

function timeoutLayer(theLayer) {
        timedHide = setTimeout("showHideLayers('" + theLayer + "','','hide')",1500);//need to have it call this.layer and hide
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

//Example: preloadImages('file.gif', 'http://www.x.com/y.gif');
function preloadImages()
{
  if(document.images)
  {
    if(!document.imageArray) document.imageArray = new Array();
    var i,j = document.imageArray.length, args = preloadImages.arguments;
    
    for(i=0; i<args.length; i++)
    {
      if (args[i].indexOf("#")!=0)
      {
        document.imageArray[j] = new Image;
        document.imageArray[j++].src = args[i];
      }
    }
  }
}

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_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=findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

// EMAIL VALIDATION

function checkEmail() {
  text=document.emailform.SENDER.value;
  if (text.indexOf("@")<3){
    alert(" This email address seems wrong. Please"
    +" check the prefix and '@' sign.");
    return false;
  }
  if ((text.indexOf(".com")<5)&&(text.indexOf(".org")<5)
    &&(text.indexOf(".gov")<5)&&(text.indexOf(".net")<5)
    &&(text.indexOf(".co.uk")<7)&&(text.indexOf(".nl")<4)&&(text.indexOf(".us")<4)
    &&(text.indexOf(".mil")<5)&&(text.indexOf(".edu")<5))
  {
     alert(" This email address seems wrong. Please"
     +" check the suffix. (It should include a .com, .edu,"
     +" .net, .org, .gov, .us, .co.uk, .nl or .mil)");
     return false;
  }
return true;
}

//DHTML email validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
function echeck(str) {

                var at="@"
                var dot="."
                var lat=str.indexOf(at)
                var lstr=str.length
                var ldot=str.indexOf(dot)
                if (str.indexOf(at)==-1){
                   alert("This email address seems wrong. Please check the prefix and '@' sign.")
                   return false
                }

                if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
                   alert("This email address seems wrong. Please check the suffix and '@' sign.")
                   return false
                }

                if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
                    alert("This email address seems wrong. Please check the dots are correctly placed.")
                    return false
                }

                 if (str.indexOf(at,(lat+1))!=-1){
                    alert("This email address seems wrong. Please check the dot placements and '@' sign.")
                    return false
                 }

                 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
                    alert("This email address seems wrong. Please check the dot placements and '@' sign.")
                    return false
                 }

                 if (str.indexOf(dot,(lat+2))==-1){
                    alert("This email address seems wrong. Please check the dots are correctly placed.")
                    return false
                 }
                
                 if (str.indexOf(" ")!=-1){
                    alert("Your email address is invalid")
                    return false
                 }

                  return true                                        
        }

function ValidateForm(formname){
    var emailID=document.forms[formname].SENDER
    
    if ((emailID.value==null)||(emailID.value=="")){
        alert("You are subbmitting your message without an email address.  No reponse to your message can be sent.")
        emailID.focus()
        return true
    }
    if (echeck(emailID.value)==false){
        emailID.value=""
        emailID.focus()
        return false
    }
    return true
 }


 // EXECUTE SITE WIDE CONTENT WRITING

document.write("<link rel=\"stylesheet\" type=\"text/css\" href=\"http://www.senate.state.tx.us/assets/styles/print.css\" media=\"print\"> \n");
document.write("<link rel=\"stylesheet\" type=\"text/css\" title=\"screen\" href=\"http://www.senate.state.tx.us/assets/styles/main.css\" media=\"screen\"> \n");
document.write("<script language=\"Javascript\" src=\"http://www.senate.state.tx.us/assets/java/menu.es.js\" type=\"text/javascript\"></script> \n");

