//------------------- funciones Javascript para Guiaservicios II -------------------------\\

n = (document.layers)? true:false
ns6 = (document.getElementById) && (!document.all)? true:false

function Subcat (formu1) {
	var i=1;
	var cat=formu1.categoria.options[formu1.categoria.selectedIndex].value;
//Almacenamos en una variable el valor del elemento seleccionado en el select de categorias
	formu1.subcategoria.options.length=0;
//Limpiamos el select de Subcategorias
	formu1.clase.options.length=0;
//Limpiamos el select de Clases
	if (n){form=document.capa.document.Oculto;}
	else{form=document.Oculto;}	
//Hemos de llamar a los select ocultos de distinta manera segun sea IE o NS
    intro=new Option("» Seleccione una » » » » » » » » » » » » » »", "0", false, false);
	formu1.subcategoria.options[0]=intro;
	for (x=0;x<form.temporal.options.length;x++) {
		if (form.temporal.options[x].value==cat) {		
			nuevo=new Option(form.temporal.options[x].text, form.temporal.options[x].title, false, false);
			formu1.subcategoria.options[i]=nuevo;
			i++;
		}
	}  
    cierre=new Option("» » » » » » » » » » » » » » » » » »", "0", false, false);
	formu1.subcategoria.options[i]=cierre;
	if (n&&!ns6) {
		formu1.subcategoria.length=i;
		formu1.subcategoria.selectedIndex=0;
		history.go(0);
	}
}

function Clase (formu2) {
	var i=1;
	var subcat=formu2.subcategoria.options[formu2.subcategoria.selectedIndex].value;
	formu2.clase.options.length=0;	
	if (n){form=document.capa.document.Oculto;}
	else{form=document.Oculto;}
    intro=new Option("» Seleccione una » » » » » » » » » » » » » »", "0", false, false);
	formu2.clase.options[0]=intro;
	for (x=0;x<form.temp.options.length;x++) {
		if (form.temp.options[x].value==subcat) {
			otro=new Option(form.temp.options[x].text, form.temp.options[x].title, false, false);
			formu2.clase.options[i]=otro;
			i++;
			}		
		}
    cierre=new Option("» » » » » » » » » » » » » » » » » »", "0", false, false);
	formu2.clase.options[i]=cierre;
	if (n) {
		formu2.clase.length=i;
		formu2.clase.selectedIndex=0;
		history.go(0);
	}
}

function checkData (){
	if (document.empresas.empresa.value == "") {
        	alert("Por favor, introduzca el nombre comercial de la empresa")
                document.empresas.empresa.focus()
                return false}
	if (document.empresas.rsocial.value == "") {
        	alert("Por favor, introduzca la razón social de la empresa")
                document.empresas.rsocial.focus()
                return false}
	if (document.empresas.cif.value == "") {
        	alert("Por favor, introduzca el CIF de la empresa")
                document.empresas.cif.focus()
                return false}
	if (document.empresas.cp.value == "") {
        	alert("Por favor, introduzca el código postal de la empresa")
                document.empresas.cp.focus()
                return false}				
	if (document.empresas.telefono1.value == "") {
        	alert("Por favor, introduzca el teléfono de la empresa")
                document.empresas.telefono1.focus()
                return false}				
	if (document.empresas.contacto.value == "") {
        	alert("Por favor, introduzca la persona de contacto en la empresa")
                document.empresas.contacto.focus()
                return false}				
	if (document.empresas.categoria.options[document.empresas.categoria.selectedIndex].value == "0") {
        	alert("Por favor, debe selecionar un sector")
                document.empresas.categoria.focus()
                return false}
	if (document.empresas.subcategoria.options[document.empresas.subcategoria.selectedIndex].value == "0") {
        	alert("Por favor, debe selecionar una actividad")
                document.empresas.subcategoria.focus()
                return false}									
	if (document.empresas.destacado.options[document.empresas.destacado.selectedIndex].value!="1") {
		if (document.empresas.pago.options[document.empresas.pago.selectedIndex].value=="0") {
 			 alert("Por favor, debe seleccionar una forma de pago");
			 document.empresas.pago.focus();
			 return false;} 
		}					
	if (document.empresas.claves.value == "") {
        	alert("Por favor, introduzca las palabras clave")
                document.empresas.claves.focus()
                return false}				
}

function cursor() {
	document.empresas.empresa.focus();
	}
	
function restrictinput(maxlength,e,placeholder){
if (window.event&&event.srcElement.value.length>=maxlength)
return false
else if (e.target&&e.target==eval(placeholder)&&e.target.value.length>=maxlength){
var pressedkey=/[a-zA-Z0-9\.\,\/]/ //detect alphanumeric keys
if (pressedkey.test(String.fromCharCode(e.which)))
e.stopPropagation()
}
}

function countlimit(maxlength,e,placeholder){
var theform=eval(placeholder)
var lengthleft=maxlength-theform.value.length
var placeholderobj=document.all? document.all[placeholder] : document.getElementById(placeholder)
if (window.event||e.target&&e.target==eval(placeholder)){
if (lengthleft<0)
theform.value=theform.value.substring(0,maxlength)
placeholderobj.innerHTML=lengthleft
}
}


function displaylimit(theform,thelimit){
var limit_text='Le quedan <b><span id="'+theform.toString()+'">'+thelimit+'</span></b> caracteres'
if (document.all||ns6)
document.write(limit_text)
if (document.all){
eval(theform).onkeypress=function(){ return restrictinput(thelimit,event,theform)}
eval(theform).onkeyup=function(){ countlimit(thelimit,event,theform)}
}
else if (ns6){
document.body.addEventListener('keypress', function(event) { restrictinput(thelimit,event,theform) }, true); 
document.body.addEventListener('keyup', function(event) { countlimit(thelimit,event,theform) }, true); 
}
}

function abreClaves() {
	subcat=document.empresas.subcategoria.options[document.empresas.subcategoria.selectedIndex].value;
	clase=document.empresas.clase.options[document.empresas.clase.selectedIndex].value;
	if (clase!=0) { append=clase} else { append=subcat};
	nombre="id_clave="+append;
	ventana="serv_empresas_claves.asp?"+nombre;
	window.open(ventana, "Guiaservicios","width=345,height=280,screenX=0,screenY=0,left=0,top=0,scrollbars=1");
	}

function abre_claves_modifi() {
	cat=document.Inserciones3.categoria.options[document.Inserciones3.categoria.selectedIndex].value;
	subcat=document.Inserciones3.subcategoria.options[document.Inserciones3.subcategoria.selectedIndex].value;
	clase=document.Inserciones3.clase.options[document.Inserciones3.clase.selectedIndex].value;
	nombre="cat="+cat+"&subcat="+subcat+"&clase="+clase;
	ventana="serv_empresas_claves.asp?"+nombre;
	window.open(ventana, "Guiaservicios","width=345,height=280,screenX=0,screenY=0,left=0,top=0,scrollbars=1");
	}
		
function check_data_modifi4 (){
	if (document.Inserciones3.categoria.options[document.Inserciones3.categoria.selectedIndex].value == "0") {
        	alert("Por favor, debe selecionar un sector")
                document.Inserciones3.categoria.focus()
                return false}
	if (document.Inserciones3.subcategoria.options[document.Inserciones3.subcategoria.selectedIndex].value == "0") {
        	alert("Por favor, debe selecionar una actividad")
                document.Inserciones3.subcategoria.focus()
                return false}									
	if (document.Inserciones3.destacado.options[document.Inserciones3.destacado.selectedIndex].value!="1") {
		if (document.Inserciones3.pago.options[document.Inserciones3.pago.selectedIndex].value=="0") {
 			 alert("Por favor, debe seleccionar una forma de pago");
			 document.Inserciones3.pago.focus();
			 return false;} 
		}					
	if (document.Inserciones3.claves.value == "") {
        	alert("Por favor, introduzca las palabras clave")
                document.Inserciones3.claves.focus()
                return false}				
}	

function setCounterValue(textarea, contador, maxLength) {
   if (textarea.value.length>maxLength) {
      textarea.value=textarea.value.substring(0,maxLength);
   }
   contador.value=maxLength-textarea.value.length;
  
}
 
function checkMaxLength (textarea, evt, maxLength) {
  if (textarea.selected && evt.shiftKey) 
    // ignore shift click for select
    return true;
  var allowKey = false;
  if (textarea.selected && textarea.selectedLength > 0)
    allowKey = true;
  else {
    var keyCode = 
      document.layers ? evt.which : evt.keyCode;
    if (keyCode < 32 && keyCode != 13)
      allowKey = true;
    else           
      allowKey = textarea.value.length < maxLength;
  }
  textarea.selected = false;
  return allowKey;
}
function storeSelection (field) {
  if (document.all) {
    field.selected = true;
    field.selectedLength = 
      field.createTextRange ?
        document.selection.createRange().text.length : 1;
  }
}	

