/* All Ammo Javascript utility functions are defined in this file */


function doRedirection(){
  window.location.href="AmmoTrial.aspx";
}

function QuickSearch(event,ID)
{
    if(event.which || event.keyCode)
    {
        if ((event.which == 13) || (event.keyCode == 13)) 
        {
            //document.getElementById(ID).click();
            //return false;
            __doPostBack(ID,"");
        }
    } 
    else 
    {
        return true
    };
}

function SelectAllChildCheckboxes(CheckBoxControl,Parent, onFinished) 
{
    var inputsCol = document.getElementById(Parent).getElementsByTagName('INPUT');
    
    if (CheckBoxControl.checked == true) 
    {
        var i;
        
        for (i=0; i < inputsCol.length; i++) 
        {
            if ((inputsCol[i].type.toUpperCase() == 'CHECKBOX')) 
            {
                inputsCol[i].checked = true;
            }
        }
    } 
    else 
    {
        var i;
        
        for (i=0; i < inputsCol.length; i++) 
        {
            if ((inputsCol[i].type.toUpperCase() == 'CHECKBOX')) 
            {
                inputsCol[i].checked = false;
            }
        }
    }
    
                
    if(typeof onFinished == 'function'){
        onFinished();
    }
   
}

function handleInputClicks(ParentID, clickFunction)
{
    $('#'+ParentID).delegate("input", "click", clickFunction);
}


function handleShowSelected()
{
    if( $('#story-list-scroll input:checked').size() > 0)
    {
        $('#show-selected').fadeIn('slow');
    }
    else
    {
        $('#show-selected').delay(600).fadeOut('slow');
    }
}

function handleShowDeleteSelected()
{
    if( $('#saved-search-scroll-content input:checked.checkbox').size() > 0)
    {
        $('.header-col2','#content-box-controls').fadeIn('slow');
    }
    else
    {
        $('.header-col2','#content-box-controls').delay(600).fadeOut('slow');
    }
}

function SelectAll(CheckBoxControl) 
{
    if (CheckBoxControl.checked == true) 
    {
        var i;
        for (i=0; i < document.forms[0].elements.length; i++) 
        {
            if ((document.forms[0].elements[i].type == 'checkbox')) 
            {
                document.forms[0].elements[i].checked = true;
            }
        }
    } 
    else 
    {
        var i;
        for (i=0; i < document.forms[0].elements.length; i++) 
        {
            if ((document.forms[0].elements[i].type == 'checkbox')) 
            {
            document.forms[0].elements[i].checked = false;
            }
        }
       
    }
    setVisibility('divMessageBox', 'none','hidden');
}

function setVisibility(id,display, visibility) {
document.getElementById(id).style.visibility = visibility;
document.getElementById(id).style.display = display;
}


function ValidateItems(ctrl)
{
        for (i=0; i < document.forms[0].elements.length; i++) 
        {
           var el=document.forms[0].elements[i];
            /* Check for 3 conditions
            Element is if type checkbox + element id is not checkAll checkbox id + element is checked 
            */
            if ((el.type == 'checkbox') && (el.id != ctrl) && (el.checked == true)) 
            {
                return true;
            }
        }
        setVisibility("divMessageBox",'','visible');
 
        return false;
}

 /* The Below Function will ensure that the CheckBoxList Control's Check Boxes Adhere To the Css Standards */
function InitCheckBoxes(){
    /* For checkbox Elements */
       var CheckBoxElements = document.form1.elements;
       for (var i=0; i < CheckBoxElements.length; i++) {
            if (CheckBoxElements[i].type=='checkbox' || CheckBoxElements[i].type=='radio')
            {
               CheckBoxElements[i].className  = 'checkbox';
            }
       }

}

/*
function initPopups(){

if (!document.getElementsByTagName) return false;

  // For Anchor Elements 
     var anchorLinks = document.getElementsByTagName("a");

     for (var i=0; i < anchorLinks.length; i++) {
           if (anchorLinks[i].className.match("popup")){
                anchorLinks[i].onclick = function() 
                {
                    window.open(this.href);
                    return false;
                }
            }
        }
        
  // For image Links
     var imgLinks = document.getElementsByTagName("img")
  
     for (var i=0; i < imgLinks.length; i++) {
       if (imgLinks[i].className.match("popupImage")){
            imgLinks[i].onclick = function() 
                {
                    window.open(this.alt);
                    return false;
                }
            }
        }
     }
     

window.onload = initPopups;
*/

function onUpdating(target, cover){
    var updateProgressDiv = $('#'+cover);
    var domTarget = $('#'+target);
    var updateProgressDivImg = $('#'+cover + " img");
    
    
    //updateProgressDiv[0].style.display = '';
    
    var pos = domTarget.offset();
    
    var w = domTarget.outerWidth() - 2;
    var h = domTarget.outerHeight() - 2;
    
    var l =  (pos.left) + 1;
    var t =  (pos.top) + 1;
    
    var imgl = Math.round(domTarget.outerWidth() / 2) - Math.round(updateProgressDivImg.outerWidth() / 2);
    var imgt = Math.round(domTarget.outerHeight() / 2) - Math.round(updateProgressDivImg.outerHeight() / 2);
    
    updateProgressDiv.css( { 
        position: 'absolute',
        zIndex: 5000,
        left: l + "px", 
        top: t + "px",
        width: w + "px",
        height: h + "px"
    } );

    updateProgressDivImg.css( { 
        position: 'absolute',
        zIndex: 5001,
        left: imgl + "px", 
        top: imgt + "px"
    } ); 
   
   //updateProgressDiv[0].style.display = '';
   //$('.overlay').css('filter', 'alpha(opacity=70)');
   //$('#'+cover).fadeIn();
   $('#'+cover).fadeTo('slow',0.7);
}
            
function onUpdated(target, cover) {
    // get the update progress div
    //var updateProgressDiv = $get(cover); 
    //var domTarget = $get(target); 
    // make it invisible
    
    //$('#' + cover).fadeOut();
    //$('.overlay').css('filter', 'alpha(opacity=0)');
    
    $('#' + cover).fadeTo('slow',0,function() {
      $(this).hide();
    });

   
    //if (jQuery.browser.msie)
    //{
    //    $('#'+target).style.removeAttribute('filter');
    //}
    
    
    //updateProgressDiv.style.display = 'none';
    //$('#'+ target).fadeTo('slow',1.0);
} 

function highlight(){
    var highlight = $("[id$=hfHighlight]");
    if(highlight.val() == '1')
    {
        /*$("[id$=news]").stop().delay(1000).fadeIn(2000, function() {
              if (jQuery.browser.msie)  this.style.removeAttribute('filter');
            }
        ).delay(1500).animate({color: "#f4b91f"},2000).delay(1000).animate({color: "#ffffff"},2000);*/
        
        $("[id$=news]").stop().delay(1500).animate({color: "#f4b91f"},2000).delay(1000).animate({color: "#ffffff"},2000);
     }
}

function getUrlParameter(name) {
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}