function loadHttpRequestReeaccion(url, divResult, form) {
    var ajax = XmlHttpRequest();
    var div = document.getElementById(divResult);
    var data = ((form != '') ? get_data(form.name) : '');
    var ID = Math.random();
    ajax.open("POST", url, true);
    ajax.onreadystatechange = function(){
        if (ajax.readyState == 0) {
            div.innerHTML = "Enviando la solicitud...";
        }
        if (ajax.readyState == 1 || ajax.readyState == 2 || ajax.readyState == 3) {
            	div.innerHTML = "";            	
        }
        if (ajax.readyState == 4) {
            if (ajax.status == 200) {
            	if(ajax.responseText != "(0)"){
            		//div.style.display = "inline"
            		div.innerHTML = "&nbsp;"+ajax.responseText
            	} else {
            		//div.style.display = "none";
            		div.innerHTML = "&nbsp;";
            	}
            } else {
                if (ajax.status == 404) {
                    div.innerHTML = "La direccion no existe";
                } else {
                    div.innerHTML = "Error: " + ajax.status;
                    return true;
                }
            }
        }
    }
    ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    ajax.setRequestHeader("Content-length", data.length);
    ajax.setRequestHeader("Connection", "close");
    ajax.send("ID=" + ID + data);
}


function contarReacciones(idContenido){
	for(var i = 0; i < arrReacciones.length; i++){
		loadHttpRequestReeaccion('../_post/ionline/contadorReacciones.php?idReaccion='+arrReacciones[i]+'&idContenido='+idContenido, 'votos_'+[i], '');
	}
}

function select_all(network,obj){
	
	var ul = document.getElementById('share-list-'+network);
	var lis = ul.childNodes;
	var limit = lis.length;
	var checked = obj.checked;
		
	for(j=1;j<limit,j<51;j++){
		
		arrChk = lis[j].getElementsByTagName('input');
		chkaa = arrChk[0];

		if(checked){
			chkaa.checked = 'checked';
			if(!share_email(chkaa.value,chkaa))return false;
		}else{
			chkaa.checked = '';
			share_email(chkaa.value,chkaa);
			}
		
	}
}


function share_email(email,obj){
	//debugger;
	var destinatarios = document.getElementById('destinatarios').value;
	
	if(destinatarios){
		arrDestinatarios = destinatarios.split(',');
	}else{
		arrDestinatarios = new Array;
	}
	
	if(obj.checked){
		
			if(!in_array(email, arrDestinatarios)){ 
				arrDestinatarios.push(email);
				if(arrDestinatarios.length > 50){
					obj.checked = '';
					alert('Ultrapassou o número máximo de destinatários (50)');
					return false;
				}
			}
			
		
	}else{
		
		var arr2 = new Array;
		var limit = arrDestinatarios.length;

		for(i=0;i<limit;i++){
		
			if(arrDestinatarios[i] != email){
				arr2.push(arrDestinatarios[i]);
			}
			
		}

		arrDestinatarios = arr2;
		
	}
	
	document.getElementById('destinatarios').value = arrDestinatarios.join();
	return true;
}







function share(network){
	
		if(document.getElementById('destinatarios').value == 'Separe os endereços de email (máx. 50) com vírgulas') 
		document.getElementById('destinatarios').value = '';
		
		if(document.getElementById('network').value){
			
			prevn = document.getElementById('network').value;
			document.getElementById('box-'+prevn).style.display = 'none';
			document.getElementById('share-img-'+prevn).src = '../_modulos/notas/_imgs/ionline/'+prevn.toLowerCase()+'.gif';
			
		}
		
		document.getElementById('share-img-'+network).src = '../_modulos/notas/_imgs/ionline/'+network.toLowerCase()+'_selected.gif';
		document.getElementById('box-'+network).style.display = 'block';
		document.getElementById('network').value = network;

	
}
function share_post(){
	
	if(!document.getElementById('network').value){
		
		alert('Por favor seleccione su agenda');
		return false;
		
	}else{
		
		network = document.getElementById('network').value;
	
	}
	
	if(!document.getElementById('owner_email_'+network).value){
		
		alert('Por favor ingrese su email');
		return false;
		
	}else{
		
		email = document.getElementById('owner_email_'+network).value.trim();
		
	}
	
	if(!document.getElementById('owner_password_'+network).value){
		
		alert('Por favor ingrese su clave');
		return false;
		
	}else{
		
		password = document.getElementById('owner_password_'+network).value.trim();
		
	}
	
	document.getElementById('share_loader').style.display = 'block';
	
	queryString = "?email="+email+"&password="+password;
	
	_post('../_post/ionline/share'+network+'.php'+queryString);
	
}


function view_imagen(actual,move){
	
	anterior = actual;
	
	if(move == 'next') actual++;
	if(move == 'prev') actual--;
	
	if(document.getElementById('fotogaleria'+actual)){
		
		hide('fotogaleria'+anterior);
		hide('fotogaleria-icon'+anterior);
		hide('fotogaleria-menu'+anterior);
		
		show('fotogaleria'+actual);
		show('fotogaleria-icon'+actual);
		show('fotogaleria-menu'+actual);
		}
	
}

function view_tab(tab_name){
	
	hide('content_'+tab_active);
	show('content_'+tab_name);
	
	document.getElementById('link_'+tab_name).className = 'active';
	document.getElementById('link_'+tab_active).className = '';
	
	tab_active = tab_name;
	
	}
	
function onMediaPlayerReady(id){
	if(id=="audioPlayer"){
		var player=document.getElementById(id);		
		player.setMedia('<data><type>audio</type><file><![CDATA['+audio+']]></file></data>');		
	}
	
	if(id=="mediaPlayer"){
		var player=document.getElementById(id);
		player.setMedia('<data><type>video</type><file><![CDATA['+video+']]></file><image><![CDATA['+video_preview+']]></image><link>'+detalle_video+'</link><publish><![CDATA['+embed+']]></publish><url>'+detalle_video+'</url><title><![CDATA['+titulo+']]></title><track>../_post/ionline/contador_videos.php?idCMSPortal=102&idCMSModulo=11&idAdjunto='+id_video+'</track></data>');
	}
}

function playAudio(id,audio){
	if(id=="audioPlayer"){
		var player=document.getElementById(id);
		player.setMedia('<data><type>audio</type><file><![CDATA['+audio+']]></file></data>');
	}
}


function calificar_notaInterior(idCMSModulo,idContenido,votos,set){
	/**/
	
	var frm 						= document.getElementById('frmRanquearNota');
	var query_string 		= '../_post/ionline/calificar.php?';
	var strError 				= false;
	var cantVotosTop		= document.getElementById('cantidadVotosViewTop');
	var cantVotosMiddle	= document.getElementById('cantidadVotosViewMiddle');
	var cantVotosBottom	= document.getElementById('cantidadVotosViewBottom');
	var cantVotos 			= document.getElementById('cantidadVotosHidden');
	
	
	frm.idCMSModulo.value 	= idCMSModulo;
	frm.idContenido.value 	= idContenido;
	frm.votos.value 		= votos;
	
	
	if(consultarGalleta('votar_'+idCMSModulo+'_'+idContenido) || consultarGalleta('votar_'+idCMSModulo+'_'+idContenido+'_sum')){
		alert("Você já avaliou esta nota.");
		strError = true;
	}
	
	
	if(!strError){
		if(cantVotosTop){
			cantVotosTop.innerHTML 		= (parseInt(cantVotos.value)+1);
		}
		
		if(cantVotosMiddle){
			cantVotosMiddle.innerHTML 		= (parseInt(cantVotos.value)+1);
		}
		
		if(cantVotosBottom){
			cantVotosBottom.innerHTML 	= (parseInt(cantVotos.value)+1);
		}
			
		for(i = 0 ; i < frm.length ; i++ ){
		  	query_string += frm.elements[i].name+"="+frm.elements[i].value+"&";
		}
		
		
		swapImage(idCMSModulo,idContenido,votos,set);
		for(i=1;i<=5;i++){
			obj = document.getElementById(set+'_'+idCMSModulo+'_'+idContenido+'_'+i);
			if(obj){
				obj.style.cursor = 'default';
				obj.onclick = null;
				obj.onmouseover  = null;
				obj.onmouseout = null;
			}
		}
		
		swapImage(idCMSModulo,idContenido,votos,'upper'+set);
		for(i=1;i<=5;i++){
			objUpper = document.getElementById('upper'+set+'_'+idCMSModulo+'_'+idContenido+'_'+i);
			if(objUpper){
				objUpper.style.cursor = 'default';
				objUpper.onclick = null;
				objUpper.onmouseover  = null;
				objUpper.onmouseout = null;
			}
		}
		
		swapImage(idCMSModulo,idContenido,votos,'middle'+set);
		for(i=1;i<=5;i++){
			objUpper = document.getElementById('middle'+set+'_'+idCMSModulo+'_'+idContenido+'_'+i);
			if(objUpper){
				objUpper.style.cursor = 'default';
				objUpper.onclick = null;
				objUpper.onmouseover  = null;
				objUpper.onmouseout = null;
			}
		}
		
		swapImage(idCMSModulo,idContenido,votos,'down'+set);
		for(i=1;i<=5;i++){
			objDown = document.getElementById('down'+set+'_'+idCMSModulo+'_'+idContenido+'_'+i);
			if(objDown){
				objDown.style.cursor = 'default';
				objDown.onclick = null;
				objDown.onmouseover  = null;
				objDown.onmouseout = null;
			}
		}
	
		_post(query_string);
		
	}
	
}

function swapImage(idModulo,idContenido,obj,set) {
		
	var img = "../../_modulos/notas/_imgs/ionline/star",
		estado = new Array("2", "3"),
		ext = ".gif";
		
    for (var i = 1; i <= obj; ++i){
			if(document.getElementById(set+"_" + idModulo +'_'+ idContenido + '_' + i)){
				document.getElementById(set+"_" + idModulo +'_'+ idContenido + '_' + i).src = img + estado[1] + ext;
			}
		}
}

function in_array (needle, haystack, argStrict) {

    var key = '', strict = !!argStrict;

    if (strict) {
        for (key in haystack) {
            if (haystack[key] === needle) {
                return true;
            }
        }
    } else {
        for (key in haystack) {
            if (haystack[key] == needle) {
                return true;
            }
        }
    }

    return false;
}

