﻿function submitMeny(param1, param2)
{
    var dat1 = document.getElementById('selDay');
    var dat2 = document.getElementById('selMonth');
    var dat3 = document.getElementById('selYear');
    
    if(dat1 && dat2 && dat3)    
    {   
        var dat = document.getElementById('param_' + param1 + '_' + param2 + '_productdate1');
        if(dat)
            dat.value = dat.value = AddZero(dat3.value) + '-' + AddZero(dat2.value) + '-' + AddZero(dat1.value) + 'T00:00:00';
         
        var label = document.getElementById('spDate');
        if(label)
            label.innerHTML = dat1.value + '.' + dat2.value + '.' + dat3.value;
    }
    
    var cb = document.getElementById('productnvparamVAL');
    if(cb)
        document.getElementById('param_' + param1 + '_' + param2 + '_productnvparam').value = (cb.checked) ? "VAL" : "DEV";      
        
    productReload(param1, param2, true);
}

function devizyValuty(param1, param2, type)
{    
    document.getElementById('tab_' + param1 + '_' + param2 +'_dev').className = (type == 'DEV') ? "active" : ""; 
    document.getElementById('tab_' + param1 + '_' + param2 +'_val').className = (type == 'VAL') ? "active isLast" : " isLast";
    document.getElementById('tabA_' + param1 + '_' + param2 +'_dev').className = (type == 'DEV') ? "active" : ""; 
    document.getElementById('tabA_' + param1 + '_' + param2 +'_val').className = (type == 'VAL') ? "active isLast" : " isLast";
    
    var par = document.getElementById('param_' + param1 + '_' + param2 + '_ExchangeType');    
    if(par)
        par.value = (type == 'DEV') ?  2 : 1;
        
    par = document.getElementById('param_' + param1 + '_' + param2 + '_productnvparam'); 
    if(par)
        par.value = type;
        
    submitMeny(param1, param2);    
}

function submitIndexy(param1, param2)
{
   var dat = document.getElementById('param_' + param1 + '_' + param2 + '_productdate1');
     // twice selMonth since all we need is year and month and like this we also eliminate the day/month-month/day problem  
	var dat1 = document.getElementById('selMonth');
    var dat2 = document.getElementById('selMonth');
    var dat3 = document.getElementById('selYear');
    
    if(dat1 && dat2 && dat3)    
    {
        dat.value = dat3.value + '-' + dat2.value + '-' + dat1.value;     
    }
    
    productReload(param1, param2);
}

function AddZero(t)
{
    if (t.length == 1)
        return "0" + t; 
    else
        return t; 
}
