function ShowNonModalWindow(URL, Height, Width, Top, Left, Center, Location, MenuBar, Resizable, Scrollbars, Status, TitleBar, Toolbar, FullScreen)
{
  var options = '';

  if(Height)
    options += 'height = ' + Height + ',';
  if(Width)
    options += 'width = ' + Width + ',';
  
  //if this option is used, height and width MUST be specified
  if(Center != null && Center)
  {
    if(Height == null || Width == null)
      throw new Error('Error with ShowWindow parameters: If Center is specifed, so should Height and Width')
  
    Left = (screen.availWidth - Width) / 2;
    Top = (screen.availHeight - Height) / 2;   
  }  

  //these must be done AFTER centering  
  if(Top || Top == 0)
    options += 'top = ' + Top + ',';
  if(Left || Left == 0)
    options += 'left = ' + Left + ',';

  if(Location != null)
    options += 'location = ' + (Location ? 'yes' : 'no') + ',';
  if(MenuBar != null)
    options += 'menubar = ' + (MenuBar ? 'yes' : 'no') + ',';
  if(Resizable != null)
    options += 'resizable = ' + (Resizable ? 'yes' : 'no') + ',';
  if(Scrollbars != null)
    options += 'scrollbars = ' + (Scrollbars ? 'yes' : 'no') + ',';
  if(Status != null)
    options += 'status = ' + (Status ? 'Yes' : 'No') + ',';
  if(TitleBar != null)
    options += 'titlebar: ' + (TitleBar ? 'Yes' : 'No') + ',';
  if(Toolbar != null)
    options += 'toolbar: ' + (Toolbar ? 'Yes' : 'No') + ',';
  if(FullScreen != null)
		options += 'fullscreen = ' + (FullScreen ? '1' : '0') + ',';
      
  return window.open(URL, '_blank', options, false);
}


function ShowHelpWindow(pageName)
{
    ShowWindow(pageName, 300, 400);
}

function ShowModalWindow(pageName, popH, popW)
{
	var options = '';
  
    options += 'dialogHeight: ' + popH + 'px;';
    options += 'dialogWidth: ' + popW + 'px;';	  

    showModalDialog(pageName,'',options);
}

function ShowWindow(pageName, popH, popW)
{
	var w=0, h=0;
	var topPos, leftPos;
	var options = '';
	  
	w=screen.Width;
	h=screen.Height;  
  
	topPos = (w-popW)/2;
	leftPos = (h-popH)/2;

    options += 'width=' + popW;
    options += ',height=' + popH;
    options += ',top=' + topPos;
    options += ',left=' + leftPos;
    options += ',scrollbars=yes';
    //options += ',dependent=yes';
    options += ',resizable=yes';
	
	window.open(pageName,'',options); 
}

function ShowSearchWindow(pageName)
{
	window.open(pageName,'Search','scrollbars=yes');
}

function HasMenuFrame()
{
  try
  {
    return parent.frames.length == 2;
  }
  catch(ex)
  {
    return 0;  
  }
}

function VerifyMenuExists(MenuURL)
{
  var fileName;
  var redirectPath;
  
  if(!HasMenuFrame())
  {
    redirectPath = GetBasePath() + 'GenericMenuPage.aspx?Source=' + GetPathFromRoot() + GetCurrentFileName() + '&Menu=' + MenuURL;
    self.location.replace(redirectPath);
  }
  else
  {
		try
		{
    fileName = GetDocName(parent.Left.location.href);
    
    if(fileName != MenuURL)
      parent.Left.location.replace(GetBasePath() + 'SideMenuForms/' + MenuURL);
    }
    catch (ex) {}
      
  }
}

function GetCurrentFileName()
{
  var fullURL = document.location.href;
  
  return fullURL.substr(GetBasePath().length + GetPathFromRoot().length);  
}

function GetDocName(fullPath)
{
  return fullPath.split("/")[fullPath.split("/").length-1];
}

function HasHeaderAndFooterFrames()
{
  try
  {
    return parent.frames.length == 3;
  }
  catch(ex)
  {
    return 0;
  }
}

function VerifyHeaderAndFootersExist()
{
  if(!HasHeaderAndFooterFrames())
    self.location.replace(GetBasePath() + 'fraHome.aspx?Redirect=' + GetCurrentPath() + GetCurrentFileName());
}

function FrameBreakOut()
{
  if (top.location != location)
    top.location.href = document.location.href;
}

function GotoBookmark(name)
{
  self.location.href = '#' + name;
}

function GotoTop()
{
  self.scrollTo(0,0);
}

/*
function HideMenuFrame()
{
  parent.MyFrameSet.cols = "0,*";
}
*/

function InitializePage()
{
  window.defaultStatus="Mountain Systems Customer Care";
}

function SetStatus(status)
{
  window.status = status;
  return true;
}

function SetPersistentStatus(status)
{
  SetStatus(status);
  window.defaultStatus = status;
  return true;
}

function Search(SearchString)
{
  ShowSearchWindow('../KnowledgeBaseSearch.aspx?Search=' + SearchString)
}

function UpdateDisplay()
{
  self.location.reload();
}
 
//clears the control if the specified value is in it 
function ClearOnEnter(control, matchValue)
{
  if(control.value == matchValue)
    control.value = '';
}

//repopulates a cleared field with the specified value
function RepopulateDefault(control, matchValue)
{
  if(control.value == '')
    control.value = matchValue;
}

function GetCurrentPath()
{
  return document.location.href.substring(0,document.location.href.lastIndexOf("/")+1);
}

function GetCurrentDomain()
{
  var protocol;
  protocol = GetCurrentProtocol();
  return ((document.location.href.substring(protocol.length)).substring(0, (document.location.href.substring(protocol.length)).indexOf("/")));
}

function GetCurrentProtocol()
{
   return document.location.href.substring(0,document.location.href.indexOf(":")+3);
}

function GetBasePath()
{
  return GetCurrentProtocol() + GetCurrentDomain() + "/Support/";
}

function GetPathFromRoot()
{
  var currPath;
  var basePath;
  var relPath;
  
  currPath = GetCurrentPath();
  basePath = GetBasePath();

  relPath = currPath.substr(basePath.length);
  if(relPath == 'undefined')
    relPath = '';
  
  return relPath;
}

function RequireBrowserVersion(requiredVersion)
{
  var browserVersion = window.navigator.userAgent;
  var version;
 
  var startPos = browserVersion.indexOf( "MSIE" );
  var endPos = browserVersion.indexOf( ";", startPos );

  version = browserVersion.substring( startPos + 5, endPos );
  
  if(version < requiredVersion)
    alert('This page requires IE version ' + requiredVersion + '.  It may not work correctly without an upgrade.');
}

function GenerateRandomString(stringLen)
{
  try
  {
    var s = '';
    var t, r;
  
    while  (s.length < stringLen)
    {
      t = (48 + Math.round(Math.random() * 74));
      r = ((t<58) || ((t>64) && (t<91)) || ((t>96) && (t<123))) ? String.fromCharCode(t) : '';
      s += r;
    }
  
    return s;
  }
  catch(e){}
}

function swap(v1, v2)
{
  var temp;
  
  temp = v1;
  v1 = v2;
  v2 = temp;
}

function ShowError(e)
{
  var msg;

  try
  {
    msg = "Sorry, there was an error on this page. This error\n"
    msg += "has been logged, and will be investigated.\n\n";
    msg += "Click OK to continue.\n\n";
    msg += "Error number: " + e.number + "\n";
    msg += "Description: " + e.description + "\n\n";
    alert(msg);
  }
  catch(ex){}
}

function ShowErrorMessage(ErrorDesc)
{
  try
  {
    var e;
    e = new Error(ErrorDesc);
    ShowError(e);
  }
  catch(ex){}
}

function ShowClientControlList()
{
  var elems = document.all;
  var len = elems.length;
  var msg = '';
  var currId;
  
  for (var loop = 0; loop<len; loop++)
  {
    currId = elems[loop].id;
    if(currId != '')
      msg += currId + '\n';
  }

  alert(msg);
}

function RightStr(str, len)
{
  var strLen = str.length;

  return str.substr(strLen - len, len)  
}

/*
function FindElement(SearchObject, FindId)
{
  var i;
  var CurrArray;
  var CurrId;
  var CurrObj;
  
  CurrArray = SearchObject.all;

  for(i = 0; i < CurrArray.length - 1; i++)
  { 
    CurrObj = CurrArray.elements[i];
    CurrId = CurrObj.id;
    
    if(CurrId == FindId)
    {
      return SearchObject.name + '.' + FindName;
    } 
    if(SearchObject.elements.length == 0)
    {
      return '';
    }
    else
    {
      return FindElement(CurrObj, FindId);
    }
  }  
}
*/
function ClickButton(ButtonId)
{  
	var Button = document.getElementById(ButtonId);
	Button.click();
}

function test()
{
  alert('this is only here for a breakpoint');
}

/*
// use: getCookie("name");
function getCookie(name)
{ 
  var cookies = document.cookie;
  var index = cookies.indexOf(name + "=");
  if (index == -1) return null;
  index = cookies.indexOf("=", index) + 1;
  var endstr = cookies.indexOf(";", index);
  if (endstr == -1) endstr = cookies.length;
  return unescape(cookies.substring(index, endstr));
}

function setCookie(name, value)
{ 
  var today = new Date();
  var expiry = new Date(today.getTime() + 28 * 24 * 60 * 60 * 1000); // plus 28 days
  if (value != null && value != "")
    document.cookie=name + "=" + escape(value) + "; expires=" + expiry.toGMTString();
  bikky= document.cookie; // update bikky
}
*/

//convert to binary search later
function SetComboboxByValue(list, value)
{
  for(var i = 0; i<list.length-1; i++)
  {
    
    if(list.options(i).value == value)
    {
      list.selectedIndex = i;
      break;
    }
  }
}

function RegisterPostback()
{
  try
  {
    PostbackPending = true;
  }
  catch(e){}
}

function DisplayHardConfirmation(PromptString)
{
  var randString;
  var stringLen = 5;
  var userInput = '';
  var shouldDelete;
  
  randString = GenerateRandomString(stringLen);

  shouldDelete = confirm(PromptString);
  
  if(shouldDelete)
    userInput = prompt('Please type the following string for confirmation to delete: ' + randString,'');
  
  if(userInput == randString)
  {
    RegisterPostback = true;
    return true;
  }
  else
    alert('The strings did not match.');
    
  return false;
}

function toUpperCase(TextboxId)
{
  var Textbox = document.getElementById(TextboxId);
  
  if(Textbox != null)
    Textbox.onKeyPress = UpperCaseOnly_KeyPress;
}

function UpperCaseOnly_KeyPress()
{
	Textbox.value = Textbox.value.toUpperCase;
}

function HideShow(TargetId)
{
	var Target;
	
	Target = document.getElementById(TargetId);
	
	if(Target == null)
		throw new Error("Unable to Find Target: " + TargetId);
		
	if(Target.style.display == '')
	{
		Target.style.display = 'none';
	}	
	else
	{
		Target.style.display = '';
	}
	
}

function areEmpty()
{
	var retVal = true;
	for( var i = 0; i < arguments.length; i++)
		retVal = retVal && isEmpty(arguments[i]);
		
	return retVal;
}

function isEmpty(TextBoxID)
{
	var TextBox = document.getElementById(TextBoxID);
	if (TextBox != null)
		return TextBox.value == "";
	else
		return false;
}

function DisableUntilNotEmpty(ControlID)
{
	var Ctrl = document.getElementById(ControlID)
	
	var enableVal = true;
	for( var i = 1; i < arguments.length; i++)
		enableVal = enableVal && !isEmpty(arguments[i]);
		
	Ctrl.disabled = !enableVal;
}

function isNumeric( x )
{
	if( typeof(x) == typeof(0) )
		return ( x >= 48 ) && ( x <= 57 );
	else if ( typeof(x) == typeof('0') )
		return ( x >= '0' ) && ( x <= '9' )
}
//Dynamically loads a stylesheet, if not already loaded.
function LoadCss(SheetName)
{
  try
  {
    var Sheets = document.styleSheets;
  
    for(var i=0; i<Sheets.length; i++)
    {
      if(Sheets[i].href == SheetName)
      {
        return;
      }
    }
    
    
    //since it was not found, add it
    var NewSheet = document.createElement('link');               
    NewSheet.rel = 'StyleSheet';
    NewSheet.href = SheetName;
    document.documentElement.firstChild.appendChild(NewSheet);
  }
  catch(e)
  {
    alert('Error loading stylesheet: ' + SheetName + '\n' +
          'This page may not be displayed correctly.\n' +
          '(reason:' + e.description + ')')
  }
}

function test()
{
	alert('hi');
}