var Dyn_DivLoad = "divLoad"
var Dyn_DivResultadoOperacion = "divLblResultadoDeOperacion"
var Dyn_Pag = "rn_contacto.asp"
var Dyn_Id	= 0

function fncInicio() {
	//Ini****************************************
	Dyn_fncEnviarTraerDatos(Dyn_Pag,2,"DatosContacto",'','',Dyn_DivLoad,'fncCargarDatosContacto')	
	//Fin****************************************
}


function fncCargarDatosContacto(root) {
	if (root.getElementsByTagName('Contacto')[0].childNodes.length > 0) {
		nodos = root.getElementsByTagName('Contacto')[0]		
		try{document.getElementById("txtNombre").value					= nodos.getElementsByTagName('NombreDeContacto')[0].childNodes.item(0).data} catch(e) {}
		try{document.getElementById("txtMail").value					= nodos.getElementsByTagName('MailDeContacto')[0].childNodes.item(0).data} catch(e) {}
		try{document.getElementById("txtId").value						= nodos.getElementsByTagName('IdDeContacto')[0].childNodes.item(0).data} catch(e) {}
		try{document.getElementById("txtTipo").value					= nodos.getElementsByTagName('TipoDeContacto')[0].childNodes.item(0).data} catch(e) {}
	}		
}


function fncEnviaMail() {
	//Ini****************************************
	
	var texto = ""
	texto = document.getElementById("txtDescripcion").value
	texto = texto.replace(/\n/g,"<br>")
	xml = ''	
	xml += '<Mail>'
		xml += '<Remitente>info@imprimidondequieras.com.ar</Remitente>'
		xml += '<Destinatario>contacto@imprimidondequieras.com.ar</Destinatario>'
		xml += '<Asunto>Consulta de usuario ' + document.getElementById("txtNombre").value + '</Asunto>'
		xml += '<Tipo>1</Tipo>'
		xml += '<Cuerpo><![CDATA[<tr><td><b>Nombre de Usuario:</b> ' + document.getElementById("txtNombre").value + '</td></tr>' 
		xml += '<tr><td><b>Id de Usuario:</b> ' + document.getElementById("txtId").value + '</td></tr>'
		xml += '<tr><td><b>Mail de Usuario:</b> ' + document.getElementById("txtMail").value + '</td></tr>'
		xml += '<tr><td><b>Consulta de Usuario:</b> <br>' + texto + '</td></tr>'
		xml += ']]></Cuerpo>'
	xml += '</Mail>'
	Dyn_fncEnviarTraerDatos(Dyn_Pag,3,'Mail',xml,'','','')
	
	//Fin***************************************
	
	return xml
}

function fncResultadoOperacionLocal(numError,resultado,formatoA,formatoD) {
	mensaje = "Error en la operacion. Numero de error: " + numError
	if (resultado == "OK") {
		mensaje = "Operación efectuada con éxito"
		formato = formatoA + mensaje + formatoD
		Dyn_fncCancelar()
		fncOkConsulta()		
		Dyn_fncOcultarMensaje(Dyn_DivResultadoOperacion)
	}
	else {
		switch (numError) {
		case "x":
			mensaje = "";
			break;
		}
		formato = formatoA + mensaje + formatoD
	}	
	document.getElementById(Dyn_DivResultadoOperacion).innerHTML = formato
}

function fncValidarDatosGrabar() {
	//Valida datos
	//Ini****************************************	
	
	formatoA = "<table width='100%' border='0' cellpadding='0' cellspacing='0'>"
	formatoA = formatoA + "<tr><td id='tdMensaje' height='20' style='background-Image:url(images/fondo_error.gif)' class='textoMensajeError'><IMG align='absmiddle' src='images/error_icon.gif'>&nbsp;"
	formatoD = "</td></tr></table>"
	
	if (document.getElementById("txtNombre").value == '') {
			document.getElementById(Dyn_DivResultadoOperacion).innerHTML = formatoA + "Debe ingresar su nombre" + formatoD; 
			document.getElementById("txtNombre").className = "contenidoCamposWarning";
			return false}
	else{
			document.getElementById("txtNombre").className = "inputLogin";}					
			
	if (document.getElementById("txtMail").value == '') {
			document.getElementById(Dyn_DivResultadoOperacion).innerHTML = formatoA + "Debe ingresar su mail" + formatoD; 
			document.getElementById("txtMail").className = "contenidoCamposWarning";
			return false}
	else{
			document.getElementById("txtMail").className = "inputLogin";}							
			
	if (document.getElementById("txtDescripcion").value == '') {
			document.getElementById(Dyn_DivResultadoOperacion).innerHTML = formatoA + "Debe ingresar su consulta" + formatoD; 
			document.getElementById("txtDescripcion").className = "contenidoCamposWarning";
			return false}
	else{
			document.getElementById("txtDescripcion").className = "inputLogin";}							
	
	//Fin****************************************
		
	return true	
}

function fncArmarXmlGrabar() {
	//Arma xml
	var xml = ''
	Dyn_PressEditar = 0
	
	//Ini****************************************
	xml += "<Consulta>"
		xml += "<IdDeContactoDeConsulta>" + document.getElementById("txtId").value + "</IdDeContactoDeConsulta>"
		xml += "<TipoDeContactoDeConsulta>" + document.getElementById("txtTipo").value + "</TipoDeContactoDeConsulta>"
		xml += "<NombreDeContactoDeConsulta>" + document.getElementById("txtNombre").value + "</NombreDeContactoDeConsulta>"
		xml += "<MailDeContactoDeConsulta>" + document.getElementById("txtMail").value + "</MailDeContactoDeConsulta>"
		
		texto = document.getElementById("txtDescripcion").value
		texto = texto.replace(/\n/g,"###")
		xml += "<DescripcionDeContactoDeConsulta>" + texto + "</DescripcionDeContactoDeConsulta>"
				
	xml += "</Consulta>"
	//Fin****************************************
	return xml	
}


function fncLimpiarCampos() {
	//Ini****************************************	
	
	document.getElementById("txtDescripcion").value = ""	

	//Fin****************************************
	fncInicio()
}

