﻿// JScript File

/* Browser detect code: */
var isDOM2 = false;
var isNS4  = false;
var isIE4  = false;
var isFireFox = false;

//identify the browser
if ( window.document.getElementById )
	{
	isDOM2 = true;
	}

if ( window.document.layers )
	{
	isNS4 = true;
	}

if ( window.document.all && !(window.document.getElementById) )
	{
	isIE4 = true;
	}

 if ( ( i = navigator.userAgent.indexOf ("Gecko" ) ) >= 0 ) 
	{
	isFireFox = true;
	}
	
/* Browser detect code End here */


//*******************************************************************
//* 
//*******************************************************************
function DisableAllButtons() {
    for (var i=0; i<document.forms[0].elements.length; i++){
        if (document.forms[0].elements[i].type=='button' || document.forms[0].elements[i].type=='submit' || document.forms[0].elements[i].type=='reset') {
            if (!(document.forms[0].elements[i].id == '' || document.forms[0].elements[i].id == 'ctl00_cntHeader_ctl00_btnSearch' )) {
                //alert(document.forms[0].elements[i].id);
                document.getElementById(document.forms[0].elements[i].id).disabled=true;
            }
        }
    }
}

//*******************************************************************
//* 
//*******************************************************************
function SetValidator ( inBool, inControlName )
{
	if ( typeof ValidatorEnable == "function" )
	{
	    l_elem = document.getElementById ( inControlName );
	    
	    if(l_elem != null)
		    ValidatorEnable ( l_elem, inBool );
	}
}


//*****************************************************************
//*  Turns ON Validation for ID
//*****************************************************************
function ValidateOn( ID )
{
    SetValidator ( true, ID );
}


//*****************************************************************
//*  Turns OFF Validation for ID
//*****************************************************************
function ValidateOff( ID )
{
    SetValidator ( false, ID );
}


//*******************************************************************
//
//*******************************************************************
function ClearErrors(IDlblError, IDvSummary)
{
    var obj = document.getElementById ( IDlblError );
    if ( obj != null ) {
        obj.innerHTML = "";
        obj.style.display = "none";
    }

    var obj = document.getElementById ( IDvSummary );
    if ( obj != null ) {
        obj.innerHTML = "";
        obj.style.display = "none";
    }
}


//*****************************************************************
//*
//*****************************************************************
function SetFocus ( inControlName )
{
	
	l_elem = document.getElementById ( inControlName );
	
	if( l_elem != null)
    {
        if( l_elem.getAttribute("type") == "radio")
        {
            l_elem.checked = true;
        }
        else
        {
            l_elem.focus();
        } 
    } 	
}

//*****************************************************************
//*  set visibility
//*****************************************************************
function SetVisibility( inControlName, inVisible)
{
    l_elem = document.getElementById ( inControlName );
	
	if( l_elem != null)
    {
        if(inVisible == true)
            ShowObject(l_elem);
        else
            HideObject(l_elem);
    } 
}

//*****************************************************************
//*  hides object by ID
//*****************************************************************
function HideID( ID )
{
    HideObject(document.getElementById( ID ));
	
}

//*****************************************************************
//* shows object by ID
//*****************************************************************
function ShowID( ID )
{
    ShowObject(document.getElementById( ID ));
}

//*****************************************************************
//*  hides object by ID for all in IDSet except IDExcept
//*****************************************************************
function HideIDSetExcept(IDSet, IDExcept)
{
    var IDSetValue = document.getElementById( IDSet );
    if (IDSetValue != null) {
        var aID = IDSetValue.value.split(',');
        var iNum = aID.length

        for ( var x = 0; x < iNum; x++ ) {
            if (aID[x] == IDExcept) {
                ShowObject(document.getElementById( aID[x] ));
            } else {
                HideObject(document.getElementById( aID[x] ));
            }
        }
    }
}


//*****************************************************************
//*  Shows object by ID for all in IDSet except IDExcept
//*****************************************************************
function ShowIDSetExcept(IDSet, IDExcept)
{
    var IDSetValue = document.getElementById( IDSet );
    if (IDSetValue != null) {
        var aID = IDSetValue.value.split(',');
        var iNum = aID.length

        for ( var x = 0; x < iNum; x++ ) {
            if (aID[x] == IDExcept) {
                HideObject(document.getElementById( aID[x] ));
            } else {
                ShowObject(document.getElementById( aID[x] ));
            }
        }
    }
}


//*****************************************************************
//*  hides object				
//*****************************************************************
function HideObject ( inObject )
{
    if(inObject != null)
    { 
	    if ( isFireFox ) 
		    {
		    inObject.style.display = "none";
		    }
	    else if ( isNS4 ) 
		    { 
		    inObject.style.visibility = "hide";
		    }
	    else if ( isIE4 || isDOM2 ) 
		    {
		    inObject.style.display = "none";
		    }
    }
}

//*****************************************************************
//* shows object		
//*****************************************************************
function ShowObject ( inObject )
{
    if(inObject != null)
    { 
	    if ( isFireFox )
		    {
		    // Note: FireFox seems to need this property 
		    // to be "un-set" in order to work correctly.
		    inObject.style.display = "";
		    }
	    else if ( isNS4 ) 
		    {
		    inObject.style.visibility = "show";
		    }
	    else if ( isIE4 || isDOM2 ) 
		    {
		    inObject.style.display = "";
		    }
    }
}


//*****************************************************************
//* disable/enable object with DISABLED = true
//*****************************************************************
function SetDisabled( inControlName, inDisable )
{
     l_elem = document.getElementById ( inControlName );
     
     if( l_elem != null )
        l_elem.disabled = inDisable;
}

//*****************************************************************
//* Disable object based on ID
//*****************************************************************
function DisableID( ID )
{
    SetDisabled( ID, true );
}

//*****************************************************************
//* Enable object based on ID
//*****************************************************************
function EnableID( ID )
{
    SetDisabled( ID, false );
}


//*******************************************************************
//*
//*******************************************************************
function richToolTip ( parentObj, e, id, strDesc )
{
	var obj = document.getElementById ( id );

    if(obj != null)
   { 
	    if ( strDesc.length > 1 )
		    {
		    obj.innerHTML = strDesc;
		    }
	    else
		    {
		    obj.innerHTML = parentObj.innerText;		
		    }

	    objDisplayToggle ( id );

	    if ( document.all )
		    {
		    var scrollCoords = getScrollCoords();
		    obj.style.left = ( scrollCoords.x + e.clientX + 15 ) + 'px';
		    obj.style.top = ( scrollCoords.y + e.clientY + 15 ) + 'px';
		    }
	    else
		    {
		    var scrollCoords = getScrollCoords();
		    obj.style.left = ( scrollCoords.x + e.clientX + 15 ) + 'px';
		    obj.style.top = ( scrollCoords.y + e.clientY + 25 ) + 'px';
		    }
    }	
}


//*******************************************************************
//*
//*******************************************************************
function getScrollCoords() 
{
	if ( typeof window.pageXOffset != "undefined" )
		{
		return {x: window.pageXOffset, y: window.pageYOffset};
		}
	else if ( ( !document.compatMode || document.compatMode == "BackCompat" ) && document.body && typeof document.body.scrollLeft != "undefined" )
		{
		return {x: document.body.scrollLeft, y: document.body.scrollTop};
		}
	else if ( document.compatMode == "CSS1Compat" && document.documentElement && typeof document.documentElement.scrollLeft != "undefined" )
		{
		return {x: document.documentElement.scrollLeft, y: document.documentElement.scrollTop};
		}
	else
		{
		return null;
		}
}


//*****************************************************************
//*
//*****************************************************************
function objDisplayToggle ( id )
{
	obj = document.getElementById ( id );
	
	if(obj != null)
    {
        //Removed inline and replaced with blanks because inline was messing up firefox display of returns row in AOBO search
	    obj.style.display == "" ? obj.style.display = "none" : obj.style.display = "";
	}
}


//*******************************************************************
//*
//*******************************************************************
function isNumeric ( val )
{
	var x = 0;
	var validChars = "0123456789";
	val = val + "";

	for ( x = 0; x < val.length; x++ ) 
		{
		if ( !( validChars.indexOf ( val.charAt ( x ) ) != -1 ) ) 
			{
			return false;
			break;
			}
		}
		
	return true;
}


//*******************************************************************
//*
//*******************************************************************
function ValidateNumber ( e )
{
    if ( window.event )
        {
        e = window.event;
        }

    if ( e.keyCode )
        {
        code = e.keyCode;
        }
    else if ( e.which )
        {
        code = e.which;
        }

    // Attempt to allow function keys, and edit keys
    if ( e.charCode == 0 )
        {
        return; 
        }

    // Attempt to disallow the shift key.
    if ( e.shiftKey )
        {
        e.preventDefault ? e.preventDefault() : e.returnValue = false;
        }

    // Only allow numbers (no decimal, etc )
    if ( ( code < 48 || code > 57 ) ) 
        {
        e.preventDefault ? e.preventDefault() : e.returnValue = false;
        }
}

//*******************************************************************
//*  This function removes all spaces within a string.
//*******************************************************************
function NoSpaces ( strValue )
{
	var temp = strValue + "";

	while ( temp.indexOf ( " " ) != -1 ) 
		{
		temp = temp.substring (0, temp.indexOf ( " " ) ) + temp.substring ( temp.indexOf ( " " ) + 1, temp.length );
		}
		
	return temp;
}


//*******************************************************************
//* Copied this here from OrderSearch and renamed to getObjStyle (from getObj), but not being used, probably because it does not return object but instead returns object style
//*******************************************************************
function getObjStyle ( id ) 
{
	var obj;
		
	if ( isNS4 ) 
		{
		obj = eval ( 'document.layers["' + id + '"]' );
		}
	else if ( isIE4 ) 
		{
		obj = eval ( 'document.all["' + id + '"].style' );
		}
	else if ( isDOM2 ) 
		{
		obj = eval ( 'document.getElementById("' + id + '").style' );
		}
		
	return obj;
}


//*****************************************************************
//* click the object/ID
//*****************************************************************
function ClickID( ID )
{
    obj = document.getElementById( ID );
    if ( obj != null ) {
        obj.click();
    }
}


//*****************************************************************
//* Check the RADIO or CHECKBOX object/ID
//*****************************************************************
function CheckID( ID )
{
    obj = document.getElementById( ID );
    if ( obj != null ) {
        if( obj.getAttribute("type") == "radio" || obj.getAttribute("type") == "checkbox") {
            obj.checked = true;
        }
    }
}


//*****************************************************************
//* Assign the Value to the ID/object
//*****************************************************************
function SetID( ID, inValue )
{
    obj = document.getElementById( ID );
    if ( obj != null ) {
        if( obj.getAttribute("value") != null) {
            obj.value = inValue;
        } else if( obj.getAttribute("text") != null) {
            obj.text = inValue;
        } else if( obj.getAttribute("selectedIndex") != null) {
            obj.selectedIndex = inValue;
        }
    }
}


//*****************************************************************
//* Assign the Value to the ID/object
//*****************************************************************
function IDsAreEqual( ID1, ID2 )
{
    var obj1 = document.getElementById( ID1 );
    var obj2 = document.getElementById( ID2 );
    var bReturn = false;
    
    if ( obj1 == null && obj2 == null ) {
        bReturn = true;
    } else if ( obj1 != null && obj2 != null ) {
        if( obj2.getAttribute("value") != null && obj2.getAttribute("value") != null) {
            if ( obj1.value = obj2.value ) bReturn = true;
        } else if( obj2.getAttribute("text") != null && obj2.getAttribute("text") != null) {
            if ( obj1.text = obj2.text) bReturn = true;
        } else if( obj2.getAttribute("selectedIndex") != null && obj2.getAttribute("selectedIndex") != null) {
            if ( obj1.selectedIndex = obj2.selectedIndex ) bReturn = true;
        }
    }
    return bReturn
}


//*****************************************************************
//* If the specified key was pressed in event (e), click ID
//*****************************************************************
function IfKeyClickID( e, Key, ID )
{
    if ( e.keyCode == Key ) {
        ClickID( ID )
    }
}


//*****************************************************************
//* click the first object if the second object is checked
//*****************************************************************
function ClickIDIfCheckedID( IDClick, IDCheck )
{
    objCheck = document.getElementById( IDCheck );
	
    if (objCheck != null ) {
        if (objCheck.checked ){
            ClickID( IDClick );
        }
    }
}


//*****************************************************************
//* Return true if the object is checked.
//*****************************************************************
function IsCheckedID( ID )
{
    var obj = document.getElementById( ID );
    var bReturn = false;
	
    if (obj != null ) {
        if( obj.getAttribute("checked") != null ) {
            if (obj.checked ){
                bReturn = true;
            }
        }
    }
    return bReturn
}


//*****************************************************************
//* click the first object if the second OR third object is checked
//*****************************************************************
function ClickIDIfCheckedIDorID( IDClick, IDCheck, IDCheck2 )
{
    objCheck = document.getElementById( IDCheck );
    objCheck2 = document.getElementById( IDCheck2 );
	
    if (objCheck != null && objCheck2 != null) {
        if (objCheck.checked || objCheck2.checked ){
            ClickID( IDClick );
        }
    } else if (objCheck != null) {
        if (objCheck.checked ){
            ClickID( IDClick );
        }
    } else if (objCheck2 != null) {
        if (objCheck2.checked ){
            ClickID( IDClick );
        }
    }

}


//*******************************************************************
//*
//*******************************************************************
function OpenDocumentWindow ( strURL ) 
{
	// check to see if the child window is already opened
	var documentWindow = null;
	
	if ( ( documentWindow == null ) || ( documentWindow.closed ) )
		{
		documentWindow = window.open ( strURL, 'Document','height=475,width=800,fullscreen=no,toolbar=no,menubar=no,scrollbars=yes,resizable=yes,status=no,location=no,top=40,left=35' );
		documentWindow.focus();
		}
	else
		{
		self.documentWindow.focus();			
		}
}


//*******************************************************************
//*
//*******************************************************************
function SelectDropdownDefault ( DropdownId, strOptionVal )
{
	var index = 0;
	var i = 0;
	var objDropdown = document.getElementById ( DropdownId );

	if ( objDropdown != null && strOptionVal.length > 0 )
		{
		for ( i = 0; i < objDropdown.length; i++ )
			{
			if ( objDropdown.options[i].value == strOptionVal )
				{
				break;
				}
			else
				{
				index++;
				}
			}

		objDropdown.selectedIndex = index;
		}
}


//*******************************************************************
//*
//*******************************************************************
function BuildDropDown ( objDropDown, strData )
{
	for ( var i = objDropDown.length; i > -1; i-- )
		{
		objDropDown.remove(i);
		}

	if ( strData.length > 0 )
		{
		var temp_array = strData.split ( "|" );

		for ( var i = 0; i < temp_array.length - 1; i = i + 2 )
			{
			objDropDown.options[objDropDown.length] = new Option ( temp_array[i + 1], temp_array[i] );
			}
		}
}


//*******************************************************************
//
//*******************************************************************
function UpdateText ( id, strTextMsg )
{
	var nestref = null;
	var ns6;
	var ns4;
	var ie4;

	//identify user's browser
	ns6 = (document.getElementById&&!document.all)? true:false;
	ns4 = (document.layers)? true:false;
	ie4 = (document.all)? true:false;

	if ( ns6 )
		{ 
		document.getElementById(id).innerHTML = strTextMsg;
		}
	else if ( ns4 ) 
		{
		var lyr = (nestref)? eval ( 'document.' + nestref + '.document.' + id + '.document') : document.layers[id].document;
		lyr.open();
		lyr.write(strTextMsg);
		lyr.close();
		}
	else if	( ie4 ) 
		{
		document.all[id].innerHTML = strTextMsg;
		}
}

