﻿// JScript File
function SelectAllCheckBoxes(strCBoxId)
{
    var cBoxes = document.getElementsByName(strCBoxId);
    if (cBoxes!=null)
    {
        
	    if(typeof(cBoxes[0])!="undefined")
	    {
	        var iLength = cBoxes.length;
	        for(var i=0; i<iLength; i++)
	        {
	           if (cBoxes[i].disabled!=true)
	           {
	             cBoxes[i].checked=true; 
	           }
	        }
	    }else{
	       if (cBoxes.disabled!=true)
	       {
	        cBoxes.checked=true;
	       }
	    }
    }
}

function SelectAllUnselectAll(strCBoxId)
{
    if(isCBoxChecked(strCBoxId))
    {
        SelectUnselectKids(strCBoxId,false);
    }else{
        SelectUnselectKids(strCBoxId,true);
    }
}


function UnselectAllCheckBoxes(strCBoxId)
{
    var cBoxes = document.getElementsByName(strCBoxId);
    if (cBoxes!=null)
    {
	    if(typeof(cBoxes[0])!="undefined")
	    {
	        var iLength = cBoxes.length;
	        for(var i=0; i<iLength; i++)
	        {
	           if (cBoxes[i].disabled!=true)
	           {
	             cBoxes[i].checked=false; 
	           }
	        }
	    }else{
	        if (cBoxes.disabled!=true)
	       {
	        cBoxes.checked=false;
	       }
	    }
    }
}

function SelectUnselectKids(strCBoxId, bChecked)
{
    if(bChecked==true)
    {
       SelectAllCheckBoxes(strCBoxId);
    }else{
        UnselectAllCheckBoxes(strCBoxId);
    }
}

function isCBoxChecked(strCBoxId)
{
    var cBoxes = document.getElementsByName(strCBoxId);
    var bRetVal=false;
    if (cBoxes!=null)
    {
	    if(typeof(cBoxes[0])!="undefined")
	    {
	        var iLength = cBoxes.length;
	        for(var i=0; i<iLength; i++)
	        {
	           if (cBoxes[i].checked)
	           {
	            bRetVal=true;
	            break;
	           }
	        }
	    }else{
	           if (cBoxes.checked)
	           {
	            bRetVal=true;
	           }
	    }
    }
    return bRetVal;
}

function isTextBoxEmpty(textboxid)
{
    var textbox = document.getElementById(textboxid);
    if (textbox!=null && textbox.value!='')
    {
        return false;
    }else{
        return true;
    }
}

function SubmitForm(formname, action, target)
{       
    //var form = $get(formname);
    var form = window.document.getElementById(formname);
    if (form!=null)
    {
        form.action=action;
        form.target=target;
        form.method='POST';
        form.submit();
    }
}

function openHelp(helpurl)
{
    var wnd = window.open(helpurl, 'Help_File', 'width=500,height=600,resizable=yes, location=no, toolbar=0,scrollbars=yes');
    wnd.focus();
    return false;
}

function openDataDetails(data_details_url)
{
    var wnd = window.open(data_details_url, 'Data_Details', 'width=600,height=600,resizable=yes, location=no, toolbar=0,scrollbars=yes');
    wnd.focus();
    return false;
}


function GetFilings(strTicker)
{       
        if (strTicker!=null && strTicker!="Ticker" && strTicker!="")
        {
            var url = "/net/secfilings/resultframe.aspx?EntityInput=" + strTicker+"&Entity=Ticker&SectionTypeID=0";
         //   var hwn = window.open(url);
         //   hwn.focus();
            window.top.location = url;
        }
        else
        {
            alert('Please enter a company ticker.');
        }
}

function GetReleases(strReg)
{   
    if (strReg!=null && strReg!="33-, 34-")
    {
        var url = "/net/sm/QuickRelease.aspx?Item=" + strReg;
        window.top.location = url;
    }
}


function GetSiteIndex(strSiteIndex)
{   
    if (strSiteIndex!=null && strSiteIndex!="e.g., no-action letters")
    {
        var url = "/net/public/SiteIndex.aspx?key=" + strSiteIndex;
        window.top.location = url;
    }
}

function CloseThisWindow()
{
    if (parent.window)
    {
        parent.window.close();
    }
}
function GoBack()
{
    window.history.back();
}
function GoBackTest()
{
    //HistoryLengthTest("In GoBackTest");
    window.history.go(-1);
    //HistoryLengthTest("After Go -1");
}

function HistoryLengthTest(message)
{
    window.console.log(message);
    window.console.log(window.history.length);
}

//get query string from the URL
function getQuerystring(key, default_)
{
  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(window.location.href);
  if(qs == null)
    return default_;
  else
    return qs[1];
}

  //don't auto-submit upon 'Enter' for predictive search field
function preventEnterKeyFromAutosubmitting(inputTextBox, inputValueSeparator)
{
    var previousCode=0;
    inputTextBox.keypress(function (e){
       if ($.browser.msie)
        return;
 
        var code = (e.keyCode ? e.keyCode : e.which);
     
        var inputValue = $.trim(inputTextBox.val());
        var endsInInputValueSeparator =inputValue.length-1==inputValue.lastIndexOf(inputValueSeparator);
     
     //try to catch two successive Enter key presses
       var enterKeyPressedTwice = (code==previousCode); //hack to make Firefox behave like IE
       previousCode=code;
     
       if(code == 13) { //13==Enter keycode
          if(!endsInInputValueSeparator)//type and enter action
          {
            return true;
          }
          else if(!enterKeyPressedTwice)
          {
            return false; 
          }
       }
       else
       {
          previousCode=0;
       }   
    });
}

function isEmailAddressValid(emailAddress)
{
    var regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4}$/;
    //copy from http://www.digitalamit.com/article/regular_expression/7.phtml
    
    return regex.test(emailAddress);
                

}
