// functions
    function createXmlHttpRequest() 
    {
    	var xmlHttp = false;
    
    	try {
    	  xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
    	} catch (e) {
    	  try {
    	    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
    	  } catch (e2) {
    	    xmlHttp = false;
    	  }
    	}
    	
    	if (!xmlHttp && typeof XMLHttpRequest != 'undefined') {
    	  xmlHttp = new XMLHttpRequest();
    	}    
    	    if (xmlHttp) 
    	        return xmlHttp;
    }
    
    function bookmark() 
    {
    	var url = 'http://surnameanalysis.com/';
    	var title = 'Name and Surname Analysis';
        
    	if(window.sidebar)
    		window.sidebar.addPanel(title, url, '');
        else if(window.external)
    		window.external.AddFavorite(url, title);
    	else
    		alert('To add page to favorites press CTRL-D');	
    }
      	
    function write_bookmark_href()
    {
        if (window.opera && window.print) 	
            document.write('<a rel="sidebar" class="v14" title="Name and Surname Analysis" href="http://surnameanalysis.com/"><img src="/images/Add-to-Favourites-Icon.gif" border="0" width="16" height="16"></a>');
        else
            document.write('<a class="v14" href="#" onclick="bookmark(); return false;"><img src="/images/Add-to-Favourites-Icon.gif" border="0" width="16" height="16"></a>');
    }
    
    function write_bookmark_href2()
    {
        if (window.opera && window.print) 	
            document.write('<a rel="sidebar" class="v14" title="Name and Surname Analysis" href="http://surnameanalysis.com/">Add to Favorites</a>');
        else
            document.write('<a class="v14" href="#" onclick="bookmark(); return false;">Add to Favorites</a>');
    }

    function checkAll(formName, name, checked)
	{
		var datalist = document.forms[formName].elements;
		for (var i = 0; i < datalist.length; i++)
			if(datalist[i].type == 'checkbox' && datalist[i].id.substr(0, name.length) == name)
				datalist[i].checked = checked;		
	}
    
	function gray_button_down(btn)
    {
        btn.style.backgroundImage = 'url(/images/gray_button_down.gif)';
    }
    
    function gray_button_up(btn)
    {
        btn.style.backgroundImage = 'url(/images/gray_button.gif)';
    }
    
    function small_gray_button_down(btn)
    {
        btn.style.backgroundImage = 'url(/images/small_gray_button_down.gif)';
    }
    
    function small_gray_button_up(btn)
    {
        btn.style.backgroundImage = 'url(/images/small_gray_button.gif)';
    }
    
    function imgFit (img, maxImgSize, resize) 
	{ 
		if(!img.naturalWidth && !img.naturalHeight)
		{
			var img2 = new Image();
			img2.src = img.src;
			img.naturalHeight = img2.height; 
	  		img.naturalWidth = img2.width; 
		}
		
		if(resize)
		{		
			img.width = maxImgSize; 
			return;
		}
		
	   	if(!maxImgSize)
			maxImgSize = 500;
			
		if(img.width == img.naturalWidth)
		{
			//уменьшаем
			if(img.width >= img.height)
			{
				img.height = Math.round(((maxImgSize)/img.width)*img.height); 
				img.width = maxImgSize; 			
			}
			else
			{
				img.width = Math.round(((maxImgSize)/img.height)*img.width); 
				img.height = maxImgSize; 
			}
			img.title = 'Увеличить';
		}
		else
		{
			//увеличиваем
			img.height = img.naturalHeight; 
	      	img.width = img.naturalWidth; 
	      	img.title = 'Уменьшить';
		}
	}
    
    function set_checked(id, checked)
	{
		if (typeof checked == 'undefined')
			document.getElementById(id).checked = !document.getElementById(id).checked;
		else
			document.getElementById(id).checked = checked;
	}
    
    function showWnd(a, w, h)
	{
		var win = window.open (a, '', 'width='+w+',height='+h+',scrollbars=0,resizable=0');
		win.focus();
	}
    
    function show_hide(id, picid)
	{
		var d = document.getElementById(id);
		
		if(d.style.display == 'none')
		{
			d.style.display = 'block';
			if(picid)
			{
				var i = document.getElementById(picid); 
				i.src = '/images/icons/minus.gif'; 
    			i.title = 'Скрыть'; 
			}
		}
		else
		{			
			d.style.display = 'none';
			if(picid)
			{
				var i = document.getElementById(picid); 
				i.src = '/images/icons/plus.gif'; 
    			i.title = 'Показать'; 
			}
		}
			
			
	}
    
    function trim(str) {
	  	return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
	}
    
    function v_button_down(btn)
    {
        btn.style.backgroundImage = 'url(/images/v_button_down.gif)';
    }
    
    function v_button_up(btn)
    {
        btn.style.backgroundImage = 'url(/images/v_button.gif)';
    }
    
    function vg_button_down(btn)
    {
        if(!btn.disabled)
            btn.style.backgroundImage = 'url(/images/vg_button_down.gif)';
    }
    
    function vg_button_up(btn)
    {
        if(!btn.disabled)
            btn.style.backgroundImage = 'url(/images/vg_button.gif)';
    }
    
    function validate_latin(value)
	{		
		var reg = /[a-zA-Z-\s\.']+/;
        var reg2 = /[a-zA-Z]+/;
		value = trim(value);
		if ((reg2.test(value)) && (value.match(reg) == value))
			return true;
		else
			return false;
	}
    
    function validate_date(value)
	{		
		var reg = /[0-3]*[0-9]+\.[0-1]*[0-9]+\.[1-2]{1}[0-9]{3}/;
		value = trim(value);
		if (value.match(reg) == value)
			return true;
		else
			return false;
	}
    
    function validate_mail(value)
	{
		var reg = /[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?/;
		if (value.match(reg))
			return true;
		else
			return false;
	}
    
    function validate_numeric(value)
	{		
		var reg = /[0-9\+]+/;
		value = trim(value);
		if (value.match(reg) == value)
			return true;
		else
			return false;
	}
// functions end
// analyse
    function changeASex()
    {
        var sex_h = document.getElementById('a_sex_h');
        var sex = document.getElementById('a_sex');
        var sex_p = document.getElementById('a_sex_p');
        
        if(sex_h.value == '1')
        {
            sex.innerHTML = 'female';
            sex_p.src = '/images/female.gif';
            sex_h.value = '2';
        }
        else
        {
            sex.innerHTML = 'male';
            sex_p.src = '/images/male.gif';
            sex_h.value = '1';
        }
        
        return false;
    }
    
    function checkBotAnalyse()
    {
        var name = trim(document.getElementById('analyse_name').value);
        var surname = trim(document.getElementById('analyse_surname').value);
        var name_bool = false;
        var surname_bool = false;
        var code_analyse_name = document.getElementById('code_analyse_name');
        var code_analyse_surname = document.getElementById('code_analyse_surname');
        
        if(!name)
            document.getElementById('analyse_name_check').src = '/images/icon_empty.gif';
        else if((name.length > 1) && validate_latin(name))
        {
            document.getElementById('analyse_name_check').src = '/images/icon_success.gif';
            name_bool = true;
        }
        else
            document.getElementById('analyse_name_check').src = '/images/icon_error.gif';
            
        if(!surname)
            document.getElementById('analyse_surname_check').src = '/images/icon_empty.gif';
        else if((surname.length > 1) && validate_latin(surname))
        {
            document.getElementById('analyse_surname_check').src = '/images/icon_success.gif';
            surname_bool = true;
        }
        else
            document.getElementById('analyse_surname_check').src = '/images/icon_error.gif';
        
        
        if(name_bool && surname_bool)
        {
            code_analyse_name.value = document.getElementById('d_code_analyse_name').value;
            code_analyse_surname.value = document.getElementById('d_code_analyse_surname').value;
        }
        else
        {
            code_analyse_name.value = '';
            code_analyse_surname.value = '';
        }
    }
    
    function validateFormAnalyse(echo)
    {
        var name = trim(document.getElementById('analyse_name').value);
        var surname = trim(document.getElementById('analyse_surname').value);
        
        if(!name)
        {
            if(echo)
                alert('Please, type your name');
                
            return false;
        }
        else if(name.length < 2)
        {
            if(echo)
                alert('Name length cannot be less than 2 symbols');
                
            return false;
        }
        else if(!validate_latin(name))
        {
            if(echo)
                alert('Name can contain only Latin characters');
                
            return false;
        }
        else if(!surname)
        {
            if(echo)
                alert('Please, type your surname');
                
            return false;
        }
        else if(surname.length < 2)
        {
            if(echo)
                alert('Surname length cannot be less than 2 symbols');
                
            return false;
        }
        else if(!validate_latin(surname))
        {
            if(echo)
                alert('Surname can contain only Latin characters');
                
            return false;
        }
        else
            return true;    
    }
// analyse end
// find
    function validateFindForm(echo)
    {
        var s = trim(document.getElementById('s').value);
        
        if(!s)
        {
            if(echo)
                alert('Please, type surname');
                
            return false;
        }
        else if(s.length < 2)
        {
            if(echo)
                alert('Surname length cannot be less than 2 symbols');
                
            return false;
        }
        else if(!validate_latin(s))
        {
            if(echo)
                alert('Surname can contain only Latin characters');
                
            return false;
        }
        else
            return true;  
    }
// find end
