function ValidateArray () {
	this.username = 0;
	this.email = 1;
}

 Val = new ValidateArray();
 var elementNum;
function Ajax(file, data, div, method)
{
     $.ajax({
        type: method,
        url: file,
        data: data,
        cache: false,
        success: function(html){
         
        	document.getElementById(div).innerHTML = html;
        //  $("#"+div).html(html);
         valid = html;
        }
     });
}

function SendMessage(file, data, div, method)
{
	document.getElementById('message'+div).value = '';
     $.ajax({
        type: method,
        url: file,
        data: data,
        cache: false,
        success: function(html){
        	
        valid = html;
        }
     });
}

function touch_ajax(file)
{
     $.ajax({
        type: "GET",
        url: file,
        data: null,
        cache: false 
     });
}


function validate(field, content, div) {
	   $.ajax({
        type: "GET",
        url: '/validations/field/'+field+'/'+content+'/',
        cache: false,
        success: function(html){
       	  if(html != ''){
       	  	$('#'+div).css("display", '');
	        string=html.split("[DELIMITER]");
	        $("#"+div).html(string[0]);
	   
	        eval("Val."+field +"= string[1]");
	   
	      }else{
	      	$('#'+div).css("display", 'none');
	      }
        }
        
     });

}

function validateUser(field, content, div, path) {
	   $.ajax({
        type: "GET",
        url: '/validations/validUser/'+content,
        cache: false,
        success: function(html){
        string=html.split("[DELIMITER]");
        $("#"+div).html(string[0]);
   
        eval("Val."+field +"= string[1]");
   
        }
        
     });

}

function validateEmail(field, content, div, path) {

     $.ajax({
        type: "GET",
        url: '/validations/validEmail/'+content,
        cache: false,
        success: function(html){
        string=html.split("[DELIMITER]");
        $("#"+div).html(string[0]);
   
        eval("Val."+field +"= string[1]");
   
        }
        
     });
}

function passwordStatus(field, content, div, path) {

     $.ajax({
        type: "GET",
        url: '/validations/passwordStatus/'+content,
        cache: false,
        success: function(html){
        string=html.split("[DELIMITER]");
        $("#"+div).html(string[0]);
   
        eval("Val."+field +"= string[1]");
   
        }
        
     });
}

function checkValidate( arr ) {
	retval = true;
	for (var i = 0;i<arr.length;i++) {

			 if ( eval("Val."+arr[i]) == 0 ) {
			 	alert('���� ��������� ���� ������ ������ �� ��������� ��������!');
			 	retval = false;
	
			 }
			 
	}
	return retval;
		
}

 
function dg_keydown(event)
{
 
	if (event.keyCode == 40)  {
		document.getElementById('users_list').focus();
		document.getElementById('users_list').selectedIndex = 0;
	 
	}
	else if ( event.keyCode == 13 ) {
		document.getElementById('key_search').style.display = 'none';	
		document.getElementById('user_id').value = 'auto';
	}
	else {
		val = document.getElementById('des').value;
		obj = document.getElementById('key_search');
		Ajax('/search/bynick/'+val,'abs','key_search','GET');
		document.getElementById('key_search').style.display = 'block';
		if ( val == '' ) {
		document.getElementById('key_search').style.display = 'none';	
		}
	}

}

function RateObject(id, star, elm){
	  $.ajax({
        type: 'POST',
        url: '/ajaxtabs/RateObject/'+id+'/'+star,
        data: null,
        cache: false,
        success: function(html){
           $(elm).parent().parent().parent().html(html);
        }
     });

}

function RateUser(id, star, elm){
	  $.ajax({
        type: 'POST',
        url: '/ajaxtabs/RateUser/'+id+'/'+star,
        data: null,
        cache: false,
        success: function(html){
           $(elm).parent().parent().parent().html(html);
        }
     });

}


function searchKeyDown(event, text, value) {
	
	if (event.keyCode == 13 ) {
		//document.getElementById('des').focus();
		document.getElementById('user_id').value = value;
		document.getElementById('des').value = text;
		document.getElementById('key_search').style.display = 'none';

		
	}
	else if ( event.keyCode != 40 && event.keyCode != 38) {
	
		document.getElementById('des').focus();
	
	}

	 
}

function searchClick(event, text, value) {
	document.getElementById('user_id').value = value;
	document.getElementById('des').value = text;
	document.getElementById('key_search').style.display = 'none';
	document.getElementById('des').focus();
}

function checkSubm(event) {
	
	if ( event.keyCode == 13 && document.getElementById('key_search').style.display != 'none') return false;
}

function execute_js(file, data)
{
     $.ajax({
        type: 'post',
        url: file,
        data: data,
        cache: false,
        success: function(html){
        	eval(html);
        }
     });
}

