var Inappropiate = {
  checkForm:function(f){
    var sMotive = f.motivo.value;
    var sUrl = f.url.value;
    
    if (sMotive!=null&&sMotive!=undefined&&sMotive!="")
    {
      if (sUrl!=null&&sUrl!=undefined&&sUrl!="")
      {      
        this.sendInappropiateMessage(sMotive,sUrl);
      }
      else{
        alert("Por favor indica la url de tu denuncia.");
        f.url.focus();
      }
    }
    else{
      alert("Por favor indica el motivo de tu denuncia.");
      f.motivo.focus();
    }
  },
  
  sendInappropiateMessage:function(sMotive,sUrl){  
    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("capa_formulario_denuncia");
		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=" + sMotive + "&u=" + sUrl;
	  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");
}
