<!-- @require yahoo/yahoo-min.js -->
<!-- @require event/event-min.js -->
<!-- @require connection/connection-min.js -->

/*
 * AjaxObjUpdTxtPers is a hypothetical object that encapsulates the transaction
 *     request and callback logic.
 *
 * handleSuccess( ) provides success case logic
 * handleFailure( ) provides failure case logic
 * processResult( ) displays the results of the response from both the
 * success and failure handlers
 * call( ) calling this member starts the transaction request.
 */
var AjaxObjUpdTxtPers = {

	URL_SVC_UPD_TXT_PERS: "./mapaCelular/svcUpdTxtPers.asp",
	IDDIV_TEXTO_PERSONALIZADO: "id_celular",
	ID_TXT_PERSONALIZADO : 'txtRememberText',
	MSG_ERROR : "En este momento no podemos atender su solicitud de actualización de texto personalizado"
						 +"\n\n Por favor, intente más tarde ...",

	handleSuccess:function(o){
    var respuesta, hayError;
    hayError = false;
    try{
      respuesta = o.responseXML.documentElement;
    }catch(err){
      alert(this.MSG_ERROR);
      document.body.style.cursor = 'auto';
      hayError = true;
    }
    if (hayError==false)
    	this.processResult(respuesta);
	},

	handleFailure:function(o){
    //alert(this.MSG_ERROR);
	alert("Transacción id: " + o.tId + "-->HTTP código de estado: " + o.status + "-->Mensaje del código de estado: " + o.statusText);
    document.body.style.cursor = 'auto';
	},

	processResult:function(respuesta){
		//mostrare mensaje de error
		nodoRespuesta    = respuesta.getElementsByTagName('RESPUESTA');
		if (nodoRespuesta[0] && nodoRespuesta[0].firstChild){
      var descripcion ='';
      if(nodoRespuesta[0].firstChild.data != 'OK')
      	descripcion = nodoRespuesta[0].firstChild.data;
			if (descripcion!=''){
				alert(descripcion);
				document.body.style.cursor = 'auto';
				return;
      }
		}

		//limpiar texto personalizado

		document.getElementById(this.ID_TXT_PERSONALIZADO).value="";

		//ocultar bloque de texto personalizado
		document.getElementById(this.IDDIV_TEXTO_PERSONALIZADO).style.display="none";

	 	document.body.style.cursor = 'auto';
	},

	startRequest:function(strCodigo, strTexto) {
		var postData =   "codigo=" +strCodigo+"&txtPersonalizado="+strTexto;
		rExp = / /gi;
		postData = postData.replace(rExp,"+");

		document.body.style.cursor = 'wait';
		YAHOO.util.Connect.asyncRequest('POST', this.URL_SVC_UPD_TXT_PERS, callbackUpdTxtPers, postData);
	}
};

/*
 * Define the callback object for success and failure
 * handlers as well as object scope.
 */
var callbackUpdTxtPers =
{
	success:AjaxObjUpdTxtPers.handleSuccess,
	failure:AjaxObjUpdTxtPers.handleFailure,
  timeout: 100000,
	scope: AjaxObjUpdTxtPers
};