// Return element by class name

	function getElementsByClass(searchClass,node,tag) {
		
		var classElements = new Array();
		
		if (node == null) {
			node = document;
		}
		
		if (tag == null) {
			tag = '*';
		}
		
		var els 		= node.getElementsByTagName(tag);
		var elsLen 	= els.length;
		var pattern = new RegExp('(^|\\\\s)'+searchClass+'(\\\\s|$)');
		
		for (i = 0, j = 0; i < elsLen; i++) {
			if (pattern.test(els[i].className)) {
				classElements[j] = els[i];
				j++;
			}
		}
		
	return classElements;
}

/* Global variables */
	var data;
	var dataCollection = '';
	var waiting = '<img style="position: relative; top: 2px; left: 3px;" src="templates/common/images/ajax.gif" alt="..." />';
	var site_vdir = '';

/* Makeup scripts */
	setClass	= function (obj, newClassName) {obj.className = newClassName;}
	removeClass = function (obj){obj.className = '';}
	hideValue	= function (obj, defaultValue){obj.value = (obj.value == defaultValue) ? '' : obj.value;}
	showValue	= function (obj, defaultValue){obj.value = (obj.value == '') ? defaultValue : obj.value;}
	showOrHideBlock = function (id,ob) {
		if (document.getElementById(id).style.display == 'none'){
			document.getElementById(id).style.display = '';			
		}else{
			document.getElementById(id).style.display = 'none';
		}   
	}
	
	hideBlock = function (id) 
	{
		$(id).style.display = 'none';
	}
	
	repairTroubleWithJS = function () {document.body.style.fontSize = 68 + Math.random()/6 + 0.75 + '%';}
	refreshCodeImage = function (){if ($('codeimageChangeable')) $('codeimageChangeable').src = 'codeimage/'+Math.random();}

/* Common functions */
	function $() 
	{    
		  var elements = new Array();    
			for (var i = 0; i < arguments.length; i++) 
		  {    
				var element = arguments[i];    
				if (typeof element == 'string')    
				  element = document.getElementById(element);    
				if (arguments.length == 1)    
				  return element;    
				elements.push(element);    
		  } 
		  return elements;    
	}
	
	function newWindow(url, width, height)
	{
		var left = Math.round((screen.width/2)-(width/2));
		var top = Math.round((screen.height/2)-(height/2));
		FormWin = window.open(url, '', "width="+width+", height="+height+", status=no, menubar=no, resizable=no, scrollbars=no,  border=no, toolbar=no, left="+left+", top="+top);
	}
	
	printit = function ()
	{
		if(window.print) window.print(); return false;
		var WebBrowser = '<object id="WebBrowserPrint" width="0" height="0" classid="clsid:8856F961-340A-11D0-A96B-00C04FD705A2"></object>';
		document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
		WebBrowserPrint.ExecWB(6, 2);
	}
	
	MyUserFunction = function () {}
	
	checkmail = function (email) 
	{ 
		dog = email.indexOf("@"); 
		if (dog == -1) return false; 
		if (email.indexOf(".") == -1) return false; 
		if ((dog < 1) || (dog > email.length - 5)) return false;  
		if ((email.charAt(dog - 1) == '.') || (email.charAt(dog + 1) == '.')) return false; 
		return true;
	} 
	 
	
/* Text tabs function */
	function hideTabElement(id) {$(id).style.display = 'none';}
	
	function hideAllTabElements()
	{
		for(var i = 0; i < document.getElementsByTagName('div').length; i++)
		if (document.getElementsByTagName('div')[i].className == 'tab-text')
		{
			document.getElementsByTagName('div')[i].style.display = 'none';
			$('link-'+document.getElementsByTagName('div')[i].id).className = '';
		}
	}
	
	function toggleTabElement(id)
	{
		hideAllTabElements();
		if ($(id).style.display == 'none')
		{
			$(id).style.display = '';
			$('link-'+id).className = 'link-hovered';
		}
		else
		{
			$(id).style.display = 'none';
			$('link-'+id).className = '';
		}
	}

/* Lang functions */
	var lang = new Array();
	function getlang (id) {if (lang[id]) return lang[id]; else id;}
	lang['fill_this_field'] 				= 'Заполните данное поле';
	lang['uncorrect_email'] 				= 'Некорректный email';
	lang['uncorrect_email'] 				= 'Некорректное поле';

		
/* Cookie function */
	setCookie = function (name, value)
	{
		var exp = new Date();
		var e = exp.getTime()+(24*60*60*30*1000);
		exp.setTime(e);
		document.cookie = name + "=" + escape(value) + ";path=/;expires="+exp.toUTCString();
	}
	getCookie = function (name)
	{
		var prefix = name + "=";
		var start = document.cookie.indexOf(prefix);
		if (start == -1) return false;
		var end = document.cookie.indexOf(";", start + prefix.length)
		if (end == -1)	end = document.cookie.length;
		return unescape(document.cookie.substring(start + prefix.length, end));
	}

/* Page navgiation */

	function go (href, block)
	{
		MyUserFunction = repairTroubleWithJS;
		
		$('pages').innerHTML = waiting;
		
		data = 'ajax=1';
		data = data + dataCollection;
		ExecuteXMLCall(href, block, 'post', data,	false, '', $(block).innerHTML);
	}
	
/* Forms  checker */
	checkForm = function ()
	{
		
		var error = 0;
	

		for (var i=0; i<fieldArray.length; i++) 
			if ($('xfield-'+fieldArray[i]))
			{
				if ($('error-'+fieldArray[i])){
					$('error-'+fieldArray[i]).innerHTML = ''; 
					if(($('xfield-'+fieldArray[i]).tagName == 'textarea' &&	 $('xfield-'+fieldArray[i]).innerHTML == '')	||
					   ($('xfield-'+fieldArray[i]).type	   == 'checkbox' && !$('xfield-'+fieldArray[i]).checked)			||
				   		($('xfield-'+fieldArray[i]).value   == ''))
				   	{
				 		$('error-'+fieldArray[i]).innerHTML = getlang('fill_this_field'); error = 1;
				 	}
				}
			}

		for (var i=0; i<emailArray.length; i++) if ($('xfield-'+emailArray[i]) && $('xfield-'+emailArray[i]).value != '')
		{
			$('error-'+emailArray[i]).innerHTML = ''; 
			
			if (!checkmail($('xfield-'+emailArray[i]).value))
			{
				$('error-'+emailArray[i]).innerHTML = getlang('uncorrect_email'); error = 1;
			}
		}
	
		if (error) return false;
	
		return true;
	}

/* End forms */
	
	
