// отображение и скрытие подменю
function vh(id) {
	if ($('#'+id).css('display')=='none') {
		$('#'+id).css('display','block');
$.post('scripts/menu_toggle.php', { v: 1, m: id });		
	}
	else {
		$('#'+id).css('display','none');
$.post('scripts/menu_toggle.php', { v: 0, m: id });		
	}	
}

function change_foto(foto,wh) {
		if (wh=='w') {
			s_wh='width:242px';
		}
		else {
			s_wh='height:182px';
		}	
	$('#bfoto').html('<img style="'+s_wh+';margin:0 auto;cursor:pointer;" onclick="view_big_foto();" src="catalog/'+foto+'" alt="" />');
}

function view_big_foto() {
	hide_window();
	var w_scroll=document.body.scrollWidth;
	var h_scroll=document.body.scrollHeight;
	var cur_scroll=self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
		$('#modal').after('<div id="sbig" style="position:absolute;top:'+(cur_scroll+50)+'px;left:0px;width:100%;text-align:center;"><img id="b_f" style="margin:0 auto;cursor:pointer;" src="'+$('#bfoto').find('img').attr('src')+'" onclick="$('+"'#modal'"+').hide();$('+"'#sbig'"+').remove()" alt="" /></div>');
	
}

function view_zayavka() {
	hide_window();
	var w_scroll=document.body.scrollWidth;
	var h_scroll=document.body.scrollHeight;
	var cur_scroll=self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
	$.post('scripts/zayavka.php',{}, function(data) {
		$('#modal').after('<div id="sz" style="position:absolute;top:'+(cur_scroll+250)+'px;left:0px;width:100%;text-align:center;">'+data+'</div>');
	});
}

function send_zayavka() {
	var err='';	
		var fio=$.trim($('#fio').val());
		if (fio.length==0) {
			err=' ФИО';
		}
		var phone=$.trim($('#phone').val());
		if (phone.length==0) {
			err=err+' телефон';
		}	
	if (err!='') {
		alert('Не заполнены обязательные поля: '+err);
	}
	else {
			var mail=$('#mail').val();
			var classif=$('#classif').val();
			var coll=$('#coll').val();
			var pr=$('#pr').val();
			var dop_info=$('#dop_info').html();
		$.post('scripts/zayavka.php',{ fio: fio, phone: phone, mail: mail, classif: classif, coll: coll, pr: pr, dop_info: dop_info }, function(data) {
			$('#sz').html(data);
		});	
	}	
	}


function read_stat(n_stat) {
		hide_window();
		var w_scroll=document.body.scrollWidth;
		var h_scroll=document.body.scrollHeight;
		var cur_scroll=self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
			$('#modal').after('<div id="container_stat" style="position:absolute;text-align:center;left:0;top:'+(cur_scroll+80)+'px;width:100%;"><div id="txt_stat" style="margin:0 auto;width:600px;height:500px;overflow-y:auto;color:#461403;text-align:justify;background-color:#faefd0;padding:10px;border:5px ridge #461403;"></div><input style="color:white;background-color:#461403;font-weight:bold;" type="button" onclick="$('+"'#modal'"+').hide();$('+"'#container_stat'"+').remove()" value="Закрыть" /></div>');
			$('#txt_stat').html($('#'+n_stat).html());
}

//закрыть/открыть окно прозрачной пленкой для показа фото
function hide_window() {
	ps=getPageSize();
	w_scroll=ps[0];
	h_scroll=ps[1];
//	var w_scroll=document.body.scrollWidth;
//	w_scroll=(document.body.scrollWidth > document.body.offsetWidth)?document.body.scrollWidth:document.body.offsetWidth;

//	var h_scroll=document.body.scrollHeight;
//	h_scroll=(document.body.scrollHeight > document.body.offsetHeight)?document.body.scrollHeight:document.body.offsetHeight;

	var cur_scroll=self.pageYOffset || (document.documentElement && document.documentElement.scrollTop) || (document.body && document.body.scrollTop);
	$('#modal').css('width',w_scroll);
	$('#modal').css('height',h_scroll);
	$('#modal').show();
}
function show_window() {
	$('#modal').hide();
}

//---------------- вспомогательные функции -----------------------
//Кроссбраузерная функция для получения размера документа. Функция возвращает массив со значениями 
//ширины и высоты страницы вместе с прокруткой (pageWidth, pageHeight) и ширины и высоты видимой 
//части страницы (windowWidth, windowHeight):
function  getPageSize(){
  var xScroll, yScroll;
  if (window.innerHeight && window.scrollMaxY) {
          xScroll = document.body.scrollWidth;
          yScroll = window.innerHeight + window.scrollMaxY;
  } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
          xScroll = document.body.scrollWidth;
          yScroll = document.body.scrollHeight;
  } else if (document.documentElement && document.documentElement.scrollHeight > document.documentElement.offsetHeight){ // Explorer 6 strict mode
          xScroll = document.documentElement.scrollWidth;
          yScroll = document.documentElement.scrollHeight;
  } else { // Explorer Mac...would also work in Mozilla and Safari
          xScroll = document.body.offsetWidth;
          yScroll = document.body.offsetHeight;
  }
  var windowWidth, windowHeight;
  if (self.innerHeight) { // all except Explorer
          windowWidth = self.innerWidth;
          windowHeight = self.innerHeight;
  } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
          windowWidth = document.documentElement.clientWidth;
          windowHeight = document.documentElement.clientHeight;
  } else if (document.body) { // other Explorers
          windowWidth = document.body.clientWidth;
          windowHeight = document.body.clientHeight;
  }
  // for small pages with total height less then height of the viewport
  if(yScroll < windowHeight){
          pageHeight = windowHeight;
  } else {
          pageHeight = yScroll;
  }

  // for small pages with total width less then width of the viewport
  if(xScroll < windowWidth){
          pageWidth = windowWidth;
  } else {
          pageWidth = xScroll;
  }
  return [pageWidth,pageHeight,windowWidth,windowHeight];
}