$(document).ready(function () {
    $('.pic a').lightBox({
        imageLoading: 'img/gallery/loading.gif',
        imageBtnClose: 'img/gallery/close.gif',
        imageBtnPrev: 'img/gallery/prev.gif',
        imageBtnNext: 'img/gallery/next.gif'
    });
    $('#buildinfo_form').jqTransform();
    $('#photo_form').jqTransform();
    $('#shema_form').jqTransform();
    $('#chefs_form').jqTransform();
    $('#recipe_form').jqTransform();
    $('#comment_form').jqTransform();
    $('#runline_form').jqTransform();
    $('#top10').jqTransform();
    $('#loginform').jqTransform();
    $('.banner_form').jqTransform();
    $('#offab_form').jqTransform();
    $('#afisha_form').jqTransform();
    $('#contentTable').dataTable();
    $('#recipetable').dataTable();
    $('#directorytable').dataTable();

    $('#sbuildsatable').dataTable();
    $('#afishatable').dataTable();

    slide("#sliding-navigation", 25, 15, 150, .8);
    slide("#sliding-subnavigation", 25, 15, 150, .8);

    $("#expample").treeview({
        animated: "fast",
        collapsed: true
    });

    $jScroller.add("#scroller_container", "#scroller", "left", 10, true);
    $jScroller.start();
    setTinyMce('.cn_Text');
    setTinyMce('.Textedit input');

    $('#startdate').datepicker({
        dateFormat: 'dd.mm.yy',
        changeMonth: true,
        changeYear: true,
        yearRange: '2010:2100',
        minDate: new Date(2010, 1 - 1, 1)
    });
    $('#enddate').datepicker({
        dateFormat: 'dd.mm.yy',
        changeMonth: true,
        changeYear: true,
        yearRange: '2010:2100',
        minDate: new Date(2010, 1 - 1, 1)

    });
    
    
});
function sent_data(value) {

    /*var str=’ajax=1&’;
    $(’#form input’).each(function(n,element){
    if($(element).attr(’type’)!=”button”){ str=str + $(element).attr(’id’) +’='+$(element).val()+’&’;}
    $.post(’templates/backend.php’,str,onShowResult);*/
    var str = "";
    $('#form' + value + ' :input').each(function (n, element) {
        if ($(element).attr('type') != "button") {
            if ($(element).attr('type') == "checkbox") {
                str += $(element).attr('id') + '=' + $(element).attr('checked') + '&';
            } else
                str += $(element).attr('id') + '=' + $(element).val() + '&';
        }
    }
);
    $.post('Fair_price.aspx', { isAjax: "true",serviceAction: "update", serviceID: value, serviceParam: str }, function (data) { location.href = location.href;});

}


function del_data(value) {

   /* var str = "";
    $('#form' + value + ' :input').each(function (n, element) {
        if ($(element).attr('type') != "button") {
            if ($(element).attr('type') == "checkbox") {
                str += $(element).attr('id') + '=' + $(element).attr('checked') + '&';
            } else
                str += $(element).attr('id') + '=' + $(element).val() + '&';
        }
    }
);*/
    if (confirm('Delete?')) {
        $.post('Fair_price.aspx', { isAjax: "true", serviceAction: "delete", serviceID: value }, function (data) { location.href = location.href; });
    }

}

function up_data(value) {

    /* var str = "";
    $('#form' + value + ' :input').each(function (n, element) {
    if ($(element).attr('type') != "button") {
    if ($(element).attr('type') == "checkbox") {
    str += $(element).attr('id') + '=' + $(element).attr('checked') + '&';
    } else
    str += $(element).attr('id') + '=' + $(element).val() + '&';
    }
    }
    );*/
    $.post('Fair_price.aspx', { isAjax: "true", serviceAction: "up", serviceID: value }, function (data) {
        location.href = location.href; 
    });

}
function down_data(value) {

    /* var str = "";
    $('#form' + value + ' :input').each(function (n, element) {
    if ($(element).attr('type') != "button") {
    if ($(element).attr('type') == "checkbox") {
    str += $(element).attr('id') + '=' + $(element).attr('checked') + '&';
    } else
    str += $(element).attr('id') + '=' + $(element).val() + '&';
    }
    }
    );*/
    $.post('Fair_price.aspx', { isAjax: "true", serviceAction: "down", serviceID: value }, function (data) { location.href = location.href;  });

}
function create_subservice(value) {

    /* var str = "";
    $('#form' + value + ' :input').each(function (n, element) {
    if ($(element).attr('type') != "button") {
    if ($(element).attr('type') == "checkbox") {
    str += $(element).attr('id') + '=' + $(element).attr('checked') + '&';
    } else
    str += $(element).attr('id') + '=' + $(element).val() + '&';
    }
    }
    );*/
    // $.post('Fair_price.aspx', { isAjax: "true", serviceAction: "create_subservice", serviceID: value }, function (data) { alert(data); /*location.href = location.href; */ });
   
    $('#serviseID').attr('value',value);
    $('#basic-modal-content').modal();
}
function sendsubservice() {
    
    var str = "";
    $('#subservisetable :input').each(function (n, element) {
        if ($(element).attr('type') != "button") {
            if ($(element).attr('type') == "checkbox") {
                str += $(element).attr('id') + '=' + $(element).attr('checked') + '&';
            } else
                str += $(element).attr('id') + '=' + $(element).val() + '&';
        }
    }
    );
    $.post('Fair_price.aspx', { isAjax: "true", serviceAction: "create_subservice", subserviceParam: str }, function (data) {
        if (data == "1") {
            location.href = location.href;
        } else {
            $("#message").css("display", "block");
        }
    });
}
function rename(value) {
    $('#serviceID2').attr('value', value);
    
    $('#rename').modal();
    $('#simplemodal-container').css('height','150');
    
}
function sendrename() {
    var str = "";
    $('#Table1 :input').each(function (n, element) {
        if ($(element).attr('type') != "button") {
            if ($(element).attr('type') == "checkbox") {
                str += $(element).attr('id') + '=' + $(element).attr('checked') + '&';
            } else
                str += $(element).attr('id') + '=' + $(element).val() + '&';
        }
    }
    );
    $.post('Fair_price.aspx', { isAjax: "true", serviceAction: "rename", subserviceParam: str }, function (data) {
        if (data == "1") {
            location.href = location.href;
        } else {
            $("#message").css("display", "block");
        }
    });
}


//âûñòàâêè

function sendstatus(value) {
    var str = "";
    $('#statustable_' + value + ' :input').each(function (n, element) {
        if ($(element).attr('type') != "button") {
            if ($(element).attr('type') == "checkbox") {
                str += $(element).attr('id') + '=' + $(element).attr('checked') + '&';
            } else {
                if ($(element).attr('type') == "radio") {
                    if ($(element).attr('checked')) {
                        str += $(element).attr('name') + '=' + $(element).attr('value') + '&';
                    }
                } else {
                    str += $(element).attr('id') + '=' + $(element).val() + '&';
                }
            }
        }
    }
    );
    $.post('Fair.aspx', { isAjax: "true", Action: "changestatus", Param: str, Fair: value }, function (data) {
        if (data == "1") {
            location.href = location.href;
        }
    });
}

function del_fair(value) {

   
    if (confirm('Delete?')) {
        $.post('Fair.aspx', { isAjax: "true", serviceAction: "delete", fairID: value }, function (data) { location.href = location.href; });
    }

}



//organizer
function org_send_down(fid,oid, sort) {

    $.post('F_organizer.aspx', { isAjax: "true", Action: "down", fairID: fid, orgID: oid, Sort: sort }, function (data) {
        if (data == "1") {
            location.href = location.href;
        } 
    });
}
function org_send_up(fid, oid, sort) {

    $.post('F_organizer.aspx', { isAjax: "true", Action: "up", fairID: fid, orgID: oid, Sort: sort }, function (data) {
        if (data == "1") {
            location.href = location.href;
        } 
    });
}
function org_send_del(fid, oid) {

    $.post('F_organizer.aspx', { isAjax: "true", Action: "del", fairID: fid, orgID: oid }, function (data) {
        if (data == "1") {
            location.href = location.href; 
        }
    });
}

//sponsors
function sp_send_down(fid, oid, sort) {

    $.post('F_sponsor.aspx', { isAjax: "true", Action: "down", fairID: fid, orgID: oid, Sort: sort }, function (data) {
        if (data == "1") {
            location.href = location.href;
        }
    });
}
function sp_send_up(fid, oid, sort) {

    $.post('F_sponsor.aspx', { isAjax: "true", Action: "up", fairID: fid, orgID: oid, Sort: sort }, function (data) {
        if (data == "1") {
            location.href = location.href;
        }
    });
}
function sp_send_del(fid, oid) {

    $.post('F_sponsor.aspx', { isAjax: "true", Action: "del", fairID: fid, orgID: oid }, function (data) {
        if (data == "1") {
            location.href = location.href;
        }
    });
}

//members

function memb_send_del(fid, mid) {

    $.post('F_member.aspx', { isAjax: "true", Action: "del", fairID: fid, orgID: mid }, function (data) {
        if (data == "1") {
            location.href = location.href;
        }
    });
}
//sections
function sc_send_down(fid, oid, sort) {

    $.post('F_section.aspx', { isAjax: "true", Action: "down", fairID: fid, orgID: oid, Sort: sort }, function (data) {
        if (data == "1") {
            location.href = location.href;
        }
    });
}
function sc_send_up(fid, oid, sort) {

    $.post('F_section.aspx', { isAjax: "true", Action: "up", fairID: fid, orgID: oid, Sort: sort }, function (data) {
        if (data == "1") {
            location.href = location.href;
        }
    });
}
function sc_send_del(fid, oid) {

    $.post('F_section.aspx', { isAjax: "true", Action: "del", fairID: fid, orgID: oid }, function (data) {
        if (data == "1") {
            location.href = location.href;
        }
    });
}

//objective
function ob_send_down(fid, oid, sort) {

    $.post('F_objective.aspx', { isAjax: "true", Action: "down", fairID: fid, orgID: oid, Sort: sort }, function (data) {
        if (data == "1") {
            location.href = location.href;
        }
    });
}
function ob_send_up(fid, oid, sort) {

    $.post('F_objective.aspx', { isAjax: "true", Action: "up", fairID: fid, orgID: oid, Sort: sort }, function (data) {
        if (data == "1") {
            location.href = location.href;
        }
    });
}
function ob_send_del(fid, oid) {

    $.post('F_objective.aspx', { isAjax: "true", Action: "del", fairID: fid, orgID: oid }, function (data) {
        if (data == "1") {
            location.href = location.href;
        }
    });
}

//program
function pr_send_down(fid, oid, sort) {

    $.post('F_program.aspx', { isAjax: "true", Action: "down", fairID: fid, orgID: oid, Sort: sort }, function (data) {
        if (data == "1") {
            location.href = location.href;
        }
    });
}
function pr_send_up(fid, oid, sort) {

    $.post('F_program.aspx', { isAjax: "true", Action: "up", fairID: fid, orgID: oid, Sort: sort }, function (data) {
        if (data == "1") {
            location.href = location.href;
        }
    });
}
function pr_send_del(fid, oid) {

    $.post('F_program.aspx', { isAjax: "true", Action: "del", fairID: fid, orgID: oid }, function (data) {
        if (data == "1") {
            location.href = location.href;
        }
    });
}

//member_obligation
function mo_send_down(fid, oid, sort) {

    $.post('F_rules.aspx', { isAjax: "true", Action: "down", fairID: fid, orgID: oid, Sort: sort }, function (data) {
        if (data == "1") {
            location.href = location.href;
        }
    });
}
function mo_send_up(fid, oid, sort) {

    $.post('F_rules.aspx', { isAjax: "true", Action: "up", fairID: fid, orgID: oid, Sort: sort }, function (data) {
        if (data == "1") {
            location.href = location.href;
        }
    });
}
function mo_send_del(fid, oid) {

    $.post('F_rules.aspx', { isAjax: "true", Action: "del", fairID: fid, orgID: oid }, function (data) {
        if (data == "1") {
            location.href = location.href;
        }
    });
}
//member_obligation
function oo_send_down(fid, oid, sort) {

    $.post('F_rules_t.aspx', { isAjax: "true", Action: "down", fairID: fid, orgID: oid, Sort: sort }, function (data) {
        if (data == "1") {
            location.href = location.href;
        }
    });
}
function oo_send_up(fid, oid, sort) {

    $.post('F_rules_t.aspx', { isAjax: "true", Action: "up", fairID: fid, orgID: oid, Sort: sort }, function (data) {
        if (data == "1") {
            location.href = location.href;
        }
    });
}
function oo_send_del(fid, oid) {

    $.post('F_rules_t.aspx', { isAjax: "true", Action: "del", fairID: fid, orgID: oid }, function (data) {
        if (data == "1") {
            location.href = location.href;
        }
    });
}
function selectcheck(value, parent) {
    $('.' + value).each(function () {
        $(this).attr("checked", $('#' + value).attr("checked"));
        selectcheck(this.id, $(this).attr("class"));

    });
    selectparent(value, parent);
}
function selectparent(value, parent) {
    $('#' + parent).each(function () {
        if ($('#' + value).attr("checked") == true) {
            $(this).attr("checked", $('#' + value).attr("checked"));
            selectparent(this.id, $(this).attr("class"));
        }
    });
}
function sendPrice() {
    var str = "";
    $(':input').each(function (n, element) {
        if ($(element).attr('type') != "button") {
            if ($(element).attr('type') == "checkbox") {
                str += $(element).attr('id') + '=' + $(element).attr('checked') + '&';
            } 
        }
    }
    );
    $.post('F_price.aspx', { isAjax: "true", Action: "price", Ids: str }, function (data) {
        alert(data);
    });
    //alert(str);
}
function slide(navigation_id, pad_out, pad_in, time, multiplier)
{
    // creates the target paths
    var list_elements = navigation_id + " li.sliding-element";
    var link_elements = list_elements + " a";

    // initiates the timer used for the sliding animation
    var timer = 0;

    // creates the slide animation for all list elements
    /*$(list_elements).each(function(i)
    {
        // margin left = - ([width of element] + [total vertical padding of element])
        //$(this).css("margin-left","-180px");
        // updates timer
        timer = (timer*multiplier + time);
        $(this).animate({
            marginLeft: "0"
        }, timer);
        $(this).animate({
            marginLeft: "15px"
        }, timer);
        $(this).animate({
            marginLeft: "0"
        }, timer);
    });*/

    // creates the hover-slide effect for all link elements
    $(link_elements).each(function(i)
    {
        $(this).hover(
            function()
            {
                $(this).animate({
                    paddingLeft: pad_out
                }, 150);
            },
            function()
            {
                $(this).animate({
                    paddingLeft: pad_in
                }, 150);
            });
    });
}
function setTinyMce(textareaId)
{
    $(textareaId).tinymce({
        // Location of TinyMCE script
        script_url : '../js/tiny_mce/tiny_mce.js',

        // General options
        theme : "advanced",
        plugins : "safari,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

        // Theme options
        theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,forecolor,backcolor",
        theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
        theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        // Drop lists for link/image/media/template dialogs
        template_external_list_url : "lists/template_list.js",
        external_link_list_url : "lists/link_list.js",
        external_image_list_url : "lists/image_list.js",
        media_external_list_url : "lists/media_list.js"

    });

    //$('#ServiceList').treeview({
    //    animated: "fast",
    //    collapsed: true
    //});


}

function sendMail() {

    var name_m = $('#name_m').get(0).value;
    var email_m = $('#email_m').get(0).value;
    var text_m = $('#text_m').get(0).value;
    var fid = $('.fair_').get(0).value;
    $.post('SendMail.aspx', { isAjax: "true", name: name_m, email: email_m, text: text_m, id: fid }, function (data) {
        alert(data);
        $('#name_m').get(0).value = "";
        $('#email_m').get(0).value = "";
        $('#text_m').get(0).value = "";
        document.getElementById('form-overlay').style.display='none'; 
        document.getElementById('form-reg').style.display='none';
    });
}
