// добавление записи в каталог
function add_prep() {
    if(confirm('Уверены, что хотите этого?')){
        var fill_str='(';
        var group_str='(';
        var save_type=$(".isshow").attr('id').slice(13,15);
        $("input.tx_catalogdb_edit_data").each(
        function() {        	group_str+=$(this).attr('id').slice(13)+', ';
            fill_str+='\''+$(this).val()+'\', ';
        });
        $("option.tx_catalogdb_edit_data").filter('[selected]').each(
        function() {
        	group_str+=$(this).attr('id').slice(13)+', ';
            fill_str+='\''+$(this).val()+'\', ';
        });
        $("textarea.tx_catalogdb_edit_data").each(
        function() {
        	group_str+=$(this).attr('id').slice(13)+', ';
            fill_str+='\''+$(this).val()+'\', ';
        });
        if ($(".isshow").attr('checked')) {        	group_str+=$(".isshow").attr('id').slice(13)+')';
        	fill_str+='1)';
        }
        else {        	group_str+=$(".isshow").attr('id').slice(13)+')';
        	fill_str+='0)';
        	}
        $.post("fileadmin/template/php/add_prep.php",
            {save_type : save_type,
             fill_str : fill_str,
             group_str : group_str},
            function(data) {            	history.go(-1);
                alert('Запись успешно добавлена!');
        });
    }
}

// сохранение изменений о группе в каталог
function save_group(save_num) {
	var save_num;
    var save_type=$(".isshow0").attr('id').slice(13,15);
    for (i=0;i<save_num;i++) {
        var save_id=$(".isshow"+i).attr('name');    	var fill_str='';
        $("input.tx_catalogdb_edit_data"+i).each(
        function() {
            fill_str+=$(this).attr('id').slice(13)+'=\''+$(this).val()+'\', ';
        });
        if ($(".isshow"+i).attr('checked')) {fill_str+=$(".isshow"+i).attr('id').slice(13)+'=1'}
        else {fill_str+=$(".isshow"+i).attr('id').slice(13)+'=0'}
        $.post("fileadmin/template/php/save_prep.php",
            {save_id : save_id,
             save_type : save_type,
             save_str : fill_str
        });
    }
    alert('Запись успешно обновлена!');
}

// удаление записи из каталога
function rem_prep(rem_id) {    var rem_id;
    if ($(".isshow").attr('id')) {var rem_type=$(".isshow").attr('id').slice(13,15);}
    else {var rem_type=$(".isshow0").attr('id').slice(13,15);}
    if(confirm('Уверены, что хотите этого?')){
        $.post("fileadmin/template/php/rem_prep.php",
            {rem_id : rem_id,
             rem_type : rem_type},
            function(data) {
                alert('Запись безвозвратно удалена!');
        });
        if (rem_type==='p_') {history.go(-1);}
        else {$("#rem_button"+rem_id).parent().parent().parent().remove();}
    }
}

// сохранение изменений о препарате в каталог
function save_prep(save_id) {	var save_id;    var fill_str='';
    var save_type=$(".isshow").attr('id').slice(13,15);
    $("input.tx_catalogdb_edit_data").each(
    function() {        fill_str+=$(this).attr('id').slice(13)+'=\''+$(this).val()+'\', ';    });
    $("option.tx_catalogdb_edit_data").filter('[selected]').each(
    function() {
        fill_str+=$(this).attr('id').slice(13)+'=\''+$(this).val()+'\', ';
    });
    $("textarea.tx_catalogdb_edit_data").each(
    function() {
        fill_str+=$(this).attr('id').slice(13)+'=\''+$(this).val()+'\', ';
    });
    if ($(".isshow").attr('checked')) {fill_str+=$(".isshow").attr('id').slice(13)+'=1'}
    else {fill_str+=$(".isshow").attr('id').slice(13)+'=0'}
    $.post("fileadmin/template/php/save_prep.php",
        {save_id : save_id,
         save_type : save_type,
         save_str : fill_str},
        function(data) {
            alert('Запись успешно обновлена!');
    });
}

// отправка заявки, работа с куками
function cookieSet(index) {
    var index;
	if($("#checkid-"+index).attr('checked')) {        $.cookie('chekIndex-' + index, 'opened', {expires: null, path: '/'});
    } else {
		$.cookie('chekIndex-' + index, null, {expires: null, path: '/'});
    }
}

// правка названий дней недели для календаря
$(document).ready(function(){
    $(".calendar-table th").filter('[abbr="Понедельник"]').html("Пн");
    $(".calendar-table th").filter('[abbr="Четверг"]').html("Чт");
    $(".calendar-table th").filter('[abbr="Пятница"]').html("Пт");
    $(".calendar-table th").filter('[abbr="Суббота"]').html("Сб");
    $(".calendar-table th").filter('[abbr="Воскресенье"]').html("Вс");
});

// хак cтилей для ие6
if ($.browser.msie && $.browser.version == 6) {
$(document).ready(function(){
   $(".tx-mmforum-table").attr("style","width:90%");
});
}

// заказ медикаментов, фармгруппа выбрана
function order_phg_select() {
$(document).ready(function(){
    $("#order_table tr").filter('[id!=order_table_header]').removeClass();
    if ($("#order_phg").val()==0) {    	i=0;
    	$("#order_table tr").filter('[id!=order_table_header]').each (
            function() {
        	    $(this).removeAttr("style");
        	    if (i%2==1) {$(this).addClass("tdm");}
        	    i++;
            }
    	);
    } else {
        $("#order_table tr").filter('[phg!='+$("#order_phg").val()+']').filter('[id!=order_table_header]').css("display","none");
        i=0;
        $("#order_table tr").filter('[phg='+$("#order_phg").val()+']').filter('[id!=order_table_header]').each(
            function() {        	    $(this).removeAttr("style");
        	    if (i%2==1) {$(this).addClass("tdm");}
        	    i++;
            }
        );
    }
});
}

// каталог, сортировка
function formofissue(foi_id, id) {
    var foi_id;
    var id
if (navigator.appName!=='Microsoft Internet Explorer') {
$(document).ready(function(){
    if ($("#formofissue"+foi_id).attr("name")==0) {
        $.post("fileadmin/template/php/formofissue.php",
            {foi_id : foi_id,
             id : id},
            function(data) {
                $("#formofissue"+foi_id).append('<ol id="formofissue_ol'+foi_id+'">'+data+'</ol>');
        });
        $("#formofissue"+foi_id).attr("name", 1);
    } else {
        $("#formofissue_ol"+foi_id).remove();
        $("#formofissue"+foi_id).attr("name", 0);
    }
});
}
}

function width(min,max){
	w = document.documentElement.clientWidth;
	return (w <= min) ? min + "px" : ((w >= max) ? max + "px" : "auto");
}