
/******************************************************************
*******************************************************************/
/*
funcion quecrea el objeto ajax
*/
var conexion = false
function Conexion()
{
		 
	if (window.XMLHttpRequest)
	{
	  	conexion = new XMLHttpRequest();
	}
	else if (window.ActiveXObject)
	{ 
	 	 conexion= new ActiveXObject("Microsoft.XMLHTTP");
	}
	
}
/******************************************************************
*******************************************************************
Funciones que verifican si existe el correo
/******************************************************************
*******************************************************************/
function mostrarEntrevista( idEntrevista){
	
	if(conexion){
		conexion.abort()
		conexion = false
	}
	peticionEntrevista(idEntrevista)
}
function peticionEntrevista(idEntrevista)
{
	if(conexion == false)
		Conexion();
			 
	if(conexion){
		conexion.open("GET","muestraEntrevista.php?idEntrevista=" + idEntrevista , true);	
		document.getElementById('load').style.visibility = 'visible'
		document.getElementById('load').style.display = 'block'
		conexion.onreadystatechange = function(){
					
			if(conexion.readyState == 4){				
				document.getElementById('load').style.visibility = 'hidden'
					document.getElementById('load').style.display = 'none'
				if(conexion.status == 200){					
					if(conexion.responseText){												
       					
						content  = conexion.responseText
						corteContent = content.split("@@@@@");
						document.getElementById('contenedorEntrevistas').innerHTML = corteContent[1]
						document.getElementById('infoEntrevista').innerHTML = corteContent[0]
						document.getElementById('idEntrevista').value = idEntrevista						
						conexion = false
					}					
				}
			}
		}
		
		conexion.send(null);
	}
}
function verificaConexion(){
	if(conexion){
		conexion.abort()
		conexion = false
	}
}
function enviaCorreo(para , de , idEntrevista){
	amigo = document.getElementById(para).value
	entrevista = document.getElementById(idEntrevista).value
	deOrigen = document.getElementById(de).value
	
	
	verificaConexion();
		
	if(conexion == false)
		Conexion();
	if(conexion){
		conexion.open("GET","enviaCorreo.php?identrevista="+ entrevista +"&para=" + amigo + "&de=" +  deOrigen, true);	
		document.getElementById('loadcorreo').style.visibility = 'visible'
		document.getElementById('loadcorreo').style.display = 'block'
		conexion.onreadystatechange = function(){
					
			if(conexion.readyState == 4){				
				
				if(conexion.status == 200){					
					if(conexion.responseText){												
						document.getElementById('loadcorreo').style.visibility = 'hidden'
						document.getElementById('loadcorreo').style.display = 'none'
						document.getElementById('respuesta').innerHTML = conexion.responseText
						if( conexion.responseText == "Correo enviado"){
							document.getElementById(para).value = ''
							document.getElementById(de).value = '';
						}
						conexion = false
					}					
				}
			}
		}
		
		conexion.send(null);
	}
}
function formaEntrevista(){	
	document.getElementById('forma').style.visibility = 'visible'
	document.getElementById('forma').style.display = 'block'	
	
}

/**********/
function SetContainerHTML(id,html,processScripts)
{
	
	mydiv = document.getElementById(id);
	//mydiv.innerHTML = html;
	if(processScripts!=false)
	{
		
	
		var elementos = mydiv.getElementsByTagName('script');
		/*mydiv.getElementsByTagName('script')[0].src
		nuevoScript = document.createElement('script');
		nuevoScript.type = 'text/javascript';
		//nuevoScript.src = mydiv.getElementsByTagName('script')[0].src;		
		nuevoScript.src ="http://tweetmeme.com/i/scripts/button111.js";		
		
		mydiv.getElementsByTagName('script')[0].parentNode.replaceChild(nuevoScript, mydiv.getElementsByTagName('script'));*/
		
		
	for(i=0;i<elementos.length;i++) {
		var elemento = elementos;
		nuevoScript = document.createElement('script');
		nuevoScript.text = elemento[i].innerHTML;
		
		nuevoScript.type = 'text/javascript';
		nuevoScript.src = "http://tweetmeme.com/i/scripts/button.js"
		elemento[i].parentNode.replaceChild(nuevoScript,mydiv.getElementsByTagName('script')[i]);
			/*if(elemento.src!=null && elemento.src.length>0)
			nuevoScript.src = elemento[i].src;
			nuevoScript.src = "cinemex/enterate"
			elemento[i].parentNode.replaceChild(nuevoScript,elemento[i]);
			}*/
		}
	}
}
