$.fn.clearForm = function() {
	return this.each(function() {
		var type = this.type, tag = this.tagName.toLowerCase();
		
		if (tag == 'form')
			return $(':input',this).clearForm();
			
		if (type == 'text' || type == 'password' || tag == 'textarea')
			this.value = '';
		else if (type == 'checkbox' || type == 'radio')
			this.checked = false;
		else if (tag == 'select')
			this.selectedIndex = -1;
	});
};

function cmbTiviCanais(div,id_tivi,id_video) {
	$.ajax({
		type:'GET',
		url:'/ajax/ajax_combo_tivi.php',
		global:false,
		data:'id-tivi='+id_tivi+"&id-video="+id_video,
		success:function(response){
			$("#div-alert").dialog("destroy");
			$("#"+div+"").html(unescape(response));
		},
		beforeSend:function(){
			dialogAlert('Please Wait...','Information',0);
		}
	})
}

function mudarIdioma(idioma,pais,source){
	window.location.href = '/ajax/ajax_muda_idioma.php?novo-idioma='+idioma+'&novo-pais='+pais+'&source='+source;
}


function codigoPlayerExterno(id_tivi){
	var tamanho 	= $("#combo-tamanhos-player").val();
	var medidas 	= (""+tamanho).split("x");												
	
	$.ajax({
		type:'GET',
		url:'/ajax/codigo_player.php',
		global:false,
		data:'id_tivi='+id_tivi+"&width="+medidas[0]+"&height="+medidas[1],
		success:function(response){
			$("#textarea-player-externo").val(response);
		}
	});
}

/* 
	This script and many more are available free online at
	The JavaScript Source!! http://javascript.internet.com
	Created by: Mark O'Sullivan :: http://lussumo.com/
 	Jeff Larson :: http://www.jeffothy.com/
 	Mark Percival :: http://webchicanery.com/ 
*/
function copy(text2copy) {
  if (window.clipboardData) {
    window.clipboardData.setData("Text",text2copy);
  } else {
    var flashcopier = 'flashcopier';
    if(!document.getElementById(flashcopier)) {
      var divholder = document.createElement('div');
      divholder.id = flashcopier;
      document.body.appendChild(divholder);
    }
    document.getElementById(flashcopier).innerHTML = '';
    var divinfo = '<embed src="imgs/_clipboard.swf" FlashVars="clipboard='+escape(text2copy)+'" width="0" height="0" type="application/x-shockwave-flash"></embed>';
    document.getElementById(flashcopier).innerHTML = divinfo;
  }
}


function dialogAlert(msg,titulo,tempo){
	var tempo = new Number(tempo);
	$("#div-alert").empty();
	$("#div-alert").attr('style','height: 133px; width: 262px;');
	$("#div-alert").dialog({
						title:titulo,
						dialogClass:'tivi',
						modal:true,
						overlay:{
							opacity:0.75,
							background:'#000000'
						},
						open:function(){
           					html  = '<div class="loader-add-videos">';
           					html += '<center>';
           					html += "<h4>"+msg+"</h4>";
                        	html += '<img src="/imgs/ajax-loader-cinza.gif" class="loader"/>';
                        	html += '</center>';
                        	html += '</div>';
							
							$("#div-alert").html(html);
						}
					});
	if(tempo > 0){
		setTimeout('$("#div-alert").dialog("destroy");',tempo);
	}
}

function dialogAlertProgress(msg,tempo,id_tivi_canal){
	var tempo = new Number(tempo);
	$("#div-alert").empty();
	$("#div-alert").attr('style','height: 133px; width: 262px;');
	$("#div-alert").dialog({
						dialogClass:'tivi',
						modal:true,
						overlay:{
							opacity:0.75,
							background:'#000000'
						},
						open:function(){
           					html  = '<div class="loader-add-videos">';
           					html += '<center>';
           					html += "<h4>"+msg+"</h4>";
                        	html += '<img src="/imgs/ajax-loader-cinza.gif" class="loader"/>';
                        	html += '</center>';
                        	html += '</div>';
							
							$("#div-alert").html(html);
						}
					});
	if(tempo > 0){
		setTimeout('$("#div-alert").dialog("destroy");',tempo);
	}
}

function dialogLogin(url,id_tivi_canal){
	$("#div-form-login").empty();
	$("#div-form-login").attr('style','height: 283px; width: 412px;');
	$("#div-form-login").dialog({
						dialogClass:'tivi',
						width:450,
						height:350,
						modal:true,
						overlay:{
							opacity:0.75,
							background:'#000000'
						},
						open:function(){
								$.ajax({
									type:'POST',
									data:"id_tivi_canal="+id_tivi_canal,
									url:url,
									success:function(response){
										$("#div-form-login").empty();
										$("#div-form-login").html(response);
									},
									beforeSend:function(){
										$("#div-form-login").html('Loading content - please wait');
									}
								});
						},
						close:function(){
							$("#div-form-login").dialog("destroy");
						}
					});
}

function dialogDadosVideo(id_tivi_canal,id_video){
	$("#div-dados-video").empty();
	$("#div-dados-video").attr('style','height: 283px; width: 412px;');
	$("#div-dados-video").dialog({
						dialogClass:'tivi',
						width:450,
						height:350,
						modal:false,
						overlay:{
							opacity:0.75,
							background:'#000000'
						},
						open:function(){
								$.ajax({
									type:'POST',
									data:"id_tivi_canal="+id_tivi_canal,
									url:'/ajax/modal_dados_video.php',
									success:function(response){
										$("#div-dados-video").empty();
										$("#div-dados-video").html(response);
									},
									beforeSend:function(){
										$("#div-dados-video").html('Loading content - please wait');
									}
								});
						},
						close:function(){
							$("#div-dados-video").dialog("destroy");
						}
					});
}

function updateProgressBar(id_tivi_canal){
	$.ajax({
		type:'POST',
		data:"id-tivi-canal="+id_tivi_canal,
		url:'/ajax/progress_bar.php',
		success:function(response){
			var arrResp = response.split("|");
			if(arrResp[0] < arrResp[1]){
				$("#progressbar").reportprogress(arrResp[0],arrResp[1]);
			}
		}
	});
}
