var Dyn_DivLoad = "divLoad"
var Dyn_DivResultadoOperacion = "divLblResultadoDeOperacion"
var Dyn_Pag = "rn_usuarios.asp"
var Dyn_Id	= 0
var IdDePuntoEntrega = 0
var IdLocalidadDePuntoEntrega = 0
var IdLocalidad = 0
var CambiaPassword = false
var esNuevo = "N"

function fncInicio() {
	//Ini****************************************	
	Dyn_fncEnviarTraerDatos(Dyn_Pag,1,"ComboProvincias",'',"selProvinciasPuntoEntrega", "divSelProvinciasPuntoEntrega",'fncDatosPuntoEntrega')	
	Dyn_fncEnviarTraerDatos(Dyn_Pag,1,"ComboFechasDias",'','selFechaNacimientoDias','divFechaNacimientoDias','fncDiasCargados')	
	//Fin****************************************
}

function fncDiasCargados() {
	Dyn_fncEnviarTraerDatos(Dyn_Pag,1,"ComboFechasMeses",'','selFechaNacimientoMeses','divFechaNacimientoMeses','fncMesesCargados')	
}

function fncMesesCargados() {
	Dyn_fncEnviarTraerDatos(Dyn_Pag,1,"ComboFechasAnios",'','selFechaNacimientoAnios','divFechaNacimientoAnios','fncAniosCargados')	
}

function fncAniosCargados() {
	Dyn_fncEnviarTraerDatos(Dyn_Pag,1,"ComboProvincias",'',"selProvincias", "divSelProvincias",'fncCargaOrigenes')
}

function fncCargaOrigenes() {
	Dyn_fncEnviarTraerDatos(Dyn_Pag,1,"ComboOrigenes",'',"selOrigenes", "divSelOrigenes",'fncDatosUsuario')
}


function fncDatosPuntoEntrega() {	
	if (esNuevo == "N") {
		Dyn_fncEnviarTraerDatos(Dyn_Pag,2,"DatosPuntoEntrega",'','',Dyn_DivLoad,'fncCargarDatosPuntoEntrega')
	}
}

function fncDatosUsuario() {	
	if (esNuevo == "N") {
		Dyn_fncEnviarTraerDatos(Dyn_Pag,2,"DatosUsuario",'','',Dyn_DivLoad,'fncCargarDatosUsuario')	
	}
}

function fncCargarDatosUsuario(root) {
	if (root.getElementsByTagName('Usuario')[0].childNodes.length > 0) {
		nodos = root.getElementsByTagName('Usuario')[0]		
		try{document.getElementById("txtCantPositivo").value			= nodos.getElementsByTagName('CantPositivoDeUsuario')[0].childNodes.item(0).data} catch(e) {}
		try{document.getElementById("txtCantNeutro").value				= nodos.getElementsByTagName('CantNeutroDeUsuario')[0].childNodes.item(0).data} catch(e) {}
		try{document.getElementById("txtCantNegativo").value			= nodos.getElementsByTagName('CantNegativoDeUsuario')[0].childNodes.item(0).data} catch(e) {}
		try{document.getElementById("txtNombre").value					= nodos.getElementsByTagName('NombreDeUsuario')[0].childNodes.item(0).data} catch(e) {}
		try{document.getElementById("txtTitNombre").innerHTML		    = nodos.getElementsByTagName('NombreDeUsuario')[0].childNodes.item(0).data + ' ' + nodos.getElementsByTagName('ApellidoDeUsuario')[0].childNodes.item(0).data} catch(e) {}
		try{document.getElementById("selProvincias").value				= nodos.getElementsByTagName('IdDeProvincia')[0].childNodes.item(0).data} catch(e) {}		
		try{document.getElementById("txtLocalidad").value				= nodos.getElementsByTagName('LocalidadDeUsuario')[0].childNodes.item(0).data} catch(e) {}
		try{IdLocalidad													= nodos.getElementsByTagName('IdDeLocalidad')[0].childNodes.item(0).data} catch(e) {}
		if (nodos.getElementsByTagName('IdDeLocalidad')[0].childNodes.length <= 0 && document.getElementById("txtLocalidad").value != '') {
			try{IdLocalidad = 'Otra'} catch(e) {}
			document.getElementById("txtTextoLocalidad").style.display = ""
			document.getElementById("txtTextoLocalidad2").style.display = ""
		}			
		try{document.getElementById("txtApellido").value				= nodos.getElementsByTagName('ApellidoDeUsuario')[0].childNodes.item(0).data} catch(e) {}
		try{document.getElementById("selFechaNacimientoDias").value		= nodos.getElementsByTagName('FechaNacimientoDeUsuarioDia')[0].childNodes.item(0).data} catch(e) {}
		try{document.getElementById("selFechaNacimientoMeses").value	= nodos.getElementsByTagName('FechaNacimientoDeUsuarioMes')[0].childNodes.item(0).data} catch(e) {}
		try{document.getElementById("selFechaNacimientoAnios").value	= nodos.getElementsByTagName('FechaNacimientoDeUsuarioAnio')[0].childNodes.item(0).data} catch(e) {}		
		try{document.getElementById("txtMail").value					= nodos.getElementsByTagName('MailDeUsuario')[0].childNodes.item(0).data} catch(e) {}
		try{document.getElementById("txtTelefono").value				= nodos.getElementsByTagName('TelefonoDeUsuario')[0].childNodes.item(0).data} catch(e) {}
		try{document.getElementById("txtCalle").value					= nodos.getElementsByTagName('CalleDeUsuario')[0].childNodes.item(0).data} catch(e) {}
		try{document.getElementById("txtNumero").value					= nodos.getElementsByTagName('NumeroDeUsuario')[0].childNodes.item(0).data} catch(e) {}
		try{
			if (nodos.getElementsByTagName('PisoDeUsuario')[0].childNodes.item(0).data==0) {
				try{document.getElementById("txtPiso").value = ""} catch(e) {}
			}
			else {
				try{document.getElementById("txtPiso").value = nodos.getElementsByTagName('PisoDeUsuario')[0].childNodes.item(0).data} catch(e) {}
			}
		} catch(e) {}
		try{
			if (nodos.getElementsByTagName('DeptoDeUsuario')[0].childNodes.item(0).data==0) {
				try{document.getElementById("txtDepto").value = ""} catch(e) {}
			}
			else {
				try{document.getElementById("txtDepto").value = nodos.getElementsByTagName('DeptoDeUsuario')[0].childNodes.item(0).data} catch(e) {}
			}
		} catch(e) {}

		try{document.getElementById("txtCp").value						= nodos.getElementsByTagName('CpDeUsuario')[0].childNodes.item(0).data} catch(e) {}
		
		if (nodos.getElementsByTagName('SexoDeUsuario')[0].childNodes.item(0).data == 'F') {			
			document.getElementById("optSexoF").checked = true
		}
		else {			
			document.getElementById("optSexoM").checked = true
		}
		
		if (nodos.getElementsByTagName('RecibePromocionesDeUsuario')[0].childNodes.item(0).data == '1') {			
			document.getElementById("optRecibrePromoS").checked = true
		}
		else {			
			document.getElementById("optRecibrePromoN").checked = true
		}
		
		
		fncTraerLocalidades('selProvincias','fncCompletarLocalidad')
	}		
}

function fncCargarDatosPuntoEntrega(root) {	
	if (root.getElementsByTagName('PuntoEntrega')[0].childNodes.length > 0) {		
		nodos = root.getElementsByTagName('PuntoEntrega')[0]						
		try{IdDePuntoEntrega											= nodos.getElementsByTagName('IdDePuntoEntrega')[0].childNodes.item(0).data} catch(e) {}		
		try{document.getElementById("selProvinciasPuntoEntrega").value	= nodos.getElementsByTagName('IdDeProvincia')[0].childNodes.item(0).data} catch(e) {}
		try{document.getElementById("txtLocalidadPuntoEntrega").value	= nodos.getElementsByTagName('LocalidadDePuntoEntrega')[0].childNodes.item(0).data} catch(e) {}
		try{IdLocalidadDePuntoEntrega									= nodos.getElementsByTagName('IdDeLocalidad')[0].childNodes.item(0).data} catch(e) {}		
		if (nodos.getElementsByTagName('IdDeLocalidad')[0].childNodes.length <= 0 && document.getElementById("txtLocalidadPuntoEntrega").value != '') {
			try{IdLocalidadDePuntoEntrega = 'Otra'} catch(e) {}
			document.getElementById("txtTextoLocalidadPuntoEntrega").style.display = ""
			document.getElementById("txtTextoLocalidadPuntoEntrega2").style.display = ""
		}	
		try{document.getElementById("txtTelefonoPuntoEntrega").value	= nodos.getElementsByTagName('TelefonoDePuntoEntrega')[0].childNodes.item(0).data} catch(e) {}
		try{document.getElementById("txtCallePuntoEntrega").value		= nodos.getElementsByTagName('CalleDePuntoEntrega')[0].childNodes.item(0).data} catch(e) {}
		try{document.getElementById("txtNumeroPuntoEntrega").value		= nodos.getElementsByTagName('NumeroDePuntoEntrega')[0].childNodes.item(0).data} catch(e) {}
		try{
			if (nodos.getElementsByTagName('PisoDePuntoEntrega')[0].childNodes.item(0).data==0) {
				try{document.getElementById("txtPisoPuntoEntrega").value = ""} catch(e) {}
			}
			else {
				try{document.getElementById("txtPisoPuntoEntrega").value = nodos.getElementsByTagName('PisoDePuntoEntrega')[0].childNodes.item(0).data} catch(e) {}
			}
		} catch(e) {}
		try{
			if (nodos.getElementsByTagName('DeptoDePuntoEntrega')[0].childNodes.item(0).data==0) {
				try{document.getElementById("txtDeptoPuntoEntrega").value = ""} catch(e) {}
			}
			else {
				try{document.getElementById("txtDeptoPuntoEntrega").value = nodos.getElementsByTagName('DeptoDePuntoEntrega')[0].childNodes.item(0).data} catch(e) {}
			}
		} catch(e) {}
		try{document.getElementById("txtCpPuntoEntrega").value			= nodos.getElementsByTagName('CpDePuntoEntrega')[0].childNodes.item(0).data} catch(e) {}													
		fncTraerLocalidades('selProvinciasPuntoEntrega','fncCompletarLocalidadPuntoEntrega')		
	}		
}


function fncCompletarLocalidadPuntoEntrega() {
	document.getElementById("selLocalidadesPuntoEntrega").value	= IdLocalidadDePuntoEntrega
}

function fncCompletarLocalidad() {	
	document.getElementById("selLocalidades").value	= IdLocalidad
}

function fncOtraLocalidad (obj) {
	if (obj.id == 'selLocalidades') {
		var cp = document.getElementById("selLocalidades").options[document.getElementById("selLocalidades").selectedIndex].attributes.getNamedItem("cp").value
		if (document.getElementById("selLocalidades").value == "Otra") {			
			document.getElementById("txtTextoLocalidad").style.display = ""
			document.getElementById("txtTextoLocalidad2").style.display = ""
			document.getElementById("txtCp").value = ""
			document.getElementById("txtCp").disabled = false
		}
		else {
			document.getElementById("txtLocalidad").value		= ""
			document.getElementById("txtTextoLocalidad").style.display = "none"
			document.getElementById("txtTextoLocalidad2").style.display = "none"
			if (cp != 1 && cp != '') {
				document.getElementById("txtCp").value = cp
				document.getElementById("txtCp").disabled = true
			}
			else {
				document.getElementById("txtCp").value = ""
				document.getElementById("txtCp").disabled = false
			}
		}
	}
	if (obj.id == 'selLocalidadesPuntoEntrega') {	
		var cp = document.getElementById("selLocalidadesPuntoEntrega").options[document.getElementById("selLocalidadesPuntoEntrega").selectedIndex].attributes.getNamedItem("cp").value
		if (document.getElementById("selLocalidadesPuntoEntrega").value == "Otra") {
			document.getElementById("txtTextoLocalidadPuntoEntrega").style.display = ""
			document.getElementById("txtTextoLocalidadPuntoEntrega2").style.display = ""
			document.getElementById("txtCpPuntoEntrega").value = ""
			document.getElementById("txtCpPuntoEntrega").disabled = false
		}
		else {
			document.getElementById("txtLocalidadPuntoEntrega").value		= ""
			document.getElementById("txtTextoLocalidadPuntoEntrega").style.display = "none"
			document.getElementById("txtTextoLocalidadPuntoEntrega2").style.display = "none"

			if (cp != 1) {
				document.getElementById("txtCpPuntoEntrega").value = cp
				document.getElementById("txtCpPuntoEntrega").disabled = true
			}
			else {
				document.getElementById("txtCpPuntoEntrega").value = ""
				document.getElementById("txtCpPuntoEntrega").disabled = false
			}
		}	
	}	
}


function fncValidarDatosGrabar() {
	//Valida datos
	//Ini****************************************
	
	document.getElementById(Dyn_DivResultadoOperacion).innerHTML = ""
	formatoA = "<table id='toppage' width='100%' border='0' cellpadding='0' cellspacing='0'>"
	formatoA = formatoA + "<tr><td id='tdMensaje' height='8' style='background-Image:url(images/fondo_error.gif)' class='textoMensajeError'><IMG align='absmiddle' src='images/error_icon.gif'>&nbsp;"
	formatoD = "</td></tr></table>"
	
	if (CambiaPassword) {
		if (document.getElementById("txtPassword").value == '') {
			document.getElementById(Dyn_DivResultadoOperacion).innerHTML = formatoA + "Debe ingresar su Contraseña Actual" + formatoD;
			document.getElementById("txtPassword").className = "contenidoCamposWarning";
			return false}
		else{
			document.getElementById("txtPassword").className = "inputLogin";}					
			
		if (document.getElementById("txtPasswordNuevo").value == '') {
			document.getElementById(Dyn_DivResultadoOperacion).innerHTML = formatoA + "Debe ingresar una Nueva Contraseña" + formatoD; 
			document.getElementById("txtPasswordNuevo").className = "contenidoCamposWarning";
			return false}
		else{
			document.getElementById("txtPasswordNuevo").className = "inputLogin";}					
			
		if (document.getElementById("txtPasswordNuevo").value != document.getElementById("txtReingresePassword").value) {
			document.getElementById(Dyn_DivResultadoOperacion).innerHTML = formatoA + "La Contraseña nueva y la Contraseña reingresada son diferentes" + formatoD; 
			document.getElementById("txtReingresePassword").className = "contenidoCamposWarning";
			return false}
		else{
			document.getElementById("txtReingresePassword").className = "inputLogin";}						
	}
	else {	
		if (IsMail(document.getElementById("txtMail").value)) {
			document.getElementById("txtMail").className = "inputLogin";}				
		else{
			document.getElementById(Dyn_DivResultadoOperacion).innerHTML = formatoA + "Debe ingresar un dirección de mail válida" + formatoD; 
			document.getElementById("txtMail").className = "contenidoCamposWarning";
			return false
			}						
				
		if (esNuevo == "S") {
			if (document.getElementById("txtPassword").value == '') {
				document.getElementById(Dyn_DivResultadoOperacion).innerHTML = formatoA + "Debe ingresar una Contraseña" + formatoD; 
				document.getElementById("txtPassword").className = "contenidoCamposWarning";
				return false}
			else{
			document.getElementById("txtPassword").className = "inputLogin";}						
				
			if (document.getElementById("txtPassword").value != document.getElementById("txtReingresePassword").value) {
				document.getElementById(Dyn_DivResultadoOperacion).innerHTML = formatoA + "Las Contraseñas ingresadas son diferentes" + formatoD; 
				document.getElementById("txtReingresePassword").className = "contenidoCamposWarning";
				return false}
			else{
			document.getElementById("txtReingresePassword").className = "inputLogin";}							
		}				
		if (document.getElementById("txtNombre").value == '') {
			document.getElementById(Dyn_DivResultadoOperacion).innerHTML = formatoA + "Debe ingresar Nombre  y Apellido" + formatoD; 
			document.getElementById("txtNombre").className = "contenidoCamposWarning";
			return false}
		else{
			document.getElementById("txtNombre").className = "inputLogin";}								
			
		if (document.getElementById("txtApellido").value == '') {
			document.getElementById(Dyn_DivResultadoOperacion).innerHTML = formatoA + "Debe ingresar Nombre  y Apellido"+ formatoD; 
			document.getElementById("txtApellido").className = "contenidoCamposWarning";
			return false}	
		else{
			document.getElementById("txtApellido").className = "inputLogin";}								
		
		if (document.getElementById("selProvincias").value == '0') {			
			document.getElementById(Dyn_DivResultadoOperacion).innerHTML = formatoA + "Debe seleccionar una provincia" + formatoD; 
			document.getElementById("selProvincias").className = "contenidoCamposWarning";
			return false}	
		else{			
			document.getElementById("selProvincias").className = "inputLogin";}									
		
		if (document.getElementById("selLocalidades").value == '0') {
			document.getElementById(Dyn_DivResultadoOperacion).innerHTML = formatoA + "Debe seleccionar una localidad" + formatoD; 
			document.getElementById("selLocalidades").className = "contenidoCamposWarning";
			return false}	
		else{			
			document.getElementById("selLocalidades").className = "inputLogin";}										
		
		if (document.getElementById("selLocalidades").value == "Otra" && document.getElementById("txtLocalidad").value == '') {
			document.getElementById(Dyn_DivResultadoOperacion).innerHTML = formatoA + "Debe ingresar una Localidad" + formatoD; 
			document.getElementById("txtLocalidad").className = "contenidoCamposWarning";
			return false}			
		else{
			document.getElementById("txtLocalidad").className = "inputLogin";}																


		if (document.getElementById("txtCp").value == '') {
			document.getElementById(Dyn_DivResultadoOperacion).innerHTML = formatoA + "Debe ingresar un Cp" + formatoD; 
			document.getElementById("txtCp").className = "contenidoCamposWarning";
			return false}			
		else{
			document.getElementById("txtCp").className = "inputLogin";}														
		
		if (document.getElementById("txtTelefono").value == '') {
			document.getElementById(Dyn_DivResultadoOperacion).innerHTML = formatoA + "Debe ingresar un número de teléfono" + formatoD; 
			document.getElementById("txtTelefono").className = "contenidoCamposWarning";
			return false}	
		else{
			document.getElementById("txtTelefono").className = "inputLogin";}											
			
		if (document.getElementById("txtCalle").value == '') {
			document.getElementById(Dyn_DivResultadoOperacion).innerHTML = formatoA + "Debe ingresar el nombre de la calle" + formatoD; 
			document.getElementById("txtCalle").className = "contenidoCamposWarning";
			return false}					
		else{
			document.getElementById("txtCalle").className = "inputLogin";}												
			
		if (!Dyn_fncEsNumeroEntero(document.getElementById("txtNumero").value)) {
			document.getElementById("divLblResultadoDeOperacion").innerHTML = formatoA + "El número de calle debe ser un número válido" + formatoD; 
			document.getElementById("txtNumero").className = "contenidoCamposWarning";
			return false}
		else{
			document.getElementById("txtNumero").className = "inputLogin";}													
			
		if (document.getElementById("txtPiso").value != '' && !Dyn_fncEsNumeroEntero(document.getElementById("txtPiso").value)) {
			document.getElementById("divLblResultadoDeOperacion").innerHTML = formatoA + "El Piso debe ser un número válido" + formatoD; 
			document.getElementById("txtPiso").className = "contenidoCamposWarning";
			return false}
		else{
			document.getElementById("txtPiso").className = "inputLogin";}														
			
		
		
		if (document.getElementById("selFechaNacimientoDias").value == '0' || document.getElementById("selFechaNacimientoMeses").value == '0' || document.getElementById("selFechaNacimientoAnios").value == '0') {
			document.getElementById(Dyn_DivResultadoOperacion).innerHTML = formatoA + "Debe seleccionar una fecha de nacimiento" + formatoD; 
			document.getElementById("selFechaNacimientoDias").className = "contenidoCamposWarning";
			document.getElementById("selFechaNacimientoMeses").className = "contenidoCamposWarning";
			document.getElementById("selFechaNacimientoAnios").className = "contenidoCamposWarning";
			return false
		}			
		else {
			document.getElementById("selFechaNacimientoDias").className = "inputLogin";
			document.getElementById("selFechaNacimientoMeses").className = "inputLogin";
			document.getElementById("selFechaNacimientoAnios").className = "inputLogin";
		}	
		
		if (document.getElementById("txtNumeroPuntoEntrega").value != '') {
			if (!Dyn_fncEsNumeroEntero(document.getElementById("txtNumeroPuntoEntrega").value)) {
				document.getElementById("divLblResultadoDeOperacion").innerHTML = formatoA + "El número de calle debe ser un número válido" + formatoD; 
				document.getElementById("txtNumeroPuntoEntrega").className = "contenidoCamposWarning";
				return false}
			else{
				document.getElementById("txtNumeroPuntoEntrega").className = "inputLogin";}													
		}	
		
		if (document.getElementById("txtPisoPuntoEntrega").value != '') {
			if (!Dyn_fncEsNumeroEntero(document.getElementById("txtPisoPuntoEntrega").value)) {
				document.getElementById("divLblResultadoDeOperacion").innerHTML = formatoA + "El Piso debe ser un número válido" + formatoD; 
				document.getElementById("txtPisoPuntoEntrega").className = "contenidoCamposWarning";
				return false}
			else{
				document.getElementById("txtPisoPuntoEntrega").className = "inputLogin";}													
		}	

	}
	//Fin****************************************	
	location.href="#toppage"
	return true	
}

function fncCambiaPassword(bol) {
	CambiaPassword = bol
}

function fncArmarXmlGrabar() {
	//Arma xml
	var xml = ''
	
	//Ini****************************************
	xml += "<Usuario>"
	xml += "<EsNuevo>" + esNuevo + "</EsNuevo>"
	if (CambiaPassword) {		
		xml += "<CambiaPassword>S</CambiaPassword>"
		xml += "<PasswordDeUsuario>"			+ document.getElementById("txtPassword").value + "</PasswordDeUsuario>"
		xml += "<PasswordNuevaDeUsuario>"		+ document.getElementById("txtPasswordNuevo").value + "</PasswordNuevaDeUsuario>"
	}
	else {		
		if (esNuevo	== "S") {	
			xml += "<PasswordDeUsuario>"		+ document.getElementById("txtPassword").value + "</PasswordDeUsuario>"
		}
		
		var fechaNacim = document.getElementById("selFechaNacimientoAnios").value + '-' + document.getElementById("selFechaNacimientoMeses").value + '-' + document.getElementById("selFechaNacimientoDias").value
		
		xml += "<CambiaPassword>N</CambiaPassword>"
		xml += "<NombreDeUsuario>"				+ document.getElementById("txtNombre").value + "</NombreDeUsuario>"
		xml += "<ApellidoDeUsuario>"			+ document.getElementById("txtApellido").value + "</ApellidoDeUsuario>"
		xml += "<MailDeUsuario>"				+ document.getElementById("txtMail").value + "</MailDeUsuario>"		
		xml += "<IdDeProvincia>"				+ document.getElementById("selProvincias").value + "</IdDeProvincia>"
		xml += "<IdDeLocalidad>"				+ document.getElementById("selLocalidades").value + "</IdDeLocalidad>"
		xml += "<LocalidadDeUsuario>"			+ document.getElementById("txtLocalidad").value + "</LocalidadDeUsuario>"
		xml += "<TelefonoDeUsuario>"			+ document.getElementById("txtTelefono").value + "</TelefonoDeUsuario>"
		xml += "<CalleDeUsuario>"				+ document.getElementById("txtCalle").value + "</CalleDeUsuario>"
		xml += "<NumeroDeUsuario>"				+ document.getElementById("txtNumero").value + "</NumeroDeUsuario>"
		xml += "<PisoDeUsuario>"				+ document.getElementById("txtPiso").value + "</PisoDeUsuario>"
		xml += "<DeptoDeUsuario>"				+ document.getElementById("txtDepto").value + "</DeptoDeUsuario>"
		xml += "<CpDeUsuario>"					+ document.getElementById("txtCp").value + "</CpDeUsuario>"
		xml += "<CantPositivo></CantPositivo>"
		xml += "<CantNegativo></CantNegativo>"
		xml += "<CantNeutro></CantNeutro>"
		xml += "<IdDeOrigen>"					+ document.getElementById("selOrigenes").value + "</IdDeOrigen>"
		xml += "<FechaNacimientoDeUsuario>"		+ fechaNacim + "</FechaNacimientoDeUsuario>"
		
		if (document.getElementById("optSexoF").checked)
			xml += "<SexoDeUsuario>F</SexoDeUsuario>"
		else
			xml += "<SexoDeUsuario>M</SexoDeUsuario>"		
		
		if (document.getElementById("optRecibrePromoS").checked)		
			xml += "<RecibePromocionesDeUsuario>1</RecibePromocionesDeUsuario>"		
		else
			xml += "<RecibePromocionesDeUsuario>0</RecibePromocionesDeUsuario>"		
					
		xml += "<PuntoEntrega>"			
			xml += "<IdDePuntoEntrega>"				+ IdDePuntoEntrega + "</IdDePuntoEntrega>"
			xml += "<IdDeProvincia>"				+ document.getElementById("selProvinciasPuntoEntrega").value + "</IdDeProvincia>"
			xml += "<IdDeLocalidad>"				+ document.getElementById("selLocalidadesPuntoEntrega").value + "</IdDeLocalidad>"
			xml += "<LocalidadDePuntoEntrega>"		+ document.getElementById("txtLocalidadPuntoEntrega").value + "</LocalidadDePuntoEntrega>"
			xml += "<TelefonoDePuntoEntrega>"		+ document.getElementById("txtTelefonoPuntoEntrega").value + "</TelefonoDePuntoEntrega>"
			xml += "<CalleDePuntoEntrega>"			+ document.getElementById("txtCallePuntoEntrega").value + "</CalleDePuntoEntrega>"
			xml += "<NumeroDePuntoEntrega>"			+ document.getElementById("txtNumeroPuntoEntrega").value + "</NumeroDePuntoEntrega>"
			xml += "<PisoDePuntoEntrega>"			+ document.getElementById("txtPisoPuntoEntrega").value + "</PisoDePuntoEntrega>"
			xml += "<DeptoDePuntoEntrega>"			+ document.getElementById("txtDeptoPuntoEntrega").value + "</DeptoDePuntoEntrega>"
			xml += "<CpDePuntoEntrega>"				+ document.getElementById("txtCpPuntoEntrega").value + "</CpDePuntoEntrega>"
		xml += "</PuntoEntrega>"
	}		
	xml += "</Usuario>"
	//Fin****************************************
	
	return xml	
}

function fncResultadoOperacionLocal(numError,resultado,formatoA,formatoD) {
	location.href="#toppage"
	mensaje = "Error en la operacion. Numero de error: " + numError
	if (resultado == "OK") {
		mensaje = "Operación efectuada con éxito"
		formato = formatoA + mensaje + formatoD
		Dyn_fncCancelar()			
		if (esNuevo	== "S") {
			setTimeout(function(){document.location.href ='iu_adm_usu_marco.asp'},3000);
		}
		else {
			Dyn_fncOcultarMensaje(Dyn_DivResultadoOperacion)
		}
	}
	else {
		switch (numError) {
		case "x":
			mensaje = "";
			break;
		}
		formato = formatoA + mensaje + formatoD
	}	
	document.getElementById(Dyn_DivResultadoOperacion).innerHTML = formato
}


function fncLimpiarCampos() {
	//Ini****************************************
	if (CambiaPassword) {			
		document.getElementById("txtPassword").value = ""
		document.getElementById("txtPasswordNuevo").value = ""
		document.getElementById("txtReingresePassword").value = ""	
	}
	else {
	 if (esNuevo	== "S") {
		document.getElementById("txtPassword").value = ""
		document.getElementById("txtReingresePassword").value = ""
		document.getElementById("selFechaNacimientoAnios").selectedIndex = 0
		document.getElementById("selFechaNacimientoMeses").selectedIndex = 0
		document.getElementById("selFechaNacimientoDias").selectedIndex = 0
		document.getElementById("txtNombre").value = ""
		document.getElementById("txtApellido").value = ""
		document.getElementById("txtMail").value = ""
		document.getElementById("selProvincias").selectedIndex = 0
		document.getElementById("selLocalidades").selectedIndex = 0
		document.getElementById("txtLocalidad").value = ""
		document.getElementById("txtTelefono").value = ""
		document.getElementById("txtCalle").value = ""
		document.getElementById("txtNumero").value = ""
		document.getElementById("txtPiso").value = ""
		document.getElementById("txtDepto").value = ""
		document.getElementById("txtCp").value = ""
		document.getElementById("selProvinciasPuntoEntrega").selectedIndex = 0
		document.getElementById("selLocalidadesPuntoEntrega").selectedIndex = 0
		document.getElementById("txtLocalidadPuntoEntrega").value = ""
		document.getElementById("txtTelefonoPuntoEntrega").value = ""
		document.getElementById("txtCallePuntoEntrega").value = ""
		document.getElementById("txtNumeroPuntoEntrega").value = ""
		document.getElementById("txtPisoPuntoEntrega").value = ""
		document.getElementById("txtDeptoPuntoEntrega").value = ""
		document.getElementById("txtCpPuntoEntrega").value = ""
		IdDePuntoEntrega = 0
	 }	
	}
	//Fin****************************************
  
}

function fncTraerLocalidades(id,fun) {
	if (id == 'selProvincias') {		
		var xml = fncArmarXmlLocalidades()
		Dyn_fncEnviarTraerDatos(Dyn_Pag,1,"ComboLocalidades",xml,"selLocalidades","divSelLocalidades",fun)		
	}
	if (id == 'selProvinciasPuntoEntrega') {		
		var xml = fncArmarXmlLocalidadesPuntoEntrega()
		Dyn_fncEnviarTraerDatos(Dyn_Pag,1,"ComboLocalidades",xml,"selLocalidadesPuntoEntrega","divSelLocalidadesPuntoEntrega",fun)		
	}
}


function fncArmarXmlLocalidades() {
	//Arma xml
	var xml = ''
	
	//Ini****************************************	
	xml += "<Localidad>"
		xml += "<IdDeProvincia>"	+ document.getElementById("selProvincias").value + "</IdDeProvincia>"		
	xml += "</Localidad>"
	//Fin****************************************	
	
	return xml	
}


function fncArmarXmlLocalidadesPuntoEntrega() {
	//Arma xml
	var xml = ''
	
	//Ini****************************************	
	xml += "<Localidad>"
		xml += "<IdDeProvincia>"	+ document.getElementById("selProvinciasPuntoEntrega").value + "</IdDeProvincia>"		
	xml += "</Localidad>"
	//Fin****************************************	
	
	return xml	
}


function fncTermClick() {
	if (document.getElementById("chkTerm").checked) {
		document.getElementById("btnRegistrarme").onmouseover = new Function("this.src='images/registrarme-N.jpg'")
		document.getElementById("btnRegistrarme").onmouseout = new Function("this.src='images/registrarme-A.jpg'")
		document.getElementById("btnRegistrarme").onmousedown = new Function("javascript:fncCambiaPassword(false);Dyn_fncGrabar()")
		document.getElementById("btnRegistrarme").src = "images/registrarme-A.jpg"		
	}
	else {
		document.getElementById("btnRegistrarme").onmouseover = ""
		document.getElementById("btnRegistrarme").onmouseout = ""
		document.getElementById("btnRegistrarme").onmousedown = ""
		document.getElementById("btnRegistrarme").src = "images/registrarme-G.jpg"		
	}
}

function fncNuevoUsu() {
	esNuevo = "S"
}

function IsMail(YourMail)
{
var Template = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/i //Formato de direccion de correo electronico
return (Template.test(YourMail)) ? 1 : 0 //Compara "YourMail" con el formato "Template" y si coincidevuelve verdadero si no devuelve falso
}

function fncVerComentarios() {
	window.open ("comentarios.asp?pag='rn_usuarios.asp'","","height=500,width=630,scrollbars=yes,status=0,unadorned=yes")
}

function fncNavega() {
	window.location.href="interconsultas_usu.asp?bu=XDFbnXGxJXHgJXgygXGyuyuGXYugyGXYGyuGASYGASYFXhghhzxhz98a66sa7s776asdtgxzy67sdttzyx67xs67576&CF=" + IdDeCasaFoto + "&SU=" + IdDeSucursal
}

function fncVerInterconsultas(error) {
	//Arma xml
	var salida = 0
	try{salida = error.getElementsByTagName('ResultadoOperacion')[0].childNodes.item(0).data} catch(e) {}

	if (salida == 1) {
		alert('Error en usuario y password')
	}

	document.getElementById("txtComentario").value = ""
	var xml = ''
	xml += "<Interconsulta>"
		xml += "<IdDeCasaFoto>"	+ IdDeCasaFoto + "</IdDeCasaFoto>"		
		xml += "<IdDeSucursal>"	+ IdDeSucursal + "</IdDeSucursal>"	
	xml += "</Interconsulta>"
	Dyn_fncEnviarTraerDatos(Dyn_Pag,1,"Interconsultas",xml,"","divInterconsultas",'')	
}

function fncVerInterconsultasPre() {
	//Arma xml
	var xml = ''
	xml += "<Interconsulta>"
	xml += "</Interconsulta>"
	Dyn_fncEnviarTraerDatos(Dyn_Pag,1,"InterconsultasPre",xml,"","divInterconsultas",'')	
}

function fncGrabaInterconsulta() {
	//Arma xml
	if (Usuario == 0 && (document.getElementById("txtMail").value == "" || document.getElementById("txtPassword").value == "")) {
		alert("Debe ingresar usuario y password")
	}
	else {
		if (document.getElementById("txtComentario").value != '') {
			var xml = ''
			xml += "<Interconsulta>"
				xml += "<Usuario>"	+ Usuario + "</Usuario>"
				if (Usuario == 0) {
					xml += "<MailDeUsuario>" + document.getElementById("txtMail").value + "</MailDeUsuario>"				
					xml += "<PasswordDeUsuario>" + document.getElementById("txtPassword").value + "</PasswordDeUsuario>"				
				}
				xml += "<IdDeCasaFoto>"	+ IdDeCasaFoto + "</IdDeCasaFoto>"		
				xml += "<IdDeSucursal>"	+ IdDeSucursal + "</IdDeSucursal>"	
				  texto = document.getElementById("txtComentario").value
				  texto = texto.replace(/\n/g,"###")
				xml += "<ConsultaDeInterconsulta>"	+ texto + "</ConsultaDeInterconsulta>"
			xml += "</Interconsulta>"
			Dyn_fncEnviarTraerDatos(Dyn_Pag,2,"GrabarInterconsultas",xml,"","",'fncVerInterconsultas')
		}
		else {
			alert("Debe ingresar una consulta")
		}
	}
}

