function check_len()
{
	if(!document.getElementById('id_filef').value.length)
	{
		alert("Вы забыли выбрать Excel файл")
		return false;
	}
	return true;
}

function csv_form_valid()
{
	if (checkbox_checker())
	{
		if (check_len())
		{
			return true;
		}
	}
	return false;
}


  function checkbox_checker3()
  {
  
      if($("input[name='shops'][checked='true']").val()==undefined && $("input[name='points'][checked='true']").val()==undefined && $("input[name='stocks'][checked='true']").val()==undefined)
      {
	alert('Вы не выбрали ни одной точки продаж.\n');
	return false;
      }
      else
      {
	//alert('shop selected');
	return true;
      }
    

}


function checkbox_checker()
{
	var checkbox_choices_shops = 0;
	var checkbox_choices_points = 0;
	var checkbox_choices_stocks = 0;
	
	if (document.forms[0].shops !=undefined)
	{
		if (document.forms[0].shops.length==undefined)
		{
			if(document.forms[0].shops.checked)
			{
				checkbox_choices_shops = 1;
			}
		}
		for (counter = 0;  counter < document.forms[0].shops.length; counter++)
		{

			if (document.forms[0].shops[counter].checked)
				{ checkbox_choices_shops = checkbox_choices_shops + 1; }

		}
	}
	if (document.forms[0].points !=undefined)
	{
		if (document.forms[0].points.length==undefined)
		{
			if(document.forms[0].points.checked)
			{
				checkbox_choices_points = 1;
			}
		}
		for (counter = 0;  counter < document.forms[0].points.length; counter++)
		{
			
			if (document.forms[0].points[counter].checked)
				{ checkbox_choices_points = checkbox_choices_points + 1; }

		}
	}
	if (document.forms[0].stocks !=undefined)
	{
		if (document.forms[0].stocks.length==undefined)
		{
			if(document.forms[0].stocks.checked)
			{
				checkbox_choices_stocks = 1;
			}
		}
		for (counter = 0;  counter < document.forms[0].stocks.length; counter++)
		{
			
			if (document.forms[0].stocks[counter].checked)
				{ checkbox_choices_stocks = checkbox_choices_stocks + 1; }

		}
	}
	if (checkbox_choices_shops == 0 && checkbox_choices_points == 0 && checkbox_choices_stocks == 0)
	{
		msg="Вы не выбрали ни одной точки продаж.\n"
		alert(msg)
		return (false);
	}
	//document.forms[0].submit();
	return (true);
}

function checkbox_checker2()
{
	var checkbox_choices_shops = 0;
	var checkbox_choices_points = 0;
	var checkbox_choices_stocks = 0;
	
	if (document.forms[1].shops !=undefined)
	{
		if (document.forms[1].shops.length==undefined)
		{
			if(document.forms[1].shops.checked)
			{
				checkbox_choices_shops = 1;
			}
		}
		for (counter = 0;  counter < document.forms[1].shops.length; counter++)
		{

			if (document.forms[1].shops[counter].checked)
				{ checkbox_choices_shops = checkbox_choices_shops + 1; }

		}
	}
	if (document.forms[1].points !=undefined)
	{
		if (document.forms[1].points.length==undefined)
		{
			if(document.forms[1].points.checked)
			{
				checkbox_choices_points = 1;
			}
		}
		for (counter = 0;  counter < document.forms[1].points.length; counter++)
		{
			
			if (document.forms[1].points[counter].checked)
				{ checkbox_choices_points = checkbox_choices_points + 1; }

		}
	}
	if (document.forms[1].stocks !=undefined)
	{
		if (document.forms[1].stocks.length==undefined)
		{
			if(document.forms[1].stocks.checked)
			{
				checkbox_choices_stocks = 1;
			}
		}
		for (counter = 0;  counter < document.forms[1].stocks.length; counter++)
		{
			
			if (document.forms[1].stocks[counter].checked)
				{ checkbox_choices_stocks = checkbox_choices_stocks + 1; }

		}
	}
	if (checkbox_choices_shops == 0 && checkbox_choices_points == 0 && checkbox_choices_stocks == 0)
	{
		msg="Вы не выбрали ни одной точки продаж.\n"
		alert(msg)
		return (false);
	}
	return (true);
}


function checkbox_checker4()
{
	var checkbox_choices_shops = 0;
	var checkbox_choices_points = 0;
	var checkbox_choices_stocks = 0;
	
	if (document.forms[0].disc_shops !=undefined)
	{
		if (document.forms[0].disc_shops.length==undefined)
		{
			if(document.forms[0].disc_shops.checked)
			{
				checkbox_choices_shops = 1;
			}
		}
		for (counter = 0;  counter < document.forms[0].disc_shops.length; counter++)
		{

			if (document.forms[0].disc_shops[counter].checked)
				{ checkbox_choices_shops = checkbox_choices_shops + 1; }

		}
	}
	if (document.forms[0].disc_points !=undefined)
	{
		if (document.forms[0].disc_points.length==undefined)
		{
			if(document.forms[0].disc_points.checked)
			{
				checkbox_choices_points = 1;
			}
		}
		for (counter = 0;  counter < document.forms[0].disc_points.length; counter++)
		{
			
			if (document.forms[0].disc_points[counter].checked)
				{ checkbox_choices_points = checkbox_choices_points + 1; }

		}
	}
	if (document.forms[0].disc_stocks !=undefined)
	{
		if (document.forms[0].disc_stocks.length==undefined)
		{
			if(document.forms[0].disc_stocks.checked)
			{
				checkbox_choices_stocks = 1;
			}
		}
		for (counter = 0;  counter < document.forms[0].disc_stocks.length; counter++)
		{
			
			if (document.forms[0].disc_stocks[counter].checked)
				{ checkbox_choices_stocks = checkbox_choices_stocks + 1; }

		}
	}
	if (checkbox_choices_shops == 0 && checkbox_choices_points == 0 && checkbox_choices_stocks == 0)
	{
		msg="Вы не выбрали ни одной точки продаж.\n"
		alert(msg)
		return (false);
	}
	return (true);
}


function switch_obj(div_id)
{
	if (document.getElementById(div_id).style.display=='none')
	{	
		document.getElementById(div_id).style.display='';
	}
	else
	{
		document.getElementById(div_id).style.display='none';
	}
}


function CheckAll() {
  for (var i = 0; i < document.FormList.elements.length; i++) {
    if(document.FormList.elements[i].type == 'checkbox'){
       document.FormList.elements[i].checked = !(document.FormList.elements[i].checked);
    }
  }
}


function SubmitControl(tocheack)
{
  if (document.all || document.getElementById)
    {
      for (i=0; i < tocheack.length;i++)
        {
          if(tocheack.elements[i].type.toLowerCase()=="submit"||tocheack.elements[i].type.toLowerCase()=="reset")
          {
            tocheack.elements[i].disabled = true
          }
        }
    }
}

function loadIHelp(id) {
	
	$.get("/shops_admin/ajax_ihelp/", {id: id },
	function(data){
		$("#ihelp_"+id).html(data);
	});
}

function show_tooltip(name,width) {
	jQuery.get("/shops_admin/ajax_ihelp/", {id: name},
	function(data){
		$("#ihelp_details_"+name).html(data);
	});
	jQuery("#tooltip_" + name).css("width", width+"px");
	jQuery("#tooltip_" + name).show('slow');
};
function hide_tooltip(name) {
	jQuery("#tooltip_" + name).hide('slow');
}


function saveIHelp(id) {
	caption = document.getElementById('id_caption_'+id).value;
	details = document.getElementById('id_details_'+id).value;
	width = document.getElementById('id_width_'+id).value;
	$.post("/shops_admin/ajax_ihelp/", {id: id, caption:caption, details:details, width:width},
	function(data){
		$("#ihelp_saved_"+id).html('Сохранено');
	});
}
