/* All Ammo Javascript utility functions are defined in this file */


function doRedirection(){
  window.location.href="AmmoTrial.aspx";
}

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;