// pops.js

$(document).ready(function(){
	var helpContent = "";
	var helpOffset = 0;
	var helpWidth = 0;
	var helpHeight = 0;
	var helpX = 0;
	var helpY = 0;
	var screenWidth = 0;
	var screenScroll = 0;
	
	$(".helpme").mouseenter(function() {
		$(this).addClass("cHelp");
		helpContent = $(this).attr("help");
		helpOffset = $(this).offset();
		$("body").append('<div id="helperBack"></div><div id="helper"><div id="helpCont">'+helpContent+'</div></div>');
		helpWidth = $("#helper").outerWidth();
		if(helpWidth > 270) {helpWidth = 270};
		
		$("#helperBack").width(helpWidth);
		$("#helper").width(helpWidth);
		helpHeight = $("#helper").innerHeight();
		$("#helperBack").height(helpHeight-3);
		
        screenScroll = $(window).scrollTop();
        screenWidth = $("body").innerWidth();
		
		$(document).bind("mousemove",function(e){
			helpX = e.pageX;
			helpY = e.pageY;
			if(helpX + helpWidth > screenWidth - 60) {helpX = screenWidth - 60 - helpWidth};
			
			helpY = helpY - helpHeight - 10;
			if(helpY < screenScroll + 15) {helpY = e.pageY + 15};
			
			$("#helperBack").css("left",helpX + 32).css("top",helpY + 2);
			$("#helper").css("left",helpX + 32).css("top",helpY);
		});
		
		$(".cHelp").mouseleave(function() {
			$(this).removeClass("cHelp");
			helpWidth = 0;
			helpHeight = 0;
			helpContent = "";
			$("#helperBack").remove();
			$("#helper").remove();
		});
	});
});







//popup.js

var ua = navigator.userAgent.toLowerCase();
var divw=0;
var divh=0;

if (document.getElementById || document.all)
	document.write('<div id="imgtrailer" style="position:absolute;visibility:hidden; z-index: 500;"></div>')

function gettrailobject()
	{
	if (document.getElementById)
		return document.getElementById("imgtrailer")
	else if (document.all)
		return document.all.trailimagid
	}

function gettrailobj()
	{
	if (document.getElementById)
		return document.getElementById("imgtrailer").style
	else if (document.all)
		return document.all.trailimagid.style
	}

function truebody()
	{
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
	}

function trailOff()
	{
	document.onmousemove='';
	gettrailobj().visibility="hidden";
	}

function trailOn(thumbimg,imgtitle,thw,thh)
	{
	if(ua.indexOf('opera') == -1 && ua.indexOf('safari') == -1)
		{
		gettrailobj().left="-500px";
		divthw = parseInt(thw);
		gettrailobject().innerHTML = '<div style="width:'+divthw+'px;"><img class="popupsimgs" src="img/'+thumbimg+'" hspase="0" border="0" width="'+thw+'" height="'+thh+'"></div>';
		gettrailobj().visibility="visible";
		divw = parseInt(thw)+25;
		divh = parseInt(thh)+130;
		document.onmousemove=followmouse;
		}
	}

function followmouse(e)
	{
	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(document.body.offsetHeight, window.innerHeight)
if(typeof e != "undefined")
	{
	if(docwidth < 15+e.pageX+divw)
		xcoord = e.pageX-divw-5;
	else
		xcoord = 15+e.pageX;
	if(docheight < 15+e.pageY+divh)
		ycoord = 15+e.pageY-Math.max(0,(divh + e.pageY - docheight - truebody().scrollTop - 30));
	else
		ycoord = 15+e.pageY;
	}
else if (typeof window.event != "undefined")
	{
	if(docwidth < 15+truebody().scrollLeft+event.clientX+divw)
		xcoord = truebody().scrollLeft-5+event.clientX-divw;
	else
		xcoord = truebody().scrollLeft+15+event.clientX;

	if(docheight < 15+truebody().scrollTop+event.clientY+divh)
		ycoord = 15+truebody().scrollTop+event.clientY-Math.max(0,(divh + event.clientY - docheight - 30));
	else
		ycoord = truebody().scrollTop+15+event.clientY;
	}
	gettrailobj().left=xcoord+"px"
	gettrailobj().top=ycoord+"px"
	}
	
	
	function showPop(id) {
		document.getElementById(id).style.display='block';
	}
	
	function hidePop(id) {
		document.getElementById(id).style.display='none';
	}
	






// cont.js

function op(ID) {
	if(document.getElementById(ID).className=='hid') {
		document.getElementById(ID).className='vis';
	} else {
		document.getElementById(ID).className='hid';
	}
}





// order.js

good_letters = new Array("A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","_", "-",".","0","1","2","3","4","5","6","7","8","9","@");
	     function emailcheck(mail) {
	     if(mail.indexOf("@") == -1 || mail.indexOf(".") == -1) {
	          return false;
	     } else {
	          for(i = 0; i < mail.length; i++){
	               smfl = 0;
	               for(k = 0; k < good_letters.length;k++) {
	                    if(mail.substr(i,1) == good_letters[k]) {
	                         smfl = 1;
	                    }
	               }
	               if(smfl == 0) return false;
	          }
	     }
	     return true;
	     }
		
		function validate(){
			var ok=true;
			f=document.forms.bask;
			if (f.company.value==''){alert('Пожалуйста, укажите компанию, которую представляете');ok=false;}
			else if (f.spera.value==''){alert('Пожалуйста, укажите сферу деятельности компании');ok=false;}
			else if (f.cname.value==''){alert('Пожалуйста, укажите контактное лицо');ok=false;}
			else if (f.phone.value==''){alert('Пожалуйста, укажите контактные телефоны');ok=false;}
			else if (f.email.value=='' || emailcheck(f.email.value)==''){alert('Укажите контактный E-mail');ok=false;}
			else if (f.order.value==''){alert('Пожалуйста, заполните поле "Ваш заказ". Чем подробнее Вы сформулируете задачу, тем лучше мы сможем ответить на Ваш запрос');ok=false;}
			else if (f.price.value==''){alert('Если Вы ограничены в бюджете, обязательно укажите. От этого может зависеть рекламная стратегия. Если у Вас нет подобных ограничений, просто нажмите любую цифру на клавиатуре');ok=false;}
			if (ok==true) return f.submit();
			else return ok;
		}
		good_nums = new Array("0","1","2","3","4","5","6","7","8","9");
		function checker(){
			var b='';
			f=document.forms.bask.price.value;
			for(i = 0; i < f.length; i++){
	             smfl = 0;
	             for(k = 0; k < good_letters.length;k++) {
	                   if(f.substr(i,1) == good_nums[k]) {
	                        smfl = 1;
							break;
	                   }
					   
	              }
				  if (smfl==1) {
					    b=b+f.substr(i,1);
				 }
	              
	         }	
			
			 return b;
		}
