﻿    /* <summary>Mouse Over for data grids.</summary>
    ** <usage>onmouseover="mo(this);" onmouseout="mo(this);</usage>
    ** <param name="elem">The element.</param>*/
    function mo(elem) 
    {
	    if (elem.className == 'data row-a') {
		    elem.className = 'data row-a-hover'
	    } else if (elem.className == 'data row-b') {
		    elem.className = 'data row-b-hover';
	    } else if (elem.className == 'data row-a-hover') {
		    elem.className = 'data row-a'
	    } else if (elem.className == 'data row-b-hover') {
		    elem.className = 'data row-b';
	    }
    }
	
	function addLoadEvent(func) {
        var oldonload = window.onload;
        if (typeof window.onload != 'function') {
            window.onload = func;
        } else {
            window.onload = function() {
                if (oldonload) {
                    oldonload();
                }
                func();
            }
        }
    }
	
	var classNameCache = "";
	
	/* <summary>Change class name.</summary>
    ** <usage></usage>
    ** <param name="elem">The element.</param>
    ** <param name="blur"></param>*/
	function changeCurrent(elem, blur) {

		if (blur == true) {
			elem.className = classNameCache;
		}
		else {
		    classNameCache = elem.className;
			elem.className = 'current';
		}
	}

    /* <summary>Client script to add AJAX error messages 
    ** to the page rather than javascript alert box </summary>*/

    
    //make sure the script is loaded before setting the event handler
    //if (Sys.WebForms != null)
    //    Sys.Application.add_load(AppLoad);
         
    /* <summary>Register the event handlers to manage client error handling.</summary>*/
    function AppLoad() {
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequest);
        Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequest);
    }
     
    /* <summary>Fires when a new async call is started.</summary>
    ** <param name="sender"></param>
    ** <param name="args"></param>*/
    function BeginRequest(sender, args) {
    }
     
    /* <summary>Fires when the async call completes - 
    ** This is where the error handling magic happens.</summary>
    ** <param name="sender"></param>
    ** <param name="args"></param>*/
    function EndRequest(sender, args) {
      // Check to see if there's an error on this request.
      if (args.get_error() != null && args.get_error() != "")
      {
        var err = args.get_error().message;
        
        //$get('ctl00_valSummary').style.visibility = "visible";
        $get('ctl00_valSummary').style.display = "";
        
        if (err.startsWith("[")){
            //unrecoverable
            $get('ctl00_valSummary').className = "messageError";
            
        }else{
            //recoverable
            $get('ctl00_valSummary').className = "messageWarning";
        }
        $get('ctl00_valSummary').innerText = err;

        // Let the framework know that the error is handled, 
        // so it doesn't throw the JavaScript alert.
        args.set_errorHandled(true);
        
      }
    }
    
    /*
     * TabPanel-related script
     *
    */
    
    if (document.images)
    {
        var blueResultImgPreLoad = new Image(20,20);
        blueResultImgPreLoad.src = document.location.protocol + "//" + document.location.hostname + "/Images/Header/allnewused-blue.gif";
        
        var blueDetailsImgPreLoad = new Image(20,20);
        blueDetailsImgPreLoad.src = document.location.protocol + "//" + document.location.hostname + "/Images/Header/proddetail-blue.gif";
    }
    
    /* End TabPanel script */
    
    function es(o)
    {
        document.getElementById("dropEditionStatus").disabled=!o.checked;
    }
    
    function toggleEnabled(chkbox)
    {      
        var disable=!chkbox.checked;
        //Alert(disable);
        document.getElementById("dropCondition").disabled = disable;
        document.getElementById("txtPublicNotes").disabled = disable;
        document.getElementById("txtPrivateNotes").disabled = disable;
        
        document.getElementById("chkTraitList_0").disabled = disable;
        document.getElementById("chkTraitList_1").disabled = disable;
        document.getElementById("chkTraitList_2").disabled = disable;
        document.getElementById("chkTraitList_3").disabled = disable;
        document.getElementById("chkTraitList_4").disabled = disable;
        document.getElementById("chkTraitList_5").disabled = disable;
        
        if(!disable)
        {
            document.getElementById("txtPrivateNotes").style.backgroundColor ="";
            document.getElementById("txtPublicNotes").style.backgroundColor ="";
        }
        else
        {
            document.getElementById("txtPrivateNotes").style.backgroundColor ="#eeeeee";
            document.getElementById("txtPublicNotes").style.backgroundColor ="#eeeeee";
        }      
    }
    
    function disableTraitBoxes()
    {
      document.getElementById("chkTraitList_0").disabled = true;
        document.getElementById("chkTraitList_1").disabled = true;
        document.getElementById("chkTraitList_2").disabled = true;
        document.getElementById("chkTraitList_3").disabled = true;
        document.getElementById("chkTraitList_4").disabled = true;
        document.getElementById("chkTraitList_5").disabled = true;
        document.getElementById("txtPrivateNotes").style.backgroundColor ="#eeeeee";
        document.getElementById("txtPublicNotes").style.backgroundColor ="#eeeeee";
    }
    
    function doSomething()
    {
        document.getElementById('imgIndicator').style.visibility="visible";
        
        document.getElementById('btnCancelAddCard').style.visibility="hidden";
        document.getElementById('btnConfirmAddCard').style.visibility="hidden";
    }
    
     function showInline (elName)
     {
	    var theElemenet = document.getElementById(elName);
	    if (theElemenet) 
	    {
		    theElemenet.style.display = "inline";
	    }
    }
    function hideInline (elName) 
    {
	    var theElemenet = document.getElementById(elName);
	    if (theElemenet) 
	    {
		    theElemenet.style.display = "none";
	    }
	}

	function SelectAllCheckboxesByGrid(CheckBoxControl, DataGridControl) 
	{
	    var form = CheckBoxControl.form;
	    if (CheckBoxControl.checked == true) {
	        var i;
	        for (i = 0; i < form.elements.length; i++) {
	            if ((form.elements[i].type == 'checkbox') &&
                    (form.elements[i].name.indexOf(DataGridControl) > -1)) {
	                form.elements[i].checked = true;
	            }
	        }
	    }
	    else {
	        var i;
	        for (i = 0; i < form.elements.length; i++) {
	            if ((form.elements[i].type == 'checkbox') &&
                    (form.elements[i].name.indexOf(DataGridControl) > -1)) {
	                form.elements[i].checked = false;
	            }
	        }
	    }
	}	
    
    function SelectAllCheckboxes(CheckBoxControl)
    {
        var form=CheckBoxControl.form;      
        if (CheckBoxControl.checked == true)
        {
            var i;
            for (i=0; i < form.elements.length; i++)
            {
                if ((form.elements[i].type == 'checkbox') &&
                    (form.elements[i].name.indexOf('ViewOrders') > -1))
                 {
                    form.elements[i].checked = true;
                 }
            }
        }
        else
        {
            var i;
            for (i=0; i < form.elements.length; i++)
            {
                if ((form.elements[i].type == 'checkbox') &&
                    (form.elements[i].name.indexOf('ViewOrders') > -1))
                {
                    form.elements[i].checked = false;
                }
            }
         }   
    }	

function toggleShippedVisibility()
{
   document.getElementById('imgIndicator').style.visibility="visible";
    
   document.getElementById('btnMarkShipped').style.visibility="hidden";
}

function KeyDownHandler(e,btn)
{
    // process only the Enter key
 
    if ((e.which && e.which == 13) || (e.keyCode && e.keyCode == 13))
    {
   // alert("Hit!");
        __doPostBack(btn, '');
        //btn.Click();
        return false;
    }
    return true;
}

function isNumberKey(evt)
{
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
    if ((charCode >= 48 && charCode <= 57) || charCode == 8 || (charCode >= 35 && charCode <= 37) || charCode == 39 || charCode == 46 || charCode == 116 || charCode == 13) 
    {
        return true;
    }
    else
    {
        return false;
    }
}
