﻿function ChangeVenueImage(ImageIDTag, VenueID, ImageTag)
{
    var ImageID = document.getElementById(ImageIDTag).value;

    if (ImageID != "")
    {
        document.getElementById(ImageTag).style.display = "block"; 
        document.getElementById(ImageTag).src = "/showimage.aspx?ImageID=" + ImageID + "&VenueID=" + VenueID;
    }
    else
    {
        document.getElementById(ImageTag).style.display = "none"; 
    }
}

function ChangeSupplierImage(ImageIDTag, SupplierID, ImageTag)
{
    var ImageID = document.getElementById(ImageIDTag).value;

    if (ImageID != "") {
        document.getElementById(ImageTag).style.display = "block";
        document.getElementById(ImageTag).src = "/showimage.aspx?ImageID=" + ImageID + "&SupplierID=" + SupplierID;
    }
    else {
        document.getElementById(ImageTag).style.display = "none";
    }
}

function getScrollBottom(p_oElem)
{
    return p_oElem.scrollHeight - p_oElem.scrollTop - p_oElem.clientHeight;
}

function ReverseContentDisplay(d) {
    if(d.length < 1) 
    { 
        return; 
    }
    
    if(document.getElementById(d).style.display == "none") 
    { 
        document.getElementById(d).style.display = "block"; 
    }
    else 
    { 
        document.getElementById(d).style.display = "none"; 
    }
}

function confirm_delete()
{
  if (confirm("Are you sure you want to delete this record? Deletions can not be undone!")==true)
    return true;
  else
    return false;
}

function confirm_clear_sel()
{
  if (confirm("Are you sure you want clear the selected listings?")==true)
    return true;
  else
    return false;
}

function confirm_clear_all()
{
  if (confirm("Are you sure you want clear the all listings?")==true)
    return true;
  else
    return false;
}

function calcvat(source, dest, vat)
{
    var s = parseFloat(source.value);
    var v = parseFloat(vat.value);
    var valid = true;

    if (isNaN(s))
    {
        source.value = "";
        valid = false;
    }    

    if (isNaN(v))
    {
        vat.value = "";
        valid = false;
    }    

    if (!valid)
    {
        return;
    }
    else
    {
        //dest.value = (s * ((v + 100) / 100)).toFixed(2);
        //source.value = s.toFixed(2);
        //vat.value = v.toFixed(2);

        dest.value = (s * ((v + 100) / 100));
        source.value = s;
        vat.value = v;
    }
}

function calcexvat(source, dest, vat)
{
    var s = parseFloat(source.value);
    var v = parseFloat(vat.value);
    var valid = true;

    if (isNaN(s))
    {
        source.value = "";
        valid = false;
    }    

    if (isNaN(v))
    {
        vat.value = "";
        valid = false;
    }    
        
    if (!valid)
    {
        return;
    }
    else
    {
//        dest.value = (s / ((v + 100) / 100)).toFixed(2);
//        source.value = s.toFixed(2);
        //        vat.value = v.toFixed(2);
        dest.value = (s / ((v + 100) / 100));
        source.value = s;
        vat.value = v;
    }
}

function calctotal(Numb,Duration,Negotiated,Amount, vatrate, Published, PublishedIncVAT)
{
    var num = parseFloat(Numb.value);
    var dur = parseFloat(Duration.value);
    var neg = parseFloat(Negotiated.value);    
    var vat = parseFloat(vatrate.value);    
    var pub = parseFloat(Published.value);    
    var pubinc = parseFloat(PublishedIncVAT.value);    
    
    var valid = true;

    if (isNaN(num))
    {
        Numb.value = "";
        valid = false;
    }    

    if (isNaN(dur))
    {
        Duration.value = "";
        valid = false;
    }    

    if (isNaN(vat))
    {
        vatrate.value = "";
        valid = false;
    }    
    
    if (isNaN(neg))
    {
        Negotiated.value = "";
        valid = false;
    }
    else
    {
        if (isNaN(pubinc) || pubinc == 0)
        {
            //PublishedIncVAT.value = neg.toFixed(2);
            PublishedIncVAT.value = neg;
            calcexvat(PublishedIncVAT,Published,vatrate);
        }
    }
    
    if (!valid)
    {
        return;
    }
    else
    {
        //Amount.value = (((num * dur) * neg) / ((vat + 100) / 100)).toFixed(2);
        Amount.value = (((num * dur) * neg) / ((vat + 100) / 100));
    }
}

function calcnewvat(Published,PublishedIncVAT,Negotiated,NegotiatedIncVAT,VatRate)
{
    calcvat(Published,PublishedIncVAT,VatRate);
    calcvat(Negotiated,NegotiatedIncVAT,VatRate);

    var pubinc = parseFloat(PublishedIncVAT.value);    
    var neginc = parseFloat(NegotiatedIncVAT.value);    

    if (pubinc > 0 || neginc > 0)
    {
        alert('Please check the rates you have just entered on this line of the charges as they will have been affected by the change in the tax rates. Always put the correct tax rate in the table first, then enter the prices.');
    }
}

function ChargesEnable(Category,Number,Duration,Published,PublishedIncVAT,Negotiated,NegotiatedIncVAT,Amount,CommissionRate,NettRate,CommissionCalc)
{
    if (Category.value == "T")
    {
        Number.setAttribute('readOnly','readonly');
        Duration.setAttribute('readOnly','readonly');
        Published.setAttribute('readOnly','readonly');
        PublishedIncVAT.setAttribute('readOnly','readonly');
        Negotiated.setAttribute('readOnly','readonly');
        NegotiatedIncVAT.setAttribute('readOnly','readonly');
        Amount.removeAttribute('readOnly');
        CommissionRate.setAttribute('readOnly', 'readonly');
        CommissionCalc.setAttribute('readOnly', 'readonly');
        NettRate.setAttribute('readOnly','readonly');
        Number.value = "";
        Duration.value = "";
        Published.value = "";
        PublishedIncVAT.value = "";
        Negotiated.value = "";
        NegotiatedIncVAT.value = "";
        CommissionRate.value = "";
        CommissionCalc.value = ""; //wd 28/01/2011
        NettRate.value = "";
    }
    else
    {
        Number.removeAttribute('readOnly');    
        Duration.removeAttribute('readOnly');    
        Published.removeAttribute('readOnly');    
        PublishedIncVAT.removeAttribute('readOnly');    
        Negotiated.removeAttribute('readOnly');    
        NegotiatedIncVAT.removeAttribute('readOnly');    
        Amount.setAttribute('readOnly','readonly');
        Amount.value = "0.00";
        CommissionRate.removeAttribute('readOnly');
        CommissionCalc.removeAttribute('readOnly');    
        NettRate.removeAttribute('readOnly');    
    }
}

