var ie = (document.all)? true:false ;

function getHTTPObject() {
  var xmlhttp;
 
  if(window.XMLHttpRequest){
    xmlhttp = new XMLHttpRequest();
  }
  else if (window.ActiveXObject){
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    if (!xmlhttp){
        xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
    }
}
  return xmlhttp;
}


var httpSuscribe = getHTTPObject(); 
function enviarSugerencia()
{
 	if(trim(document.form_sug.sugerencias.value)=="")
	{ alert("Introduzca la sugerencia."); return; }
 	if(trim(document.form_sug.email.value)=="")
	{ alert("Introduzca la Email."); return; }

	var myrand=parseInt(Math.random()*99999999);
	var sugerencias = document.getElementById('sugerencias').value;
	var email = document.getElementById('email').value;
 	var modurl= "send_sugerencia.php?e=1&email="+email+"&sugerencias="+sugerencias+"&myrand="+myrand;
	alert(modurl);
 	httpSuscribe.open("GET", modurl, true);
	httpSuscribe.onreadystatechange = rsp_enviarSugerencia;
	httpSuscribe.send(null);
}

function rsp_enviarSugerencia() 
{
	if (httpSuscribe.readyState == 4) 
	{
		if(httpSuscribe.status == 200) 
		{
 			document.getElementById('sugerencias').value="";
			alert("Su mensaje ha sido enviado");
		document.form_sug.reset();
		}	
	} 
	else
	{
		document.getElementById('ID_LOAD_SUSC').innerHTML='enviando...';
	}
}

function OpenWind(page, nompage, w, h,statusscroll) 
{
if(statusscroll=='si') statusscroll = 1; 
var w = window.open(page,nompage,'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+statusscroll+',top=0,left=0,width='+w+',height='+h+'');
x = (screen.width - 600) / 2;
y = (screen.height - 550) / 2; 
w.moveTo(x, y); 
w.focus();

}

 


function getfileextensionSimple(inputId, ID_DIV_EXTENSION) 
{  
	var fileinput = document.getElementById(inputId);  
	if(!fileinput ) return "";  
	var filename = fileinput.value;  
	if( filename.length == 0 ) return "";  
	var dot = filename.lastIndexOf(".");  
	if( dot == -1 ) return "";  
	var extension = filename.substr(dot,filename.length); 
	document.getElementById(ID_DIV_EXTENSION).value = extension;
} 

function menu_desplegable_mostrar(nombre_id){
document.getElementById(nombre_id).style.display="block";
}

function menu_desplegable_ocultar(nombre_id){
 document.getElementById(nombre_id).style.display="none";
}

function esMail(mail)
{
	var Template = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; //Formato de direccion de correo electronico
	
		if (!Template.test(mail)) 
		{	
			return true;
		}		else
		{return false;}
	
}

function trim(cadena)
{
	for(i=0; i<cadena.length; )
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(i+1, cadena.length);
		else
			break;
	}

	for(i=cadena.length-1; i>=0; i=cadena.length-1)
	{
		if(cadena.charAt(i)==" ")
			cadena=cadena.substring(0,i);
		else
			break;
	}
	
	return cadena;
}