var tabs=7;//Numero de tabs en los formularios deingreso de publicacion
window.onload=function(){
	//para el encabezado
	MM_preloadimages1('img/boton2.2.jpg','img/boton1.1.jpg');
	//Para el aviso de primera carga de contenido
	document.getElementById("cargando").style.display="none";
	//botones('');
	document.getElementById("contenido").style.display="block";
	
	if(getCookie("user")){
		validarusuario_inicio();
		listar_publicaciones('');
		paginas_listado();
		
		setCookie("idpub",'', getExpDate(0,0,0));
		setCookie("idpub",'', getExpDate(0,0,0),"/");
		
		setCookie("lstcnt",'', getExpDate(0,0,0));
		setCookie("lstcnt",'', getExpDate(0,0,0),"/");
		
		setCookie("lstmg",'', getExpDate(0,0,0),"/");
		setCookie("lstmg",'', getExpDate(0,0,0));
		
		setCookie("idcont",'', getExpDate(0,0,0));
		
		document.getElementById("cuerpo").innerHTML=document.getElementById("misofetas").innerHTML;
		//document.getElementById("misofetas").style.display="block";
	}else{
		salir();
	}	
}

/*****************************Funciones de página principal - Publicacion***********************************/

function listar_publicaciones(pagina){
	var conexion = conexionajax();
	conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
	conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	conexion.onreadystatechange = function() {
		if (conexion.readyState==4) {	
			var texto = conexion.responseText;
			document.getElementById("lista_publicaciones").innerHTML="";
			document.getElementById("lista_publicaciones").innerHTML+=texto;
			paginas_listado(pagina);
		}
	}
	data='';
	data+="acciones=listar_publicaciones";
	data+="&idusuario="+getCookie("user");
	data+="&pagina="+pagina;
	conexion.send(data);
}

function paginas_listado(pagina){
	var conexion = conexionajax();
	conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
	conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	conexion.onreadystatechange = function() {
		if (conexion.readyState==4) {	
			var texto = conexion.responseText;
			document.getElementById("paginador_publicaciones").innerHTML="";
			document.getElementById("paginador_publicaciones").innerHTML+=texto;
		}
	}
	data='';
	data+="acciones=paginacion";
	data+="&idusuario="+getCookie("user");
	data+="&pagina="+pagina;
	conexion.send(data);
}

function eliminar_publicacion(id,pagina){
var conexion = conexionajax();
	conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
	conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	conexion.onreadystatechange = function() {
		if (conexion.readyState==4) {	
			var texto = conexion.responseXML;
			if(texto.getElementsByTagName("data")[0].firstChild.nodeValue == '1'){
				alert("Publicacion eliminada satisfactoriamente");
				listar_publicaciones(pagina);
			}else if(texto.getElementsByTagName("data")[0].firstChild.nodeValue == '0'){
				alert("Su solicitud no ha sido procesada,\nPor favor intente de nuevo");
			}
		}
	}
	data='';
	data+="acciones=eliminar_publicacion";
	data+="&idpublicacion="+id;
	conexion.send(data);
}

function nueva_publicacion(){
	document.getElementById("modificando").value="no";
	document.getElementById("cuerpo").innerHTML=document.getElementById("nueva_publicacion").innerHTML;
	//document.getElementById("nueva_publicacion").style.display='block';
	setCookie("idpub",'', getExpDate(0,0,0));
	setCookie("idpub",'', getExpDate(0,0,0),"/");
	
	setCookie("lstcnt",'', getExpDate(0,0,0));
	setCookie("lstcnt",'', getExpDate(0,0,0),"/");
	
	setCookie("lstmg",'', getExpDate(0,0,0),"/");
	setCookie("lstmg",'', getExpDate(0,0,0));
	
	setCookie("idcont",'', getExpDate(0,0,0));
	general('');
	listar_pais("lst_paises_pub");
}

function detalle_publicacion(id){
	ancho=650;
	alto=500;
	var izq= parseInt((screen.availWidth/2) - (ancho/2));
	var top= parseInt((screen.availHeight/2) - (alto/2));
	var ventana_detalle=window.open("includes/detallepub.php?id="+id, "", "status=no,menubar=no,height="+alto+",width="+ancho+",left="+izq+",top="+top+",screenX="+izq+",screenY="+top+" ");	
	ventana_detalle.focus();
}

/*****************************Funciones de reclamos - Publicacion***********************************/
function envio_reclamo(){
	if(document.getElementById("tipo_reclamo").value!='' && document.getElementById("txt_reclamos").value!=''){
	var conexion = conexionajax();
	conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
	conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	conexion.onreadystatechange = function() {
		if (conexion.readyState==4) {	
			listado=document.getElementById("atributos").getElementsByTagName('input').length;			
			var texto = conexion.responseXML;
			if(texto.getElementsByTagName("data")[0].firstChild.nodeValue == '1'){
				alert("Su reclamo ha sido enviado satisfactoriamente,\n en breve nos comunicaremos con usted");
				window.location.href ='misofertas.php';
			}else if(texto.getElementsByTagName("data")[0].firstChild.nodeValue == '0'){
				alert("Su solicitud no ha sido procesada,\nPor favor intente de nuevo");
			}
		}
	}
	data='';
	data+="acciones=insert_reclamo";
	data+="&idusuario="+getCookie("user");
	data+="&tipo_reclamo="+document.getElementById("tipo_reclamo").value;
	data+="&txt_reclamos="+document.getElementById("txt_reclamos").value;
	conexion.send(data);
	}else{
		alert("Debe llenar todos los campos para poder procesar su reclamo");
	}
}

/*****************************Funciones de edición - Publicacion***********************************/

function editar_pub(id){
	setCookie("idpub",id, getExpDate(1,1,1));
	for(var i=0; i<tabs; i++){
		document.getElementById("pestanias_"+i).style.color="#02D202";
	}
	document.getElementById("modificando").value="si";
	document.getElementById("ver_pub").style.display="block";
	document.getElementById("cuerpo").innerHTML=document.getElementById("nueva_publicacion").innerHTML;
	document.getElementById("pub_general").style.display='block';
	document.getElementById("pestanias_0").className="pestana2";
	document.getElementById("txt_nombre_facturacion").disabled=true;
	document.getElementById("txt_apellido_facturacion").disabled=true;
	document.getElementById("txt_dirfiscal").disabled=true;
	document.getElementById("result_dirfis").disabled=true;
	document.getElementById("lst_documento_facturacion").disabled=true;
	document.getElementById("txt_docnumero").disabled=true;
	mostrar_fpagopub(id);
	mostrar_tarifas(id);
	listar_contactos(id);
	contenido_tab4(id);
	setTimeout("contenido_tab3("+id+")",100);
	contenido_tab2(id);
	contenido_tab1(id);		
}

function contenido_tab4(id){
	var conexion = conexionajax();
	conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
	conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	conexion.onreadystatechange = function() {
		if (conexion.readyState==4) {	
			var texto = conexion.responseXML;
			/*tipo de divisa*/
			tdivisa=document.getElementById("lst_divisa");
			option=document.createElement("option");
			option.setAttribute("value",texto.getElementsByTagName("iddivisa")[0].firstChild.nodeValue);
			option.setAttribute("selected","true");
			option.innerHTML=texto.getElementsByTagName("divisa")[0].firstChild.nodeValue;
			tdivisa.appendChild(option);
			document.getElementById("txt_precio").value=texto.getElementsByTagName("precio")[0].firstChild.nodeValue;
			document.getElementById("txt_centimos_precio").value=texto.getElementsByTagName("centimos")[0].firstChild.nodeValue;
			mostrar_formaspago(id);
		}
	}
	data='';
	data+="acciones=mostrar_precio";
	data+="&idpublicacion="+id;
	conexion.send(data);
}

function contenido_tab3(id){
	var conexion = conexionajax();
	conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
	conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	conexion.onreadystatechange = function() {
		if (conexion.readyState==4) {	
			var texto = conexion.responseXML;
			/*Mostrar capacidad*/
			capacidad=document.getElementById("lst_capacidad");
			option=document.createElement("option");
			option.setAttribute("value",texto.getElementsByTagName("capacidad")[0].firstChild.nodeValue);
			option.setAttribute("selected","true");
			option.innerHTML=texto.getElementsByTagName("capacidad")[0].firstChild.nodeValue;
			capacidad.appendChild(option);
			/*Mostrar numero de habitaciones*/
			habitaciones=document.getElementById("lst_habitaciones");
			option=document.createElement("option");
			option.setAttribute("value",texto.getElementsByTagName("habitaciones")[0].firstChild.nodeValue);
			option.setAttribute("selected","true");
			option.innerHTML=texto.getElementsByTagName("habitaciones")[0].firstChild.nodeValue;
			habitaciones.appendChild(option);
			/*Mostrar tipo de transaccion*/
			transaccion=document.getElementById("lst_tipo_trans");
			option=document.createElement("option");
			option.setAttribute("value",texto.getElementsByTagName("tipo_transaccion")[0].firstChild.nodeValue);
			option.setAttribute("selected","true");
			option.innerHTML=texto.getElementsByTagName("transaccion")[0].firstChild.nodeValue;
			transaccion.appendChild(option);
			/*fechas*/
			fecha1=texto.getElementsByTagName("desde")[0].firstChild.nodeValue;
			fecha2=texto.getElementsByTagName("hasta")[0].firstChild.nodeValue;
			desde= fecha1.split("-");
			hasta= fecha2.split("-");
			/*Dia inicio*/
			diai=document.getElementById("lst_diainicio");
			option=document.createElement("option");
			option.setAttribute("value",desde[2]);
			option.setAttribute("selected","true");
			option.innerHTML=desde[2];
			diai.appendChild(option);
			/*Mes inicio*/
			mesi=document.getElementById("lst_mesinicio");
			option=document.createElement("option");
			option.setAttribute("value",desde[1]);
			option.setAttribute("selected","true");
			option.innerHTML=desde[1];
			mesi.appendChild(option);
			/*Año inicio*/
			anioi=document.getElementById("lst_anioinicio");
			option=document.createElement("option");
			option.setAttribute("value",desde[0]);
			option.setAttribute("selected","true");
			option.innerHTML=desde[0];
			anioi.appendChild(option);
			/*Dia fin*/
			diaf=document.getElementById("lst_diafin");
			option=document.createElement("option");
			option.setAttribute("value",hasta[2]);
			option.setAttribute("selected","true");
			option.innerHTML=hasta[2];
			diaf.appendChild(option);
			/*Mes fin*/
			mesf=document.getElementById("lst_mesfin");
			option=document.createElement("option");
			option.setAttribute("value",hasta[1]);
			option.setAttribute("selected","true");
			option.innerHTML=hasta[1];
			mesf.appendChild(option);
			/*Año fin*/
			aniof=document.getElementById("lst_aniofin");
			option=document.createElement("option");
			option.setAttribute("value",hasta[0]);
			option.setAttribute("selected","true");
			option.innerHTML=hasta[0];
			aniof.appendChild(option);
			/*Dia y noches*/
			fechacalculo();
		}
	}
	data='';
	data+="acciones=mostrar_disponibilidad";
	data+="&idpublicacion="+id;
	conexion.send(data);
}

function contenido_tab2(id){
	var conexion = conexionajax();
	conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
	conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	conexion.onreadystatechange = function() {
		if (conexion.readyState==4) {	
			var texto = conexion.responseXML;
			document.getElementById("txt_atributos").value=texto.getElementsByTagName("descripcion")[0].firstChild.nodeValue;
			textCounter(document.getElementById('txt_atributos'),document.getElementById('result2'),500);
			mostrar_atributos(id);
		}
	}
	data='';
	data+="acciones=mostrar_descripcion";
	data+="&idpublicacion="+id;
	conexion.send(data);
}

function contenido_tab1(id){
	var conexion = conexionajax();
	conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
	conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	conexion.onreadystatechange = function() {
		if (conexion.readyState==4) {	
			var texto = conexion.responseXML;
			if(texto.getElementsByTagName("data")[0].firstChild.nodeValue == '1'){
				document.getElementById("txt_complejo").value=texto.getElementsByTagName("nombre")[0].firstChild.nodeValue;
				document.getElementById("txt_ciudad").value=texto.getElementsByTagName("ciudad")[0].firstChild.nodeValue;
				document.getElementById("txt_direccion").value=texto.getElementsByTagName("direccion")[0].firstChild.nodeValue;
				setTimeout("listar_pais('lst_paises_pub')",10);
				setTimeout("mostrar_paises('"+texto.getElementsByTagName("idpais")[0].firstChild.nodeValue+"','"+texto.getElementsByTagName("pais")[0].firstChild.nodeValue+"')",100);
				setTimeout("listar_estado('lst_estados_pub',document.getElementById('lst_paises_pub'))",150);
				setTimeout("mostrar_estados('"+texto.getElementsByTagName("idestado")[0].firstChild.nodeValue+"','"+texto.getElementsByTagName("estados")[0].firstChild.nodeValue+"')",1000);
				mostrar_categoria(texto.getElementsByTagName("idpblcategoria")[0].firstChild.nodeValue,texto.getElementsByTagName("categoria")[0].firstChild.nodeValue);
				if(texto.getElementsByTagName("web")[0].firstChild.nodeValue!=""){
					document.getElementById("txt_pweb").value=texto.getElementsByTagName("web")[0].firstChild.nodeValue;
				}
			}
		}
	}
	data='';
	data+="acciones=mostrar_general";
	data+="&idpublicacion="+id;
	conexion.send(data);
}

function mostrar_categoria(id,nombre){
	/*Mostrar categoria*/
	optioncat_editar=document.createElement("option");
	optioncat_editar.setAttribute("value",id);
	optioncat_editar.setAttribute("selected","true");
	optioncat_editar.innerHTML=nombre;
	document.getElementById("lst_categorias").appendChild(optioncat_editar);
}

function mostrar_paises(id,pais){
	combopais_editar=document.getElementById("lst_paises_pub");
	option_peditar=document.createElement("option");
	option_peditar.setAttribute("value",id);
	option_peditar.setAttribute("selected","true");
	option_peditar.innerHTML=pais;
	combopais_editar.appendChild(option_peditar);
}

function mostrar_estados(id,estado){
	optionest_editar=document.createElement("option");
	optionest_editar.setAttribute("value",id);
	optionest_editar.setAttribute("selected","true");
	optionest_editar.innerHTML=estado;
	document.getElementById("lst_estados_pub_select").appendChild(optionest_editar);
}

function mostrar_atributos(id){
	var conexion = conexionajax();
	conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
	conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	conexion.onreadystatechange = function() {
		if (conexion.readyState==4) {	
			listado=document.getElementById("atributos").getElementsByTagName('input').length;			
			var texto = conexion.responseXML;
			if(texto.getElementsByTagName("data")[0].firstChild.nodeValue == '1'){
				atributos_bd=texto.getElementsByTagName("listado")[0].firstChild.nodeValue;
				lista_atributos= atributos_bd.split("@");
				//alert(lista_atributos.length);
				for(var i=0; i<listado; i++){
					for(var y=0;y<lista_atributos.length;y++){
						if(document.getElementById("chk_caracteristica"+i).value==lista_atributos[y]){
							document.getElementById("chk_caracteristica"+i).checked=true;
						}
					}
				}
			}
		}
	}
	data='';
	data+="acciones=mostrar_atributos";
	data+="&idusuario="+getCookie("user");
	data+="&idpublicacion="+id;
	conexion.send(data);
}

function mostrar_formaspago(id){
	var conexion = conexionajax();
	conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
	conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	conexion.onreadystatechange = function() {
		if (conexion.readyState==4) {	
			var listado=document.getElementById("formaspago").getElementsByTagName('input').length;			
			var texto = conexion.responseXML;
			if(texto.getElementsByTagName("data")[0].firstChild.nodeValue == '1'){
				var formaspago_bd=texto.getElementsByTagName("listado")[0].firstChild.nodeValue;
				var lista_formapagos= formaspago_bd.split("@");
				//alert(lista_atributos.length);
				for(var i=0; i<listado; i++){
					for(var y=0;y<lista_formapagos.length;y++){
							if(document.getElementById("chk_formapago"+i).value==lista_formapagos[y]){
							document.getElementById("chk_formapago"+i).checked=true;
						}
					}
				}
			}
		}
	}
	data='';
	data+="acciones=mostrar_formaspago";
	data+="&idusuario="+getCookie("user");
	data+="&idpublicacion="+id;
	conexion.send(data);
}

function mostrar_tarifas(id){
	var conexion = conexionajax();
	conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
	conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	conexion.onreadystatechange = function() {
		if (conexion.readyState==4) {	
			listado=document.getElementById("factura_pub").getElementsByTagName('input').length;			
			var texto = conexion.responseXML;
			if(texto.getElementsByTagName("data")[0].firstChild.nodeValue == '1'){
				res_tarifas=texto.getElementsByTagName("listado")[0].firstChild.nodeValue;
				lista_tarifas= res_tarifas.split("@");
				//alert(lista_atributos.length);
				for(var i=0; i<listado; i++){
					document.getElementById("tarifas_check"+i).disabled=true;
					for(var y=0;y<lista_tarifas.length;y++){
						if(document.getElementById("tarifas_check"+i).value==lista_tarifas[y]){
							document.getElementById("tarifas_check"+i).checked=true;
						}
					}
				}
				chequeados(listado);
			}
		}
	}
	data='';
	data+="acciones=mostrar_tarifas";
	data+="&idusuario="+getCookie("user");
	data+="&idpublicacion="+id;
	conexion.send(data);
	
}

function mostrar_fpagopub(id){
	var conexion = conexionajax();
	conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
	conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	conexion.onreadystatechange = function() {
		if (conexion.readyState==4) {	
			var texto = conexion.responseXML;
			var listado=document.getElementById("chck_formaspago").getElementsByTagName('input').length;			
			for(var i=0; i<listado; i++){
				document.getElementById("frmpagos_check"+i).disabled=true;
				if(document.getElementById("frmpagos_check"+i).value==texto.getElementsByTagName("idformapago")[0].firstChild.nodeValue){
					document.getElementById("frmpagos_check"+i).checked=true;
				}
			}
		}
	}
	data='';
	data+="acciones=mostrar_fpagopub";
	data+="&idpublicacion="+id;
	conexion.send(data);
	
}


/*****************************Boton Siguiente - Guardar***********************************/
function siguiente_pestania(id){
	if(document.getElementById("pestanias_0").className=='pestana2'){
		guardar_general(id);
	}
	
	if(document.getElementById("pestanias_1").className=='pestana2'){
		guardar_descripcion(id);
	}
	
	if(document.getElementById("pestanias_2").className=='pestana2'){
		guardar_disponibilidad(id);
	}
	
	if(document.getElementById("pestanias_3").className=='pestana2'){
		guardar_precio(id);
	}
	//Contactos
	imagenestab=0;
	if(document.getElementById("pestanias_4").className=='pestana2'){
		if(getCookie('lstcnt')==1){
			imagenes(id);
			imagenestab=1;
		}else{
			alert("Debe registrar por lo menos un contacto para poder continuar");
		}
	}
	
	tarifastab=0;
	if(document.getElementById("pestanias_5").className=='pestana2' && imagenestab==0){
		document.getElementById("pestanias_6").disabled=false;
		tarifas(id);
		if(getCookie('lstmg')==1){
			document.getElementById('pestanias_5').style.color='#02D202';
		}
		tarifastab=1;
	}
	
	if(document.getElementById("pestanias_6").className=='pestana2' && tarifastab==0){
		var paso=0;
		
		if(document.getElementById("datos_precios").style.display=='block' && paso==0){
			document.getElementById("datos_precios").style.display='none';
			guardar_factura(id);
			paso=1;
		}
		
		if(document.getElementById("aviso_publicacion").style.display=='block' && paso==0){
			formas_pago(id);			
			paso=1;
		}
				
		if(document.getElementById("datos_facturacion").style.display=='block' && paso==0){
			datos_facturacion();
		}
	}
}
/*****************************Acciones boton anterior ***********************************/
function anterior_pestania(id)
{
	if(document.getElementById("pestanias_1").className=='pestana2')
	{
		general(id);	
	}
	
	if(document.getElementById("pestanias_2").className=='pestana2')
	{
		descripcion(id);	
	}
	
	if(document.getElementById("pestanias_3").className=='pestana2')
	{
		disponibilidad(id);	
	}
	
	if(document.getElementById("pestanias_4").className=='pestana2')
	{
		precio(id);	
	}
	
	if(document.getElementById("pestanias_5").className=='pestana2')
	{
		cantactos(id);	
	}
	
	if(document.getElementById("pestanias_6").className=='pestana2' && document.getElementById("datos_precios").style.display=='block')
	{
		imagenes(id);	
	}
	
	if(document.getElementById("pestanias_6").className=='pestana2' && document.getElementById("aviso_publicacion").style.display=='block')
	{
		document.getElementById("datos_facturacion").style.display='none';
		document.getElementById("datos_precios").style.display='block';
		document.getElementById("aviso_publicacion").style.display='none';
	}
	
	if(document.getElementById("pestanias_6").className=='pestana2' && document.getElementById("datos_facturacion").style.display=='block')
	{
		document.getElementById("datos_facturacion").style.display='none';
		document.getElementById("datos_precios").style.display='none';
		document.getElementById("aviso_publicacion").style.display='block';
		document.getElementById("btn_siguiente").value='Siguiente >>';
	}
}

/*****************************Acciones pestaña General ***********************************/
function general(id){
	for(var i=0; i<tabs; i++){
		if(i!=0){
			document.getElementById("pestanias_"+i).setAttribute("class","pestana");
			document.getElementById("pestanias_"+i).className="pestana";
		}else{
			document.getElementById("pestanias_"+i).setAttribute("class","pestana2");
			document.getElementById("pestanias_"+i).className="pestana2";
		}
	}
	document.getElementById("pub_general").style.display='block';
	document.getElementById("pub_dsecripcion").style.display='none';
	document.getElementById("pub_disponibilidad").style.display='none';
	document.getElementById("pub_precio").style.display='none';
	document.getElementById("pub_contacto").style.display='none';
	document.getElementById("pub_imagenes").style.display='none';
	document.getElementById("pub_tarifas").style.display='none';
	document.getElementById("btn_anterior").style.display='none';
}

function guardar_general(id){
	if(document.getElementById("lst_categorias").value!=""&&
	document.getElementById("txt_complejo").value!=""&&
	document.getElementById("lst_paises_pub").value!=""&&
	document.getElementById("lst_estados_pub_select").value!=""&&
	document.getElementById("txt_ciudad").value!=""&&
	document.getElementById("txt_direccion").value!=""
	){
		var conexion = conexionajax();
		conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
		conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		conexion.onreadystatechange = function() {
			if (conexion.readyState==4) {
				//datos de usuario
				var texto = conexion.responseXML;
				if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '1'){
					/*Seteando la cookie del usuario para que dure una hora (dias, horas, minutos)*/
					if(getCookie("idpub")){
						setCookie("idpub",getCookie("idpub"), getExpDate(1,0,0));
					}else{
						setCookie("idpub",texto.getElementsByTagName("idpublicacion")[0].firstChild.nodeValue, getExpDate(1,0,0));
					}
					setTimeout("descripcion('"+getCookie("idpub")+"')",100);
					document.getElementById("pestanias_1").disabled=false;
					document.getElementById('pestanias_0').style.color='#02D202';
				}else{
					alert("Ha ocurrido un error al procesar su requerimiento\nPor favor intente de nuevo");
				}
			}
		}
		data='';
		data+="acciones=guardageneral";
		data+="&idusuario="+getCookie("user");
		data+="&idpublicacion="+id;
		/*Datos del formulario*/
		data+="&lst_categorias="+document.getElementById("lst_categorias").value;
		data+="&txt_complejo="+document.getElementById("txt_complejo").value;
		data+="&lst_paises="+document.getElementById("lst_paises_pub").value;
		data+="&lst_estados="+document.getElementById("lst_estados_pub_select").value;
		data+="&txt_ciudad="+document.getElementById("txt_ciudad").value;
		data+="&txt_direccion="+document.getElementById("txt_direccion").value;
		data+="&txt_pweb="+document.getElementById("txt_pweb").value;
		conexion.send(data);
	}else{
		alert("Todos los campos son obligatorios");
	}
}

function cambio_precio(id){
	/*Si no es resort debe ser puesto el precio por noche*/
	if(id!='2'){
		document.getElementById("pordia").style.display="block";
	}else{
		document.getElementById("pordia").style.display="none";
	}
}

/*****************************Acciones pestaña Descripcion ***********************************/

function descripcion(id){
	for(var i=0; i<tabs; i++){
		if(i!=1){
			document.getElementById("pestanias_"+i).setAttribute("className","pestana");
			document.getElementById("pestanias_"+i).className="pestana";
		}else{
			document.getElementById("pestanias_"+i).setAttribute("className","pestana2");
			document.getElementById("pestanias_"+i).className="pestana2";
		}
	}
	document.getElementById("pub_general").style.display='none';
	document.getElementById("pub_disponibilidad").style.display='none';
	document.getElementById("pub_dsecripcion").style.display='block';
	document.getElementById("pub_precio").style.display='none';
	document.getElementById("pub_contacto").style.display='none';
	document.getElementById("pub_imagenes").style.display='none';
	document.getElementById("pub_tarifas").style.display='none';
	document.getElementById("btn_anterior").style.display='block';
}

function guardar_descripcion(id){
	var atributos=parseInt(document.getElementById("num_atributos").innerHTML);	
	listado='';
	for(var i=0; i<atributos;i++){
		if(document.getElementById("chk_caracteristica"+i).checked==true){
			listado+=document.getElementById("chk_caracteristica"+i).value+"@";	
		}
	}
	if(listado!='' && document.getElementById("txt_atributos").value!=''){
		var conexion = conexionajax();
		conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
		conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		conexion.onreadystatechange = function() {
			if (conexion.readyState==4) {
				//datos de usuario
				var texto = conexion.responseXML;
				if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '1'){
					/*Seteando la cookie del usuario para que dure una hora (dias, horas, minutos)*/
					if(getCookie("idpub")){
						setCookie("idpub",getCookie("idpub"), getExpDate(1,0,0));
					}else{
						setCookie("idpub",texto.getElementsByTagName("idpublicacion")[0].firstChild.nodeValue, getExpDate(1,0,0));
					}
					setTimeout("disponibilidad('"+id+"')",100);
					document.getElementById("pestanias_2").disabled=false;
					document.getElementById('pestanias_1').style.color='#02D202';
				}else if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue =='0'){
					alert("Ha ocurrido un error al procesar su requerimiento\nPor favor intente de nuevo");
				}
			}
		}
		data='';
		data+="acciones=guarda_atributo";
		data+="&idusuario="+getCookie("user");
		data+="&idpublicacion="+id;
		/*Datos del formulario*/
		data+="&idatributos="+listado;
		data+="&txt_atributos="+document.getElementById("txt_atributos").value;
		conexion.send(data);
	}else{
		alert("Debe completar toda la información requerida para procesar su solicitud");
	}
}



/*****************************Acciones pestaña Disponibilidad ***********************************/

function disponibilidad(id){
	for(var i=0; i<tabs; i++){
		if(i!=2){
			document.getElementById("pestanias_"+i).setAttribute("className","pestana");
			document.getElementById("pestanias_"+i).className="pestana";
		}else{
			document.getElementById("pestanias_"+i).setAttribute("className","pestana2");
			document.getElementById("pestanias_"+i).className="pestana2";
		}
	}
	document.getElementById("pub_general").style.display='none';
	document.getElementById("pub_disponibilidad").style.display='block';
	document.getElementById("pub_dsecripcion").style.display='none';
	document.getElementById("pub_precio").style.display='none';
	document.getElementById("pub_contacto").style.display='none';
	document.getElementById("pub_imagenes").style.display='none';
	document.getElementById("pub_tarifas").style.display='none';
	document.getElementById("btn_anterior").style.display='block';
}

function guardar_disponibilidad(id){
	if(
	document.getElementById("lst_tipo_trans").value!=''&&
	document.getElementById("lst_capacidad").value!=''&&
	document.getElementById("lst_habitaciones").value!=''&&
	document.getElementById("lst_diainicio").value!=''&&
	document.getElementById("lst_mesinicio").value!=''&&
	document.getElementById("lst_anioinicio").value!=''&&
	document.getElementById("lst_diafin").value!=''&&
	document.getElementById("lst_mesfin").value!=''&&
	document.getElementById("lst_aniofin").value!=''
	){
		var conexion = conexionajax();
		conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
		conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		conexion.onreadystatechange = function() {
			if (conexion.readyState==4) {
				//datos de usuario
				var texto = conexion.responseXML;
				if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '1'){
					/*Seteando la cookie del usuario para que dure una hora (dias, horas, minutos)*/
					if(getCookie("idpub")){
						setCookie("idpub",getCookie("idpub"), getExpDate(1,0,0));
					}else{
						setCookie("idpub",texto.getElementsByTagName("idpublicacion")[0].firstChild.nodeValue, getExpDate(1,0,0));
					}
					setTimeout("precio('"+id+"')",100);
					document.getElementById("pestanias_3").disabled=false;
					document.getElementById('pestanias_2').style.color='#02D202';
				}else if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue =='0'){
					alert("Ha ocurrido un error al procesar su requerimiento\nPor favor intente de nuevo");
				}
			}
		}
		data='';
		data+="acciones=guarda_descripcion";
		data+="&idusuario="+getCookie("user");
		data+="&idpublicacion="+id;
		/*Datos del formulario*/
		data+="&lst_capacidad="+document.getElementById("lst_capacidad").value;
		data+="&lst_habitaciones="+document.getElementById("lst_habitaciones").value;
		data+="&lst_diainicio="+document.getElementById("lst_diainicio").value;
		data+="&lst_mesinicio="+document.getElementById("lst_mesinicio").value;
		data+="&lst_anioinicio="+document.getElementById("lst_anioinicio").value;
		data+="&lst_diafin="+document.getElementById("lst_diafin").value;
		data+="&lst_mesfin="+document.getElementById("lst_mesfin").value;
		data+="&lst_aniofin="+document.getElementById("lst_aniofin").value;
		data+="&lst_tipo_trans="+document.getElementById("lst_tipo_trans").value;
		conexion.send(data);
	}else{
		alert("Debe completar toda la información requerida para procesar su solicitud");	
	}
}

//Cálculo de d�as entre una fecha y otra
function daysBetween (inicio, fin){
	var DSTadjust=0;
	//Constantes para ser utilizadas para los c�lculos siguientes
	oneMinute=1000*60;
	var oneDay = oneMinute * 60 * 24;
	//iguala las horas en caso de que los objetos la incluyan
	inicio.setHours(0);
	inicio.setMinutes(0);
	inicio.setSeconds(0);
	fin.setHours(0);
	fin.setMinutes(0);
	fin.setSeconds(0);
	// tenemos en cuenta los ajustes del horario de verano
	if(fin > inicio){
		DSTadjust =(fin.getTimezoneOffset() - inicio.getTimezoneOffset())* oneMinute;
	}else{
		DSTadjust =(inicio.getTimezoneOffset() - fin.getTimezoneOffset())* oneMinute;
	}
	
	var diff = Math.abs(fin.getTime() - inicio.getTime()) - DSTadjust;
	return Math.ceil (diff/oneDay);
}

//tomando lo datos para hacer posible el c�lculo de d�as y noches
function fechacalculo(){
	var resultado = 0;
	if(document.getElementById("lst_diainicio").value!="" &&
	document.getElementById("lst_mesinicio").value!="" &&
	document.getElementById("lst_anioinicio").value!=""
	){
		var inicio = new Date (document.getElementById("lst_anioinicio").value,document.getElementById("lst_mesinicio").value-1,document.getElementById("lst_diainicio").value);
	}
	
	if(document.getElementById("lst_diafin").value!="" &&
	document.getElementById("lst_mesfin").value!="" &&
	document.getElementById("lst_aniofin").value!=""
	){
		var fin = new Date (document.getElementById("lst_aniofin").value,document.getElementById("lst_mesfin").value-1,document.getElementById("lst_diafin").value);
	}
	
	if(
	document.getElementById("lst_diainicio").value!="" &&
	document.getElementById("lst_mesinicio").value!="" &&
	document.getElementById("lst_anioinicio").value!="" &&
	document.getElementById("lst_diafin").value!="" &&
	document.getElementById("lst_mesfin").value!="" &&
	document.getElementById("lst_aniofin").value!=""
	){
		if(fin > inicio){
			resultado= daysBetween(inicio, fin);
		}else{
			document.getElementById("lst_diainicio").value="";
			document.getElementById("lst_mesinicio").value="";
			document.getElementById("lst_anioinicio").value="";
			document.getElementById("lst_diafin").value="";
			document.getElementById("lst_mesfin").value="";
			document.getElementById("lst_aniofin").value="";
			alert("La fecha de inicio debe ser menor a la fecha de fin");
		}
	}
	
	if(resultado!=0){
		document.getElementById("diasnoches").innerHTML=(resultado+1)+" d&iacute;as y "+resultado+" noches";	
		document.getElementById("Totaldias").style.display="block";
	}
}


/*****************************Acciones pestaña Precio ***********************************/

function precio(id){
	for(var i=0; i<tabs; i++){
		if(i!=3){
			document.getElementById("pestanias_"+i).setAttribute("className","pestana");
			document.getElementById("pestanias_"+i).className="pestana";
		}else{
			document.getElementById("pestanias_"+i).setAttribute("className","pestana2");
			document.getElementById("pestanias_"+i).className="pestana2";
		}
	}
	document.getElementById("pub_general").style.display='none';
	document.getElementById("pub_dsecripcion").style.display='none';
	document.getElementById("pub_disponibilidad").style.display='none';
	document.getElementById("pub_precio").style.display='block';
	document.getElementById("pub_contacto").style.display='none';
	document.getElementById("pub_imagenes").style.display='none';
	document.getElementById("pub_tarifas").style.display='none';
	document.getElementById("btn_anterior").style.display='block';
}

function guardar_precio(id){
	var formaspagos=document.getElementById("formaspago").getElementsByTagName('input').length;
	listado='';
	for(var i=0; i<formaspagos;i++){
		if(document.getElementById("chk_formapago"+i).checked==true){
			listado+=document.getElementById("chk_formapago"+i).value+"@";	
		}
	}
	if(
	document.getElementById("lst_divisa").value!=''&&
	document.getElementById("txt_precio").value!=''&&
	listado !=''
	){
		var conexion = conexionajax();
		conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
		conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		conexion.onreadystatechange = function() {
			if (conexion.readyState==4) {
				//datos de usuario
				var texto = conexion.responseXML;
				if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '1'){
					/*Seteando la cookie del usuario para que dure una hora (dias, horas, minutos)*/
					if(getCookie("idpub")){
						setCookie("idpub",getCookie("idpub"), getExpDate(1,0,0));
					}else{
						setCookie("idpub",texto.getElementsByTagName("idpublicacion")[0].firstChild.nodeValue, getExpDate(1,0,0));
					}
					setTimeout("cantactos('"+id+"')",100);
					document.getElementById("pestanias_4").disabled=false;
					document.getElementById('pestanias_3').style.color='#02D202';
				}else if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue =='0'){
					alert("Ha ocurrido un error al procesar su requerimiento\nPor favor intente de nuevo");
				}
			}
		}
		if(document.getElementById("txt_centimos_precio").value==''){
			centimos='00';
		}else{
			centimos=document.getElementById("txt_centimos_precio").value;
		}
		data='';
		data+="acciones=guarda_precio";
		data+="&idusuario="+getCookie("user");
		data+="&idpublicacion="+id;
		/*Datos del formulario*/
		data+="&lst_divisa="+document.getElementById("lst_divisa").value;
		data+="&txt_precio="+document.getElementById("txt_precio").value+"."+centimos;
		data+="&formaspago="+listado;
		conexion.send(data);
	}else{
		alert("Debe completar toda la información requerida para procesar su solicitud");	
	}
}
/*****************************Acciones pestaña Contacto ***********************************/

function cantactos(id){
	listar_contactos(id);
	for(var i=0; i<tabs; i++){
		if(i!=4){
			document.getElementById("pestanias_"+i).setAttribute("className","pestana");
			document.getElementById("pestanias_"+i).className="pestana";
		}else{
			document.getElementById("pestanias_"+i).setAttribute("className","pestana2");
			document.getElementById("pestanias_"+i).className="pestana2";
		}
	}
	document.getElementById("pub_general").style.display='none';
	document.getElementById("pub_dsecripcion").style.display='none';
	document.getElementById("pub_disponibilidad").style.display='none';
	document.getElementById("pub_precio").style.display='none';
	document.getElementById("pub_contacto").style.display='block';
	document.getElementById("pub_imagenes").style.display='none';
	document.getElementById("pub_tarifas").style.display='none';
	document.getElementById("btn_anterior").style.display='block';
}

function listar_contactos(id){
	document.getElementById("botones_navegabilidad").style.display='block';
	var conexion = conexionajax();
	conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
	conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	conexion.onreadystatechange = function() {
		if (conexion.readyState==4) {
			//datos de usuario
			var texto = conexion.responseText;
			document.getElementById("pub_contacto").innerHTML="";
			document.getElementById("pub_contacto").innerHTML+=texto;
			if(getCookie('lstcnt')=='1'){
				document.getElementById("pestanias_4").style.color="#02D202";
				document.getElementById("pestanias_5").disabled=false;
			}
			if(getCookie("idcont")==1){
				document.getElementById("chk_contacto").style.display='none';
			}
		}
	}
	data='';
	data+="acciones=listar_contactos";
	data+="&idusuario="+getCookie("user");
	data+="&idpublicacion="+id;
	conexion.send(data);
}

function usuario_contacto(id){
	var conexion = conexionajax();
	conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
	conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	conexion.onreadystatechange = function() {
		if (conexion.readyState==4) {
			//datos de usuario
			var texto = conexion.responseXML;
			if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '1'){
				setCookie("idcont","1", getExpDate(1,0,0));
				document.getElementById("chk_contacto").style.display='none';
				listar_contactos(id);
			}else{
				alert("Ha ocurrido un error al procesar su requerimiento\nPor favor intente de nuevo");
			}
		}
	}
	data='';
	data+="acciones=usuario_contacto";
	data+="&idusuario="+getCookie("user");
	data+="&idpublicacion="+id;
	conexion.send(data);
}

function nuevo_contacto(id,idcontacto){
	document.getElementById("pub_contacto").innerHTML=document.getElementById("pub_nuevocontacto").innerHTML;
	document.getElementById("botones_navegabilidad").style.display='none';
	listar_telefonos_contacto(id,idcontacto);
}

function agregar_telefono_contacto(id,idcontacto){
	if(document.getElementById("lst_telefonos_cont").value!='' &&
	document.getElementById("txt_codigo_cont").value!="" &&
	document.getElementById("txt_numero_cont").value!=""){
		var conexion = conexionajax();
		conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
		conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		conexion.onreadystatechange = function() {
			if (conexion.readyState==4) {
				//datos de usuario
				var texto = conexion.responseXML;
				if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '1'){
					/*Seteando la cookie del usuario para que dure una hora (dias, horas, minutos)*/
					listar_telefonos_contacto(id,idcontacto);
				}else{
					alert("Ha ocurrido un error al procesar su requerimiento\nPor favor intente de nuevo");
				}
			}
		}
		data='';
		data+="acciones=agregar_telefono_contacto";
		data+="&idusuario="+getCookie("user");
		data+="&idpublicacion="+id;
		data+="&idnuevocontac="+idcontacto;
		data+="&lst_telefonos_cont="+document.getElementById("lst_telefonos_cont").value;
		data+="&txt_codigo_cont="+document.getElementById("txt_codigo_cont").value;
		data+="&txt_numero_cont="+document.getElementById("txt_numero_cont").value;
		conexion.send(data);
	}else{
		alert("Para agregar un nuevo teléfono debe llenar todos los campos requeridos");
	}
}

function eliminar_telefono_contacto(id,idcontacto){
	var conexion = conexionajax();
	var idtelefono='';
	num=document.getElementById("lista_tlf_cnt").getElementsByTagName('input').length;
	for(var i=0; i< num; i++){
		if(document.getElementById("opc_idtelefono_cnt"+i).checked==true){
			idtelefono+="@"+document.getElementById("opc_idtelefono_cnt"+i).value;		
		}
	}
	conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
	conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	conexion.onreadystatechange = function() {
		if (conexion.readyState==4) {
			var texto = conexion.responseXML;
			if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '1'){
				//mensaje de registro satisfactorio
				alert("Número(s) de teléfono eliminado satisfactoriamente");
				listar_telefonos_contacto(id,idcontacto);
			}else if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '0'){
				//mensaje d eerror
				alert("Ha ocurrido un error al procesar su información\nVerifique sus datos e intente de nuevo");
			}
		}
	}
	conexion.send("acciones=eliminar_telefono_cont&idtelefono="+idtelefono);
}

function guardar_contacto(id,idcontacto){
	var conexion = conexionajax();
	if(document.getElementById("txt_nombrecontacto").value!="" &&
	document.getElementById("txt_apellidocontacto").value!="" &&
	document.getElementById("txt_emailcontacto").value!="" ){
		conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
		conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		conexion.onreadystatechange = function() {
			if (conexion.readyState==4) {
				var texto = conexion.responseXML;
				if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '1'){
					//mensaje de registro satisfactorio
					alert("Contacto agregado satisfactoriamente");
					listar_contactos(id);
					/*borrando la cookies creada*/
					setCookie("idncnt",'', getExpDate(0,0,0));
				}else if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '0'){
					//mensaje d eerror
					alert("Ha ocurrido un error al procesar su información\nVerifique sus datos e intente de nuevo");
				}
			}
		}
		data='';
		data+="acciones=usuario_contacto";
		data+="&idusuario="+getCookie("user");
		data+="&idpublicacion="+id;
		data+="&idnuevocontac="+idcontacto;
		data+="&txt_nombrecontacto="+document.getElementById("txt_nombrecontacto").value;
		data+="&txt_apellidocontacto="+document.getElementById("txt_apellidocontacto").value;
		data+="&txt_emailcontacto="+document.getElementById("txt_emailcontacto").value;
		conexion.send(data);
	}else{
		alert("Debe completar todos los datos del contacto para poder procesar su petición");
	}
}

function listar_telefonos_contacto(id,idcontacto){
	var conexion = conexionajax();
	conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
	conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	conexion.onreadystatechange = function() {
		if (conexion.readyState==4) {
			//datos de usuario
			var texto = conexion.responseText;
			/*Seteando la cookie del usuario para que dure una hora (dias, horas, minutos)*/
			document.getElementById("centro_telf_cont").innerHTML="";
			document.getElementById("centro_telf_cont").innerHTML+=texto;
			setCookie("idncnt",document.getElementById("nuevo_contacto").innerHTML, getExpDate(1,0,0));
		}
	}
	data='';
	data+="acciones=listar_telefonos_contactos";
	data+="&idusuario="+getCookie("user");
	data+="&idpublicacion="+id;
	data+="&idcontacto="+idcontacto;
	conexion.send(data);
}

function editar_contacto(id,idcontacto){
	var conexion = conexionajax();
	conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
	conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	conexion.onreadystatechange = function() {
		if (conexion.readyState==4) {
			var texto = conexion.responseXML;
			if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '1'){
				listar_telefonos_contacto(id,idcontacto.value);
				document.getElementById("pub_contacto").innerHTML=document.getElementById("pub_nuevocontacto").innerHTML;
				document.getElementById("txt_nombrecontacto").value=texto.getElementsByTagName("nombre")[0].firstChild.nodeValue;
				document.getElementById("txt_apellidocontacto").value=texto.getElementsByTagName("apellido")[0].firstChild.nodeValue;
				document.getElementById("txt_emailcontacto").value=texto.getElementsByTagName("email")[0].firstChild.nodeValue;
				document.getElementById("botones_navegabilidad").style.display='none';
			}
		}
	}
	data='';
	data+="acciones=mostrar_contactos";
	data+="&idcontacto="+idcontacto.value;
	conexion.send(data);
}

function eliminar_contacto(id,idcontacto){
	var conexion = conexionajax();
	conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
	conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	conexion.onreadystatechange = function() {
		if (conexion.readyState==4) {
			var texto = conexion.responseXML;
			if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '1'){
				alert("Contacto eliminado satisfactoriamente");
				listar_contactos(id);
			}else{
				alert("Ha ocurrido un error al procesar su información\nVerifique sus datos e intente de nuevo");
			}
		}
	}
	data='';
	data+="acciones=eliminar_contacto";
	data+="&idcontacto="+idcontacto.value;
	conexion.send(data);
}

function detalle_contacto(id,idcontacto){
	ancho=350;
	alto=250;
	var izq= parseInt((screen.availWidth/2) - (ancho/2));
	var top= parseInt((screen.availHeight/2) - (alto/2));
	var ventana_detalle=window.open("includes/detallecnt.php?id="+idcontacto.value, "", "status=no,menubar=no,height="+alto+",width="+ancho+",left="+izq+",top="+top+",screenX="+izq+",screenY="+top+" ");	
	ventana_detalle.focus();
}

/*****************************Acciones pestaña Imágenes ***********************************/

function imagenes(id){
	for(var i=0; i<tabs; i++){
		if(i!=5){
			document.getElementById("pestanias_"+i).setAttribute("className","pestana");
			document.getElementById("pestanias_"+i).className="pestana";
		}else{
			document.getElementById("pestanias_"+i).setAttribute("className","pestana2");
			document.getElementById("pestanias_"+i).className="pestana2";
		}
	}
	document.getElementById("pub_general").style.display='none';
	document.getElementById("pub_dsecripcion").style.display='none';
	document.getElementById("pub_disponibilidad").style.display='none';
	document.getElementById("pub_precio").style.display='none';
	document.getElementById("pub_contacto").style.display='none';
	document.getElementById("pub_imagenes").style.display='block';
	document.getElementById("pub_tarifas").style.display='none';
	document.getElementById("btn_anterior").style.display='block';	
}

/*****************************Acciones Datos de Facturación ***********************************/

function tarifas(id){
	for(var i=0; i<tabs; i++){
		if(i!=6){
			document.getElementById("pestanias_"+i).setAttribute("className","pestana");
			document.getElementById("pestanias_"+i).className="pestana";
		}else{
			document.getElementById("pestanias_"+i).setAttribute("className","pestana2");
			document.getElementById("pestanias_"+i).className="pestana2";
		}
	}
	document.getElementById("pub_general").style.display='none';
	document.getElementById("pub_dsecripcion").style.display='none';
	document.getElementById("pub_disponibilidad").style.display='none';
	document.getElementById("pub_precio").style.display='none';
	document.getElementById("pub_contacto").style.display='none';
	document.getElementById("pub_imagenes").style.display='none';
	document.getElementById("pub_tarifas").style.display='block';
	document.getElementById("datos_precios").style.display='block';
	document.getElementById("btn_anterior").style.display='block';
}

function mostrar_cliente(){
	document.getElementById("pub_tarifas").style.display='block';
	document.getElementById("datos_precios").style.display='none';
	document.getElementById("aviso_publicacion").style.display='none';
	document.getElementById("datos_facturacion").style.display='block';
	var conexion = conexionajax();
		conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
		conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		conexion.onreadystatechange = function() {
			if (conexion.readyState==4) {
				var texto = conexion.responseXML;
				if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '1'){
					document.getElementById("txt_dirfiscal").value=texto.getElementsByTagName("direecion_fiscal")[0].firstChild.nodeValue;
					document.getElementById("txt_nombre_facturacion").value=texto.getElementsByTagName("nombre")[0].firstChild.nodeValue;
					document.getElementById("txt_apellido_facturacion").value=texto.getElementsByTagName("apellido")[0].firstChild.nodeValue;
					document.getElementById("txt_docnumero").value=texto.getElementsByTagName("numero_documento")[0].firstChild.nodeValue;
					/*tipo de documento*/
					documentos=document.getElementById("lst_documento_facturacion");
					option.setAttribute("value",texto.getElementsByTagName("tipo_documento")[0].firstChild.nodeValue);
					option.setAttribute("selected","true");
					option.innerHTML=texto.getElementsByTagName("documento")[0].firstChild.nodeValue;
					documentos.appendChild(option);	
					setTimeout('textCounter(document.getElementById("lst_documento_facturacion"),document.getElementById("result_dirfis"),500)',100);		
				}else{
					document.getElementById("txt_nombre_facturacion").value=texto.getElementsByTagName("nombre")[0].firstChild.nodeValue;
					document.getElementById("txt_apellido_facturacion").value=texto.getElementsByTagName("apellido")[0].firstChild.nodeValue;
				}
			}
		}
		data='';
		data+="acciones=mostrar_cliente";
		data+="&idusuario="+getCookie("user");
		data+="&idpublicacion="+getCookie("idpub");
		conexion.send(data);
}

/*Guardando datos de facturación*/
function datos_facturacion(){
	if(
	document.getElementById("lst_documento_facturacion").value !=""&&
	document.getElementById("txt_docnumero").value !=""&&
	document.getElementById("txt_nombre_facturacion").value !=""&&
	document.getElementById("txt_apellido_facturacion").value !=""&&
	document.getElementById("txt_dirfiscal").value !=""
	){
		var conexion = conexionajax();
		conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
		conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
		conexion.onreadystatechange = function() {
			if (conexion.readyState==4) {
				//datos de usuario
				var texto = conexion.responseXML;
				if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '1'){
					terminar_publicacion();
				}else if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue =='0'){
					alert("Ha ocurrido un error al procesar su requerimiento\nPor favor intente de nuevo");
				}
			}
		}
		data='';
		data+="acciones=prefil_facturacion";
		data+="&idusuario="+getCookie("user");
		data+="&idpublicacion="+getCookie("idpub");
		/*Datos del formulario*/
		data+="&lst_documento="+document.getElementById("lst_documento_facturacion").value;
		data+="&txt_docnumero="+document.getElementById("txt_docnumero").value;
		data+="&txt_dirfiscal="+document.getElementById("txt_dirfiscal").value;
		data+="&txt_apellido_facturacion="+document.getElementById("txt_apellido_facturacion").value;
		data+="&txt_nombre_facturacion="+document.getElementById("txt_nombre_facturacion").value;
		conexion.send(data);
	}else{
		alert("Debe completar toda la información requerida para procesar su solicitud");
	}
}

function guardar_factura(id){
	num=document.getElementById("factura_pub").getElementsByTagName('input').length;
	idservicio='';
	for(var i=0; i< num; i++){
		if(document.getElementById("tarifas_check"+i).checked==true){
			idservicio+="@"+document.getElementById("tarifas_check"+i).value;		
		}
	}
	
	
	var conexion = conexionajax();
	conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
	conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	conexion.onreadystatechange = function() {
		if (conexion.readyState==4) {
			//datos de usuario
			var texto = conexion.responseXML;
			if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '1'){
				document.getElementById("pub_tarifas").style.display='block';
				document.getElementById("datos_precios").style.display='none';
				document.getElementById("aviso_publicacion").style.display='block';
				document.getElementById("datos_facturacion").style.display='none';
				document.getElementById("total_pago").innerHTML=document.getElementById("total_pagar").innerHTML
			}else if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue =='0'){
				alert("Ha ocurrido un error al procesar su requerimiento\nPor favor intente de nuevo");
			}
		}
	}
	data='';
	data+="acciones=guardar_factura";
	data+="&idusuario="+getCookie("user");
	data+="&idpublicacion="+getCookie("idpub");
	/*Datos del formulario*/
	data+="&idservicios="+idservicio;
	conexion.send(data);
}

function chequeados(num,base){
	for(var i=0; i<num; i++){
		if(i==0){
			var total_pagar_cuenta= parseFloat(document.getElementById("total"+i).innerHTML);
		}
		if(document.getElementById("tarifas_check"+i).checked==true && i!=0){
			total_pagar_cuenta+=parseFloat(document.getElementById("total"+i).innerHTML);	
		}
	}
	
	total_imprimir = total_pagar_cuenta.toFixed(2);// para dos decimales
	document.getElementById("total_pagar").innerHTML=total_imprimir;
}

/*****************************Acciones Forma de pago ***********************************/
function formas_pago(id){
	var listado=document.getElementById("chck_formaspago").getElementsByTagName('input').length;			
	for(var i=0; i<listado; i++){
		if(document.getElementById("frmpagos_check"+i).checked==true){
			forma=document.getElementById("frmpagos_check"+i).value;
		}
	}
	var conexion = conexionajax();
	conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
	conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	conexion.onreadystatechange = function() {
		if (conexion.readyState==4) {
			//datos de usuario
			var texto = conexion.responseXML;
			if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '1'){
				document.getElementById("aviso_publicacion").style.display='none';
				document.getElementById("datos_facturacion").style.display='block';
				document.getElementById("ver_pub").style.display="none";
				document.getElementById("btn_siguiente").value="Terminar";
				document.getElementById("identificador_pago").value=texto.getElementsByTagName("idpago")[0].firstChild.nodeValue;
				document.getElementById("monto_pago").value=document.getElementById("total_pago").innerHTML;
				document.getElementById("forma_pp").value=forma;
				mostrar_cliente(id);
			}else if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue =='0'){
				alert("Ha ocurrido un error al procesar su requerimiento\nPor favor intente de nuevo");
			}
		}
	}
	data='';
	data+="acciones=forma_pago";
	data+="&idusuario="+getCookie("user");
	data+="&idpublicacion="+getCookie("idpub");
	/*Datos del formulario*/
	data+="&idformapago="+forma;
	data+="&total="+document.getElementById("total_pago").innerHTML;
	conexion.send(data);
}
/********************************************Terminar la piblicacion****************************************************************/

function terminar_publicacion(){
	var conexion = conexionajax();
	conexion.open('POST', '..'+document.getElementById("carpeta_raiz").innerHTML+'includes/publicacion.php');
	conexion.setRequestHeader('Content-Type','application/x-www-form-urlencoded; charset=UTF-8');
	conexion.onreadystatechange = function() {
		if (conexion.readyState==4) {
			//datos de usuario
			var texto = conexion.responseXML;
			if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue == '1'){
				if(document.getElementById("modificando").value=="no"){
					var f_pago=parseInt(document.getElementById("forma_pp").value);
					if(f_pago<3){
						document.getElementById("cuerpo_pestanias").style.display="none";
						pago_virtual(document.getElementById("monto_pago").value,'publicacion',document.getElementById("identificador_pago").value);
					}else{
						alert("Su publicación ha sido registrada satisfactoriamente");
						window.location.href ='misofertas.php';	
					}
				}else{
					alert("Su publicación ha sido modificada satisfactoriamente");
					window.location.href ='misofertas.php';
				}
			}else if(texto.getElementsByTagName("resultado")[0].firstChild.nodeValue =='0'){
				alert("Ha ocurrido un error al procesar su requerimiento\nPor favor intente de nuevo");
				document.getElementById("pub_tarifas").style.display='block';
				document.getElementById("cargando_form").style.display='none';
			}
		}else{
			document.getElementById("cargando_form").style.display='block';
			document.getElementById("pub_tarifas").style.display='none';
		}
	}
	data='';
	data+="acciones=activar_publicacion";
	data+="&idusuario="+getCookie("user");
	data+="&idpublicacion="+getCookie("idpub");
	data+="&modificando="+document.getElementById("modificando").value;
	conexion.send(data);
}