function form_action(form_id,input_id,action,check)  
{
	if(action != '')
	{		
	    if(!check)
	    {
    		if($('.chk_select:checked').length == 0 && action != 'set_position')
    		{
    			alert('Выберите хотя бы один элемент из списка');			
    		}	
    		else
    		{
    			document.getElementById(input_id).value = action;			
    			document.getElementById(form_id).submit();
    		}
	    }
	    else
	    {
            document.getElementById(input_id).value = action;           
            document.getElementById(form_id).submit();	    
	    }
	}	
	else
	{
		return false;
	}
}

function init_table_hover(id_table, children_class)
{
	var children_class = children_class || 'chk_select';
	if(id_table)
	{
		$('#' + id_table + ' tr').click(
		    function(e){
		    	if (e.target.tagName != 'INPUT')
		    	{
		    		var chk_box = $('.' + children_class, this);
		    		$(chk_box).attr('checked', !$(chk_box).attr('checked'));
		    	}
		    	e.stopPropagation();
		    }
		);
		$('#' + id_table + ' tr').hover(
		    function(){
		    	$(this).addClass('hover');
		    },
		    function(){
		    	$(this).removeClass('hover');
		    }
		);
	}
}

function init_checkbox()
{
	$('input:checkbox').each(function(){
		var checked = $(this).attr('checked');
	    $(this)
		    .hide()
	    	.after('<div  class="checkbox ' + (checked ? ' checked' : '') +'">&nbsp;</div>');
	    
	    $('div.checkbox').click(function(){
	    		$(this).prev().click();
	    		var checked = !$(this).prev().attr('checked');
	    		if(checked)
	    		{
	    			$(this).addClass('checked');
	    		}
	    		else
	    		{
	    			$(this).removeClass('checked');
	    		}
	    	});
	});
}

function init_checkall(parent_id, children_class)
{
	var parent_id = parent_id || 'id_all';
	
	if(!$('.' + children_class).not(':checked').length)
	{
		$('#' + parent_id).attr('checked','checked');
	}
	
	$('#' + parent_id).click(function(){
		$('.' + children_class).attr('checked', $(this).attr('checked'));
	});
	
	$('.' + children_class).click(function() {
		var count = $('.' + children_class).not(':checked').length;
		$('#' + parent_id).attr('checked', (count > 0) ? '' : 'checked');
	});
}

function clone_element_by_button(parent_id, clone_id, button_id)
{
	$('#' + button_id).click(function() {
		$('#' + parent_id).append($('#' + clone_id).clone().show());
		
		click_on_price('delete_price');
		
		return false;
	});	
}

function click_on_price(class_price)
{
	$("." + class_price).click(function(){

		if(confirm('Действительно удалить размер и цену?'))
		{
			$(this).parent().parent().remove();
			count = $("." + class_price).length;	

			if(count <= 1)
			{
				$('#new_size_all th').hide();
			}
			
			
		} 
		
		return false;
	});
}
function onkey(e,but)
{
    var but = $(but);
    var exp = /[^\d]/g;
    but.val(but.val().replace(exp,''));
    if(parseInt(but.val(),10) > but.attr('max'))
    {
        but.addClass('red')
        .val(but.attr('max'));
        return false;
    }
    else
    {
        but.removeClass('red');
    }
    
    return true;
}
