function isEmail(str)
{
	if (str.indexOf(' ') != -1) return false;
	var erEmail = /^[^@]+@[^\.]+(\.[^\.]+)+$/;
	var valida = erEmail.test(str);
	if(valida) return true;
	else return false;
}

var Inappropiate = {
  checkForm:function(f){
    var smail = f.email.value;
    var sdescrip = f.descrip.value;
    
    if (smail!=null&&smail!=undefined&&smail!=""&&isEmail(smail))
    {
      if (sdescrip!=null&&sdescrip!=undefined&&sdescrip!="")
      { 
      	if (window.location.href.indexOf("chueca")>=0)
      		f.site.value="chueca";
      	f.action="/SInappropiateListener";
      	f.method="post";
        f.submit();
        
        //this.sendInappropiateMessage(smail,sdescrip);
      }
      else{
        alert("Por favor introduce la descripcion del reporte de abuso.");
        f.descrip.focus();
      }
    }
    else{
      alert("Por favor indica un e-mail correcto.");
      f.email.focus();
    }
  },
  
  sendInappropiateMessage:function(smail,sdescrip){  
    var sTxtError = "Se ha producido un error al enviar tu mensaje. Por favor, vuelve a intentarlo.";
    
    if (this.oXmlHttpReq==null) {
	     this.oXmlHttpReq = CreateXMLHttpRequest();
    } else {
	     this.oXmlHttpReq.abort();
	  }	
	
		var oSelf = this;
		var oResultMsj = parent.document.getElementById("resultado_mensaje");
		var oForm = parent.document.getElementById("contenedor_abusos");
		var oMsj = parent.document.getElementById("capa_resultado_denuncia");
		
		this.oXmlHttpReq.onreadystatechange = function()
		{		
		    if (oSelf.oXmlHttpReq.readyState == 4) {
		        if (oSelf.oXmlHttpReq.status == 200) {
		            //habra que ver que hace cuando devuelve ok
			    	   var oDOMDocument = LoadXmlFromStr(oSelf.oXmlHttpReq.responseText);
			    	   var sResult = oDOMDocument.documentElement.firstChild.nodeValue;
			    	   if (sResult=="true")
			    	   {
                Inappropiate.hideLayer(oForm);
		            Inappropiate.viewLayer(oMsj);  
               }
               else{
                alert(sTxtError); 
               }
		        }else{		/*
			    	   oResultMsj.innerHTML = sTxtError;
               Inappropiate.hideLayer(oForm);
		           Inappropiate.viewLayer(oMsj);*/ 
		        }
		    }      
		};		
	
	  var sMsgUrl = "/SInappropiateListener?m=" + smail + "&d=" + sdescrip;
	  this.oXmlHttpReq.open("GET", sMsgUrl, true);
	  this.oXmlHttpReq.setRequestHeader("Cache-Control", "no-cache");
	  this.oXmlHttpReq.send(null);
  },
  
  viewLayer:function(layer){
    layer.style.visibility="visible";
    layer.style.display="";    
  },
  
  hideLayer:function(layer){
    layer.style.visibility="hidden";
    layer.style.display="none";
  }
}

function denunciarContenido(){
  viewLayer("layer_over");
}

function loadIframe(iframe){		
	var destino = window.top.location.href;
	destino = destino.substring(destino.indexOf("://")+3);
	iframe.src = "http://espacio.ya.com/SSpace/$M=sendinappropiate$URL=" + destino;
	}
