﻿////////////////////////////////////////////////////////////
// РАСЧЕТ И ВЫВОД ВАРИАНТОВ ВИЗЫ ///////////////////////////
////////////////////////////////////////////////////////////

function setOverallPrice()
{
    var price = 0;
    
    price += eval(getPrice("txtInvitationProcedurePrice"));
    //price += eval(getPrice("txtInvitationDeliveryPrice"));
    price += eval(getPrice("txtConsulateProcedurePrice"));
    price += eval(getPrice("txtConsulateProcedureComissionPrice"));
    price += eval(getPrice("txtInsurancePrice"));
    price += eval(getPrice("txtPassportRegistrationPrice"));
    price += eval(getPrice("txtPassportDeliveryPrice"));
    price += eval(getPrice("txtRegistrationPrice"));
    
    //document.getElementById(txtOverallPriceId).innerHTML = price;
    return price;
}

function setCustomPrices(oMainVisaVariant)
{   
    setPrice("txtInvitationProcedurePrice", (oMainVisaVariant.InvitationProcedure != null) ? oMainVisaVariant.InvitationProcedure.Price : "");
    //setPrice("txtInvitationDeliveryPrice", (oMainVisaVariant.InvitationDelivery != null) ? oMainVisaVariant.InvitationDelivery.Price : "");
    setPrice("txtConsulateProcedurePrice", (oMainVisaVariant.ConsulateProcedure != null) ? oMainVisaVariant.ConsulateProcedure.Price : "");
    setPrice("txtConsulateProcedureComissionPrice", (oMainVisaVariant.ConsulateProcedureComission != null) ? oMainVisaVariant.ConsulateProcedureComission.Price : "");
    setPrice("txtInsurancePrice", (oMainVisaVariant.Insurance != null) ? oMainVisaVariant.Insurance.Price : "");
    setPrice("txtPassportRegistrationPrice", (oMainVisaVariant.PassportRegistration != null) ? oMainVisaVariant.PassportRegistration.Price : "");
    setPrice("txtPassportDeliveryPrice", (oMainVisaVariant.PassportDelivery != null) ? oMainVisaVariant.PassportDelivery.Price : "");
    setPrice("txtRegistrationPrice", (oMainVisaVariant.Registration != null) ? oMainVisaVariant.Registration.Price : "");
}

function getOverallDate(calendar, ov)
{
    var i;
    var dDiff = 0;
    var date = getDate(calendar);
    var strDate = "";
    
    if (ov.DateVisaAt != null)
    {
        today = new Date();
        date.setDate(today.getDate() + 1);
    }
    //alert("Overall date1: " + date);
    if (ov.InvitationProcedure != null)
    {
        var dDiffInvitationProcedure = convertProcedureTimeToDays(ov.InvitationProcedure.ProcedureTimeValue, ov.InvitationProcedure.ProcedureTimeType);
        if ((ov.InvitationProcedure.ProcedureTimeType == 2) || (ov.InvitationProcedure.ProcedureTimeType == 4))
        {        
            dDiffInvitationProcedure = getDateWeekendDiff(date, dDiffInvitationProcedure, 1, ov.SpecialWorkdays, ov.Holidays);          
        }
        date.setDate(date.getDate() + dDiffInvitationProcedure); 
        //alert(date + ", " + dDiffInvitationProcedure);
    }

    if (ov.ConsulateProcedure != null)
    {
        var dDiffConsulateProcedure = convertProcedureTimeToDays(ov.ConsulateProcedure.ProcedureTimeValue, ov.ConsulateProcedure.ProcedureTimeType);
        if ((ov.ConsulateProcedure.ProcedureTimeType == 2) || (ov.ConsulateProcedure.ProcedureTimeType == 4))
        {  
            dDiffConsulateProcedure = getDateWeekendDiff(date, dDiffConsulateProcedure, 1, ov.SpecialWorkdays, ov.Holidays); 
        }
        date.setDate(date.getDate() + dDiffConsulateProcedure);
        //alert(date + ", " + dDiffInvitationProcedure);
    }
  
    if ((ov.GetPassportFromClientTimeLimit == null) && (ov.PassportRegistration != null))
    {
        var dDiffPassportFromClientTimeLimit = 1;
        dDiffPassportFromClientTimeLimit = getDateWeekendDiff(date, dDiffPassportFromClientTimeLimit, 1, ov.SpecialWorkdays, ov.Holidays);   
        date.setDate(date.getDate() + dDiffPassportFromClientTimeLimit);
        //alert(date);
    }
    
    if ((ov.GetPassportFromClientTimeLimit != null) && (ov.PassportRegistration == null))
    {   
        var dDiffPassportFromClientTimeLimit = 1;
        dDiffPassportFromClientTimeLimit = getDateWeekendDiff(date, dDiffPassportFromClientTimeLimit, -1, ov.SpecialWorkdays, ov.Holidays);   
        date.setDate(date.getDate() - dDiffPassportFromClientTimeLimit);
    }
    
    if (ov.PassportDelivery != null)
    {
        var dDiffPassportDelivery = eval(ov.PassportDelivery.ProcedureTimeValue);
        dDiffPassportDelivery = getDateWeekendDiff(date, dDiffPassportDelivery, 1, ov.SpecialWorkdays, ov.Holidays); 
        date.setDate(date.getDate() + dDiffPassportDelivery);
    }

    return date;
}

function setOverallDate(calendar, ov)
{     
    var dDate = new Date(1981, 2, 2);
    var date = getOverallDate(calendar, ov);
    
    // Вывод результирующей даты, если она больше минмальная 02.03.1980
    if (date > dDate)
    {
        strDate = date.getDate()+ "/" + (date.getMonth()+1) + "/" + date.getFullYear();
        //document.getElementById(txtOverallDateId).innerHTML = strDate;
    }
    return strDate;
}

// Вывод вариантов для быстрого расчета
function setVisaVariants(txtVisaVariantsId, calendar, oVisaVariant, oVisaCalcTranslation)
{
    var i;
    var str = "";    
    var ar = getVisaVariants(oVisaVariant);    
    var nInvitationProcedurePriceDiff = 0;
    var nConsulateProcedurePriceDiff = 0;
    var nInvitationProcedureDateDiff1 = 0;
    var nInvitationProcedureDateDiff2 = 0;
    var nConsulateProcedureDateDiff1 = 0;   
    var nConsulateProcedureDateDiff2 = 0;    
    arVisaVariants = new Array();
    
    // Сортировка массива варинтов по дате
    ar.sort(compareByDate);    
    
    // Удаление из массива вариантов значений с одинаковыми датами, но большой стоимостью
    //ar = sortVisaVariantsByDate(ar, oVisaVariant);    

    // Расчет и вывод данных для основного варианта    
    var nMainPrice = setOverallPrice();
    var strMainDate = setOverallDate(calendar, oVisaVariant);

    if ((nMainPrice > 0) && (strMainDate != ""))
    {
        str += "<table>";
	    str += "<tr style=\"font-size:10pt;\">";
	    str += "    <td><input type=\"button\" name=\"btnVisaVariant\" id=\"btnVisaVariant\" value=\"" + oVisaCalcTranslation.SelectButton + "\" onClick=\"remindVisaVariant(-1, " + nMainPrice + ", '" + strMainDate + "');\"></td>";
	    str += "    <td>€" + nMainPrice + "</td>";
	    str += "    <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
	    str += "    <td>" + strMainDate + "</td>";
	    str += "    <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
	    str += "</tr>";
	    str += "</table><br>";
	}
    var strOldDate = "";
    var nOldPrice = 0;

    // Расчет и вывод остальных вариантов
    for (i = 0; i < ar.length; i++)
    {
        var visa = ar[i];
        var currentPrice = nMainPrice;
        ////var arCurrentDate = strMainDate.split("/");
        ////var currentDate = new Date(eval(arCurrentDate[2]), eval(arCurrentDate[1])-1, eval(arCurrentDate[0]));   
        var currentDate = getDate(calendar);
        var strCurrentDate = ""; 
        var days1_1 = days1_2 = price1_1 = price1_2 = 0;
        var days2_1 = days2_2 = price2_1 = price2_2 = 0;
        var price3_1 = price3_2 = 0;
        var days3_1 = 0;
        
        if (oVisaVariant.InvitationProcedure != null)
        {    
            price1_2 = oVisaVariant.InvitationProcedure.Price.replace(",", ".");
            //days1_2 = convertProcedureTimeToDays(oVisaVariant.InvitationProcedure.ProcedureTimeValue, oVisaVariant.InvitationProcedure.ProcedureTimeType);
            // Если рабочие дни, то происходит следующее...
            //if (oVisaVariant.InvitationProcedure.ProcedureTimeType == 2)
            //    days1_2 = getDateWeekendDiff(currentDate, eval(days1_2), -1, oVisaVariant.SpecialWorkdays, oVisaVariant.Holidays);  
            //currentDate.setDate(currentDate.getDate() - days1_2); 
        }            
        
        if (visa.InvitationProcedure != null)
        {
            price1_1 = visa.InvitationProcedure.Price.replace(",", ".");
            days1_1 = convertProcedureTimeToDays(visa.InvitationProcedure.ProcedureTimeValue, visa.InvitationProcedure.ProcedureTimeType);            
            if ((visa.InvitationProcedure.ProcedureTimeType == 2) || (visa.InvitationProcedure.ProcedureTimeType == 4))
                days1_1 = getDateWeekendDiff(currentDate, eval(days1_1), 1, oVisaVariant.SpecialWorkdays, oVisaVariant.Holidays);    
            currentDate.setDate(currentDate.getDate() + days1_1); 
        }

        if (oVisaVariant.ConsulateProcedure != null)
        {
            price2_2 = oVisaVariant.ConsulateProcedure.Price.replace(",", ".");
            //days2_2 = convertProcedureTimeToDays(oVisaVariant.ConsulateProcedure.ProcedureTimeValue, oVisaVariant.ConsulateProcedure.ProcedureTimeType);
            //if (oVisaVariant.ConsulateProcedure.ProcedureTimeType == 2)
            //    days2_2 = getDateWeekendDiff(currentDate, eval(days2_2), -1, oVisaVariant.SpecialWorkdays, oVisaVariant.Holidays);  
            //currentDate.setDate(currentDate.getDate() - days2_2);   
        }    
        
        if (oVisaVariant.ConsulateProcedureComission != null)
        {
            price3_2 = oVisaVariant.ConsulateProcedureComission.Price.replace(",", ".");            
        }
        
        if (visa.ConsulateProcedure != null)
        {                        
            price2_1 = visa.ConsulateProcedure.Price.replace(",", ".");          
            days2_1 = convertProcedureTimeToDays(visa.ConsulateProcedure.ProcedureTimeValue, visa.ConsulateProcedure.ProcedureTimeType);
            if ((visa.ConsulateProcedure.ProcedureTimeType == 2) || (visa.ConsulateProcedure.ProcedureTimeType == 4))
            {
                days2_1 = getDateWeekendDiff(currentDate, eval(days2_1), 1, oVisaVariant.SpecialWorkdays, oVisaVariant.Holidays);    
            }
            currentDate.setDate(currentDate.getDate() + days2_1);  
        }
        
        if (visa.ConsulateProcedureComission != null)
        {
            price3_1 = visa.ConsulateProcedureComission.Price.replace(",", ".");
        }
        
        nInvitationProcedurePriceDiff = eval(price1_1) - eval(price1_2);
        nConsulateProcedurePriceDiff = eval(price2_1) - eval(price2_2) + eval(price3_1) - eval(price3_2); 
        var currentPriceModifier = eval(nInvitationProcedurePriceDiff) + eval(nConsulateProcedurePriceDiff);
        var newPrice = eval(currentPrice) + currentPriceModifier;

        // Учитываем выходные дни в течении дополнительного времени
        //currentDateModifier += getDateWeekendDiff(currentDate, currentDateModifier);   
        //currentDate.setDate(currentDate.getDate() + currentDateModifier);        

        if ((oVisaVariant.GetPassportFromClientTimeLimit == null) && (oVisaVariant.PassportRegistration != null))
        {
            var dDiffPassportFromClientTimeLimit = 1;
            dDiffPassportFromClientTimeLimit = getDateWeekendDiff(currentDate, dDiffPassportFromClientTimeLimit, 1, oVisaVariant.SpecialWorkdays, oVisaVariant.Holidays);   
            currentDate.setDate(currentDate.getDate() + dDiffPassportFromClientTimeLimit);
        }
        
        if ((oVisaVariant.GetPassportFromClientTimeLimit != null) && (oVisaVariant.PassportRegistration == null))
        {   
            var dDiffPassportFromClientTimeLimit = 1;
            dDiffPassportFromClientTimeLimit = getDateWeekendDiff(currentDate, dDiffPassportFromClientTimeLimit, -1, oVisaVariant.SpecialWorkdays, oVisaVariant.Holidays);   
            currentDate.setDate(currentDate.getDate() - dDiffPassportFromClientTimeLimit);
        }
        
        if (oVisaVariant.PassportDelivery != null)
        {
            var dDiffPassportDelivery = eval(oVisaVariant.PassportDelivery.ProcedureTimeValue);
            dDiffPassportDelivery = getDateWeekendDiff(currentDate, dDiffPassportDelivery, 1, oVisaVariant.SpecialWorkdays, oVisaVariant.Holidays); 
            currentDate.setDate(currentDate.getDate() + dDiffPassportDelivery);
        }

        // Учитываем, если результат попадает на выходной день
        currentDate = getDateInWeekendCase(currentDate, 0);

        strCurrentDate = currentDate.getDate()+ "/" + (currentDate.getMonth()+1) + "/" + currentDate.getFullYear();
                //alert(currentDate + ": " + days1_1 + "===" + days2_1 + " $" + newPrice);
                
        if ((strOldDate != strCurrentDate) && (strCurrentDate != strMainDate))
        {
        if (currentPriceModifier != 0)
        {
            if (i==0)
            {
                str += oVisaCalcTranslation.OtherVariants + ":<br><br>";
                str += "<table>";
            }
        
            // Учитываем отсеянный вариант визы в массиве вариантов
            arVisaVariants.push(visa);
        
            str += "<tr>";
            str += "<td><input type=\"button\" name=\"btnVisaVariant\" id=\"btnVisaVariant\" value=\"" + oVisaCalcTranslation.SelectButton + "\" onClick=\"remindVisaVariant(" + (arVisaVariants.length - 1) + ", " + newPrice + ", '" + strCurrentDate + "');\"></td>";
            
            // Установка даты готовности паспорта
            if (currentDate != "NaN")
            {
                str += "<td>";
                str += strCurrentDate;
                str += "</td>";
                str += "<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
            }           
            
            // Установка стоимости
            str += "<td>&euro;" + newPrice + "</td>";
            str += "<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
            
            // Установка зарактеристик варианта
            str += "<td>";
            if (oVisaVariant.InvitationProcedure != null)
            {
                str += oVisaCalcTranslation.Invitation + ":&nbsp;" + visa.InvitationProcedure.Text + "<br>"
            }
            if (oVisaVariant.ConsulateProcedureComission != null)
            {
                str += oVisaCalcTranslation.ConsulateProcedure + ":&nbsp;" + visa.ConsulateProcedureComission.Text + "<br>"
            }
            str += "</td>";
            str += "</tr>"; 
            if (i == (ar.length-1))
            {
                str += "</table>";
            }
            strOldDate = strCurrentDate;
            nOldPrice = newPrice;
        } 
        }
    }

    document.getElementById(txtVisaVariantsId).innerHTML = str;
}

// Вывод вариантов для ручного расчета
function setManualVisaVariants(id, calendar, oMainVisaVariant, oVisaCalcTranslation)
{
    var i, j;
    var str = "";
    var strMainVariant = "";
    var nMainPrice = 0;
    var strMainDate = "";
    var ar = getManualVisaVariants(oMainVisaVariant);    
    var nInvitationProcedurePriceDiff = 0;
    var nConsulateProcedurePriceDiff = 0;
    var nInvitationProcedureDateDiff1 = 0;
    var nInvitationProcedureDateDiff2 = 0;
    var nConsulateProcedureDateDiff1 = 0;   
    var nConsulateProcedureDateDiff2 = 0; 
    var dateVisaAt = (oMainVisaVariant.DateVisaAt == null) ? null : new Date(oMainVisaVariant.DateVisaAt.getFullYear(), oMainVisaVariant.DateVisaAt.getMonth(), oMainVisaVariant.DateVisaAt.getDate()); 
    var dateIn = (oMainVisaVariant.DateIn == null) ? null : new Date(oMainVisaVariant.DateIn.getFullYear(), oMainVisaVariant.DateIn.getMonth(), oMainVisaVariant.DateIn.getDate()); 
    arVisaVariants = new Array(); 
    ar.sort(compareByDate);    
    //alert(oMainVisaVariant.DateVisaAt + "\n" + dateVisaAt);
    
    // Расчет данных для основного варианта    
    var nMainPrice = setOverallPrice();
    var strMainDate = setOverallDate(calendar, oMainVisaVariant);    
    var nMainPriceTemp = nMainPrice;
    var strMainDateTemp = strMainDate;
    var strOldDate = "";
    
    for (i = 0; i < ar.length; i++)
    {
        var visa = ar[i]; 
        var currentPrice = nMainPrice;
        //var arCurrentDate = strMainDate.split("/");
        //var currentDate = new Date(eval(arCurrentDate[2]), eval(arCurrentDate[1])-1, eval(arCurrentDate[0])); 
        var currentDate = getDate(calendar);
        var strCurrentDate = ""; 
        var days1_1 = days1_2 = price1_1 = price1_2 = 0;
        var days2_1 = days2_2 = price2_1 = price2_2 = 0;
        var price3_1 = price3_2 = 0;
        var days3_1 = 0;          
        
        if (oMainVisaVariant.ConsulateProcedure != null)
        {   
            price2_2 = oMainVisaVariant.ConsulateProcedure.Price.replace(",", ".");
            //days2_2 = convertProcedureTimeToDays(oMainVisaVariant.ConsulateProcedure.ProcedureTimeValue, oMainVisaVariant.ConsulateProcedure.ProcedureTimeType);
            //if (oVisaVariant.ConsulateProcedure.ProcedureTimeType == 2)
            //    days2_2 = getDateWeekendDiff(currentDate, eval(days2_2), -1, oMainVisaVariant.SpecialWorkdays, oMainVisaVariant.Holidays);  
            //currentDate.setDate(currentDate.getDate() - days2_2);
        }  

        if (oMainVisaVariant.InvitationProcedure != null)
        {    
            days1_2 = convertProcedureTimeToDays(oMainVisaVariant.InvitationProcedure.ProcedureTimeValue, oMainVisaVariant.InvitationProcedure.ProcedureTimeType);
            //price1_2 = oMainVisaVariant.InvitationProcedure.Price.replace(",", ".");
            //if (oVisaVariant.InvitationProcedure.ProcedureTimeType == 2)
            //    days1_2 = getDateWeekendDiff(currentDate, eval(days1_2), -1, oMainVisaVariant.SpecialWorkdays, oMainVisaVariant.Holidays);  
            //currentDate.setDate(currentDate.getDate() - days1_2); 
       }  
      
        if (visa.InvitationProcedure != null)
        {
            days1_1 = convertProcedureTimeToDays(visa.InvitationProcedure.ProcedureTimeValue, visa.InvitationProcedure.ProcedureTimeType);            
            
            price1_1 = visa.InvitationProcedure.Price.replace(",", ".");
            if ((visa.InvitationProcedure.ProcedureTimeType == 2) || (visa.InvitationProcedure.ProcedureTimeType == 4))
            {                
                days1_1 = getDateWeekendDiff(currentDate, eval(days1_1), 1, oMainVisaVariant.SpecialWorkdays, oMainVisaVariant.Holidays); 
            }
            currentDate.setDate(currentDate.getDate() + days1_1); 
        } 
        
        if (oMainVisaVariant.ConsulateProcedureComission != null)
        {
            price3_2 = oMainVisaVariant.ConsulateProcedureComission.Price.replace(",", ".");
        }

        if (visa.ConsulateProcedure != null)
        {
            days2_1 = convertProcedureTimeToDays(visa.ConsulateProcedure.ProcedureTimeValue, visa.ConsulateProcedure.ProcedureTimeType);            
            price2_1 = visa.ConsulateProcedure.Price.replace(",", ".");  
            if ((visa.ConsulateProcedure.ProcedureTimeType == 2) || (visa.ConsulateProcedure.ProcedureTimeType == 4))
                days2_1 = getDateWeekendDiff(currentDate, eval(days2_1), 1, oMainVisaVariant.SpecialWorkdays, oMainVisaVariant.Holidays);    
            currentDate.setDate(currentDate.getDate() + days2_1);          
        }
        
        if (visa.ConsulateProcedureComission != null)
        {
            price3_1 = visa.ConsulateProcedureComission.Price.replace(",", ".");
        }

        if ((oMainVisaVariant.GetPassportFromClientTimeLimit == null) && (oMainVisaVariant.PassportRegistration != null))
        {
            var dDiffPassportFromClientTimeLimit = 1;
            dDiffPassportFromClientTimeLimit = getDateWeekendDiff(currentDate, dDiffPassportFromClientTimeLimit, 1, oMainVisaVariant.SpecialWorkdays, oMainVisaVariant.Holidays);   
            currentDate.setDate(currentDate.getDate() + dDiffPassportFromClientTimeLimit);
        }
        
        if ((oMainVisaVariant.GetPassportFromClientTimeLimit != null) && (oMainVisaVariant.PassportRegistration == null))
        {   
            var dDiffPassportFromClientTimeLimit = 1;
            dDiffPassportFromClientTimeLimit = getDateWeekendDiff(currentDate, dDiffPassportFromClientTimeLimit, -1, oMainVisaVariant.SpecialWorkdays, oMainVisaVariant.Holidays);   
            currentDate.setDate(currentDate.getDate() - dDiffPassportFromClientTimeLimit);
        }
        
        if (oMainVisaVariant.PassportDelivery != null)
        {
            var dDiffPassportDelivery = eval(oMainVisaVariant.PassportDelivery.ProcedureTimeValue);
            dDiffPassportDelivery = getDateWeekendDiff(currentDate, dDiffPassportDelivery, 1, oMainVisaVariant.SpecialWorkdays, oMainVisaVariant.Holidays); 
            currentDate.setDate(currentDate.getDate() + dDiffPassportDelivery);
        }

        nConsulateProcedurePriceDiff = eval(price2_1) - eval(price2_2) + eval(price3_1) - eval(price3_2);
        nInvitationProcedurePriceDiff = eval(price1_1) - eval(price1_2);
        var currentPriceModifier = eval(nInvitationProcedurePriceDiff) + eval(nConsulateProcedurePriceDiff);
        var newPrice = nMainPrice + currentPriceModifier;

        if (currentDate != "NaN")
        {
            currentDate = getDateInWeekendCase(currentDate, 0);
            strCurrentDate = currentDate.getDate()+ "/" + (currentDate.getMonth()+1) + "/" + currentDate.getFullYear();
        }  
        
        if (i==0)
        {
            str += oVisaCalcTranslation.OtherVariants + ":<br><br>";
            str += "<table>";
        }
        
        // Проверка и установка самой близкого и самого дешевого варианта по дате
        var dd1 = (currentDate != null) ? new Date(currentDate.getFullYear(), currentDate.getMonth(), currentDate.getDate()) : null;
        var dd2 = (dateVisaAt != null) ? new Date(dateVisaAt.getFullYear(), dateVisaAt.getMonth(), dateVisaAt.getDate()) : dd1;
        var dd3 = (dateIn != null) ? new Date(dateIn.getFullYear(), dateIn.getMonth(), dateIn.getDate()) : dd1;

        if (((dd1 <= dd2) && (dd1 <= dd3)))
        {        
            nMainPriceTemp = newPrice;
	        strMainDateTemp = strCurrentDate;
        }     

        if ((strOldDate != strCurrentDate))
        {
            if ((currentPriceModifier != 0) && (newPrice != 0))
            {
                // Учитываем отсеянный вариант визы в массиве вариантов
                arVisaVariants.push(visa);
            
                str += "<tr>";
                str += "<td><input type=\"button\" name=\"btnVisaVariant\" id=\"btnVisaVariant\" value=\"" + oVisaCalcTranslation.SelectButton + "\" onClick=\"remindVisaVariant(" + (arVisaVariants.length - 1) + ", " + newPrice + ", '" + strCurrentDate + "');\"></td>";
                
                // Установка даты готовности паспорта
                if (currentDate != "NaN")
                {
                    str += "<td>"; //== -" + days1_2 + "=== +" + days1_1 + "== -" + days2_2 + "=== +" + days2_1 + "==";
                    str += strCurrentDate;
                    str += "</td>";
                    str += "<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
                }           
                
                // Установка стоимости
                str += "<td>&euro;" + newPrice + "</td>";
                str += "<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
                
                // Установка зарактеристик варианта
                str += "<td>";
                if (visa.InvitationProcedure != null)
                {
                    str += oVisaCalcTranslation.Invitation + ":&nbsp;" + visa.InvitationProcedure.Text + "<br>"
                }
                if (visa.ConsulateProcedureComission != null)
                {
                    str += oVisaCalcTranslation.ConsulateProcedure + ":&nbsp;" + visa.ConsulateProcedureComission.Text + "<br>"
                }
                
                str += "</td>";
                str += "</tr>"; 
                
                strOldDate = strCurrentDate;
            } 
            if (i == (ar.length-1))
            {
                str += "</table>";
            }            
        }
    }
    
    // Вывод данных для основного варианта  
    var strMain = ""; 
    if ((nMainPriceTemp > 0) && (strMainDateTemp != ""))
    {
        strMain += "<table>";
	    strMain += "<tr style=\"font-size:10pt;\">";
	    strMain += "    <td><input type=\"button\" name=\"btnVisaVariant\" id=\"btnVisaVariant\" value=\"" + oVisaCalcTranslation.SelectButton + "\" onClick=\"remindVisaVariant(-1, " + nMainPrice + ", '" + strMainDate + "');\"></td>";
	    strMain += "    <td>€" + nMainPriceTemp + "</td>";
	    strMain += "    <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
	    strMain += "    <td>" + strMainDateTemp + "</td>";
	    strMain += "    <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>";
	    strMain += "</tr>";
	    strMain += "</table><br>";
	} 
    
    // Склейка строки с данными основного варианта и сотальных
    str = strMain + str;

    
    document.getElementById(id).innerHTML = str;

}

function remindVisaVariant(index, price, date)
{
    document.location.href = "VisaOrder.aspx?t=1";
    //document.location.href = "./OrderEdit.aspx";
    //alert(arVisaVariants[index] + ", " + price + ", " + date);
}

////////////////////////////////////////////////////////////
// UTILITES: SETTERS  //////////////////////////////////////
////////////////////////////////////////////////////////////

function updatePrice(id, val, isPlus)
{
    var curPrice = getPrice(id);
    
    if ((curPrice > 0) && (val != ""))
    {
        val = val.replace(",", ".");
        curPrice = (isPlus) ? (curPrice + eval(val)) : (curPrice - eval(val));
        setPrice(id, curPrice);
    }
}

function setPrice(id, val)
{
    var textPrice = document.getElementById(id);
    var textPriceSign = document.getElementById(id + "Sign");
    textPrice.innerHTML = (val == "") ? "" : val;
    textPriceSign.style.display = (textPrice.innerHTML.length > 0) ? "block" : "none";
}

function updateDate(calendar, val, arSpecialWorkdays, arHolidays)
{
    var date = getDate(calendar);     
    val = getDateWeekendDiff(date, val, 1, arSpecialWorkdays, arHolidays); 
    date.setDate(date.getDate() + val);
    setDate(calendar, date);    
}

function setDate(calendar, val)
{
    var dDate = new Date(1981, 2, 2);
    if (val > dDate)
    {    
        calendar.SetDate(val);
    }
}

function setCurrentDate(calendar)
{
    var newDate = new Date();
    var todaysDate = new Date(newDate.getFullYear(), newDate.getMonth(), newDate.getDate());
    calendar.SetDate(todaysDate);
}

function setDefaultDate(calendar)
{
    var todaysDate = new Date(1980, 0, 1);
    calendar.SetDate(todaysDate);
}

/////////////////////////////////////////////////////////  
// UTILITES: GETTERS  ///////////////////////////////////
/////////////////////////////////////////////////////////
    
function getPrice(id)
{
    var price = 0;
    var textPrice = document.getElementById(id);
    if (textPrice.innerHTML.length > 0)
    {
        str = textPrice.innerHTML.replace(",", ".");
        price += eval(str);
    }
    return price;
}
    
function getDate(calendar)
{
    return calendar.GetDate();
}

function getDateWeekendDiff(date, dDiff, sign, arSpecialWorkdays, arHolidays)
{
    var dateTemp = new Date(date);
    if (dateTemp == "NaN")
        return 0;

    var i = 0;
    var dateStartDay = dateTemp.getDay(); 

    for (i = 0; i < dDiff; i++)
    {
        dateTemp.setDate(dateTemp.getDate() + (1*sign));
        dateStartDay = dateTemp.getDay(); 
        
        if ((dateStartDay == 6) || (dateStartDay == 0))
        {
            if (!IsDateContains(arSpecialWorkdays, dateTemp))
            {
                dDiff += 1;        
            }
        }
        else
        {
            if (IsDateContains(arHolidays, dateTemp))
            {
                dDiff += 1;        
            }
        }
    }
    
    return dDiff;
}

function getDateInWeekendCase(date, sign)
{
    var day = date.getDay();

    if (day == 6)
    {
        date.setDate(date.getDate() + 2);    
    }
    else if (day == 0)
    {
        date.setDate(date.getDate() + 1);  
    }
    return date;
}


function convertProcedureTimeToDays(val, type)
{
    var newVal = val;
    
    if (type == 3)
    {
        newVal = eval(val)*7;
    }
    else if (type == 4)
    {
        newVal = eval(val)/24;
        if (newVal < 1)
            newVal = 0;
    }
    return newVal;
}

function convertDurationTimeToDays(val, type)
{
    var newVal = val;
    
    if (type == 2)
    {
        newVal = eval(val)*7;
    }
    else if (type == 3)
    {
        newVal = eval(val)*30;
    }
    else if (type == 4)
    {
        newVal = eval(val)*365;
    }
    return newVal;
}

function convertDurationFromDays(durationValue)
{
    var durationValue = durationValue;
    var durationValueType = 1;

    if ((durationValue > 0) && (durationValue < 31))
    {
        durationValue = 30;
    }
    else if ((durationValue > 30) && (durationValue < 91))
    {
        durationValue = 90;
    }
    else if ((durationValue > 90) && (durationValue < 181))
    {
        durationValue = 180;
    }
    else if (durationValue > 180)
    {
        durationValue = Math.ceil(durationValue / 365);
        durationValueType = 4;
    }    
    return [durationValue, durationValueType];
}


function convertDurationFromDays2(durationValue)
{
    var durationValue = durationValue;
    var durationValueType = 1;

    if ((durationValue > 0) && (durationValue < 11))
    {
        durationValue = 10;
    }
    if ((durationValue > 10) && (durationValue < 31))
    {
        durationValue = 30;
    }
    else if ((durationValue > 30) && (durationValue < 91))
    {
        durationValue = 3;
        durationValueType = 3;
    }
    else if ((durationValue > 90) && (durationValue < 181))
    {
        durationValue = 6;
        durationValueType = 3;
    }
    else if (durationValue > 180)
    {
        durationValue = Math.ceil(durationValue / 365);
        durationValueType = 4;
    }    
    return [durationValue, durationValueType];
}

function getConsulateProcedure(valProcedureType, valCitizenship)
{
    var p = arConsulateProcedureComissions[valProcedureType];

    if (p == null)
        return null;

    for (i=0; i<arConsulateProcedures.length; i++)
    {     
        if ((arConsulateProcedures[i].Text == valCitizenship) &&
            (arConsulateProcedures[i].ProcedureType == p.ProcedureType))
        {
            return arConsulateProcedures[i];
        }
    }
    return null;
}

function getInvitationProceduresByEntryType(EntryType)
{
    var ar = new Array();
    
    for (i=0; i<arInvitationProcedures.length; i++)
    {     
        if (((arInvitationProcedures[i].DurationValue == EntryType.DurationValue) &&
            (arInvitationProcedures[i].DurationType == EntryType.DurationType) &&
            (arInvitationProcedures[i].EntryType == EntryType.EntryType) &&
            (arInvitationProcedures[i].Field == EntryType.Field)))
        {
            //alert("(" + arInvitationProcedures[i].DurationValue + "==" + EntryType.DurationValue + ")\n(" + arInvitationProcedures[i].DurationType + "==" + EntryType.DurationType + ")\n(" + arInvitationProcedures[i].EntryType + "==" + EntryType.EntryType + ")\n");
            ar.push(arInvitationProcedures[i]);
        }
    }
    return ar;
}

// Самая дешевая процедура приглашения по пользоватльским даннным в ручном варианте
function getChipInvitationProcedureByManualParameters(oMainVisaVariant)
{
    var n = 1000000;  
    var index = 0;  
    var arInvitationProcedures = getInvitationProceduresByManualParameters(oMainVisaVariant);
    
    for (i=0; i<arInvitationProcedures.length; i++)
    {
        if (eval(arInvitationProcedures[i].Price) < n)
        {
            n = arInvitationProcedures[i].Price
            index = i;
        }
    } 

    if(arInvitationProcedures.length > 0)
        return arInvitationProcedures[index];   
    return null;
}

// Формирование выборки процедур приглашения по пользоватльским даннным в ручном варианте
function getInvitationProceduresByManualParameters(oMainVisaVariant)
{
    var ar = new Array();    
    var durationValue = convertDurationFromDays(oMainVisaVariant.TripDuration)[0];
    var durationValueType = convertDurationFromDays(oMainVisaVariant.TripDuration)[1];    
    var strEntryTypes = ((oMainVisaVariant.IsOneEntry) ? "1" : "") + ((oMainVisaVariant.IsTwoEntry) ? "2" : "") + ((oMainVisaVariant.IsMultiEntry) ? "3" : "");
    var strTripTypes = ((oMainVisaVariant.IsBusinessTrip) ? "1" : "") + ((oMainVisaVariant.IsTouristicTrip) ? "2" : "");

    for (i=0; i<arInvitationProcedures.length; i++)
    {         
        if ((arInvitationProcedures[i].DurationValue == durationValue) &&
            (arInvitationProcedures[i].DurationType == durationValueType) &&
            (strEntryTypes.indexOf(arInvitationProcedures[i].EntryType) > -1) && 
            (strTripTypes.indexOf(arInvitationProcedures[i].Field) > -1))
        {
            //alert("(" + arInvitationProcedures[i].DurationValue + "==" + EntryType.DurationValue + ")\n(" + arInvitationProcedures[i].DurationType + "==" + EntryType.DurationType + ")\n(" + arInvitationProcedures[i].EntryType + "==" + EntryType.EntryType + ")\n");
            ar.push(arInvitationProcedures[i]);
        }
    }
    return ar;   
}

// Самая дешевая консульская процедура
function getChipConsulateProcedure(valCitizenship)
{
    var n = 1000000;  
    var index = 0;  
    
    for (i=0; i<arConsulateProcedures.length; i++)
    {     
        if (arConsulateProcedures[i].Text == valCitizenship)
        {
            if (eval(arConsulateProcedures[i].Price) < n)
            {
                n = arConsulateProcedures[i].Price
                index = i;
            }
        }
    }
    
    if (arConsulateProcedures.length > 0)    
        return arConsulateProcedures[index];  
    return null;
}

// Самая дешевая комиссия на консульскую процедуру
function getChipConsulateProcedureComission()
{
    var n = 1000000;  
    var index = 0;  
    
    for (i=0; i<arConsulateProcedureComissions.length; i++)
    {     
        if (eval(arConsulateProcedureComissions[i].Price) < n)
        {
            n = arConsulateProcedureComissions[i].Price
            index = i;
        }
    }

    if (arConsulateProcedureComissions.length > 0)    
        return arConsulateProcedureComissions[index];  
    return null;
}

// Поиск страховки по пользоватльским даннным в ручном варианте
function getInsuranceByManualParameters(oMainVisaVariant)
{
    var ar = new Array();    
    var durationValue = convertDurationFromDays2(oMainVisaVariant.TripDuration)[0];
    var durationValueType = convertDurationFromDays2(oMainVisaVariant.TripDuration)[1];    

    for (i=0; i<arInsurances.length; i++)
    {         
        if ((arInsurances[i].DurationValue == durationValue) &&
            (arInsurances[i].DurationType == durationValueType))
        {
            //alert("(" + arInvitationProcedures[i].DurationValue + "==" + EntryType.DurationValue + ")\n(" + arInvitationProcedures[i].DurationType + "==" + EntryType.DurationType + ")\n(" + arInvitationProcedures[i].EntryType + "==" + EntryType.EntryType + ")\n");
            return arInsurances[i];
        }
    }
    return null;   
}

function getChipVisaVariant(oMainVisaVariant, isInvitation, isVisaOffer, isInsurance)
{
    oMainVisaVariant.InvitationProcedure = (isInvitation) ? getChipInvitationProcedureByManualParameters(oMainVisaVariant) : null;
    oMainVisaVariant.ConsulateProcedure = (isVisaOffer) ? getChipConsulateProcedure(oMainVisaVariant.Citizenship) : null;   
    oMainVisaVariant.ConsulateProcedureComission = (isVisaOffer) ? getChipConsulateProcedureComission() : null;
    oMainVisaVariant.Insurance = (isInsurance) ? getInsuranceByManualParameters(oMainVisaVariant) : null;
    
    //var currentDate = getOverallDate(calendar, oMainVisaVariant);
    
    //if (oMainVisaVariant.DateVisaAt
    
    return oMainVisaVariant;
}

// Формирование коллекции вариантов для быстрого расчета
function getVisaVariants(oMainVisaVariant)
{
    var i, k;   
    var oNewVisaVariant; 
    var arVisaVariants = new Array();    
    var arAvailInvitationProcedures = new Array(oMainVisaVariant.InvitationProcedure); // Массив "по-умолчанию" с InvitationProcedure из текущего объекта oMainVisaVariant   
    var arAvailConsulateProcedureComissions = new Array(oMainVisaVariant.ConsulateProcedureComission); // Массив "по-умолчанию" с ConsulateProcedureComissions из текущего объекта oMainVisaVariant   
    
    if (oMainVisaVariant.InvitationProcedure != null) 
    {
        arAvailInvitationProcedures = getInvitationProceduresByEntryType(oMainVisaVariant.EntryType);
    }
    if (oMainVisaVariant.ConsulateProcedureComission != null) 
    {
        arAvailConsulateProcedureComissions = arConsulateProcedureComissions;
    }
    
    for (i = 0; i < arAvailInvitationProcedures.length; i++)
    {
        for (k = 0; k < arAvailConsulateProcedureComissions.length; k++)
        {            
            oNewVisaVariant = new VisaVariant(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
            oNewVisaVariant.InvitationProcedure = arAvailInvitationProcedures[i];
            if (oMainVisaVariant.ConsulateProcedure != null)
            {
                oNewVisaVariant.ConsulateProcedure = getConsulateProcedure(k, oVisaVariant.Citizenship);            
                oNewVisaVariant.ConsulateProcedureComission = arAvailConsulateProcedureComissions[k];
            }
            arVisaVariants.push(oNewVisaVariant); 
        }
    }

    //alert(arVisaVariants[arVisaVariants.length-2].ConsulateProcedure.Price+ " " + arVisaVariants[arVisaVariants.length-1].ConsulateProcedure.Price);
    return arVisaVariants;
}

// Формирование коллекции вариантов для ручного расчета
function getManualVisaVariants(oMainVisaVariant)
{
    var i, k;   
    var oNewVisaVariant; 
    var arVisaVariants = new Array();    
    var arAvailInvitationProcedures = new Array(null); // Массив "по-умолчанию" с InvitationProcedure из текущего объекта oMainVisaVariant   
    var arAvailConsulateProcedureComissions = new Array(null); // Массив "по-умолчанию" с ConsulateProcedureComissions из текущего объекта oMainVisaVariant   
    
    if (oMainVisaVariant.InvitationProcedure != null) 
    {
        arAvailInvitationProcedures = getInvitationProceduresByManualParameters(oMainVisaVariant);
    }
    if (oMainVisaVariant.ConsulateProcedure != null)
    {
        arAvailConsulateProcedureComissions = arConsulateProcedureComissions;
    }
    
    for (i = 0; i < arAvailInvitationProcedures.length; i++)
    {
        for (k = 0; k < arAvailConsulateProcedureComissions.length; k++)
        {            
            oNewVisaVariant = new VisaVariant(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
            if (oMainVisaVariant.InvitationProcedure != null) 
            {
                oNewVisaVariant.InvitationProcedure = arAvailInvitationProcedures[i];
            }
            if (oMainVisaVariant.ConsulateProcedure != null)
            {
                oNewVisaVariant.ConsulateProcedure = getConsulateProcedure(k, oMainVisaVariant.Citizenship);            
                oNewVisaVariant.ConsulateProcedureComission = arAvailConsulateProcedureComissions[k];
            }
            
            //if (oMainVisaVariant.DateVisaAt != null)
            //{
            //    oNewVisaVariant.DateVisaAt = oMainVisaVariant.DateVisaAt
            //}
            arVisaVariants.push(oNewVisaVariant);   
        }
    }

    //alert(arVisaVariants[arVisaVariants.length-2].ConsulateProcedure.Price+ " " + arVisaVariants[arVisaVariants.length-1].ConsulateProcedure.Price);
    return arVisaVariants;
}

/////////////////////////////////////////////////////////
// UTILITES: SORTING  ///////////////////////////////////                  
/////////////////////////////////////////////////////////

function compareByDate(a, b)
{
    var days1_1 = 0;
    var days1_2 = 0;
    var days2_1 = 0;
    var days2_2 = 0;
    
    if (a.InvitationProcedure != null)    
        days1_1 = convertProcedureTimeToDays(a.InvitationProcedure.ProcedureTimeValue, a.InvitationProcedure.ProcedureTimeType); 
    if (a.ConsulateProcedure != null)           
        days1_2 = convertProcedureTimeToDays(a.ConsulateProcedure.ProcedureTimeValue, a.ConsulateProcedure.ProcedureTimeType);
    var currentDateModifier1 = eval(days1_1) + eval(days1_2);
    
    if (b.InvitationProcedure != null)    
        days2_1 = convertProcedureTimeToDays(b.InvitationProcedure.ProcedureTimeValue, b.InvitationProcedure.ProcedureTimeType); 
    if (b.ConsulateProcedure != null)               
        days2_2 = convertProcedureTimeToDays(b.ConsulateProcedure.ProcedureTimeValue, b.ConsulateProcedure.ProcedureTimeType);
    var currentDateModifier2 = eval(days2_1) + eval(days2_2);

    return currentDateModifier1 - currentDateModifier2;
}


function compareByPrice(a, b)
{
    var price1_1 = 0;
    var price1_2 = 0;
    var price2_1 = 0;
    var price2_2 = 0;
    
    if (a.InvitationProcedure != null)    
        price1_1 = a.InvitationProcedure.Price; 
    if (a.ConsulateProcedure != null)           
        price1_2 = a.ConsulateProcedure.Price;
    var price1 = eval(price1_1) + eval(price1_2);
    
    if (b.InvitationProcedure != null)    
        price2_1 = b.InvitationProcedure.Price; 
    if (b.ConsulateProcedure != null)               
        price2_2 = b.ConsulateProcedure.Price;
    var price2 = eval(price2_1) + eval(price2_2);

    return price1 - price2;
}

/////////////////////////////////////////////////////////
// UTILITES: DISABLING, CLEARING, UNCHECKING  ///////////
/////////////////////////////////////////////////////////  

function disableAll(val)
{
    document.getElementById("ddlDurations").disabled = ((val == "1") && (document.getElementById("cbxIsInvitation").checked)) ? false : true;
	document.getElementById("ddlEntryTypes").disabled = ((val == "1") && (document.getElementById("cbxIsInvitation").checked)) ? false : true;
	document.getElementById("ddlInvitationProcedures").disabled = ((val == "1") && (document.getElementById("cbxIsInvitation").checked)) ? false : true;
	//document.getElementById("ddlInvitationDelivery").disabled = true;
	//document.getElementById("cbxInvitationDeliveryTimeLimit").disabled = true;
	document.getElementById("ddlConsulateProcedures").disabled = ((val == "1") && (document.getElementById("cbxIsVisaOffer").checked)) ? false : true;
	document.getElementById("ddlInsurances").disabled = ((val == "1") && (document.getElementById("cbxIsInsurance").checked)) ? false : true;
	document.getElementById("ddlPassportDelivery").disabled = ((val == "1") && (document.getElementById("cbxIsPassportDelivery").checked)) ? false : true;
	document.getElementById("cbxPassportDeliveryTimeLimit").disabled = ((val == "1") && (document.getElementById("cbxIsPassportDelivery").checked)) ? false : true;
	document.getElementById("ddlPassportRegistration").disabled = ((val == "1") && (document.getElementById("cbxIsPassportRegistration").checked)) ? false : true;
	document.getElementById("cbxPassportRegistrationTimeLimit").disabled = ((val == "1") && (document.getElementById("cbxIsPassportRegistration").checked)) ? false : true;
	document.getElementById("cbxGetPassportFromClientTimeLimit").disabled = (val == "1")  ? false : true;
	document.getElementById("cbxManualOneEntry").disabled = true;
	document.getElementById("cbxManualTwoEntry").disabled = true;
	document.getElementById("cbxManualMultiEntry").disabled = true;
	document.getElementById("cbxManualTouristicTrip").disabled = true;
	document.getElementById("cbxManualBusinessTrip").disabled = true;
}

function uncheckedAll()
{
    // Флажки в секции "Услуги"
    document.getElementById("cbxIsInvitation").checked = false;
	document.getElementById("cbxIsInvitation").checked = false;
	document.getElementById("cbxIsInvitation").checked = false;
	document.getElementById("cbxIsVisaOffer").checked = false;
	document.getElementById("cbxIsInsurance").checked = false;
	document.getElementById("cbxIsPassportDelivery").checked = false;
	document.getElementById("cbxIsPassportRegistration").checked = false;
	document.getElementById("cbxIsHotelAppart").checked = false;
	document.getElementById("cbxIsRegistration").checked = false;
	
	// Фладжки в секции "Общие данные" для ручного расчета
	uncheckedManualAll();
}

function uncheckedManualAll()
{
    document.getElementById("cbxManualOneEntry").checked = false;
	document.getElementById("cbxManualTwoEntry").checked = false;
	document.getElementById("cbxManualMultiEntry").checked = false;
	document.getElementById("cbxManualTouristicTrip").checked = false;
	document.getElementById("cbxManualBusinessTrip").checked = false;
}

function clearAll()
{			
    document.getElementById("ddlDurations").value = "-1";
    document.getElementById("ddlCitizenships").value = "-1";
	document.getElementById("ddlEntryTypes").value = "-1";
	document.getElementById("ddlInvitationProcedures").value = "-1";
	//document.getElementById("ddlInvitationDelivery").value = "-1";
	//document.getElementById("cbxInvitationDeliveryTimeLimit").checked = false;
	document.getElementById("ddlConsulateProcedures").value = "-1";
	document.getElementById("ddlInsurances").value = "-1";
	document.getElementById("ddlPassportDelivery").value = "-1";
	document.getElementById("ddlPassportRegistration").value = "-1";
	document.getElementById("ddlRegistrationOptions").value = "-1";
    document.getElementById("cbxPassportDeliveryTimeLimit").checked = false;
	document.getElementById("cbxPassportRegistrationTimeLimit").checked = false;
	document.getElementById("cbxGetPassportFromClientTimeLimit").checked = false;
	//document.getElementById("txtOverallDate").innerHTML = "";
	//document.getElementById("txtOverallPrice").innerHTML = "";
	
    setPrice("txtInvitationProcedurePrice", "");
    //setPrice("txtInvitationDeliveryPrice", "");
    setPrice("txtConsulateProcedurePrice", "");
    setPrice("txtConsulateProcedureComissionPrice", "");
    setPrice("txtInsurancePrice", "");
    setPrice("txtPassportRegistrationPrice", "");
    setPrice("txtPassportDeliveryPrice", "");
    setPrice("txtRegistrationPrice", "");
    
    document.getElementById("txtInvitationProcedurePriceSign").style.display = "none";
    //document.getElementById("txtInvitationDeliveryPriceSign").style.display = "none";
    document.getElementById("txtConsulateProcedurePriceSign").style.display = "none";
    document.getElementById("txtConsulateProcedureComissionPriceSign").style.display = "none";
    document.getElementById("txtInsurancePriceSign").style.display = "none";
    document.getElementById("txtPassportRegistrationPriceSign").style.display = "none";
    document.getElementById("txtPassportDeliveryPriceSign").style.display = "none";
    document.getElementById("txtRegistrationPriceSign").style.display = "none";    
}

function disableAnyList(val, ddl)
{
	if (document.getElementById("ddlCalcType").value == "1")
	{
		document.getElementById(ddl).disabled = (val == true) ? false : true;
	}
}	

function disableAnyCalendar(val, calendar)
{
    if (val)
    {
        calendar.DateInput.Disable();
        calendar.PopupButton.onclick = null;
    }
    else
    {
        calendar.DateInput.Enable();
        calendar.PopupButton.onclick = function()
        {
            calendar.TogglePopup();
             return false;
        };
    }
}