/////////////////////////////////////////////////////////////////////////////////////////

function vote(user ,post_type, act, post_id, author){ 
   var cookie = post_type+"_"+user+"_"+post_id;
    var name = 'vote'+  post_type+"_"+user+"_"+post_id;
	if (get_cookie(name)==cookie){
		
	}else{	
					if (post_type=='release'){
						$("#release_rate_"+post_id).html("<img src='/ajax/img/ajax_loader.gif' />");
					}
					if (post_type=='artist'){
						$("#artist_rate_"+post_id).html("<img src='/ajax/img/ajax_loader.gif' />");
					}
					if (post_type=='news'){
						$("#news_rate_"+post_id).html("<img src='/ajax/img/ajax_loader.gif' />");
					}
					
					$.post("./ajax/vote.php", {author_id : author ,user_id : user ,post_type : post_type ,act : act, post_id : post_id}, function(data){
					   if (data.length>0 && data!="error"){ 
						 //alert(data);
							if (post_type=='release'){
								if (data > 0){
								$("#release_rate_"+post_id).html("&nbsp;+"+data+"&nbsp;");
								}else{
								$("#release_rate_"+post_id).html("&nbsp;"+data+"&nbsp;");
								}
							}
							
							if (post_type=='news'){
							
								if (data > 0){
								$("#news_rate_"+post_id).html("&nbsp;+"+data+"&nbsp;");
								}else{
								$("#news_rate_"+post_id).html("&nbsp;"+data+"&nbsp;");
								}
							}
							
							if (post_type=='artist'){
							
								if (data > 0){
								$("#artist_rate_"+post_id).html("&nbsp;+"+data+"&nbsp;");
								}else{
								$("#artist_rate_"+post_id).html("&nbsp;"+data+"&nbsp;");
								}
							}
					
						
						 set_cookie(name,cookie,360);
						 data="";
						 }
					   if (data=="error"){
						 alert('no!!');
					   }
	
	 
  })
  }
} 

///////////////////////////////////////JS - COOKIE//////////////////////////////////////////////////

function set_cookie(cookie_name, value, expire)
{
    var expire_date = new Date();
    
    expire_date.setDate(expire_date.getDate() + expire);
    document.cookie = (cookie_name + "=" + escape(value) + ((expire == null) ? "" : ";expires=" + expire_date.toGMTString()));

    return true;
}
function get_cookie(cookie_name)
{
    if (document.cookie.length > 0) {
        cookie_start = document.cookie.indexOf(cookie_name + "=");
        
        if (cookie_start != -1) { 
            cookie_start = ((cookie_start + cookie_name.length) + 1); 
            cookie_end   = document.cookie.indexOf(";", cookie_start);
            
            if ( cookie_end == -1) {
                cookie_end = document.cookie.length;
            }
            
            return unescape(document.cookie.substring(cookie_start, cookie_end));
        } 
    }
    
    return false;
}



function ajaxFileUpload(literal) 
	{
	var fileToUpload = document.getElementById('fileToUpload');
	var hide_this = document.getElementById('hide_this');
	var up_img = document.getElementById('up_img');
	var cur_ava = document.getElementById('cur_ava_img');
	
	var ava_alax = document.getElementById('ava_alax');
	ava_alax.innerHTML = '<img src="/ajax/img/ajax_loader.gif" width="16" height="11" />';
	
	if (literal=="1"){ 
		var photo = document.getElementById('photo2');
				$("#loading")
		.ajaxStart(function(){
			$(this).show();
		})
		.ajaxComplete(function(){
			$(this).hide();
		});

		$.ajaxFileUpload
		( 
			{
				url:'/ajax/upload.php?type=news',
				secureuri:false,
				fileElementId:'fileToUpload',
				dataType: 'json',
				success: function (data, status) 
				{
				
					if(typeof(data.error) != 'undefined')
					{
						if(data.error != '')
						{
							ava_alax.innerHTML = '<span style="color:#FF0000">'+data.error+'</span>';
						}else
						{
							fileToUpload.value = '';
							ava_alax.innerHTML = '<span style="color:#006600">'+data.msg+'</span>';
                            photo.value = data.ava;
							hide_this.style.display='none';
							up_img.innerHTML = '<img src="../../images/news/'+data.f+'" />';
						}
					}
				},
				error: function (data, status, e)
				{
					ava_alax.innerHTML = '<span style="color:orange;">'+e+'</span>';	 				
				}
			}
		)
	}
	if (literal=="2"){
		var photo = document.getElementById('photo2');
				$("#loading")
		.ajaxStart(function(){
			$(this).show();
		})
		.ajaxComplete(function(){
			$(this).hide();
		});

		$.ajaxFileUpload
		(
			{
				url:'/ajax/upload.php?type=release',
				secureuri:false,
				fileElementId:'fileToUpload',
				dataType: 'json',
				success: function (data, status)
				{
					if(typeof(data.error) != 'undefined')
					{
						if(data.error != '')
						{
							ava_alax.innerHTML = '<span style="color:#FF0000">'+data.error+'</span>';
						}else
						{
							fileToUpload.value = '';
							ava_alax.innerHTML = '<span style="color:#006600">'+data.msg+'</span>';
                            photo.value = data.ava;
							hide_this.style.display='none';
							up_img.innerHTML = '<img src="../../images/release/'+data.f+'" />';
						}
					}
				},
				error: function (data, status, e)
				{
					ava_alax.innerHTML = '<span style="color:#FF0000">'+e+'</span>';					
				}
			}
		)
	}
	if (literal=="3"){
	var photo = document.getElementById('photo2');
				$("#loading")
		.ajaxStart(function(){ 
			$(this).show();
		})
		.ajaxComplete(function(){
			$(this).hide();
		});

		$.ajaxFileUpload
		(
			{
				url:'/ajax/upload.php?type=avatar',
				secureuri:false,
				fileElementId:'fileToUpload',
				dataType: 'json',
				success: function (data, status)
				{
					if(typeof(data.error) != 'undefined')
					{
						if(data.error != '')
						{
							ava_alax.innerHTML = '<span style="color:#FF0000">'+data.error+'</span>';
						}else
						{
							fileToUpload.value = '';
							ava_alax.innerHTML = '<span style="color:#006600">'+data.msg+'</span>';
									photo.value = data.ava;
							
									$("#cur_ava").css({"display" : "inline"});
									$("#edit_ava").css({"display" : "none"});
									//$("#hide_this").css({"display" : "none"});
									cur_ava.innerHTML = '<img src="../../images/avatar/'+data.f+'" />'; 
						}
					}
				},
				error: function (data, status, e)
				{
					ava_alax.innerHTML = '<span style="color:#FF0000">'+e+'</span>';					
				}
			}
		)
	}
	if (literal=="4"){
		var photo = document.getElementById('photo2');
				$("#loading")
		.ajaxStart(function(){
			$(this).show();
		})
		.ajaxComplete(function(){
			$(this).hide();
		});

		$.ajaxFileUpload
		(
			{
				url:'/ajax/upload.php?type=artist',
				secureuri:false,
				fileElementId:'fileToUpload',
				dataType: 'json',
				success: function (data, status)
				{
					if(typeof(data.error) != 'undefined')
					{
						if(data.error != '')
						{
							ava_alax.innerHTML = '<span style="color:#FF0000">'+data.error+'</span>';
						}else
						{
							fileToUpload.value = '';
							ava_alax.innerHTML = '<span style="color:#006600">'+data.msg+'</span>';
                            photo.value = data.ava;
							hide_this.style.display='none';
							up_img.innerHTML = '<img src="../../images/artist/'+data.f+'" />';
						}
					}
				},
				error: function (data, status, e)
				{
					ava_alax.innerHTML = '<span style="color:#FF0000">'+e+'</span>';					
				}
			}
		)
	}
	
	//var reg=/\+/g    
	//var literal_s=str.replace(literal, "google");

	
	

		
		
		
		return false;

	}
