// JavaScript Document
function Contactar(contacto) {
	ancho = 450;
	alto = 425;
	dia = new Date();
	id = dia.getTime();
	var theTop=(screen.height/2)-(alto/2);
	var theLeft=(screen.width/2)-(ancho/2);
	var propiedades='height='+alto+',width='+ancho+',top='+theTop+',left='+theLeft+',scrollbars=no,toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0';
	window.open("/Contactar/"+ contacto,id,propiedades);
}
function ContactarMasivo(contacto) {
	ancho = 525; 
	alto = 550; 
	dia = new Date();
	id = dia.getTime();
	var theTop=(screen.height/2)-(alto/2);
	var theLeft=(screen.width/2)-(ancho/2);
	var propiedades='height='+alto+',width='+ancho+',top='+theTop+',left='+theLeft+',scrollbars=no,toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0';
	window.open("/ContactarMasivo/"+ contacto,id,propiedades);
}

function recuerdaClaveClasficado(registrado) {
	ancho = 500;
	alto = 250;
	dia = new Date();
	id = dia.getTime();
	var theTop=(screen.height/2)-(alto/2);
	var theLeft=(screen.width/2)-(ancho/2);
	var propiedades='height='+alto+',width='+ancho+',top='+theTop+',left='+theLeft+',scrollbars=no,toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0';
	window.open("/Recuerda-clave-clasificados/"+ registrado,id,propiedades);
}

function cambia_subcategorias(){
	var categoria
	categoria = document.f1.categoria[document.f1.categoria.selectedIndex].value;
	if (categoria != 0) {
		mis_subcategorias=eval("subcategorias_" + categoria);
		subcategoriasNum = mis_subcategorias.length;
		num_subcategorias = eval("subcategoriasID_" + categoria);
		document.f1.ssubcategoria.length = subcategoriasNum;
		for(i=0;i<subcategoriasNum;i++){
			document.f1.ssubcategoria.options[i].value=num_subcategorias[i]
			document.f1.ssubcategoria.options[i].text=mis_subcategorias[i]
		}
	}else{	document.f1.ssubcategoria.length = 0
		document.f1.ssubcategoria.options[0].value = "0"
		document.f1.ssubcategoria.options[0].text = "-"
	}
	document.f1.ssubcategoria.options[1].selected = true
	
	if(categoria=='00414' ||categoria =='00915' || categoria=='00460' ||categoria =='00492' ){
		var item = document.getElementById('empre');
		item.style.display = 'none';
		var elem = document.getElementById('msg_construcciones');
		elem.style.display = '';
		window.open("../construcciones-popup.php","Mensaje Construcciones","width=700,height=400,location=no,menubar=no,toolbar=no,scrollbars=no,resizable=no");
	} else {
		var item = document.getElementById('empre');
		item.style.display = '';
		var elem = document.getElementById('msg_construcciones');
		elem.style.display = 'none';
	}

}

function cambia_estrellas(){
	var subrubro
	var item = document.getElementById('aEstrellas');
	subrubro = document.f1.ssubcategoria[document.f1.ssubcategoria.selectedIndex].value;
	if (subrubro != 0)
		if(subrubro == 2) item.style.display = '';
		else item.style.display = 'none';
}

function datos_adicionales(){
	var item = document.getElementById('DatosAdic');
	var subrubro = document.f1.ssubcategoria[document.f1.ssubcategoria.selectedIndex].value;
	if (subrubro == 0)
		item.style.display = 'none';
	else
		item.style.display = '';
}

function validar(f1) {
	// valida extension del valor del titulo
	if (f1.titulo.value.length < 3) {
		alert("Escriba por lo menos 3 caracteres en el campo \"Empresa / Servicio / Profesional\".");
		f1.titulo.focus();
		return (false);
	}

	if(f1.categoria[document.f1.categoria.selectedIndex].value == "0"){
		alert("Debe definir un rubro para su inscripción.");
		f1.categoria.focus();
		return (false);
	}
	if(f1.ssubcategoria[document.f1.ssubcategoria.selectedIndex].value == "0"){
		alert("Debe definir un subrubro para su inscripción.");
		f1.ssubcategoria.focus();
		return (false);
	}

	if (f1.descripcion.value.length < 40) {
		alert("Debe completar el campo \"Descripción\".");
		f1.descripcion.focus();
		return (false);
	}

	if (f1.calle.value.length < 4) {
		alert("Debe completar la calle en el campo \"Dirección\".");
		f1.calle.focus();
		return (false);
	}
	// define validacion del codigo postal
	if (f1.codigopostal.value.length < 4) {
		alert("Debe completar el campo \"Código postal\".");
		f1.codigopostal.focus();
		return (false);
	}
	var checkOK = "ABCDEFGHIJKLMNÑOPQRSTUVWXYZÁÉÍÓÚ" + "abcdefghijklmnñopqrstuvwxyzáéíóú" + "0123456789 ";
	var checkStr = f1.codigopostal.value;
	var allValid = true;
	for (i = 0; i < checkStr.length; i++) {
		ch = checkStr.charAt(i);
		for (j = 0; j < checkOK.length; j++)
			if (ch == checkOK.charAt(j))
				break;
		if (j == checkOK.length) {
			allValid = false;
			break;
		}
	}
	if (!allValid) {
		alert("Escriba letras y/o números en el campo \"Código Postal\".");
		f1.codigopostal.focus();
		return (false);
	}
//
	if(f1.localidad[document.f1.localidad.selectedIndex].value == "-" || f1.localidad[document.f1.localidad.selectedIndex].value == "undefined"){
		alert("Debe definir localidad.");
		f1.localidad.focus();
		return (false);
	}

	if (f1.telefono.value.length < 5 || f1.caractel.value.length < 3 ) {
		alert("Debe completar el campo \"Teléfono\".");
		f1.telefono.focus();
		return (false);
	}
	if(!ValidaEmail(f1.email.value) || trim(f1.email.value)=='' ) { 
		alert("Debe indicar una dirección de correo electrónico válida.");
		f1.email.focus();
		return (false);
	}
	if (f1.nombreresp.value.length < 4) {
		alert("Escriba por lo menos 4 caracteres en el campo \"Nombre y Apellido\".");
		f1.nombreresp.focus();
		return (false);
	}
	if(!ValidaEmail(f1.email.value) || trim(f1.email.value)=='' ) { 
		alert("Debe indicar una dirección de correo electrónico válida.");
		f1.email.focus();
		return (false);
	}
	if (f1.telefonoresp.value.length < 5) {
		alert("Debe completar el campo \"Teléfono del responsable\".");
		f1.telefonoresp.focus();
		return (false);
	}
	if (f1.codigo_catch.value.length < 4) {
		alert("Debe completar el campo \"Código de verificación\".");
		f1.codigo_catch.focus();
		return (false);
	}

	return (true);
}

function embedFlash(pathCompleto,pelicula,ancho,alto,alternativo){
	document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="'+ancho+'" height="'+alto+'" title="'+alternativo+' - www.cordoba.com.ar">');
	document.write('<param name="movie" value="'+pathCompleto+pelicula+'.swf" />');
	document.write('<param name="quality" value="high" />');
	document.write('<embed src="'+pathCompleto+pelicula+'.swf" width="'+ancho+'" height="'+alto+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash"></embed>');
	document.write('</object>');
}
function disableCampoForm(element_id){
	var element = document.getElementById(element_id);
	element.style.backgroundColor = '#FFF';
	element.style.color = '#333';
	element.disabled = true;
}

function enableCampoForm(element_id){
	var element = document.getElementById(element_id);
	if(element.disabled == true){
		element.style.backgroundColor = '#FFF';
		element.style.color = '#000';
		element.disabled = false;
	} else element.disabled = true;
}

function HabilitaTarjetas(){
	var elementos = document.f1.elements.length;	
	if(document.f1.recibe_tar.checked == true) {
		for(i=0; i<elementos; i++){
			if(document.f1.elements[i].name.substr(0,8) == 'tarjeta_')
				document.f1.elements[i].disabled = false
		}
	} else {
		for(i=0; i<elementos; i++){
			if(document.f1.elements[i].name.substr(0,8) == 'tarjeta_') {
				document.f1.elements[i].checked = false; 
				document.f1.elements[i].disabled = true; 
			}
		}
	}
}

function toggleRows(capa) {
	dataTable = document.getElementById(capa);
	toggle(dataTable);
}

function toggle(item) {
	if (item.style.display == '') {
		item.style.display = 'none';
		opening = false;
	} else {
		item.style.display = '';
		opening = true;
	}
}

function cuentaCaracteres(campo){
	if ((document.getElementById(campo).value.length)<250)
		document.getElementById('caracteres').value = 250 - document.getElementById(campo).value.length;
	else	alert("Tenga en cuenta que ha superado la cantidad \n de caracteres aceptados para el campo Descripción");
}

function abreDestino(url,nombre,ancho,alto){
	var theTop=(screen.height/2)-(alto/2);
	var theLeft=(screen.width/2)-(ancho/2);
	var propiedades='height='+alto+',width='+ancho+',top='+theTop+',left='+theLeft+',scrollbars=no';
	window.open(url,nombre,propiedades);
}

function cambia_provincia(){
	var pais
	pais = document.f1.pais[document.f1.pais.selectedIndex].value
	if (pais == 12 ) {
		document.f1.provincia.disabled = false ;
		document.f1.localidad.disabled = false ;
		document.f1.tel_pais.disabled = true ;
		document.f1.cel_pais.disabled = true ;
		mis_provincias=eval("provincias");
		num_provincias = mis_provincias.length ;
		document.f1.provincia.length = num_provincias;
		for(i=0;i<num_provincias;i++){
			var separado = mis_provincias[i].split("|");
			document.f1.provincia.options[i].value=separado[1];
			document.f1.provincia.options[i].text=separado[0]; 
		}
		document.f1.barrio.disabled = false;
		document.f1.CiudadExtranj.disabled = true;
	}else{
		document.f1.provincia.disabled = true;
		document.f1.provincia.length = 1
		document.f1.provincia.options[0].value = "-"
		document.f1.provincia.options[0].text = "-"
		document.f1.localidad.disabled = true ;
		document.f1.localidad.length = 1
		document.f1.localidad.options[0].value = "-"
		document.f1.localidad.options[0].text = "-"
		document.f1.tel_pais.disabled = false;
		document.f1.cel_pais.disabled = false;
		document.f1.barrio.disabled = true;
		document.f1.CiudadExtranj.disabled = false;
	}
	document.f1.provincia.options[0].selected = true
}

function cambia_localidad(){
	var prov;
	prov = document.f1.provincia[document.f1.provincia.selectedIndex].value; 
	document.f1.prov.value = document.f1.provincia[document.f1.provincia.selectedIndex].text; 
	if (prov != 0) {
		document.f1.localidad.disabled = false ;
		mis_localidades = eval("localidades_" + prov) ;
		num_localidades = mis_localidades.length;
		document.f1.localidad.length = num_localidades;
		for(i=0;i<num_localidades;i++){
			var separado = mis_localidades[i].split("|");
			document.f1.localidad.options[i].value=separado[1];
			document.f1.localidad.options[i].text=separado[0];
		}
	} else {
		document.f1.localidad.disabled = true ;
		document.f1.localidad.length = 1
		document.f1.localidad.options[0].value = "-"
		document.f1.localidad.options[0].text = "-"
	}
	document.f1.localidad.options[0].selected = true 
}

function cambia_localidad_clasif(){
	var prov;
	prov = document.alta.c_provincia[document.alta.c_provincia.selectedIndex].value; 
	document.alta.prov.value = document.alta.c_provincia[document.alta.c_provincia.selectedIndex].text; 
	if (prov != 0) {
		document.alta.c_localidad.disabled = false ;
		mis_localidades = eval("localidades_" + prov) ;
		num_localidades = mis_localidades.length;
		document.alta.c_localidad.length = num_localidades;
		for(i=0;i<num_localidades;i++){
			var separado = mis_localidades[i].split("|");
			document.alta.c_localidad.options[i].value=separado[1];
			document.alta.c_localidad.options[i].text=separado[0];
		}
	} else {
		document.alta.c_localidad.disabled = true ;
		document.alta.c_localidad.length = 1 
		document.alta.c_localidad.options[0].value = "-"
		document.alta.c_localidad.options[0].text = "-"
	}
	document.alta.c_localidad.options[0].selected = true 
}

function cambiar_localidad(padre, hidden,hijo){
	var prov;
	prov = padre[padre.selectedIndex].value; 
	hidden.value = padre[padre.selectedIndex].text; 
	if (prov != 0) {
		hijo.disabled = false ;
		mis_localidades = eval("localidades_" + prov) ;
		num_localidades = mis_localidades.length;
		hijo.length = num_localidades;
		for(i=0;i<num_localidades;i++){
			var separado = mis_localidades[i].split("|");
			hijo.options[i].value=separado[1];
			hijo.options[i].text=separado[0];
		}
	} else {
		hijo.disabled = true ;
		hijo.length = 1 
		hijo.options[0].value = "-"
		hijo.options[0].text = "-"
	}
	hijo.options[0].selected = true 
}

function cambia_modelo_clasif(){
	var marca;
	marca = document.alta.ca_marca[document.alta.ca_marca.selectedIndex].value; 
	document.alta.marca.value = document.alta.ca_marca[document.alta.ca_marca.selectedIndex].text; 
	if (marca != 0) {
		document.alta.ca_modelo.disabled = false ;
		mis_modelos = eval("modelos_" + marca) ;
		num_modelos = mis_modelos.length;
		document.alta.ca_modelo.length = num_modelos;
		for(i=0;i<num_modelos;i++){
			var separado = mis_modelos[i].split("|");
			document.alta.ca_modelo.options[i].value=separado[1];
			document.alta.ca_modelo.options[i].text=separado[0];
		}
	} else {
		document.alta.ca_modelo.disabled = true ;
		document.alta.ca_modelo.length = 1 
		document.alta.ca_modelo.options[0].value = "-"
		document.alta.ca_modelo.options[0].text = "-"
	}
	document.alta.ca_modelo.options[0].selected = true 
}

function popup(pagina,id,ancho,alto){
	var theTop=(screen.height/2)-(alto/2);
	var theLeft=(screen.width/2)-(ancho/2);
	var propiedades='height='+alto+',width='+ancho+',top='+theTop+',left='+theLeft+',scrollbars=yes';
	window.open(pagina,id,propiedades);
}

function popupflexible(pagina,id,ancho,alto){
	var theTop=(screen.height/2)-(alto/2);
	var theLeft=(screen.width/2)-(ancho/2);
	var propiedades='height='+alto+',width='+ancho+',top='+theTop+',left='+theLeft+',scrollbars=yes';
	window.open(pagina,id,propiedades);
}

function validarRegistroPotenciado(f1) {
	if(f1.clave.value < 4 || f1.clave.value != f1.clave1.value){
		alert("Su clave no coindice o la misma es menor al largo recomendado,\n se recomienda un mínimo de 5 caracteres.\nPor favor ingresela nuevamente.");
		f1.clave1.value = "";
		f1.clave1.focus();
		return (false);
	} else {
		if (f1.apellido.value.length < 1) {
			alert("Indique su apellido.");
			f1.apellido.focus();
			return (false);
		}
		if (f1.nombre.value.length < 1) {
			alert("Indique su nombre.");
			f1.nombre.focus();
			return (false);
		}
		if (f1.pclave.value.length < 5) {
			alert("No ha definido su Palabra de verificación o la misma es menor al largo recomendado,\n se recomienda un mínimo de 7 caracteres.");
			f1.pclave.focus();
			return (false);
		}
		if (f1.dninumero.value.length < 1) {
			alert("Indique su número de documento.");
			f1.dninumero.focus();
			return (false);
		}
		if(f1.dia[document.f1.dia.selectedIndex].value == "-"){
			alert("Debe indicar el día de en que nacio.");
			f1.dia.focus();
			return (false);
		}
		if(f1.mes[document.f1.mes.selectedIndex].value == "-"){
			alert("Debe indicar el mes de en que nacio.");
			f1.dia.focus();
			return (false);
		}
		if(f1.anio[document.f1.anio.selectedIndex].value == "-"){
			alert("Debe indicar el año de en que nacio.");
			f1.dia.focus();
			return (false);
		}
		if(f1.pais[document.f1.pais.selectedIndex].value == "-"){
			alert("Debe indicar su país.");
			f1.pais.focus();
			return (false);
		} else {
			if (f1.pais[document.f1.pais.selectedIndex].value == "12") {//es Argentina?
				if(f1.provincia[document.f1.provincia.selectedIndex].value == "0" ){
					alert("Debe indicar su provincia.");
					f1.provincia.focus();
					return (false);
				}
				if(f1.localidad[document.f1.localidad.selectedIndex].value == "-"){
					alert("Debe indicar su ciudad. Si la misma no figura, seleccione la última opción del listado: \"Otra Ciudad\".");
					f1.localidad.focus();
					return (false);
				}
			}
		}
		if(!ValidaEmail(f1.email.value) || trim(f1.email.value)=='') { 
			alert("Debe indicar una dirección de correo electrónico válida.");
			f1.email.focus();
			return (false);
		}
		if (f1.tel_prefijo.value.length < 1 || f1.telefono.value.length < 1 ) {
			alert("Debe indicar su teléfono.");
			f1.tel_prefijo.focus();
			return (false);
		}
		if(f1.ecivil[document.f1.ecivil.selectedIndex].value == "-"){
			alert("Debe indicar su estado civil.");
			f1.ecivil.focus();
			return (false);
		}
		if(f1.educacion[document.f1.educacion.selectedIndex].value == "-"){
			alert("Debe indicar su nivel de educación.");
			f1.educacion.focus();
			return (false);
		}
		if(f1.ocupacion[document.f1.ocupacion.selectedIndex].value == "-"){
			alert("Debe indicar su ocupación.");
			f1.ocupacion.focus();
			return (false);
		}
	}
	return (true);
}

function SoloNumeros(valor){
	ascii= valor.charCodeAt(valor.length -1);
	if(ascii>= 48 & ascii<= 57) /*si es nro*/
		return(valor);
	else {
		valor = valor.substring(0,valor.length-1)
		return(valor);
	}
}

function ValidaEmail(valor){
	re=/^[_a-z0-9-]+(.[_a-z0-9-]+)*@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,3})$/
	if(!re.exec(valor)) {
		return false;
	} else {
		return true;
	}
}
