// JavaScript Document
var gModalColor = "#000";
var gModalOpacity = 0.2;

// correct formating to checkboxes and radio buttons
jQuery(document).ready(function(){
  try
  { 
    // set margins on radio and checkboxes
    jQuery("input[type='checkbox']").css("border","none");
    jQuery("input[type='checkbox']").css("margin-right",".5em");
    jQuery("input[type='checkbox']").css("margin-left","0px");
    jQuery("input[type='radio']").css("border","none");
    jQuery("input[type='radio']").css("margin-right",".5em");
    jQuery("input[type='radio']").css("margin-left","0px");
    jQuery("input[type='image']").css("border","none");
    
    // ScrollTo link configuration
    // back to top links - ScrollTo config - use "a.BTT" in body to activate
    jQuery('a.BTT').click(function(){
      jQuery('#idPageTop').ScrollTo(800); // see id in body tag    
      return false;
    });
    // JumpLink - ScrollTo config - use "a.JumpLink" in body to activate
    jQuery('a.JumpLink').click(function(){
      jQuery(jQuery(this).attr("href")).ScrollTo(800); //gets where to go from href attr
      return false;
    });
    
    // scroll to if a anchor is passed in hash
      sLocation = new String(location.hash);
      sLocation = sLocation.substr(0); 
      if(sLocation.length > 0 )
      {
        window.location.hash = 'idPageTop'; // see id in body tag  
        window.location.hash = '';
        self.setTimeout(function(){jQuery(sLocation.toString()).ScrollTo(800)}, 100);        
      }

  } 
  catch(er) {}
  // error message from captcha, logins, or any .asp validation that goes back to original page
  sbErrorMsg(); // function is located in "/common/head.asp";  javascript code that runs is created and inserted into function is located in "/common/_subroutines.asp")
});


////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
// Ted's function for an on load dialog box that takes arguments

var jqDialogAutoPopupStatus = 0;

function jqDialogAutoPopup(o) 
{
  //default values if not passed
  o.Container = (typeof o.Container == 'undefined') ? '#ModalPopup' : o.Container;
  o.Title = (typeof o.Title == 'undefined') ? '' : o.Title;
  o.Content = (typeof o.Content == 'undefined') ? 'An undefined error has occured' : o.Content;
  o.URL = (typeof o.URL == 'undefined') ? null : o.URL;
  o.Width = (typeof o.Width == 'undefined') ? 'auto' : o.Width;
  o.Width = ( (typeof o.Width == 'number' && (o.Width + 0) == 0 ) ) ? 'auto' : o.Width; // if Width is set to 0 then Width becomes automatic
  o.Width = ( (jQuery.browser.msie && (parseFloat(jQuery.browser.version) < 8) && (o.Width) == 'auto' )) ? '450' : o.Width; // if browser is EI and version <8 and Width is set to 'auto' (line above) then Width becomes automatic
  o.Height = (typeof o.Height == 'undefined') ? 'auto' : o.Height;
  o.ShowEffect = (typeof o.ShowEffect == 'undefined') ? 'scale' : o.ShowEffect; // scale
  o.HideEffect = (typeof o.HideEffect == 'undefined') ? 'scale' : o.HideEffect; // scale
  o.EffectSpeed = (typeof o.EffectSpeed == 'undefined') ? 'fast' : o.EffectSpeed; //fast
  o.ModalBackground = (typeof o.ModalBackground == 'undefined') ? '#ModalBackground' : o.ModalBackground;
  o.ModalColor = (typeof o.ModalColor == 'undefined') ? gModalColor : o.ModalColor;
  o.ModalOpacity = (typeof o.ModalOpacity == 'undefined') ? gModalOpacity : o.ModalOpacity;
	var windowWidth = document.documentElement.clientWidth;
  var windowHeight = document.documentElement.clientHeight;
  //loads popup only if it is disabled
	if(jqDialogAutoPopupStatus==0)
  {
    jQuery(o.ModalBackground).css({
    	"height": windowHeight * 10, 
    	"width": windowWidth,
    	"background": o.ModalColor,
    	"opacity": 0.0 // this is used because the current seleced style has a background
//    	"opacity": o.ModalOpacity
    });    
    jQuery(o.ModalBackground).bgiframe();
    jQuery(o.ModalBackground).fadeIn(o.EffectSpeed, function(){
      //display dialog
      jQuery(o.Container).html(o.Content);
      if(o.URL)
      {
        jQuery.ajax({
          url: o.URL,
          success: function(html)
          {
            jQuery(o.Container).html(html);      
          }
        });
      }
      
      jQuery(o.Container).css( 'display', 'block' ) ;
  
    	jQuery(o.Container).dialog({
        autoOpen: false,
        show: o.ShowEffect,
        hide: o.HideEffect,
        title: o.Title,
        width: o.Width,
        height: o.Height,
        modal: true,
        close: function()
          {  
            jQuery(o.ModalBackground).fadeOut(o.EffectSpeed);
            jqDialogAutoPopupStatus = 0;
            try
            { 
              jQuery(o.Container).css( 'display', '' ) ;
              v_varFormFieldThatNeedsfocus.focus();
            } 
            catch(er) {} 
    			},
    		buttons: {
    			"Close": function()
          { 
            jQuery(o.Container).dialog("close"); 
    			}
    		}		
    	});
    	jQuery(o.Container).dialog("open");
    });
    jqDialogAutoPopupStatus = 1;
  }
}


////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
// display a action to prevent users from clicking the submit button more than once
function sbAfterFormSubmit()
{
	var windowWidth = document.documentElement.clientWidth;
  var windowHeight = document.documentElement.clientHeight;
  jQuery('#ModalBackground').css({
  	"height": windowHeight, 
  	"width": windowWidth
  });    
  jQuery('#idAjaxLoading').css({
  	"height": windowHeight, 
  	"width": windowWidth
  });    

  // with ie 6... reposition #ModalBackground and #idAjaxLoading to the scroll position (or the stuff will be at the toop of the page)
  if ( jQuery.browser.msie && (parseInt(jQuery.browser.version) < 7)  )
  {
    // this code for finding the scroll position works with all browsers (even though we are only doing the reposition for ie 6)
    var iScrollTop = document.body.scrollTop; // most browsers
    if (iScrollTop == 0)
    {
      if (window.pageYOffset) // only firefox
        iScrollTop = window.pageYOffset;
      else
        iScrollTop = (document.body.parentElement) ? document.body.parentElement.scrollTop : 0; // ie (I think)
    }
  jQuery('#ModalBackground').css({"top": iScrollTop});
  jQuery('#idAjaxLoading').css({"top": iScrollTop});
  }
  
  jQuery('#ModalBackground').bgiframe();
  jQuery('#ModalBackground').fadeIn(100);
  jQuery('#idAjaxLoading').fadeIn(100);
}




////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////// preload checkboxes, radio buttons and pull downs ///////////////////////////////////
/////////////// ideal for redisplay after captcha                ///////////////////////////////////
//Example:      sbPreloadPreviousValues(document.frmForm.SOME_Select_Radio_Checkbox, '<% = session.Contents("SOME_Select_Radio_Checkbox") %>');
//Details:                             ( ^^^^^^^ some input as DOM object ^^^^^^   , '^^^^^^    a string value to search     ^^^^^^        ');
function sbPreloadPreviousValues(oInput,sValues)
{
  if(typeof(oInput.selectedIndex) != 'undefined') //pull down
  {
    for(i=0;i<oInput.length;i++)
    {
      if(sValues == oInput[i].value)
      {
        oInput.selectedIndex = i;
        break;
      }
    }  
  }
  else if(typeof(oInput.length) == 'undefined') //single checkbox in group
  {
    if(sValues.indexOf(oInput.value) > -1)
      oInput.checked = true;
  }
  else //check each checkbox or radio button
  {
    var a_Values = sValues.split(",");
    for(i=0;i<oInput.length;i++)
    {
      for(j=0;j<a_Values.length;j++)
      {
        if( jQuery.trim(oInput[i].value) == jQuery.trim(a_Values[j]) )
          oInput[i].checked = true;
      }
    }
  }
}

////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
function sbClearForm(oForm)  //  oForm = some input as DOM object     //Example: document.frmForm
{
  for(i=0;i<oForm.length - 1;i++)
  {
    oInput = oForm[i];
    if(typeof(oInput.selectedIndex) != 'undefined') //pull down
      oInput.selectedIndex = 0;
  try
  { 
    oInput.checked = false;
    if(oInput.length > 1)
    {
      for(j=0;oInput.length;j++)
      {
        oInput[j].checked = false;
      }
    }
    oInput.value = '';
  } 
  catch(er) {}

      
      
  }
}






