var defaultSelected;

function txtAreaSelect(id) {
    if(document.getElementById(id)) {
        document.getElementById(id).focus();
        document.getElementById(id).select();
		  return true;
	 }
}

function scrollToButton(id,bottomMargin) {
    if(document.getElementById) {
        if(document.getElementById(id)) {
            var target=document.getElementById(id); 
            if(typeof target.scrollIntoView != 'undefined') {
                target.scrollIntoView(false); /* to bottom of window */
					 window.scrollBy(0,bottomMargin); /* move up a tad */
            }
        }
    }    
}

function axis(script,fieldName,fieldValue)
	{
	location.href=script+'?HighwayChile='+HighwayChile+'&passport='+Passport+'&'+fieldName+'='+fieldValue;	
	}

function doCache(id)
	{
	if(document.getElementById)
	    {
	    var lmenu=document.getElementById(id);
		 defaultSelected=lmenu.options.selectedIndex;
	    return true;	
	    }		
	}
	
function doReq(id,script)
   {
	if(document.getElementById)
	    {		
	    var list=document.getElementById(id);
		 list.className="listIsWorking";
		 list.blur();
		 var fld=escape(list.name); /* URL encode */
		 location.href=script+'?HighwayChile='+HighwayChile+'&passport='+Passport+'&fieldalias='+fld;
		 }
	}
	
function doVal(id,script)
   {
	if(document.getElementById)
	    {
	    var list=document.getElementById(id);
		 list.className="listIsWorking";
		 var fld=escape(list.name);  /* URL encode */
		 var opt=list.options[list.selectedIndex].value;		 	
		 /*list.blur();  for Safari this needs to be AFTER we fetch the selected value */
		 list.options.selectedIndex=defaultSelected;	
		 location.href=script+'?HighwayChile='+HighwayChile+'&passport='+Passport+'&fieldalias='+fld+'&valoption='+opt;		 
       }
    }		

function openBlurb(page)
	{
	var spec='scrollbars=yes,width=500,height=500';	
	window.open(page,'blurb',spec);
	return;
	}
function rab(t)
    {
	 window.open('http://www.smallgreentree.net/cgi-bin/tellafriend.cgi?ticket='+t+'&jscript=1&source='+escape(document.URL),
'','scrollbars=yes,width=450,height=310');
	 }
	 
function newWindowMessage()
	{
	var s="The page you are requesting will open in a new browser window.\n\n";	
	s+="That will not use the same secure connection as this control panel - ";
	s+="But that's OK in this case!";
	alert(s);
	return true;
	}
	
function doSGTPreview()
    {
	 if(document.getElementById)
	     {
	     var lmenu=document.getElementById('sgtpreview');					  
		  var d=lmenu.options[lmenu.selectedIndex].value;
		  if(d == 'nopreview')
		      {
				alert('Sorry! The preview option is not available as your template page is not set up yet');	
				}
	 	  else
		      {
				alert('The preview will open in a new browser window');
	 	      window.open(d,'_blank','');		  
				}
		  }
	 }	
	 
function globalCheck(prefix,action) 	{
	if(document.getElementById) {
	   var limit=document.getElementById('sgt_datarows');
	   for(var x=0; x<limit.value; x++) {
	   	  var chkbox=document.getElementById(prefix+x);
			  if(action) { chkbox.checked=true; }
			  else { chkbox.checked=false; }
	   }
	}  
   else {alert('Sorry! Your browser does not support this Javascript function');}	   
}	 	 
