/**
 * CMS ArDmin
 *
 * @author Artem Demchenkov <lunoxot@mail.ru>
 * @version 4.3.1
 *
 * BSD License
 */
 
var n="none";

// visible of element

function vis(name,im)
{
	divs=document.getElementById(name);
	imgs=document.getElementById(im);
	if(imgs.style.display=="block")
	{
		divs.style.display="block";
		imgs.style.display="none";
	}
	else
	{
		divs.style.display="none";
		imgs.style.display="block";
	}
}

// smiles for form

function Smile(what)
{
	document.form.textarea.value=document.form.textarea.value+''+what;
} 

// scroll motion after click by button

function ScrollTopNow(action)
{
	if(action="click")
	{
		n="none";
	}
	
	if(document.compatMode == "BackCompat")
	{
		var sc=document.body.scrollTop;
	}
	else
	{
		var sc=document.documentElement.scrollTop;
	}
	
	if(sc>200 && n=="none")
	{
		if(document.compatMode == "BackCompat")
		{
			document.body.scrollTop=sc-1;
		}
		else
		{
			var sc=document.documentElement.scrollTop;
		}
		setTimeout('ScrollTopNow()', 1);
	}
	else
	{
		n="yes";	
	}
}

// XMLHttpRequest

function getXmlHttp() 
{
	var xRequest=null;
	if (window.XMLHttpRequest) 
	{
		// Mozilla/Safari
		xRequest=new XMLHttpRequest();
	}
	else if (typeof ActiveXObject != "undefined")
	{
		xRequest=new ActiveXObject
		// Internet Explorer
		("Microsoft.XMLHTTP");
	}
	
	return xRequest;
}

// send message from form

function Send_message()
{
	var mail=document.getElementById('mail').value;
	var name=document.getElementById('name').value;
	var cap=document.getElementById('cap').value+'.jpg';
	var cap_real=document.getElementById('cap_real').value;
	var textarea=document.getElementById('textarea').value;
	
	if(name=='' || mail=='' || textarea=='') 
	{
        document.getElementById ('for_text').innerHTML="<p style='color:#FF0000'>,   </p>";
    }
    else 
	{
        if(cap!=cap_real) 
		{
            document.getElementById ('for_text').innerHTML="<p style='color:#FF0000'>   </p>";
        }
        else 
		{
			var reg = /[0-9a-z_]+@[0-9a-z_^.]+.[a-z]{2,3}/i;
			if(reg.test(mail))
			{
				document.getElementById ('for_text').innerHTML="Waiting...";
				var params = 'text=' + encodeURIComponent(textarea) + '&name=' + encodeURIComponent(name) + '&mail=' + encodeURIComponent(mail) + '&hidden=1';
				
				var xmlhttp = getXmlHttp()
				xmlhttp.open('POST', 'client_files/public/php/form_answer.php', true);
				
				xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
						
				xmlhttp.onreadystatechange = function() {
				  if (xmlhttp.readyState == 4) {
					 if(xmlhttp.status == 200) 
					 {
						document.getElementById ('for_text').innerHTML=xmlhttp.responseText;
						ScrollTopNow("click");
					 }
				  }
				};
				xmlhttp.send(params);
			}
			else
			{
				document.getElementById ('for_text').innerHTML="<p style='color:#FF0000'> email  </p>";
			}
		}
	}
}

// picture moving

var is_mouse_down=false;
var last_x = 0;
var last_y = 0;
function map_mouse_down(obj,event){
	var mdiv = document.getElementById('map');
	is_mouse_down=true;
	if(is_mouse_down==true){
		document.body.style.cursor='move';
	} else {
		document.body.style.cursor='auto';
	}
	last_x=event.screenX;
	last_y=event.screenY;
	
}

function map_mouse_out(){
	var mdiv = document.getElementById('map');
	is_mouse_down=false;
	document.body.style.cursor='auto';
}

function move_map(dx,dy){
	var mimg = document.getElementById('map_img');
	var t=new String;

	t=mimg.style.marginLeft;
	t=t.substring(0,t.length-2)
	l=t*1;//переводим в число
	t=mimg.style.marginTop;
	t=t.substring(0,t.length-2)
	d=t*1;//переводим в число
	mimg.style.marginLeft=l+dx+'px';
	mimg.style.marginTop=d+dy+'px';	
}

function map_mouse_move(obj,event){
	if(is_mouse_down==true){
		var mimg = document.getElementById('map_img');
		t=mimg.style.marginLeft;
		t=t.substring(0,t.length-2)
		l=t*1;//переводим в число
		t=mimg.style.marginTop;
		t=t.substring(0,t.length-2)
		d=t*1;//переводим в число
		move_map(event.screenX-last_x,event.screenY-last_y);
		last_x=event.screenX;
		last_y=event.screenY;
	}
}

function map_move_to_center(){
	var mimg = document.getElementById('map_img');
	mimg.style.marginLeft=-Math.round(img_width/2-img_container_width/2)+'px';
	mimg.style.marginTop=-Math.round(img_height/2-img_container_height/2)+'px';
}

function map_smaller(){
	var mimg = document.getElementById('map_img');
	img_width=img_width-img_width_step;
	img_height=img_height-img_height_step;
	mimg.style.width=img_width+'px';
	mimg.style.height=img_height+'px';
	move_map(Math.round(img_width_step/2),Math.round(img_height_step/2));
}

function map_bigger(){
	var mimg = document.getElementById('map_img');
	img_width=img_width+img_width_step;
	img_height=img_height+img_height_step;
	mimg.style.width=img_width+'px';
	mimg.style.height=img_height+'px';
	move_map(Math.round(-img_width_step/2),Math.round(-img_height_step/2));
}

function map_original_size(){
	var mimg = document.getElementById('map_img');
	mimg.style.width=img_width_original+'px';
	mimg.style.height=img_height_original+'px';
	move_map(Math.round((img_width-img_width_original)/2),Math.round((img_height-img_height_original)/2));
	img_width=img_width_original;
	img_height=img_height_original;
}

function map_mousewheel(event)
{
	event = event ? event : window.event;
	var wheelData = event.detail ? event.detail * -1 : event.wheelDelta / 40;
	
	if(wheelData>0)
		map_bigger();
	else 
		map_smaller();
	
	return cancelEvent(event);
}

function cancelEvent(e)
{
	e = e ? e : window.event;
	if(e.stopPropagation)
		e.stopPropagation();
	if(e.preventDefault)
		e.preventDefault();
	e.cancelBubble = true;
	e.cancel = true;
	e.returnValue = false;
	return false;
}

function hookEvent(element, eventName, callback)
{
	if(typeof(element) == "string")
		element = document.getElementById(element);
	if(element == null)
		return;
	if(element.addEventListener)
	{
		if(eventName == 'mousewheel')
		{
			element.addEventListener('DOMMouseScroll',
			callback, false);
		}
		element.addEventListener(eventName, callback, false);
	}
	else if(element.attachEvent)
	element.attachEvent("on" + eventName, callback);
}

// left menu

function openMenu(node){
	var subMenu = node.parentNode.getElementsByTagName("ul")[0];
	subMenu.style.display == "none" ? subMenu.style.display = "block" : subMenu.style.display = "none";
	subMenu.style.display == "none" ? node.getElementsByTagName("img")[0].setAttribute('src', 'client_files/public/images/left_menu_open.gif') : node.getElementsByTagName("img")[0].setAttribute('src', 'client_files/public/images/left_menu_close.gif');
}

function allClose(){
	var list = document.getElementById("menu_left").getElementsByTagName("ul");
	for(var i = 0; i < list.length; i++) {
		list[i].style.display = "none";
	}
}
