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 touch_ajax(file)
{
     $.ajax({
        type: "GET",
        url: file,
        data: null,
        cache: false 
     });
}
 
 
function post_ajax(file, fields)
{
     $.ajax({
        type: "POST",
        url: file,
        data: fields,
        cache: false,
          success: function(html){
        }
     });
}
 
function validate(field, content, div, success, error) {
	   $.ajax({
        type: "GET",
        url: '/validations/field/'+field+'/'+content+'/'+success+'/'+error,
        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('Fill all fields!');
			 	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 AjaxMsgs(file, data, div) {
	$.ajax({
		type: "GET",
		url: file,
		data: data,
		cache: false,
		success: function(html) {
			var old_num = $("#count_messages").val();
			if (html != old_num ) {
				if ( html > 0 ) $("#"+div).addClass("green"); else  $("#"+div).removeClass("green");
				$("#"+div).html("("+html+")"); 
			}
			setTimeout("AjaxMsgs('"+file+"', '', '"+div+"');", 15000);
		}
	});
}

function checkMsg() {
	AjaxMsgs("/main/countMessages", "", "count_messages");
}



function SetCountry(width)
{	id = document.getElementById('country_id').value;
	
	
     $.ajax({
        type: 'POST',
        url:'/ajaxtabs/set_country/'+id+'/'+width,
        data: null,
        cache: false,
        success: function(html){
         
        	document.getElementById('country').innerHTML = html;
        //  $("#"+div).html(html);
         //valid = html;
        }
     });
}

function SetJobCountry()
{	id = document.getElementById('job_country_id').value;
	
     $.ajax({
        type: 'POST',
        url:'/ajaxtabs/set_job_country/'+id,
        data: null,
        cache: false,
        success: function(html){
         
        	document.getElementById('job_country').innerHTML = html;
        //  $("#"+div).html(html);
         //valid = html;
        }
     });
}

function SetCity(width)
{	id = document.getElementById('state_id').value;
	
     $.ajax({
        type: 'POST',
        url:'/ajaxtabs/set_city/'+id+'/'+width,
        data: null,
        cache: false,
        success: function(html){
         
        	document.getElementById('city').innerHTML = html;
        //  $("#"+div).html(html);
         //valid = html;
        }
     });
}

function SetJobCity()
{	id = document.getElementById('job_state_id').value;
	
     $.ajax({
        type: 'POST',
        url:'/ajaxtabs/set_job_city/'+id,
        data: null,
        cache: false,
        success: function(html){
         
        	document.getElementById('job_city').innerHTML = html;
        //  $("#"+div).html(html);
         //valid = html;
        }
     });
}

function RaiseClicks(pr, link) {
	
     $.ajax({
        type: 'POST',
        url: '/ajaxtabs/rase/'+pr,
        data: null,
        cache: false,
        success: function(html){
       
        	//document.getElementById(div).innerHTML = html;
        //  $("#"+div).html(html);
        window.open(link);return true;
         valid = html;
        }
     });
}

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

}

function sndReport(report_div_id){
	
	
	var text = $("#text_" + report_div_id).val();
	var url = document.location.href;
	
	if ( text != '' ) {
	
	$.ajax({
        type: 'POST',
        url: '/ajaxtabs/SendReport/'+text+'/',
        data: 'message='+url,
        cache: false,
        success: function(html){
	     

	   }
     });
     
	}

	
	setVisible(report_div_id);
	
	
}



function changeView(pic, album){
	

	$.ajax({
        type: 'POST',
        url: '/ajaxtabs/ChangeView/'+pic+'/'+album,
        data: null,
        cache: false,
        success: function(html){
         	document.getElementById('main_photo').innerHTML = html;
        }
     });
}

function validateEmail(field, content, div) {
     
     $.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 SearchMe()
{
	if(document.getElementById('text_key').value.length>2)
		
		window.location='/tags-'+document.getElementById('text_key').value.replace(" ","-")+'.html';
	return false;
}
 
