
/**
 * Помечаем день как груглосуточный
 */
function setAllDay(day){
	var worktime = $(".day"+day).find("td:eq(3)").find('input');

    (worktime.attr('disabled')==0)? worktime.attr('disabled',1) : worktime.attr('disabled',0);
}


/**
* Помечаем день Выходным либо Рабочим через checkbox...
* Входные параметры:
* Номер дня недели.
*/
function setWeekend(day,force){	
	var worktime = $(".day"+day).children(":not(:eq(1))");	
	    
	    worktime.find(":checkbox").attr('checked',0);
	    
	    worktime = worktime.find("input");
	    
        if (!isset(force))
        {
	        if (worktime.attr('disabled')==0)
		        worktime.attr('disabled',1);
	        else 
		        worktime.attr('disabled',0);
        }
        else
        {
            if (force)
                worktime.attr('disabled',1);
            else 
                worktime.attr('disabled',0);
        }
}


/**
* Устанавливаем рабочее время выбранное в первых полях
*/
function setDefineWorktime(block)
{
	var setbegin = $(block+" .day1").find("input[name=office_rasp_worktime_begin[]]").val();
	var setend 	 = $(block+" .day1").find("input[name=office_rasp_worktime_end[]]").val();
	
    for (i=2;i<=7;i++)
    {    
        worktime=$(block+" .day"+i);
        
        var begin = worktime.find("input[name=office_rasp_worktime_begin[]]")
        var end   = worktime.find("input[name=office_rasp_worktime_end[]]");
                 
        begin.val(setbegin);        
        end.val(setend);
    }
    
    setDefineDinner();
    
    return false;
}

function addOffice(){	
	var num = $("div.offices > table:last-child").attr('id');
	num = num.substring(6,8);		
	num++;	
	var body = '<table class="office" id="office'+num+'">'+$("#office1").html()+"</table>";	
	$("div.offices").append(body);
	
	$("#office"+num+" .number").html(num+')');
	$("#office"+num+" .deleteoffice").html('<a href="#" onclick="return deleteOffice('+num+')">X</a>');	
	
	$("#office"+num+" input[name=office_street[]]").autocomplete("/ajax/get_street/",
    {    	
    	delay:400,
    	minChars:1,
    	matchSubset:1,
    	autoFill:false,
    	cacheLength:1,
    	max:100,
    	multiple:false,
    	mustMatch:false
    });
    $('#office'+num+' ._clear').attr('value','');
	return false;
}

function deleteOffice(id_office){
	$("#office"+id_office).remove();
	return false;
}

function noOffice(){
	if ($("#no_office").attr('checked')!=false){
		$(".offices").hide();
		$(".nooffices").show();		
	}
	else {
		$(".offices").show();
		$(".nooffices").hide();
	}
	
	return false;
}