function WFST(){
	this.baseURL = "http://visor.grafcan.es/wfst/Callejero?";
}

WFST.prototype.ExtjsPOST = function(data) {
    Ext.Ajax.request({
    	url: this.baseURL,
    	headers: {'Content-Type': 'text/xml'},
        method: 'POST',
        params : data,
        //xmlData: data,
        success: function(response,options){
			var fid;
			var errTxt='';
			try{
				if ($ie())
					fid = response.responseXML.getElementsByTagName("ogc:FeatureId")[0].attributes.getNamedItem("fid").text;
				else
					fid = response.responseXML.getElementsByTagNameNS("*","FeatureId")[0].attributes.getNamedItem("fid").textContent;
			} catch(e){
				errTxt = response.responseXML.getElementsByTagName("ServiceException")[0].text||response.responseXML.getElementsByTagName("ServiceException")[0].textContent;
			}
			if (fid) {
				fid = fid.substring(fid.indexOf('.')+1);
	    		Ext.MessageBox.alert('Información de errores - Callejero', 'Su información, con el código de incidencia '+fid+', ha sido enviada con éxito y será tenida en cuenta en futuras revisiones del Callejero. Gracias por su colaboración.');
			} else if (errTxt!='')
				Ext.MessageBox.alert('Información de errores - Callejero', 'Ocurrió un error en la notificación:\n\n'+errTxt);
			else
				Ext.MessageBox.alert('Información de errores - Callejero', 'Su información ha sido enviada con éxito y será tenida en cuenta en futuras revisiones del Callejero. Gracias por su colaboración.');
        },
        failure: function(response,options){
            Ext.MessageBox.alert('Failed', 'Unable to add values');
        }
    });
}


WFST.prototype.addVia = function (comment, action_id, user_id, sender, lat, lng){
	/*
	 * ex: -14.68476,28.54958
	 */
    var data = '';
    data  += '<?xml version="1.0" encoding="UTF-8"?>';
    data  += '<wfs:Transaction service="WFS" version="1.0.0"';
    data  += '                xmlns:wfs="http://www.opengis.net/wfs"';
    data  += '                xmlns:idecan="http://idecan.grafcan.es/"';
    data  += '                xmlns:gml="http://www.opengis.net/gml"';
    data  += '                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"';
    data  += '                xsi:schemaLocation="http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.0.0/WFS-transaction.xsd">';
    data  += '        <wfs:Insert>';
    data  += '                <idecan:apppoi_poicallejero>';
    data  += '                        <idecan:action_id>' + action_id +'</idecan:action_id>';
    data  += '                        <idecan:user_id>' + user_id + '</idecan:user_id>';
    data  += '                        <idecan:comment>' + comment  + '</idecan:comment>';
    data  += '                        <idecan:geometry>';
    data  += '                                <gml:Point>';
    data  += '                                        <gml:coordinates decimal="." cs="," ts=" ">' + lng + ',' + lat + '</gml:coordinates>';
    data  += '                                </gml:Point>';
    data  += '                        </idecan:geometry>';
	data  += '                        <idecan:sender>' + sender + '</idecan:sender>';
    data  += '                </idecan:apppoi_poicallejero>';
    data  += '        </wfs:Insert>';
    data  += '</wfs:Transaction>';
    this.ExtjsPOST(data);
}

