over=0;
overM=0;


function isValidEmail (email, strict)
{
 if ( !strict ) email = email.replace(/^\s+|\s+$/g, '');
 return (/^([a-z0-9_\-]+\.)*[a-z0-9_\-]+@([a-z0-9][a-z0-9\-]*[a-z0-9]\.)+[a-z]{2,4}$/i).test(email);
}

function checkForm(form) {
 var el,  
 elName, 
 value, 
 type; 
 mas = {};
 sm = document.getElementById("statusmessage");
 var errorList = [];
 var errorList2 = [];
 var errorText = {
 1 : "\"Имя\"",
 2 : "\"E-mail\"",
 3 : "Неверно заполнено поле \"E-mail\".",
 4 : "\"Название компании\"",
 5 : "\"Сфера деятельности\"",
 6 : "\"Город\""
 }
 for (var i = 0; i < form.elements.length; i++) {
 el = form.elements[i];
 elName = el.nodeName.toLowerCase();
 value = el.value;
 mas[el.name] = value;
 if (elName == "input") { // INPUT
 type = el.type.toLowerCase();
 switch (type) {
 case "text" :
 if (el.name == "name" && value == "") errorList.push(1);
 if (el.name == "email" && value == "") errorList.push(2);
 if (el.name == "email" && value != "" && !isValidEmail(value)) errorList2.push(3);
 if (el.name == "company" && value == "") errorList.push(4);
 if (el.name == "sfera" && value == "") errorList.push(5);
 if (el.name == "city" && value == "") errorList.push(6);
 break;
 default :
 break;
 }
 } else if (elName == "textarea") { // TEXTAREA

 } else if (elName == "select") { // SELECT

 } else {

 }
 }
 if ((!errorList.length) && (!errorList2.length)) {


$.post('/getlink.php', {email:mas['email'],fio:mas['name'],company:mas['company'],sfera:mas['sfera'],city:mas['city'],pid:mas['pid']}, function(data){
		sm.innerHTML = "На Ваш E-mail была отправлена ссылка на скачивание.<br>Спасибо за проявленный интерес."; 
	});
setTimeout("$.fancybox.close();", 3000);
return false;
//return true;
} else {
 var errorMsg = "";
  if (errorList.length) errorMsg = "Заполните, пожалуйста, поле ";
  if (errorList.length>1) errorMsg = "Заполните, пожалуйста, поля: ";
 for (i = 0; i < errorList.length; i++) {
 errorMsg += errorText[errorList[i]];
 if (i!=errorList.length-1) errorMsg += ", "; else errorMsg += ". ";
 }
 if (errorList2[0]==3) errorMsg += errorText[3];
 sm.innerHTML = errorMsg;
// alert(errorMsg);
 return false;
}
}


$(document).ready( function() {

	$("#inline").fancybox({
				'titlePosition'		: 'inside',
				'transitionIn'		: 'none',
				'transitionOut'		: 'none'
			});


	$("a.lightbox").lightBox();

	$("#menu").mouseover(function() {over=1;});

	$("#menu").mouseleave(
		function() {
				if (over==1 && overM==1) {
				$("div.menu").removeClass("select");				
				$("div.submenu").hide();				
				}
		}
	);

	$("#menu div.menu").hover(
		function() {
				overM=1;
				$("div.menu").removeClass("select");
				$(this).addClass("select");
				$("div.submenu").hide();				
				$("div.submenu",$(this).parent("div.item")).show();				
		}
	);
	$("#menu div.submenu div").hover(
		function() {
			if (!$(this).hasClass("select") && !$(this).hasClass("sep")) {
				$(this).addClass("select2");
            }
		}, function() {
			if (!$(this).hasClass("select") && !$(this).hasClass("sep")) {
				$(this).removeClass("select2");
			}
		}
	);
	$("div.content-photos div").hover(
		function() {
			$("div.tips",this).show();
		}, function() {
			$("div.tips",this).hide();
		}
	);
	$("div.news-item").hover(
		function() {
			$("div.title a",this).css("color","222222");
			$("a.white",this).css("color","ffffff");
		}, function() {
			$("div.title a",this).css("color","39312e");
			$("a.white",this).css("color","b0ae9c");
		}
	);
});

function valuation(id) {
	if ($("#valuation"+id).hasClass("opens")) {
    	$("#valuation"+id).slideUp("fast");
		$("#valuation"+id).removeClass("opens");
		$("a",$("#valuation"+id).parent("div")).addClass("dashed");
    } else {
    	$("div.valuation").slideUp("fast");
		$("a",$("div.valuation").parent("div")).addClass("dashed");
    	$("#valuation"+id).slideDown("slow");
		$("#valuation"+id).addClass("opens");
		$("a",$("#valuation"+id).parent("div")).removeClass("dashed");
    }
}
function service(id) {
	if ($("#service"+id).hasClass("opens")) {
    	$("#service"+id).slideUp("fast");
		$("#service"+id).removeClass("opens");
		$("a",$("#service"+id).parent("div")).addClass("dashed");
    } else {
    	$("div.service").slideUp("fast");
		$("a",$("div.service").parent("div")).addClass("dashed");
    	$("#service"+id).slideDown("slow");
		$("#service"+id).addClass("opens");
		$("a",$("#service"+id).parent("div")).removeClass("dashed");
    }
}
