/*function lstclin()
{
	if(document.getElementById('clinlst').style.visibility == 'hidden')
		document.getElementById('clinlst').style.visibility = 'visible';
	else
		document.getElementById('clinlst').style.visibility = 'hidden';
}
function pl()
{
	document.getElementById('clinlst').style.visibility = 'hidden';
}
*/
/*
function lstsm()
{
	if(document.getElementById('sitmapMM').style.visibility == 'hidden')
	{
		document.getElementById('sitmapMM').style.visibility = 'visible';
		document.getElementById('showfullst').style.visibility = 'hidden';
	}
	else
	{
		document.getElementById('sitmapMM').style.visibility = 'hidden';
		document.getElementById('showfullst').style.visibility = 'visible';
	}
}
*/
/*function plsm()
{
	document.getElementById('sitmapMM').style.visibility = 'hidden';
}
*/




var InClinList = false;


// курсор на форме запись на прием или нет
var isinFrmCur = false;
/*function plzp(id)
{
	document.getElementById(id).style.visibility = 'hidden';
}
*/
function zphsw(id)
{
	if(document.getElementById(id).style.visibility == 'hidden')
		document.getElementById(id).style.visibility = 'visible';
	else
		document.getElementById(id).style.visibility = 'hidden';
}











// total splash hide
function haspl()
{
	var i = 1;
	while(document.getElementById("subinfo-"+i))
	{
		if(document.getElementById("subinfo-"+i).style.display != 'none')
			document.getElementById("subinfo-"+i).style.display = 'none';
		i++;
	}
}

// амплитуда шага (px)
var ampl = 10;
// всего шагов
var totalstep = 5;
// время шара (милисек)
var stepTime = 30;
// глобальная, для общего доступа [не задавать]
var currstep = totalstep;
var lock = false;

function swspl(i)
{
	if(!lock)
	{
		lock = true;
		if(!document.getElementById("subinfo-"+i))
			return;

		var direct = 0;
		// повторное нажатие по вкладке.
		if(document.getElementById("subinfo-"+i).style.display != 'none')
		{
			direct = 1;
		}
		if(!direct)
			currstep = totalstep;
		else
			currstep = 0;
		splsh(i,direct);
	}
}

function splsh(i,direction)
{
	switch(direction)
	{
		case 0:
			document.getElementById("subinfo-"+i).style.display = 'block';
			if( currstep == 0 )
			{
				document.getElementById("subinfo-"+i).style.height = "auto";
				lock = false;
				return;
			}
			break;
		case 1:
			if(currstep == totalstep)
			{
				document.getElementById("subinfo-"+i).style.display = 'none';
				lock = false;
				return;
			}
			break;
	}

	document.getElementById("subinfo-"+i).style.height = ampl*(totalstep - currstep) + "px";
	window.setTimeout("splsh("+i+","+direction+")",stepTime);
	if(!direction)
		currstep--;
	else
		currstep++;
}




var qPrim=false;
function showPBlock1()
{
	document.getElementById('qPrim').style.visibility = 'visible';
}


var popUpWin=0;
function popUpWindow(URLStr, left, top, width, height)
{

  if(popUpWin)
  {
	if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWinH', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
  popUpWin.focus();
}





function pc_check_ta( id_ta, id_lb ) {
	if( document.getElementById(id_ta).value.match(/^[\s]*$/) ) {
		document.getElementById(id_lb).className = 'labErr';
		return false;
	}
	else {
		document.getElementById(id_lb).className = 'lablOk';
		return true;
	}
}

function pc_check_dis( btn_id ) {
	res1 = pc_check_ta('pc_name', 'pc_name_label');
	res2 = pc_check_ta('pc_phone', 'pc_phone_label');
	res3 = pc_check_ta('pc_probl', 'pc_probl_label');
}

function pc_check_dis2( ) {
	res1 = pc_check_ta('pc_name', 'pc_name_label');
	res2 = pc_check_ta('pc_phone', 'pc_phone_label');
	res3 = pc_check_ta('pc_probl', 'pc_probl_label');
	if(res1 && res2 && res3){	return true} else { alert('Пожалуйста, заполните поля, отмеченные  красным цветом.');	return false;}
}

$(
  function(){

  	// Dialog
				$('#dialog').dialog({
					autoOpen: false,
					width: 310,
					height: 420,
					modal: true,
					draggable:false,
					resizable: false
				});

				// Dialog Link
				$('#dialog_link').click(function(){
					var curAkciia=document.getElementById("reklama-header").innerHTML;

					var objSel = document.getElementById("akciia");
					for (var i=0; i < objSel.options.length; i++)
  					{
      					objSel.options[i].selected=false;
      					if (objSel.options[i].value==curAkciia) objSel.options[i].selected=true;
  					}

					$('#dialog').dialog('open');
					return false;
				});
				// Dialog Link
				$('#dialog_link1').click(function(){
					$('#dialog').dialog('open');
					return false;
				});

				// Dialog Link
				$('#vrezka_link').click(function(){
					var curAkciia=$('#vrezkaCurId').attr("value");

					var objSel = document.getElementById("akciia");
					for (var i=0; i < objSel.options.length; i++)
  					{
      					objSel.options[i].selected=false;
      					if (objSel.options[i].value==curAkciia) objSel.options[i].selected=true;
  					}
					$('#dialog').dialog('open');
					return false;
				});

				$('#dialog1').dialog({
					autoOpen: false,
					width: 310,
					modal: true,
					draggable:false,
					resizable: false
				});
				// Dialog Link
				$('#dialog1_link1').click(function(){
					$('#dialog1').dialog('open');
					return false;
				});
				// Dialog Link
				$('#for_form').click(function(){
					$('#dialog1').dialog('open');
					return false;
				});

				$("#present-video").dialog({
				autoOpen: false,
				modal: true,
				width: 740,
				buttons: {}
				});
				$("#video-block").click(function(){
					$("#present-video").dialog("open");
				});
				$(".dialog-close").click(function(){
					$("#present-video").dialog("close");
				});


				$("#formclose").click(function(){
		$("#dialog").dialog("close");
	});

	$("#formbutton").click(function(){
		$("p span").css("color", "#f1ece6");

		var arSpamPhone = ["1234567", "7654321", "1111111", "2222222", "3333333", "4444444", "5555555", "6666666", "7777777", "8888888", "9999999", "0000000"];
		var reg=new RegExp("^[-\s)(0-9]+$");

		if (jQuery.trim($('#fio').attr("value")) == "") {
			$("span", $('#fio').parent()).css("color","red");
		} else if (jQuery.trim($('#phone').attr("value")) == "" || jQuery.inArray(jQuery.trim($('#phone').attr("value")), arSpamPhone)!=-1 || !reg.test(jQuery.trim($('#phone').attr("value"))) || jQuery.trim($('#phone').attr("value")).length<7) {
			$("span", $('#phone').parent()).css("color","red");
		} else if (jQuery.trim($('#message').val()) == "") {
			$("span", $('#message').parent()).css("color","red");
		} else {
			$.ajax({
				url: "/bitrix/templates/doktorvolos/includes/form_send.php",
				type: "POST",
				dataType: "html",
				data:"fio="+$('#fio').attr("value")+"&phone="+$('#phone').attr("value")+"&message="+$('#message').val()+"&akciia="+$('#akciia').val(),
				beforeSend: function(){
					$("#formmaindiv").animate({opacity: 0},200, function(){
						$('<div></div>')
							.html('Подождите...<br><img src="/bitrix/templates/doktorvolos/includes/15.gif" />')
							.prependTo($("#forminfo"));
					});

				},
				success: function(data){
					$("#forminfo").empty();
					$('<div></div>')
						.html(data+'Ваше сообщение доставлено.')
						.prependTo($("#forminfo"));
				}
			});
		}

	});

	$("#formbutton1").click(function(){
		$("p span").css("color", "#f1ece6");

		var arSpamPhone = ["1234567", "7654321", "1111111", "2222222", "3333333", "4444444", "5555555", "6666666", "7777777", "8888888", "9999999", "0000000"];
		var reg=new RegExp("^[-\s)(0-9]+$");

		if (jQuery.trim($('#fio1').attr("value")) == "") {
			$("span", $('#fio1').parent()).css("color","red");
		} else if (jQuery.trim($('#phone1').attr("value")) == "" || jQuery.inArray(jQuery.trim($('#phone1').attr("value")), arSpamPhone)!=-1 || !reg.test(jQuery.trim($('#phone1').attr("value"))) || jQuery.trim($('#phone1').attr("value")).length<7) {
			$("span", $('#phone1').parent()).css("color","red");
		} else {
			$.ajax({
				url: "/bitrix/templates/doktorvolos/includes/form_send1.php",
				type: "POST",
				dataType: "html",
				data:"fio="+$('#fio1').attr("value")+"&phone="+$('#phone1').attr("value")+"&day="+$('#day1').val()+"&formName="+$('#formName1').val(),
				beforeSend: function(){
					$("#formmaindiv1").animate({opacity: 0},200, function(){
						$('<div></div>')
							.html('Подождите...<br><img src="/bitrix/templates/doktorvolos/includes/15.gif" />')
							.prependTo($("#forminfo1"));
					});

				},
				success: function(data){
					$("#forminfo1").empty();
					$('<div></div>')
						.html(data+'Ваше сообщение доставлено.')
						.prependTo($("#forminfo1"));
				}
			});
		}

	});

  	// раскраска таблицы
	//$("#body td:nth-child(even)").addClass("tdprice");
  	//$("#body tr:nth-child(odd)").addClass("odd");
  	$("#body #vrachi-table td:nth-child(even)").addClass("tdprice-no");
  	$("#body #vrachi-table tr:nth-child(odd)").addClass("odd-no");
  	$("#body #year-table td:nth-child(even)").addClass("tdprice-no");
  	$("#body #year-table tr:nth-child(odd)").addClass("odd-no");
  	$("#body .vrezka td:nth-child(even)").addClass("tdprice-no1");
  	$("#body .vrezka tr:nth-child(odd)").addClass("odd-no");

  	// раскрыть / свернуть слой
	$("div.level1 li.spacer").click(function() {
		if ($("div:visible", $(this).parent()).size()>0) {
			$("div", $(this).parent()).animate({height: "hide"}, 200);
			$(this).addClass("click");
		} else if ( $("div:hidden", $(this).parent()).size()>0 ) {
			$("div", $(this).parent()).animate({height: "show"}, 200);
			$(this).removeClass("click");
		}
	});

	$("#akciia_link").click(function() {
		if ($("#akciia_detail:visible").size()>0) {
			$("#akciia_detail").animate({height: "hide"}, 200);
			$("#akciia_linkoff_div").animate({height: "hide"}, 50);
			$(this).animate({height: "show"}, 50);
		} else if ( $("#akciia_detail:hidden").size()>0 ) {
			$("#akciia_detail").animate({height: "show"}, 200);
			$("#akciia_linkoff_div").animate({height: "show"}, 50);
			$(this).animate({height: "hide"}, 50);
		}
	});

	$("#akciia_linkoff").click(function() {
		if ($("#akciia_detail:visible").size()>0) {
			$("#akciia_detail").animate({height: "hide"}, 200);
			$("#akciia_link").animate({height: "show"}, 50);
			$("#akciia_linkoff_div").animate({height: "hide"}, 50);
		} else if ( $("#akciia_detail:hidden").size()>0 ) {
			$("#akciia_detail").animate({height: "show"}, 200);
			$("#akciia_link").animate({height: "hide"}, 50);
			$("#akciia_linkoff_div").animate({height: "show"}, 50);
		}
	});
  }
)
