var languageselector = 'eng';
lang=0;
eng=new Array(97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,87,82,84,83,67,74,90); 
geo=new Array(4304,4305,4330,4307,4308,4324,4306,4336,4312,4335,4313,4314,4315,4316,4317,4318,4325,4320,4321,4322,4323,4309,4332,4334,4327,4310,4333,4326,4311,4328,4329,4319,4331,91,93,59,39,44,46,96);
 
function selectLanguage() {
         languageselector = 'eng';
         if (document.mainForm.geoswitch.checked == true) {
                languageselector = 'geo';
         }
} 
function switchgeo() {
            if ( 1 ) {
                  for (i=0; i<=geo.length; i++) {
                        if (eng[i]==event.keyCode) {  
                              event.keyCode=geo[i];
}
                  }
            }
            return true;
}
function CreateTextMask(elementid, masktext)
{
    var element = document.getElementById(elementid);
    
    element.value = masktext;
    
    element.onfocus = function()
    {
        if (element.value == masktext)
        {
            //element.className = "maskable-false";
            element.value = "";
        }
    }
    
    element.onblur = function()
    {
        if (element.value.length == 0)
        {
            //element.className = "maskable-true";
            element.value = masktext;
        }
    }
}

function registrationBox() {
    var maskHeight = $(document).height();
    var maskWidth = $(window).width();
    $('#mask').css({'width':maskWidth,'height':maskHeight});
    //$('#mask').fadeIn(1000); 
    $('#mask').fadeTo(1,0.3); 
    $('.combo').hide();
    var winH = $(window).height();
    var winW = $(window).width();
    $('#dialog').css('width', 500);
    $('#dialog').css('height', 500);
    $('#dialog').css('top',  winH/2-$('#dialog').height()/2);
    $('#dialog').css('left', winW/2-$('#dialog').width()/2);
    $('#dialog').load('registrationForm.php');
    $('#dialog').fadeIn(100);
    $('#mask').click(function () {
    	$('.combo').show();
    	$('.window').hide();
    	$('#mask').hide();
    });
};

function IsNumeric(sText){
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;
	for (i = 0; i < sText.length && IsNumber == true; i++){
	Char = sText.charAt(i);
	if(ValidChars.indexOf(Char) == -1){
	IsNumber = false;
	}
	}
	return IsNumber;
}

	function strstr (haystack, needle, bool) {
	 
	    var pos = 0;
	    
	    haystack += '';
	    pos = haystack.indexOf( needle );
	    if (pos == -1) {
	        return false;
	    } else{
	        if (bool){
	            return haystack.substr( 0, pos );
	        } else{
	            return haystack.slice( pos );
	        }
	    }
	}

function confirmbox(lnk) {
jConfirm('<img src="img/messages/prz_confirm.gif" border="0">', '', function(r) {
    if(r===true){
    	location.href=$("#" + lnk).attr("href");
    }else{
    	return false;
    }
});
return false;
}

function isValidEmailAddress(emailAddress) {
    var pattern = new RegExp(/^(("[\w-\s]+")|([\w-]+(?:\.[\w-]+)*)|("[\w-\s]+")([\w-]+(?:\.[\w-]+)*))(@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$)|(@\[?((25[0-5]\.|2[0-4][0-9]\.|1[0-9]{2}\.|[0-9]{1,2}\.))((25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\.){2}(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})\]?$)/i);
    return pattern.test(emailAddress);
}

function check_encoding(txt){	  
	  $.ajax({
	  	    url: 'check_encoding.php',
	  	    type: "POST",
	  	    async: false,
	  	    cache: false,
	  	    data: 'string='+ txt,
	  	    success: function (data) {
				  		res = false;
				  		if(data!=1){
				  			res=false;
				  		}else{
				  			res=true;
				  		}
	  	    		}
	  });
	  return res;
}

function RegistrationCheck(){
	if($("#name").val()==''){
		$("#error_holder").html('&#1047;&#1072;&#1087;&#1086;&#1074;&#1085;&#1110;&#1090;&#1100; &#1087;&#1086;&#1083;&#1077; &#1030;&#1084;&#8242;&#1103;!');
		$("#name").css( {'border' : '2px solid #d01f25'} );
		$("#name").focus();
		return false;
	}
	if($("#email_reg").val()==''){
		$("#error_holder").html('&#1047;&#1072;&#1087;&#1086;&#1074;&#1085;&#1110;&#1090;&#1100; &#1087;&#1086;&#1083;&#1077; E-mail!');
		$("#email_reg").css( {'border' : '2px solid #d01f25'} );
		$("#email_reg").focus();
		return false;
	}

	if(isValidEmailAddress($("#email_reg").val())===false){
		$("#error_holder").html('&#1055;&#1086;&#1084;&#1080;&#1083;&#1082;&#1072; &#1091; &#1087;&#1086;&#1083;&#1110; E-mail!');
		$("#email_reg").css( {'border' : '2px solid #d01f25'} );
		$("#email_reg").focus();
		return false;
	}
	
	$.post("check_unique_email.php", { email: $("#email_reg").val() },
			function(data){
				if(data==2){
					$("#error_holder").html('&#1055;&#1086;&#1084;&#1080;&#1083;&#1082;&#1072; &#1091; &#1087;&#1086;&#1083;&#1110; E-mail!');
					$("#email_reg").css( {'border' : '2px solid #d01f25'} );
					$("#email_reg").focus();
					return false;
				}
				if(data==1){
					$("#error_holder").html('&#1058;&#1072;&#1082;&#1080;&#1081; E-mail &#1074;&#1078;&#1077; &#1079;&#1072;&#1088;&#1077;&#1108;&#1089;&#1090;&#1088;&#1086;&#1074;&#1072;&#1085;&#1086;!');
					$("#email_reg").css( {'border' : '2px solid #d01f25'} );
					$("#email_reg").focus();
					return false;
				}else{
					if($("#cellphone_code").val()=='0'){
						$("#error_holder").html('&#1054;&#1073;&#1077;&#1088;&#1110;&#1090;&#1100; &#1087;&#1088;&#1077;&#1092;&#1110;&#1082;&#1089; &#1084;&#1086;&#1073;&#1110;&#1083;&#1100;&#1085;&#1086;&#1075;&#1086; &#1086;&#1087;&#1077;&#1088;&#1072;&#1090;&#1086;&#1088;&#1072;!');
						$("#cellphone_code").css( {'border' : '2px solid #d01f25'} );
						$("#cellphone_code").focus();
						return false;
					}
					if($("#cellphone").val()==''){
						$("#error_holder").html('&#1047;&#1072;&#1087;&#1086;&#1074;&#1085;&#1110;&#1090;&#1100; &#1087;&#1086;&#1083;&#1077; &#1085;&#1086;&#1084;&#1077;&#1088; &#1084;&#1086;&#1073;&#1110;&#1083;&#1100;&#1085;&#1086;&#1075;&#1086; &#1090;&#1077;&#1083;&#1077;&#1092;&#1086;&#1085;&#1091;!');
						$("#cellphone").css( {'border' : '2px solid #d01f25'} );
						$("#cellphone").focus();
						return false;
					}

					if(IsNumeric($("#cellphone").val())===false){
						$("#error_holder").html('&#1055;&#1086;&#1084;&#1080;&#1083;&#1082;&#1072; &#1091; &#1087;&#1086;&#1083;&#1110; &#1084;&#1086;&#1073;. &#1090;&#1077;&#1083;&#1077;&#1092;&#1086;&#1085;!');
						$("#cellphone").css( {'border' : '2px solid #d01f25'} );
						$("#cellphone").focus();						
					}
					
					var cellphone = "38" + $("#cellphone_code").val() + $("#cellphone").val();
					$.post("check_unique_cellphone.php", { cellphone: cellphone },
							function(data){
								if(data==2){
									$("#error_holder").html('&#1055;&#1086;&#1084;&#1080;&#1083;&#1082;&#1072; &#1091; &#1087;&#1086;&#1083;&#1110; &#1084;&#1086;&#1073;. &#1090;&#1077;&#1083;&#1077;&#1092;&#1086;&#1085;!');
									$("#cellphone").css( {'border' : '2px solid #d01f25'} );
									$("#cellphone").focus();
									return false;
								}
								if(data==1){
									$("#error_holder").html('&#1058;&#1072;&#1082;&#1080;&#1081; &#1084;&#1086;&#1073;. &#1090;&#1077;&#1083;&#1077;&#1092;&#1086;&#1085; &#1074;&#1078;&#1077; &#1079;&#1072;&#1088;&#1077;&#1108;&#1089;&#1090;&#1088;&#1086;&#1074;&#1072;&#1085;&#1086;!');
									$("#cellphone").css( {'border' : '2px solid #d01f25'} );
									$("#cellphone").focus();
									return false;
								}else{
									document.forms['registrationForm'].submit();
									return true;
								}
							}
					);
				}
			}
	);
}
function RegistrationErrorClear(id){
	$("#error_holder").html('');
	$("#" + id).css( {'border' : '1px solid #ffffff'} );
}

function LoginCheck(){
	if($("#email_login").val()==''){
		$("#error_holder").html('&#1047;&#1072;&#1087;&#1086;&#1074;&#1085;&#1110;&#1090;&#1100; &#1087;&#1086;&#1083;&#1077; E-mail!');
		$("#email_login").css( {'border' : '2px solid #d01f25'} );
		$("#email_login").focus();
		return false;
	}

	if(isValidEmailAddress($("#email_login").val())===false){
		$("#error_holder").html('&#1055;&#1086;&#1084;&#1080;&#1083;&#1082;&#1072; &#1091; &#1087;&#1086;&#1083;&#1110; E-mail!');
		$("#email_login").css( {'border' : '2px solid #d01f25'} );
		$("#email_login").focus();
		return false;
	}
	
	if($("#password").val()==''){
		$("#error_holder").html('&#1047;&#1072;&#1087;&#1086;&#1074;&#1085;&#1110;&#1090;&#1100; &#1087;&#1086;&#1083;&#1077; &#1087;&#1072;&#1088;&#1086;&#1083;&#1100;!');
		$("#password").css( {'border' : '2px solid #d01f25'} );
		$("#password").focus();
		return false;
	}
	document.forms['loginForm'].submit();
	return true;
}

function CommentCheck(){
	if($("#comment").val()==''){
		$("#err_comment").html('&#1047;&#1072;&#1087;&#1086;&#1074;&#1085;&#1110;&#1090;&#1100; &#1087;&#1086;&#1083;&#1077; &#1090;&#1077;&#1082;&#1089;&#1090; &#1087;&#1080;&#1090;&#1072;&#1085;&#1085;&#1103;!');
		$("#comment").css( {'border' : '2px solid #d01f25'} );
		$("#comment").focus();
		return false;
	}
	document.forms['commentForm'].submit();
	return true;
}
function UploadCheck(){
	if($("#file").val()==''){
		$("#err_upload").html('&#1054;&#1073;&#1077;&#1088;&#1110;&#1090;&#1100; &#1092;&#1072;&#1081;&#1083; &#1076;&#1083;&#1103; &#1079;&#1072;&#1074;&#1072;&#1085;&#1090;&#1072;&#1078;&#1077;&#1085;&#1085;&#1103;!');
		$("#file").css( {'border' : '2px solid #d01f25'} );
		$("#file").focus();
		return false;
	}
	document.forms['uploadForm'].submit();
	return true;
}
function UploadErrorClear(id){
	$("#err_upload").html('');
	$("#" + id).css( {'border' : '1px solid #ffffff'} );
}
function CommentErrorClear(id){
	$("#err_comment").html('');
	$("#" + id).css( {'border' : '1px solid #ffffff'} );
}
function VoteCheck(){
	var res;
	$(".poll").each(function (i) {
		if($(this).attr('checked')){
			res=1;
		}
	});
	if(res==1){
		document.forms['voteForm'].submit();
		return true;
	}else{
		$("#error_vote").html('&#1054;&#1073;&#1077;&#1088;&#1110;&#1090;&#1100; &#1074;&#1110;&#1076;&#1087;&#1086;&#1074;&#1110;&#1076;&#1100;!');
		return false;
	}
}
function VoteErrorClear(id){
	$("#error_vote").html('');
}







