
function cAddress(aData, sType)
{
    this.cAddress = this;
    this.aData = aData;    
    this.sType = sType;    
    this.sPrefix = (sType == 'invoice' ? 'i' : 'd');
}

cAddress.prototype.OnChange = function(e)
{
    var src = (window.event)? window.event.srcElement : e.target;
    var nIdA = src.options[ src.selectedIndex ].value;

    for (var i=0;i < this.aData.length; i++)
        if (nIdA == this.aData[i].i) { this.Fill(this.aData[i]); break;}

}
cAddress.prototype.Fill = function(aAddress)
{
    getE(this.sPrefix+'Firm').value        = aAddress.f;
    getE(this.sPrefix+'Street').value      = aAddress.s;
    getE(this.sPrefix+'City').value        = aAddress.c;
    getE(this.sPrefix+'ZipCode').value     = aAddress.z;
    getE(this.sPrefix+'CountryName').value = aAddress.s;
    
    this.SetVisibility(aAddress.i);
}

cAddress.prototype.SetVisibility = function(id)
{
    getE(this.sPrefix+'Firm').readOnly               = (id != 0);
    getE(this.sPrefix+'Street').readOnly             = (id != 0);
    getE(this.sPrefix+'City').readOnly               = (id != 0);
    getE(this.sPrefix+'ZipCode').readOnly            = (id != 0);
    getE(this.sPrefix+'CountryName').readOnly        = (id != 0);
    
    getE(this.sPrefix+'CountryName').style.display   = (id != 0 ? '' : 'none');
    getE(this.sPrefix+'CountrySelect').style.display = (id != 0 ? 'none' : '');
}

function ControlDataOrder()
{
    return true;
    if (getE('selInvoiceAddress').options[getE('selInvoiceAddress').selectedIndex].value == 0 )
    {
        if ( !IsFieldEmpty( getE('iFirm'), "Vyplňte název firmy u fakturační adresy." ) ) return false;
        if ( !IsFieldEmpty( getE('iStreet'), "Vyplňte název ulice u fakturační adresy." ) ) return false;
        if ( !IsFieldEmpty( getE('iCity'), "Vyplňte název obce u fakturační adresy."  ) ) return false;
        if ( !IsFieldEmpty( getE('iZipCode'), "Vyplňte PSČ u fakturační adresy." ) ) return false;
    }
    if (getE('selDeliveryAddress').options[getE('selDeliveryAddress').selectedIndex].value == 0 )
    {
        if ( !IsFieldEmpty( getE('dFirm'), "Vyplňte název firmy u dodací adresy." ) ) return false;
        if ( !IsFieldEmpty( getE('dStreet'), "Vyplňte název ulice u dodací adresy." ) ) return false;
        if ( !IsFieldEmpty( getE('dCity'), "Vyplňte název obce u dodací adresy."  ) ) return false;
        if ( !IsFieldEmpty( getE('dZipCode'), "Vyplňte PSČ u dodací adresy." ) ) return false;
    }
    
    return true;
}

function setFrmData(id)
{
    if (getE('selInvoiceAddress') && getE('iSelAddress'+id) ) { getE('iSelAddress'+id).value  = getE('selInvoiceAddress').options[getE('selInvoiceAddress').selectedIndex].value; }
    if (getE('selDeliveryAddress') && getE('dSelAddress'+id) ) { getE('dSelAddress'+id).value = getE('selDeliveryAddress').options[getE('selDeliveryAddress').selectedIndex].value; }
    if (getE('InfoText') && getE('note'+id) ) { getE('note'+id).value = getE('InfoText').value; }
}
