   
function CheckRegForm()    
{        
    var bSuccess = true;
    if (!CheckField('OrgName', /.{3,64}/))
    {
        ShowAllError('OrgName');
        //return false;
        bSuccess = false;
    } 
    else
    {
        HideAllError('OrgName');
    }
    
    if (!CheckField('OrgNameEN', /.{3,64}/))
    {
        ShowAllError('OrgNameEN'); 
        //return false;
        bSuccess = false; 
    }
    else
    {
        HideAllError('OrgNameEN');
    } 
    
    if (!CheckField('RegDate', /[0-9]{2}\.[0-9]{2}\.[0-9]{4}/))
    {
        ShowAllError('RegDate'); 
        //return false;
        bSuccess = false; 
    }
    else
    {
        HideAllError('RegDate');
    }
        
    if(!CheckSelectDownField('OrgType'))       
    {
        ShowAllError('OrgType'); 
        //return false;
        bSuccess = false; 
    }
    else
    {
        HideAllError('OrgType');
    }
    
    if(getObject('OrgType').value != 'Неформална гражданска група')
    {
        if(!CheckSelectDownField('Statute'))       
        {
            ShowAllError('Statute'); 
            //return false;
            bSuccess = false; 
        }
        else
        {
            HideAllError('Statute');
        } 
    }
        
    if(!CheckSelectDownField('Region'))       
    {
        ShowAllError('Region'); 
        //return false;
        bSuccess = false; 
    }
    else
    {
        HideAllError('Region');
    } 
    
    if(!CheckField('Town', /.{2,}/))       
    {
        ShowAllError('Town'); 
        //return false;
        bSuccess = false; 
    }
    else
    {
        HideAllError('Town');
    } 
    
    if(!CheckField('Address', /.{2,}/))       
    {
        ShowAllError('Address'); 
        //return false;
        bSuccess = false; 
    }
    else
    {
        HideAllError('Address');
    }
    
    if(!getObject('Phone').value.match(/[0-9 \+\(\)\-,;]{6,}/) && !getObject('Mobile').value.match(/[0-9 \+\(\)\-,;]{6,}/))
    {
        ShowAllError('Phone');
        //return false;
        bSuccess = false; 
    }
    else
    {
        HideAllError('Phone');
    }

    if(!CheckField('EMail', /.{3,}@.{3,}\..{2,}/))       
    {
        ShowAllError('EMail'); 
        //return false;
        bSuccess = false; 
    }
    else
    {
        HideAllError('EMail');
    }

    if(!CheckField('Representative', /.{2,} .{2,}/))       
    {
        ShowAllError('Representative'); 
        //return false;
        bSuccess = false; 
    }
    else
    {
        HideAllError('Representative');
    }    

    if(!CheckField('Members', /.{2,} .{2,}/))       
    {
        ShowAllError('Members'); 
        //return false;
        bSuccess = false; 
    }
    else
    {
        HideAllError('Members');
    }     
      
    if(!CheckSelectField('ScopeOfActivity'))       
    {
        ShowAllError('ScopeOfActivity'); 
        //return false;
        bSuccess = false; 
    }
    else
    {
        HideAllError('ScopeOfActivity');
    } 
    
    /*
    if(!CheckField('LastProject', /.{2,}/))       
    {
        return false;
    }  
    */
    //return true;
    return bSuccess;
}   

function ChangeOrgType(strSelectedValue)
{
    if(strSelectedValue == 'Неформална гражданска група')
    {
        document.getElementById("Statute").disabled = true;
        document.getElementById("Statute")[0].selected = true;
    }    
    else
    {
        document.getElementById("Statute").disabled = false;  
    }
}

/*
function ConvertCyrToLatin (pCyrField, pLatinField) 
{
    cyr = "абвгдежзийклмнопрстуфхцчшщъьюяАБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЬЮЯ1234567890-.\", ";
    lat_bg = new Array('a','b','v','g','d','e','zh','z','i','y','k','l','m','n','o','p','r','s','t','u','f','h','ts','ch','sh','sht','a','y','yu','ya','A','B','V','G','D','E','Zh','Z','I','Y','K','L','M','N','O','P','R','S','T','U','F','H','Ts','Ch','Sh','Sht','A','Y','Yu','Ya','1','2','3','4','5','6','7','8','9','0','-','.','\"',','," ");

    var latin_str = "";
    var i;
    
    var value = pCyrField.value;
    for (i=0; i<value.length; i++)
    {
        var letter = value.charAt(i);
        var index = cyr.indexOf(letter);
        if ((-1) == index)
        {
            if (0 == i) 
            {
                latin_str = letter;
            }
            else 
            {
                latin_str += letter;
            }
        }
        else
        {
            if (0 == i) 
            {
                latin_str = lat_bg[index];
            }
            else 
            {
                latin_str += lat_bg[index];
            }
        }
    }
    pLatinField.value = latin_str;
    return;
}
*/

function GetXmlHttpObject()
{
    var xmlHttp = null;
    try
    {
        // Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
    }
    catch (e)
    {
        // Internet Explorer
        try
        {
            xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
        }
        catch (e)
        {
            try
            {
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e)
            {
                alert("Your browser does not support AJAX!");
            }
        }
    }
    return xmlHttp;
}
    
var strComboboxLabel = ''; 

var pTimer; 
function GetItemsTimer(strKey, strLabel)
{
    if(strKey.length < 3 && pTimer)
    {
        clearTimeout(pTimer);
        RemoveCombolist();
    }
    else
    {
        clearTimeout(pTimer);
        pTimer = window.setTimeout(function() { GetItems(strKey, strLabel); }, 500);  
    }
}
  
function GetItems(strKey, strLabel) 
{           
    var xmlHttp = GetXmlHttpObject();
    if(xmlHttp)
    {
        xmlHttp.onreadystatechange = function()
        {
            if(xmlHttp.readyState == 4)
            {
                var re = new RegExp('[a-z]+');
                if (xmlHttp.responseText.match(re))       
                {
                    RemoveCombolist();
                    
                    var ComboList = document.createElement('DIV');
                    ComboList.id = 'combolist'; 
                    ComboList.className = 'combolist'; 
                    ComboList.innerHTML = xmlHttp.responseText;
                    document.getElementById(strLabel + "Combobox").appendChild(ComboList);
                    strComboboxLabel = strLabel; 
                }
            }
        }
        var d = new Date();    
        xmlHttp.open("GET", strRootPath + "ajax.php?m=registration&v=combo&label=" + strLabel + "&key=" + Url.encode(strKey) + "&t=" + d.getTime(), true); 
        xmlHttp.send(null);
    }
}

function SetComboValue(pValue)
{
    document.getElementById(strComboboxLabel).value = pValue.innerHTML;
    RemoveCombolist();    
}

function RemoveCombolist()
{
    if(document.getElementById("combolist") && strComboboxLabel != '')
    {
        document.getElementById(strComboboxLabel + "Combobox").removeChild(document.getElementById("combolist")); 
        strComboboxLabel = '';
    }
}

/**
*
*  URL encode / decode
*  http://www.webtoolkit.info/
*
**/
 
var Url = {
 
    // public method for url encoding
    encode : function (string) {
        return escape(this._utf8_encode(string));
    },
 
    // public method for url decoding
    decode : function (string) {
        return this._utf8_decode(unescape(string));
    },
 
    // private method for UTF-8 encoding
    _utf8_encode : function (string) {
        string = string.replace(/\r\n/g,"\n");
        var utftext = "";
 
        for (var n = 0; n < string.length; n++) {
 
            var c = string.charCodeAt(n);
 
            if (c < 128) {
                utftext += String.fromCharCode(c);
            }
            else if((c > 127) && (c < 2048)) {
                utftext += String.fromCharCode((c >> 6) | 192);
                utftext += String.fromCharCode((c & 63) | 128);
            }
            else {
                utftext += String.fromCharCode((c >> 12) | 224);
                utftext += String.fromCharCode(((c >> 6) & 63) | 128);
                utftext += String.fromCharCode((c & 63) | 128);
            }
 
        }
 
        return utftext;
    },
 
    // private method for UTF-8 decoding
    _utf8_decode : function (utftext) {
        var string = "";
        var i = 0;
        var c = c1 = c2 = 0;
 
        while ( i < utftext.length ) {
 
            c = utftext.charCodeAt(i);
 
            if (c < 128) {
                string += String.fromCharCode(c);
                i++;
            }
            else if((c > 191) && (c < 224)) {
                c2 = utftext.charCodeAt(i+1);
                string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
                i += 2;
            }
            else {
                c2 = utftext.charCodeAt(i+1);
                c3 = utftext.charCodeAt(i+2);
                string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
                i += 3;
            }
 
        }
 
        return string;
    }
}
    
var strCurrentToolTipID    
function ShowToolTip(strToolTipID)
{
    alert
    HideToolTip();
    document.getElementById(strToolTipID).style.display = 'block';   
    strCurrentToolTipID = strToolTipID; 
}

function HideToolTip()
{
    if(strCurrentToolTipID)
    {
        document.getElementById(strCurrentToolTipID).style.display = 'none';
        strCurrentToolTipID = null;
    }
}   