﻿function changeStateElements(row) {

    if (document.getElementById(contentPlaceHolder + "CheckBox" + row).checked) {
        for (var i = 2; i < row; i++) {

            if (document.getElementById(contentPlaceHolder + "datepicker" + i).disabled &&
                document.getElementById(contentPlaceHolder + "CheckBox" + row).checked) {
                alert("devi attivare le valutazioni in sequenza, senza saltarne");

                document.getElementById(contentPlaceHolder + "CheckBox" + row).checked = false;
            }
        }

        if (document.getElementById(contentPlaceHolder + "CheckBox" + row).checked) {
            document.getElementById(contentPlaceHolder + "datepicker" + row).disabled = false;
            document.getElementById(contentPlaceHolder + "weightOfControl" + row).disabled = false;
            document.getElementById(contentPlaceHolder + "heightOfControl" + row).disabled = false;
            document.getElementById(contentPlaceHolder + "craneOfControl" + row).disabled = false;

        }
    } else {
        for (var i = row+1; i <= 5; i++) {

            if (!document.getElementById(contentPlaceHolder + "datepicker" + i).disabled) {
                alert("Se vuoi disattivare delle valutazioni, lo devi fare in sequenza");

                document.getElementById(contentPlaceHolder + "CheckBox" + row).checked = true;
                break;
            }
        }

        if (!document.getElementById(contentPlaceHolder + "CheckBox" + row).checked) {
            document.getElementById(contentPlaceHolder + "datepicker" + row).disabled = true;
            document.getElementById(contentPlaceHolder + "weightOfControl" + row).disabled = true;
            document.getElementById(contentPlaceHolder + "heightOfControl" + row).disabled = true;
            document.getElementById(contentPlaceHolder + "craneOfControl" + row).disabled = true;

            document.getElementById(contentPlaceHolder + "datepicker" + row).value = "";
            document.getElementById(contentPlaceHolder + "weightOfControl" + row).value = "";
            document.getElementById(contentPlaceHolder + "heightOfControl" + row).value = "";
            document.getElementById(contentPlaceHolder + "craneOfControl" + row).value = "";
        }
    }
}

function submitForm() {

    if ($("#"+contentPlaceHolder + "ValidationSummary1").html().replace(" ", "") != "") {
        $("#div_loading").css("min-width", $("body").outerWidth(true));
        $("#div_loading").css("min-height", $(document).attr("height"));
        $("#div_loading").css("opacity", "0.3");
        $("#div_loading").show();

        $("#img_loading").css("top", $(document).scrollTop() + 100);
        $("#img_loading").css("left", ($(document).attr("width") / 2) - 176);
        $("#img_loading").show();
    }
}

$(document).ready(function() {
/*
alert($('#' + contentPlaceHolder + 'Hidden_datepicker1').attr('value'));
alert($('#' + contentPlaceHolder + 'datepicker1').attr('value'));

    $('#' + contentPlaceHolder + 'datepicker1').attr('value', $('#' + contentPlaceHolder + 'Hidden_datepicker1').attr('value'));
    $('#' + contentPlaceHolder + 'datepicker2').attr('value', $('#' + contentPlaceHolder + 'Hidden_datepicker2').attr('value'));
    $('#' + contentPlaceHolder + 'datepicker3').attr('value', $('#' + contentPlaceHolder + 'Hidden_datepicker3').attr('value'));
    $('#' + contentPlaceHolder + 'datepicker4').attr('value', $('#' + contentPlaceHolder + 'Hidden_datepicker4').attr('value'));
    $('#' + contentPlaceHolder + 'datepicker5').attr('value', $('#' + contentPlaceHolder + 'Hidden_datepicker5').attr('value'));
*/

    if ($('#' + contentPlaceHolder + 'beginResults').length > 0) {
        document.location.href = '#' + contentPlaceHolder + 'beginResults';
    }

    $(".graphics").colorbox({ width: "620", height: "590", iframe: true });
    $("#sm_frm1").hide();

    $('#' + contentPlaceHolder + 'tabs').tabs();
    $('a[href^="#tabs"]').each(function() {

        $(this).attr("href", $(this).attr("href").substring(0, 1) + contentPlaceHolder + $(this).attr("href").substring(1));
    });


    //Select all anchor tag with rel set to tooltip
    $('td[rel=tooltip]').attr('style', 'cursor:help;');

    
    //select all the a tag with name equal to modal  
    $('a[name=modal]').click(function(e) {
    //Cancel the link behavior  
    e.preventDefault();
    //Get the A tag  
    var id = $(this).attr('href');

        //Get the screen height and width  
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();

        //Set height and width to mask to fill up the whole screen  
    $('#mask').css({ 'width': maskWidth, 'height': maskHeight });

        //transition effect       
    $('#mask').fadeIn(1000);
    $('#mask').fadeTo("slow", 0.8);

        //Get the window height and width  
    var winH = $(window).height();
    var winW = $(window).width();

        //Set the popup window to center  
    $(id).css('top', winH / 2 - $(id).height() / 2);
    $(id).css('left', winW / 2 - $(id).width() / 2);

        //transition effect  
    $(id).fadeIn(2000);

    });
    
    //if close button is clicked  
    $('.window .close').click(function(e) {
    //Cancel the link behavior  
    e.preventDefault();
    $('#mask, .window').hide();
    });

    //if mask is clicked  
    $('#mask').click(function() {
    $(this).hide();
    $('.window').hide();
    });
    
    //if mask is clicked  
    $('#printData').click(function() {

        if (!$('#' + contentPlaceHolder + 'tabs').length) {
            alert('Non hai ancora eseguito alcun calcolo da stampare ');

        } else {

            var printDocument = window.open("printData.html", "printWindow");
            printDocument.focus();
        }

        return false;
    });

});

$(function() {

    // Tabs
    //		        $('#' + contentPlaceHolder + 'tabs').tabs();
    $('#tabs').tabs();

    // Datepicker
    $('input[id^="' + contentPlaceHolder + 'datepicker"]').datepicker({
        inline: true
    });

    $('input[id^="' + contentPlaceHolder + 'datepicker"]').datepicker('option', 'dateFormat', 'dd/mm/yy');

    $('input[id^="' + contentPlaceHolder + 'Hidden_"]').each(function() {

        if ($(this).attr("value")) {

            var pos = $(this).attr("id").indexOf("Hidden_");
            //		                $("#" + $(this).attr("id").substring(pos+7)).attr("value", $(this).attr("value"));
            $("#" + contentPlaceHolder + $(this).attr("id").substring(pos + 7)).attr("value", $(this).attr("value"));
        }
    });

    //hover states on the static widgets
    $('#dialog_link, ul#icons li').hover(
					function() { $(this).addClass('ui-state-hover'); },
					function() { $(this).removeClass('ui-state-hover'); }
				);
});

