/*
	This is the javascript file for the FMCSA Web site
*/
 
/* Printing Functions */
		var oPrintWindow = null;
		function Print(sPage)
		{
			if (oPrintWindow != null && oPrintWindow.closed == false)
				oPrintWindow.close();
			var oPrintWindow = window.open("/print.asp?URL="+sPage, "fmcsa_PrintWindow", "height=680, width=680, resizable=yes, dependent=yes, scrollbars=yes");
		}

		var js_url

		function print_appendix(sPage) {

				window.open(sPage , 'fmcsa_PrintWindow', 'height=680, width=680, resizable=yes, dependent=yes, scrollbars=yes')

		}

		function PrintURL(sPage)
		{
			if (oPrintWindow != null && oPrintWindow.closed == false)
				oPrintWindow.close();
			var oPrintWindow = window.open(sPage, "fmcsa_PrintWindow", "height=680, width=800, resizable=yes, dependent=yes, scrollbars=yes");
		}

/* Formatting Functions */

		function fixTD()
		{
			var theight = -1;
			for (var i=0; i < document.all.length; i++) {
				
				if(document.all.item(i).id.toString() == "TOCTop") {
					theight = document.all.item(i).offsetHeight;
				} 
				
				if(document.all.item(i).id.toString() == "toc1") {
					document.all.item(i).height = theight - document.all.item(i).offsetTop-5;
				}
			}			
        }


/* Created for Cross Border section */

			function MM_jumpMenu(targ,selObj,restore){ //v3.0
			  //alert(selObj.options[selObj.selectedIndex].value);
			  document.location.href = selObj.options[selObj.selectedIndex].value;
			  //eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
			  if (restore) selObj.selectedIndex=0;
			}

/* Search Functions */

		function clearSearch()
		{
			var txtSearch ;
			var txtSearch=document.getElementById("q");
			
			txtSearch.value=txtSearch.value.replace(/^ */, "").replace(/ *$/, "");
			//if (txtSearch.value.toLowerCase() == "Search This Site".toLowerCase())
				txtSearch.value = "";
        }

		function fillSearch()
		{
			var txtSearch ;
			var txtSearch=document.getElementById("q");
			
			txtSearch.value=txtSearch.value.replace(/^ */, "").replace(/ *$/, "");
			if (txtSearch.value.toLowerCase() == "".toLowerCase())
				txtSearch.value = "Search All FMCSA Sites";
        }
        
/* Date Format */

		function print_date(){
			var cur_date = new Date();
   			var hours = cur_date.getHours();
   			hours -= 5;
			cur_date.setHours(hours);
			var monthName = new Array("January", "February", "March", "April",
   			 							"May", "June", "July", "August", "September",
   										"October", "November", "December");
			var cur_month=cur_date.getMonth();
			cur_day = cur_date.getDate();
			var suffix = "th";
			if ((cur_day == 1) || (cur_day == 21) || (cur_day == 31)) {
				suffix = "st"
			} else if ((cur_day == 2)  || (cur_day == 22)) {
					suffix = "nd"
					}
					else if ((cur_day == 3) || (cur_day == 23)) {
						suffix = "rd"
						}
			suffix = "";
			/* var GMTtime = new Date();*/
			document.write(monthName[cur_month] + '&#160;' + cur_day + suffix + ',&#160;' + cur_date.getFullYear());
			/* document.write ('<br/>' + GMTtime.getMonth() + '&#160;' + GMTtime.getDate() + '&#160;' + GMTtime.getFullYear() + '&#160;' + GMTtime.getHours()) */
		}        
		
function search_rules() {
	document.google.Google_URL.value = "http://google2.dot.gov/search?q=site:www.fmcsa.dot.gov/rules-regulations/administration/fmcsr/%20" + document.google.q1.value + "&num=1000&btnG=Search&site=DOT_Pages&output=xml&client=default_frontend&filter=0";
	document.google.submit();
	 return true;
   }
   
		 var myWindow =''   
       function popupwin(sURL) {
		//alert('hello')
        if (myWindow.location && !myWindow.closed)
        {
            myWindow.location.href = sURL;
            myWindow.focus();
        }
        else
        {
    	    myWindow = window.open(sURL, 'myWindow', 'width=550,height=550,left=150,top=150,scrollbars=yes,resizable=yes,toolbar=no,location=no');
	        myWindow.focus();
			
	    }
    }


function resizeOuterTo(w,h) {
 if (parseInt(navigator.appVersion)>3) {
   if (navigator.appName=="Netscape") {
    top.outerWidth=w;
    top.outerHeight=h;
   }
   else top.resizeTo(w,h);
 }
}


function launch(){
    if ((screen.width >1024)&&(screen.height >768)){
        nw = window.open("course/s1.asp","main",'TITLE = "No FEAR Act Awareness",width=770,height=590,left=100,top=50,scrollbars=yes,toolbar=no,location=no,status=yes');
		nw.resizeTo(780,640);
		 nw.focus();
    }
 
else if ((screen.width <=1024)&&(screen.height <=768)){
      nw = window.open("course/s1.asp","main",'width=770,height=590,left=100,top=50,scrollbars=yes,toolbar=no,location=no,status=yes');
	  nw.resizeTo(780,640);
	nw.focus();	  
     }
}

function launchtraining() 
{
    if ((screen.width >1024)&&(screen.height >768))
      {
	  
        nw = window.open("course/s1.asp","main",'TITLE = "FMCSA IT Security Awareness Quiz",width=770,height=590,left=100,top=50,scrollbars=yes,toolbar=no,location=no,status=yes');
		nw.resizeTo(780,640);
		 nw.focus();
       }
 
else if ((screen.width <=1024)&&(screen.height <=768))


     {
      nw = window.open("course/s1.asp","main",'width=770,height=590,left=100,top=50,scrollbars=yes,toolbar=no,location=no,status=yes');
	  nw.resizeTo(780,640);
    	nw.focus();	  
      }
   
}

function launchControltraining() 
{
    if ((screen.width >1024)&&(screen.height >768))
      {
	  
        nw = window.open("course/s1.asp","Controlmain",'TITLE = "FMCSA Internal Control Awareness Course and Quiz",width=770,height=590,left=100,top=50,scrollbars=yes,toolbar=no,location=no,status=yes');
		nw.resizeTo(780,640);
		 nw.focus();
       }
 
else if ((screen.width <=1024)&&(screen.height <=768))


     {
      nw = window.open("course/s1.asp","Controlmain",'width=770,height=590,left=100,top=50,scrollbars=yes,toolbar=no,location=no,status=yes');
	  nw.resizeTo(780,640);
    	nw.focus();	  
      }
   
}

function cmmssst_validate(){
//	alert("hi");

 	with(window.document.contact){ 
		  	name.value=name.value.replace(/^ */, "").replace(/ *$/, "")
		 	if(name.value=="") {
				alert("You must enter name")
				name.focus();
				return false
			}
			
		  	company.value=company.value.replace(/^ */, "").replace(/ *$/, "")
		 	if(company.value=="") {
				alert("You must enter company name")
				company.focus();
				return false
			}
		  	email.value=email.value.replace(/^ */, "").replace(/ *$/, "")
		 	if(email.value=="") {
				alert("You must enter your email")
				email.focus();
				return false
			}	
			return true;					
	}
}

/* getting started test resize script added for wizard's 508 compliance */

//      Document Text Sizer- Copyright 2003 - Taewook Kang.  All rights reserved.
//	Web Site: http://txkang.com
//      Script featured on Dynamic Drive (http://www.dynamicdrive.com)
//      Specify affected tags. Add or remove from list:     
var tgs = new Array( 'div','td','tr','span','p', 'li', 'ul', 'ol', 'a', 'body', 'form','input', 'img');

//Specify spectrum of different font sizes:

var szs = new Array( 'xx-small','x-small','small','medium','large','x-large', 'xx-large' );
var startSz = 3;

function ts( trgt,inc ) {
	if (!document.getElementById) return
	var d = document,cEl = null,sz = startSz,i,j,cTags;
	sz += inc;
	if ( sz < 0 ) sz = 0;
	if ( sz > 6 ) sz = 6;
	startSz = sz;
	if ( !( cEl = d.getElementById( trgt ) ) ) cEl = d.getElementsByTagName( trgt )[ 0 ];
	cEl.style.fontSize = szs[ sz ];
	for ( i = 0 ; i < tgs.length ; i++ ) {
		cTags = cEl.getElementsByTagName( tgs[ i ] );
		for ( j = 0 ; j < cTags.length ; j++ ) cTags[ j ].style.fontSize = szs[ sz ];
	}	
	
}





/**
 * 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("invalid email")
		   return false
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   alert("invalid email")
		   return false
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    alert("invalid email")
		    return false
		}

		 if (str.indexOf(at,(lat+1))!=-1){
		    alert("invalid email")
		    return false
		 }

		 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		    alert("invalid email")
		    return false
		 }

		 if (str.indexOf(dot,(lat+2))==-1){
		    alert("invalid email")
		    return false
		 }
		
		 if (str.indexOf(" ")!=-1){
		    alert("invalid email")
		    return false
		 }

 		 return true					
	}






/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}



<!--
/*  TRB questionnaire form support 
facts-research/research-technology/conference/topic-questionnaire.htm */
function doAnalysis(qnum)
{

for (i=0;i<document.m0101.Analysis.length;i++) {
	if (document.m0101.Analysis[i].checked) {
		var user_input = document.m0101.Analysis[i].id;
		if (qnum == "q100"){
			document.m0101.analysisOther.readOnly=false;
		}
		else
		{
			document.m0101.analysisOther.readOnly=true;
		}
		
		

	}
}


}
function doResearch(rnum)
{

for (i=0;i<document.m0101.Research.length;i++) {
	if (document.m0101.Research[i].checked) {
		var user_input = document.m0101.Research[i].id;
		if (rnum == "q102"){
			document.m0101.researchOther.readOnly=false;
		}
		else
		{
			document.m0101.researchOther.readOnly=true;
		}
		
		

	}
}


}
function doTechnology(snum)
{


for (i=0;i<document.m0101.Technology.length;i++) {
	if (document.m0101.Technology[i].checked) {
		var user_input = document.m0101.Technology[i].id;
		if (snum == "q114"){
			document.m0101.technologyOther.readOnly=false;
		}
		else
		{
			document.m0101.technologyOther.readOnly=true;
		}
		
		

	}
}


}
/* end of TRB questionnaire form support */



function checkForm()
{



var isChecked = 0;
var validTopic = 0;
var  topicLength = 4;

var errorMsg0 = "Please Select at least 1 topic. \n Thank you."
var errorMsg1 = "Suggested topics must contain at least " + topicLength + " letters. "

var AnalysisTxt,auser_input;
AnalysisTxt = document.m0101.analysisOther.value;


   for (i=0; i < (document.m0101.Analysis.length - 1); i++)             // is Analysis radio 1 - 4 selected
   {    
    var auser_input = document.m0101.Analysis[i].checked;

      if(auser_input ==  true)
	  {
	    isChecked = 1;	     
	   }
	 }
	 
	      if(document.m0101.Analysis[4].checked == true)
	 { 
	    
              isChecked = 1;

              if(AnalysisTxt != "" && AnalysisTxt != null && 	 AnalysisTxt.length >= topicLength)
	      {	 	        
                 validTopic = 0;
	      }
	        else 
	      {
	          validTopic = 1;
	       }
	         
	 }
	 	 
	 
/* end analysis radio check  Begin Research radio check */
 var ResearchTxt,ruser_input;
     ResearchTxt = document.m0101.researchOther.value;


   for (i=0; i < (document.m0101.Research.length - 1); i++)             // is Research radio 1 - 2 selected
   {    
    var ruser_input = document.m0101.Research[i].checked;

      if(ruser_input ==  true)
	  {
	    isChecked = 1;	     
	   }
	 }
	
	 if(document.m0101.Research[2].checked == true)

	 { 
            isChecked = 1	;
	    if(ResearchTxt != "" && ResearchTxt != null && 	 ResearchTxt.length >= topicLength)
	    {	 	        
                 validTopic = 0;
	      }
	        else 
	      {
	          validTopic = 1;
	       }
	         
	 }
	
/* end Research radio check  Begin Technology radio check */
	 	 
var TechnologyTxt,tuser_input;
TechnologyTxt = document.m0101.technologyOther.value;

   for (i=0; i < (document.m0101.Technology.length - 1); i++)             // is Technology radio 1 - 2 selected
   {    
    var tuser_input = document.m0101.Technology[i].checked;

      if(tuser_input ==  true)
	  {
	    isChecked = 1;	     
	   }
	 }
	 
	 if(document.m0101.Technology[4].checked == true)
	 { 
              isChecked = 1	;
	    if(TechnologyTxt != "" && TechnologyTxt != null && 	 TechnologyTxt.length >= topicLength)
	    {	 	        
                 validTopic = 0;
	      }
	        else 
	      {
	          validTopic = 1;
	       }
	         
	 }
	  /* end Technology radio check */


    /* process submit  */

if( isChecked == 0 && validTopic == 0 )
{
alert("Please select at least one topic.");
return false;
}
else if ( isChecked == 1 && validTopic == 1)
{
alert("Please enter a topic in the 'Other' field.");
return false;
}
else 
{
//alert("OK to submit");
return true;
}


/*
switch (isChecked)
{
case 1:
      alert("submit the form");
      return false;
  break;    
case 2:
	alert(errorMsg1);
      //return an error message;  
     return false;
  break;
default:
	alert(errorMsg0);
      //return an error message;  
     return false;
}


*/

  /*  if(isChecked == 1)
    {
      alert("submit the form");
      return false;
    }
	 else
    {  
	alert(errorMsg+isChecked);
      //return an error message;  
     return false;
    }
  */
}  
	
 	 function trim(string) 
	 {
		var temp = "";
		string = '' + string;
		splitstring = string.split(" ");
		for(i = 0; i < splitstring.length; i++)
		temp += splitstring[i];
		return temp;
		
		}  		

//-->


