﻿// JScript File

function ClickCellButton(gridName, itemName){
    
    var cell=igtbl_getCellById(itemName);
    if (cell != null && cell.Column.Key == "Delete")
    {
        if(confirm("Delete this item?"))
        {        
        }
        else
        {
	        igtbl_cancelPostBack(gridName)        
        }
        //alert (cell.Column.Key );
    }
}

function checkFile(filename)
{
   var file = document.getElementById(filename);
   //alert(file.value);
   
    if(file != null && file.value == null || file.value.length == 0)
    {
        alert('no file selected');
        return false;
    }
    else
    {
        return true;
    }
}

function confirmUpdate()
{
    if(confirm("Update this item?"))
    {
        return true;
    }
    else
    {
        return false;
    }
} 

function confirmDelete()
{
    if(confirm("Delete this item?"))
    {
        return true;
    }
    else
    {
        return false;
    }
} 
   
//used by pages to move dynamically named client side IsDirty variable values.
var visibleAddressIsDirty = false;

function isPageDirty(includeAddresses)
{
    var retVal = false
    for(i=0; i<fieldsArray.length; i++)
    {
        //if any dirty flags are true, return false.
        if(fieldsArray[i][2]==true)
        {
            retVal = true;
            break;
        }
    }
    //if page has an address control and includes this function, check it.
    if(includeAddresses){
        putAddressDirtyIntoVisibleVariable();
        if(visibleAddressIsDirty == true)
        {
            retVal = true
        }
    }
    return retVal;
}

function setPageDirty(id, value)
{
    for(i=0; i<fieldsArray.length; i++)
    {
        if(fieldsArray[i][0] == id){
            //set the dirty flag.
            fieldsArray[i][2] = (String(value) != fieldsArray[i][1]);
        }
    }
}

function confirmNoSave(includeAddresses)
{
    retVal=true;
    if(isPageDirty(includeAddresses) && !confirm("Do you wish to leave without saving changes?"))
    {
        return false;
    }
    return retVal;
}    


function confirmDisable()
{
    if(confirm("Disable this item?"))
    {
        return true;
    }
    else
    {
        return false;
    }
}    

function allowUpload(filename)
{
   var file = document.getElementById(filename);
   //alert(file.disabled);
   file.disabled = false;
}

function PickListTrigger(pickListID, controlID, triggerValue, triggerEnabled)
{
    var pickList = document.getElementById(pickListID);
    var control = document.getElementById(controlID);
    //alert(pickList);
    //alert(control);
    //alert(controlID);
   
    if (pickList != null && control != null)
    {    
        //Item Selected Has Trigger
        if (pickList[pickList.selectedIndex].text.toUpperCase() == triggerValue.toUpperCase())
        {
            if (triggerEnabled.toLowerCase() == 'false')
            {control.disabled = true;}
            else
            {control.disabled = false;}
        }
        else
        {
            if (triggerEnabled.toLowerCase() == 'false' && control.disabled == true)
            {control.disabled = false;}
            if (triggerEnabled.toLowerCase() == 'true' && control.disabled == false)
            {control.disabled = true;}
        }               
    }
}

function ToggleUpload(fileValue, txtFileNameId, uploadButton)
{
    //debugger;
    //alert(fileValue);
    //alert(uploadButton); 
    
    var txtFileName = document.getElementById(txtFileNameId);
    var button = document.getElementById(uploadButton);
    //alert(button.className);
        
    if (fileValue != null)
    {
        //alert('test');
        button.className = 'off';
        //button.className='buttonAdd';
        txtFileName.value = fileValue;       
    }
    else
    {
        //alert('test');
        button.className = '';
        //button.className='buttonAddOff';
        txtFileName.value = '';
    }

}

function ToggleUpload2(fileValue, itemName)
{
    //debugger;
    //alert(fileValue);
    //alert(itemName);
    
    //var grid = igtbl_getGridById('ctl00_ContentPlaceHolder1_grid');     
    var grid = igtbl_getGridById('ctl00_ContentPlaceHolder1_grid');  
       
    var row = null;
    if (grid != null) row = grid.Rows.getRow(itemName);
    var cell = null;
    if (row != null) cell = row.getCell(13);
        
    if (fileValue != null && cell != null)
    {
        cell.Element.className = 'gridViewCell';
        //cell1.Column.ButtonClass = 'gridNoButton ctl00xContentPlaceHolder1xgrid-' + itemName + '-13-cbc';       
    }
    else
    {
        if (cell != null)
            cell.Element.className = 'gridNoButtonCell';
        //cell1.Column.ButtonClass = 'gridView ctl00xContentPlaceHolder1xgrid-' + itemName + '-13-cbc';
    }
    
    //alert(cell1.Column.ButtonClass);

}


			
function enableControl(controlName, flag)
{
	if (document.getElementById(controlName) != null ) 
	    {
            var control = document.getElementById(controlName);
    
	        control.disabled = !flag;
        }
}

