function renderHTML(jUrl, jParam, jDiv,jTab){
	$.post(jUrl, { parameter:jParam, div:jDiv, tab:jTab },
	   function(data)
	   {
 	     $('#'+jDiv).html(data);
	   });
	
}


function renderVAL(jUrl, jParam, jDiv,jTab){
	$.post(jUrl, { parameter:jParam, div:jDiv, tab:jTab },
	   function(data)
	   {
 	     $('#'+jDiv).val(data);
	   });
	
}

function renderVALToFacebook(jUrl, jParam, jDiv,jTab,ads_slot){
	$.post(jUrl, { parameter:jParam, div:jDiv, tab:jTab },
	   function(data)
	   {
 	     $('#'+jDiv).val(data+'-'+ads_slot);
	   });
	
}


function updateStat(jUrl, jParam, jDiv,jTab){
	$.post(jUrl, { parameter:jParam, div:jDiv, tab:jTab },
	   function(data)
	   {
 	     //$('#'+jDiv).html(parseInt($('#'+jDiv).html())+parseInt(data));
 	    $('[id^=\''+jDiv+'\']').html( parseInt( $('[id^=\''+jDiv+'\']').html())+parseInt(data) )
	   });
	
}


function sendComment(jUrl, jParam,jMsg, jDiv, jSev){
	if(messageLogin()){
		$.post(jUrl, { parameter:jParam, div:jDiv, serv:jSev, msg: $('#'+jMsg).val() },
		   function(data)
		   {
	 	     $('#'+jDiv).html(data);
	 	     $('#'+jMsg).val('');
		   });
	}
	
}
function sendComment2(jUrl, jParam,jMsg, jDiv, jSev){
	//if(messageLogin()){
		$.post(jUrl, { parameter:jParam, div:jDiv, serv:jSev, msg: $('#'+jMsg).val() },
		   function(data)
		   {
	 	     $('#'+jDiv).html(data);
	 	     $('#'+jMsg).val('');
		   });
	//}
	
}
function sendDelComment(jUrl, jParam){
	
		$.post(jUrl, { parameter:jParam },
		   function(data)
		   {	 	   
	 	    jQuery.facebox($('.div_sendDelComment').html());
			return false;
		   });
	
	
}

function sendCommentOnPL(jUrl,jMsg, jDiv){
	
	$.post(jUrl, { msg: $('#'+jMsg).val() },
	   function(data)
	   {
 	     $('#'+jDiv).html(data);
	   });
	
}


function player(jUrl,jGcode,jDiv,jNextId,jAutoStart){	
	var jagen;
	if(isIE && isWin && !isOpera){
		 jagen=1;
	}else{
		 jagen=2;
	}
	$.post(jUrl, { GCODE:jGcode, nextId:jNextId, autoStart:jAutoStart, userAgen:jagen},
			   function(data)
			   {				
		 	     $('#'+jDiv).html(data);
			   });
		
}
function addPlaylist(url,jDiv,flag){	

	if(url){
		$.ajax({ url: url, 
				beforeSend:function(){ 
	            $('#'+jDiv).html('<img src="images/loader-facebok.gif" />'); 
	        	},
				success: function(data){	
	        			        		
	        		//$('#'+jDiv).html(data);
	        		
	        		var temp = new Array(); 
	        			temp = data.split('::|::');
	        		
	        			if(flag!=1){
	        				$('div.complete-status').css("display","block");
		        			$('div.complete-status').html(temp[0]);	        			
	        			}
	        			$('#playlist-tmp-num').html(temp[1]);
						$('#'+jDiv).html(temp[2]);
					
		      	}
		});
	}
		
}
function ajaxFramework(url,jDiv){	

	if(url){
		$.ajax({ url: url, 
				beforeSend:function(){ 
	            $('#'+jDiv).html('<img src="images/loader-facebok.gif" />'); 
	        	},
				success: function(data){
	        			if(data){
	        				$('#'+jDiv).html(data)     			
	        			}
		      	}
		});
	}
		
}

function ajaxFrameworkClass(url,jClass){	

	if(url){
		$.ajax({ url: url, 
				beforeSend:function(){ 
	            $('.'+jClass).html('<img src="images/loader-facebok.gif" />'); 
	        	},
				success: function(data){
	        			if(data){
	        				$('.'+jClass).html(data)     			
	        			}
		      	}
		});
	}
		
}

function ajaxFrameworkVal(url,jDiv){	

	if(url){
		$.ajax({ url: url, 
				success: function(data){
	        			if(data){
	        				$('#'+jDiv).val(data)     			
	        			}
		      	}
		});
	}
		
}

function setIDSong(jDiv,jGcode){
	$('#'+jDiv).val(jGcode);
}

function setSongCover(jDiv,jGcode){

	$.ajax({ url: 'main/getSongCover/'+jGcode, 
			beforeSend:function(){ 
            $('#'+jDiv).html('<img src="images/loader-facebok.gif" />'); 
        	},
			success: function(data){
        			if(data){
        				$('#'+jDiv).html(data);
        				$("#"+jGcode).addClass("playing");
        			}
	      	}
	});

}

function linkTo(url,jGcode){
	window.location=url+'/'+jGcode;
	//alert(jGcode);

}

function copyit(field) {
	   var temp=document.getElementById(field);
	   temp.focus()
	   temp.select()
	   therange=temp.createTextRange()
	   therange.execCommand("Copy")
}

function logout(url,locate){
	window.location.href = url;
	/*
	$.ajax({
		url: url,
		type: "POST",
		data: {vredirect : window.location.href},
		success: function(data) {
		alert(data);
		//alert(locate);
			if(data){
				//window.location.href = data;
			}else{
				//window.location.href = locate;
			}
				
	  	}
	});
	*/
}

function ckeckrude( data ,cid)
{
	//block คำหยาบ และประโยคที่จะนำมาแทนที่
	var wordrude = new Array ( "ashole","a s h o l e","a.s.h.o.l.e","bitch","b i t c h","b.i.t.c.h","shit","s h i t","s.h.i.t","fuck","dick","f u c k","d i c k","f.u.c.k","d.i.c.k","มึง","มึ ง","ม ึ ง","ม ึง","มงึ","มึ.ง","มึ_ง","มึ-ง","มึ+ง","กู","ควย","ค ว ย","ค.ว.ย","คอ วอ ยอ","คอ-วอ-ยอ","ปี้","เหี้ย","ไอ้เหี้ย","เฮี้ย","ชาติหมา","ชาดหมา","ช า ด ห ม า","ช.า.ด.ห.ม.า","ช า ติ ห ม า","ช.า.ติ.ห.ม.า","สัดหมา","สัด","เย็ด","หี","สันดาน","แม่ง","ระยำ","ส้น ตีน","แตด","แสส","แสด","แสรด","คุวย","คุวย","จวย","กวย");
	var wordchange = '<font style="color:red">xxx</font>';
	
	for ( n = 0 ; n < wordrude.length ; n++ )
	{
	pattern = new RegExp( wordrude[n] , "gi" );
	data = data.replace( pattern , wordchange );
	};
	
	$('#'+cid).html(data);
	//document.write(data);
	//return data;
}

function write_html(html){
	document.write('<font style="color:red">xxx</font>');
}

function HtmlEncode(html) {
	return $('<div/>').text(html).html();
}

function HtmlDecode(text) {
	return $('<div/>').html(text).text();
}

function autocomplete(vurl,jcat,jid,jbt){
			    var options = {
			      serviceUrl: vurl,
			      width: 300,
			      minChars:3, 
			      delimiter: /(,|;)\s*/,
			      onSelect: function(value, data){
			    	$('#'+jid).val(data);
			    	$('#'+jbt).click();
			    	//alert('You selected: ' + value + ', ' + data); 
			      },
			      deferRequestBy: 0, //miliseconds
			      params: { search_cat: jcat },
			      noCache: false //set to true, to disable caching
			    };

			    a1 = $('#'+jid).autocomplete(options);

}
