// JavaScript Document
// 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') ? '#dialog' : o.Container;
  o.Title = (typeof o.Title == 'undefined') ? 'Alert' : 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') ? 250 : o.Width;
  o.ShowEffect = (typeof o.ShowEffect == 'undefined') ? '' : o.ShowEffect;
  o.HideEffect = (typeof o.HideEffect == 'undefined') ? '' : o.HideEffect;
  o.ModalBackground = (typeof o.ModalBackground == 'undefined') ? '#ModalBackground' : o.ModalBackground;
  o.ModalColor = (typeof o.ModalColor == 'undefined') ? '#000' : o.ModalColor;
  o.ModalOpacity = (typeof o.ModalOpacity == 'undefined') ? '0.3' : o.ModalOpacity;
	var windowWidth = document.documentElement.clientWidth;
  var windowHeight = document.documentElement.clientHeight;
  //loads popup only if it is disabled
	if(jqDialogAutoPopupStatus==0)
  {
    $(o.ModalBackground).css({
    	"height": windowHeight, 
    	"width": windowWidth,
    	"background": o.ModalColor,
    	"opacity": o.ModalOpacity
    });    
    $(o.ModalBackground).bgiframe();
    $(o.ModalBackground).fadeIn("normal", function(){
      //display dialog
      $(o.Container).html(o.Content);
      if(o.URL)
      {
        $.ajax({
          url: o.URL,
          success: function(html)
          {
            $(o.Container).html(html);      
          }
        });
      }
    	$(o.Container).dialog({
        autoOpen: true,
        show: o.ShowEffect,
        hide: o.HideEffect,
        title: o.Title,
        width: o.Width,
    		buttons: {
    			"Ok": function()
          { 
            $(o.Container).dialog("close"); 
            $(o.ModalBackground).fadeOut("normal");
            jqDialogAutoPopupStatus = 0;
    			}
           
    		}		
    	});
    });
    jqDialogAutoPopupStatus = 1;
  }
}


/////////////// 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;
      }
    }
  }
}


////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
// Redirects after a pause, great to refresh after an update or delete
function sbRedirectAfterPause(sUrl, iMilliseconds)
{
    self.setTimeout(function(){window.location.href = sUrl;}, iMilliseconds);
}

