
function showPopup(popup, phot) {

	$('#photoPopup photo_im').remove();

   /// Добавляем новую
    var img = new Image();

    img.onload = function() {
        $('#photoPopup').append(this);
        $('#photoPopup img').hide();
        $('#photoPopup img').fadeIn(200);
    };
    img.src = '/img/actions2.jpg';
    
	blackBack = $('<div id="blackBack"></div>');
	wh = (document.documentElement.clientHeight > document.body.clientHeight) ? document.documentElement.clientHeight : document.body.clientHeight;
	blackBack.height(wh).click(closePopup).appendTo('body');
	//iframeBack = $('<iframe id="iframeBack"></iframe>');
	//iframeBack.height(document.body.clientHeight).appendTo('body');
	currentOffset2 = 0;
	currentOffset = document.documentElement.scrollTop || document.documentElement.scrollTop;
	var windowHeight;
	windowHeight = document.documentElement.clientHeight;
	if (windowHeight < $('#'+popup).height()) {
		currentOffset = (currentOffset + 10);
	} else {
		currentOffset2 = parseInt((windowHeight - $('#'+popup).height()) / 2);
	}
	pLeft = (document.body.clientWidth - $('#'+popup).width()) / 2;
	$('#'+popup).css({top:currentOffset+currentOffset2,left:pLeft}).show();
}

function closePopup() {
	$('#iframeBack').remove();
	$('#blackBack').remove();
	$('.popup').hide();
}
function setCenter(item) {
	
	windowHeight = document.documentElement.clientHeight;
	currentOffset = document.documentElement.scrollTop || document.documentElement.scrollTop;
	currentOffset = currentOffset + parseInt((windowHeight - $(item).height()) / 2);
	pLeft = (document.body.clientWidth - $(item).width()) / 2;
	$(item).css({top:currentOffset,left:pLeft}).show();
}

function showPhoto(popup, phot, wid, hei) {
	$('#cont img').remove();
   /// Добавляем новую
   
    var img = new Image();

    img.onload = function() {
        $('#cont').append(this);
        $('#cont img').hide();
        $('#cont img').fadeIn(200);
        $('#cont img').addClass('image');
    };
    img.src = phot;
    img.width = wid;
    img.height = hei;

    $('#photoPopup').width(wid);
    $('#photoPopup').height(hei);
    
	blackBack = $('<div id="blackBack"></div>');
	blackBack.height(document.body.clientHeight).click(closePopup).appendTo('body');
	iframeBack = $('<iframe id="iframeBack"></iframe>');
	iframeBack.height(document.body.clientHeight).appendTo('body');
	var photoPopup = $('#photoPopup');
	setCenter(photoPopup);
	photoPopup.show();
}


function ShowHideBlock(id,href) {
    var item = null;
    if (document.getElementById) {
        item = document.getElementById(id);
          href = document.getElementById(href);
    }
    else if (document.all) {
        item = document.all[id];
          href = document.all[href];
    }
    else if (document.layers) {
        item = document.layers[id];
          href = document.layers[href];
    }
    if (!item) {
    }
    else if (item.style) {
        if (item.style.display == "none") {
            item.style.display = "";
               href.innerHTML = "краткая информация";

        }
        else {
            item.style.display = "none";
               href.innerHTML = "подробная информация";
        }
    }
    else {
        item.visibility = "show";
          href.innerHTML = "краткая информация";
    }
}

function closePopup() {
	$('#iframeBack').remove();
	$('#blackBack').remove();
	$('.popup').hide();
}

function prefunc(prod) {
	$('#spectech').val(prod);
}

function mesSend()
{

	$.post('/messages_jx.php',
	{
		name: $('#name').val(),
		email: $('#email').val(),
		phone: $('#tel').val(),
		comment: $('#comment').val()
	},
	onMesSuccess
	    );   
	     $('#forma').hide();
	    $('#forma').empty();
	    $('#do').show();
}

function ordSend()
{

	$.post('/orders_jx.php',
	{
		name: $('#name').val(),
		email: $('#email').val(),
		phone: $('#tel').val(),
		product: $('#spectech').val(),
		comment: $('#comment').val()
	},
	onMesSuccess
	    );
	     $('#forma').hide();
	    $('#forma').empty();
	    $('#do').show();
}

function spaSend()
{

	$.post('/spares_jx.php',
	{
		name: $('#name').val(),
		email: $('#email').val(),
		phone: $('#tel').val(),
		comment: $('#comment').val()
	},
	onMesSuccess
	    );
	    $('#forma').hide();
	    $('#forma').empty();
	    $('#do').show();
}

function onMesSuccess(data)
{
	$("#do").hide();
	$('#forma').show();
	$("<p>"+data+"</p>").appendTo("#forma");
}


function isValidEmail (email)
{
 return (/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email);
}

function sendFormContacts(field) {
var str = $('#email').val();
 if (field == "email") {
  if ((str != "")&&((isValidEmail(str)))) {
   $('#email').removeClass('textInput inputRequired')
   $('#email').addClass('textInput');
  }
  else{
   $('#email').removeClass('textInput')
   $('#email').addClass('textInput inputRequired');
  }
 }
 else
 {
 	if ($('#'+field).val()!=''){
 		$('#'+field).removeClass('textInput inputRequired')
       $('#'+field).addClass('textInput');}
    else{ 	   
       $('#'+field).removeClass('textInput')
       $('#'+field).addClass('textInput inputRequired');}  
 }
 
 if (($('#name').val() != "") && (isValidEmail(str)) && ($('#tel').val() != ""))  {
  $('#sending').attr('disabled', false);
 }
 else {
  $('#sending').attr('disabled', true);
 } 
}

function sendFormOrders(field) {
var str = $('#email').val();
 if (field == "email") {
  if ((str != "")&&((isValidEmail(str)))) {
   $('#email').removeClass('textInput inputRequired')
   $('#email').addClass('textInput');
  }
  else{
   $('#email').removeClass('textInput')
   $('#email').addClass('textInput inputRequired');
  }
 }
 else
 {
 	if ($('#'+field).val()!=''){
 	   $('#'+field).removeClass('textInput inputRequired')
       $('#'+field).addClass('textInput');}
    else{ 	   
       $('#'+field).removeClass('textInput')
       $('#'+field).addClass('textInput inputRequired');}  
 }
 
 if (($('#name').val() != "") && (isValidEmail(str)) && ($('#tel').val() != "") && ($('#spectech').val() != ""))  {
  $('#sending').attr('disabled', false);
 }
 else {
  $('#sending').attr('disabled', true);
 } 
}

$(document).ready(function(){
	if ( (!$.browser.opera) && (!$.browser.msie) && (document.documentElement.clientHeight > document.body.clientHeight)  ) {
		wh = document.documentElement.clientHeight;
		$('#wrap').height(wh);
		/*$('img').load(function(){
	        	wh = (document.documentElement.clientHeight > document.body.clientHeight) ? document.documentElement.clientHeight : document.body.clientHeight;
			$('#wrap').height(wh);
		})*/
	}
})