/* CONFIG */

var overlayBorderWidth=11;

/* FUNCTIONS */

function overlayOpen(width,height,content){
	var widthCN=width+overlayBorderWidth*2;
	var heightCN=height+overlayBorderWidth*2;
	$('#overlayBorder').css("width",widthCN+"px");
	$('#overlayBorder').css("height",heightCN+"px");
	$('#overlayContent').css("width",width+"px");
	$('#overlayContent').css("height",height+"px");
	$("#overlayContent").html(content);
	overlayCenter();
	
	$('#overlayShadow').css("display","block");
	
		$('#overlayMain').css("display","block");
		var endTop=parseInt($("#overlayContent").css("top"));
		var height=parseInt($("#overlayContent").css("height"));
		var startTop=(height+30)*(-1);
		
		$('#overlayBorder').css("top",startTop+"px");
		$('#overlayContent').css("top",startTop+"px");
		
		$('#overlayBorder').animate({top: endTop}, 500);
		$('#overlayContent').animate({top: endTop}, 500);
}

function overlayClose(){
	
		var endTop=parseInt($("#overlayContent").css("top"));
		var height=parseInt($("#overlayContent").css("height"));
		var startTop=(height+30)*(-1);
		
		$('#overlayBorder').animate({top: startTop}, 500);
		$('#overlayContent').animate({top: startTop}, 500,function(){
			$('#overlayBorder').css("top",endTop+"px");
			$('#overlayContent').css("top",endTop+"px");
			$("#overlayContent").html("");
			$('#overlayShadow').css("display","none");
			$('#overlayMain').css("display","none");
		});
	
}

function overlayCenter(){
	var width=parseInt(parseInt($('#overlayContent').css("width"))/2);
	var height=parseInt(parseInt($('#overlayContent').css("height"))/2);
	var widthW=parseInt(parseInt($(window).width())/2);
	var heightW=parseInt(parseInt($(window).height())/2);
	
	var leftP=widthW-width;
	var topP=heightW-height;
	var leftPCN=widthW-width;
	var topPCN=heightW-height;

	$('#overlayBorder').css("left",leftPCN+"px");
	$('#overlayBorder').css("top",topPCN+"px");
	$('#overlayContent').css("left",leftP+"px");
	$('#overlayContent').css("top",topP+"px");
}

$(window).resize(function(){overlayCenter();});








function CallMeSubmit(){
	var res = true;
	if (res==true&&checkStrObj('mail')==false){alert('Укажите e-mail.'); res=false;}
	if (res==true&&isValidEmail(document.getElementById('mail').value)==false){alert('Пожалуйста, проверьте введенный e-mail.'); res=false;}
	if (res==true&&checkStrObj('phone')==false){alert('Укажите телефон.'); res=false;}
	if (res==true&&checkStrObj('name')==false){alert('Укажите ФИО.'); res=false;}
	if (res==true&&checkStrObj('order')==false){alert('Напишите содержание заявки.'); res=false;}
	return res;
}

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 TrimStr(s) {
  s = s.replace( /^\s+/g, '');
  return s.replace( /\s+$/g, '');
}

function checkStrObj(obj){
	var res = false;
	var objSel = document.getElementById(obj);
	var val = objSel.value;
	if (TrimStr(val)=='') res=false; else res=true;
	return res;
}
