function getXmlHttp(){
	var xmlhttp
	try {
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	} catch (e) {
		try {
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		} catch (e1) {
      			xmlhttp = false;
		}
	}
	
	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
		xmlhttp = new XMLHttpRequest();
	}

	return xmlhttp;
}




$(document).ready(function(){
	




function detectIE6(){
  var browser = navigator.appName;
  if (browser == "Microsoft Internet Explorer"){
    var b_version = navigator.appVersion;
    var re = /\MSIE\s+(\d\.\d\b)/;
    var res = b_version.match(re);
    if (res[1] <= 6){
      return true;
    }
  }
  return false;
}



var contentHeight = $(window).height()
var newHeight

newHeight = contentHeight - 347;
newHeight = newHeight + 'px'	

document.getElementById('content').style.minHeight = newHeight

	  if ( detectIE6() ){
		  document.getElementById('content').style.height = newHeight
		}



	$(".item1").hover(
	  function () {
	   $(this).css('background-image', 'url(http://195.248.234.111/~bumermarke/img/item1.jpg)');
	   $(this).children('a').css('color', '#428cff');
	   
	  }, 
	  function () {
	   $(this).css('background-image', 'none');
	   $(this).children('a').css('color', '#ccc');
	  }
	);
	
	
	$(".item2").hover(
	  function () {
	   $(this).css('background-image', 'url(http://195.248.234.111/~bumermarke/img/item2.jpg)');
	   $(this).children('a').css('color', '#428cff');
	   
	  }, 
	  function () {
	   $(this).css('background-image', 'none');
	   $(this).children('a').css('color', '#ccc');
	  }
	);

	$(".item3").hover(
	  function () {
	   $(this).css('background-image', 'url(http://195.248.234.111/~bumermarke/img/item3.jpg)');
	   $(this).children('a').css('color', '#428cff');
	   
	  }, 
	  function () {
	   $(this).css('background-image', 'none');
	   $(this).children('a').css('color', '#ccc');
	  }
	);

	$(".item4").hover(
	  function () {
	   $(this).css('background-image', 'url(http://195.248.234.111/~bumermarke/img/item4.jpg)');
	   $(this).children('a').css('color', '#428cff');
	   
	  }, 
	  function () {
	   $(this).css('background-image', 'none');
	   $(this).children('a').css('color', '#ccc');
	  }
	);




	$(".car1").hover(
	  function () {
	  $(this).css('backgroundPosition', '0 -109px');
	  if ( detectIE6() ){
		  $(this).css('backgroundPosition', '0 -108px');
		}
	  
	  
	  
	   
	  }, 
	  function () {
	  $(this).css('backgroundPosition', '0 0px');
	  }
	);


	$(".car2").hover(
	  function () {
	  $(this).css('backgroundPosition', '0 -109px');
	  if ( detectIE6() ){
		  $(this).css('backgroundPosition', '0 -108px');
		}
	   
	  }, 
	  function () {
	  $(this).css('backgroundPosition', '0 0px');
	  }
	);


	$(".car3").hover(
	  function () {
	  $(this).css('backgroundPosition', '0 -109px');
	  if ( detectIE6() ){
		  $(this).css('backgroundPosition', '0 -108px');
		}
	   
	  }, 
	  function () {
	  $(this).css('backgroundPosition', '0 0px');
	  }
	);


	$(".car4").hover(
	  function () {
	  $(this).css('backgroundPosition', '0 -109px');
	  if ( detectIE6() ){
		  $(this).css('backgroundPosition', '0 -108px');
		}
	   
	  }, 
	  function () {
	  $(this).css('backgroundPosition', '0 0px');
	  }
	);


	$(".car5").hover(
	  function () {
	  $(this).css('backgroundPosition', '0 -109px');
	  if ( detectIE6() ){
		  $(this).css('backgroundPosition', '0 -108px');
		}
	   
	  }, 
	  function () {
	  $(this).css('backgroundPosition', '0 0px');
	  }
	);


	$(".car6").hover(
	  function () {
	  $(this).css('backgroundPosition', '0 -109px');
	  if ( detectIE6() ){
		  $(this).css('backgroundPosition', '0 -108px');
		}
	   
	  }, 
	  function () {
	  $(this).css('backgroundPosition', '0 0px');
	  }
	);


	$(".car7").hover(
	  function () {
	  $(this).css('backgroundPosition', '0 -109px');
	  if ( detectIE6() ){
		  $(this).css('backgroundPosition', '0 -108px');
		}
	   
	  }, 
	  function () {
	  $(this).css('backgroundPosition', '0 0px');
	  }
	);




});

function question()
{
	
		if(!document.getElementById('name').value || !document.getElementById('emails').value || !document.getElementById('phone').value || !document.getElementById('text').value){
			
			 document.getElementById('errorempty').innerHTML = 'Пожалуйста, заполните все поля отмеченные *'
			 document.getElementById('errorempty').style.display = 'block'
		 }
		 
		 else {
			 
			var text = 'name=' + document.getElementById('name').value + '&emails=' + document.getElementById('emails').value + '&phone=' + document.getElementById('phone').value + '&text=' + document.getElementById('text').value

			var req = getXmlHttp()
			req.open('POST', 'library/question.php', true)
			req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			req.send(text);
			req.onreadystatechange = function() {
			
			if (req.readyState < 4){
				document.getElementById('errorempty').style.display = 'block'
				document.getElementById('errorempty').innerHTML = '<img src="img/working.gif">'
				}
			if (req.readyState == 4) {
				if(req.status == 200) {
					
			document.getElementById('errorempty').innerHTML = 'Ваш вопрос отправлен'
			document.getElementById('errorempty').style.display = 'block'
			document.getElementById('name').value = ''
			document.getElementById('emails').value = ''
			document.getElementById('phone').value = ''
			document.getElementById('text').value = ''
			document.getElementById('answers').innerHTML = req.responseText
	
					
				}
			}
		}

			 
			 
			 
			 
			 
	}
}


function order(divis)
{
	
	if(divis == 3)
	{
		if( (document.getElementById('series').value == 0) || (document.getElementById('smodel').value == 0) || (document.getElementById('spart').value == 0) || !document.getElementById('name').value || !document.getElementById('phone').value ){
			
			 document.getElementById('errorempty').innerHTML = 'Пожалуйста, заполните все поля отмеченные *'
			 document.getElementById('errorempty').style.display = 'block'
		 }
		 else {
			 
			 var text = 'divis=' + divis + '&idseries=' + document.getElementById('series').value + '&idmodel=' + document.getElementById('smodel').value + '&spart=' + document.getElementById('spart').value + '&name=' + document.getElementById('name').value + '&phone=' + document.getElementById('phone').value + '&text=' + document.getElementById('text').value


			var req = getXmlHttp()
			req.open('POST', 'library/order.php', true)
			req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			req.send(text);
			
			req.onreadystatechange = function() {
			
			if (req.readyState < 4){
				document.getElementById('errorempty').style.display = 'none'
				}
			if (req.readyState == 4) {
				if(req.status == 200) {
					
			 document.getElementById('errorempty').innerHTML = 'Ваша заказ принят'
			 document.getElementById('errorempty').style.display = 'block'
	
					
					}
				}
			}


		}
	}
	else {
			var text = 'divis=' + divis + '&idseries=' + document.getElementById('series').value + '&idmodel=' + document.getElementById('smodel').value
			
			if(divis == 1 || document.getElementById('series').value == 0)
			{
				document.getElementById('part').innerHTML = '<select id="spart"><option value="0">Пусто</option></select>'
			}
			
			var req = getXmlHttp()
			req.open('POST', 'library/order.php', true)
			req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			req.send(text);
			req.onreadystatechange = function() {
			
			if (req.readyState < 4){
				document.getElementById('errorempty').style.display = 'none'
				}
			if (req.readyState == 4) {
				if(req.status == 200) {
					
					if(divis == 1)
					{
						document.getElementById('model').innerHTML = req.responseText
						document.getElementById('errorempty').style.display = 'none'

					}

					if(divis == 2)
					{
						document.getElementById('part').innerHTML = req.responseText
						document.getElementById('errorempty').style.display = 'none'
						
					}
					
	
					
				}
			}
		}

	}
			 
}





function images(id)
{
	
			 
			var text = 'id=' + id

			var req = getXmlHttp()
			req.open('POST', 'library/images.php', true)
			req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
			req.send(text);
			req.onreadystatechange = function() {
			
			if (req.readyState < 4){
				document.getElementById('catalogPictures').innerHTML = ''
				}
			if (req.readyState == 4) {
				if(req.status == 200) {
					
			document.getElementById('catalogPictures').innerHTML = req.responseText
	
					
				}
			}
		}

			 
}

function closeFrame(id,d) {
	if(!d){
		var parent = document.getElementsByTagName('BODY')[0];
		parent.removeChild(document.getElementById(id))
		parent.removeChild(document.getElementById('darkdiv'))
	}
	else {
		var parent = document.getElementById('toolbar'+d);
		parent.removeChild(document.getElementById(id))
	}
}


function makeFrame(tagId, w, h)
{
	var parent = document.getElementsByTagName('BODY')[0];
    newDiv = document.createElement('div');
    var darkDiv = document.createElement('div');
	
	newDiv.id = tagId;
	parent.appendChild(newDiv);

	darkDiv.id = 'darkdiv';
	parent.appendChild(darkDiv);

	var contentHeight = document.getElementsByTagName('html')[0].clientHeight;
	var contentWidth = document.getElementsByTagName('html')[0].clientWidth;
	
	htmlHeight = document.body.clientHeight
			
	var divTop = ((contentHeight - h) / 2) + (document.documentElement.scrollTop || document.body.scrollTop)
	var divLeft = ((contentWidth  / 2) - w)
	
	divTop = divTop + 'px'
	$("#"+tagId).css("margin-top", divTop);
	$("#"+tagId).css("margin-left", divLeft);

	$("#darkdiv").css("width", contentWidth);
	$("#darkdiv").css("height", htmlHeight);

	document.getElementById('darkdiv').innerHTML = htmlHeight
}



function showPictures(id)
{
	makeFrame('showPictures', '400', '600');
	document.getElementById('showPictures').innerHTML = '<center><a href="javascript:closeFrame(\'showPictures\');"><img src="/img/upload/'+id+'" width="800"></a></center>'

}
