var parametrosFlash;  // var paso de parametros desde un objeto flash

function SwitchMenu(obj){
	if(document.getElementById)
	{
	var el = document.getElementById(obj);
	var ar = document.getElementById("cont").getElementsByTagName("DIV");
		if(el.style.display == "none")
		{
			//if (0) //tancar tots cuan vols obrir aquest
			for (var i=0; i<ar.length; i++)
			{
				ar[i].style.display = "none";
			}
			el.style.display = "block";
		}
		else
		{
			el.style.display = "none";
		}
	}
}
function ChangeClass(menu, newClass)
{ 
	  var navegador = navigator.appName;
	  //alert(navegador);
		if (navegador=="Netscape")
		{
			 if (document.getElementById)
			 { 
				document.getElementById(menu).setAttribute("class",newClass);
				//document.getElementById(menu).class = newClass; 
			 } 
		}
		if (navegador=="Microsoft Internet Explorer")
		{
			 if (document.getElementById)
			 { 
				document.getElementById(menu).className = newClass;
			 } 
		}
} 

function ChangeClass2(id1,id2,id3,id4,id5,newClass)
{ 
		var rows = document.getElementsByTagName("tr");
		for(var i in rows) 
		{
			if (rows[i].className=='fgris' || rows[i].className=='frojo')
			rows[i].className = "fgris";
		}
		
		var links = document.getElementsByTagName("a");
		for(var i in links) 
		{
			if (links[i].className=='linknormal' || links[i].className=='linkresaltar')
			links[i].className = "linknormal";
		}

		
	 	 
		  var navegador = navigator.appName;
		 // alert(navegador);
			if (navegador=="Netscape")
			{
				 if (document.getElementById)
				 { 
					if (id1!=0)
					{
						control = "id"+id1;
						document.getElementById(control).setAttribute("class",newClass);
						control = "tr"+id1;
						document.getElementById(control).setAttribute("class",'frojo');
					}
					if (id2!=0)
					{
						control = "id"+id2;
						document.getElementById(control).setAttribute("class",newClass);
						control =  "tr"+id2;
						document.getElementById(control).setAttribute("class",'frojo');
					}
					if (id3!=0)
					{
						control = "id"+id3;
						document.getElementById(control).setAttribute("class",newClass);
						control = "tr"+id3;
						document.getElementById(control).setAttribute("class",'frojo');
					}
					
					if (id4!=0)
					{
						control = "id"+id4;
						document.getElementById(control).setAttribute("class",newClass);
						control = "tr"+id4;
						document.getElementById(control).setAttribute("class",'frojo');
					}
					if (id5!=0)
					{
						control = "id"+id5;
						document.getElementById(control).setAttribute("class",newClass);
						control = "tr"+id5;
						document.getElementById(control).setAttribute("class",'frojo');
					}



				 } 
			}
			if (navegador=="Microsoft Internet Explorer")
			{
				 if (document.getElementById)
				 { 
				 	if (id1!=0)
					{
						control = "id"+id1;
						document.getElementById(control).className = newClass;
						control = "tr"+id1;
						document.getElementById(control).className = 'frojo';
					}
					if (id2!=0)
					{
						control = "id"+id2;
						document.getElementById(control).className = newClass;
						control = "tr"+id2;
						document.getElementById(control).className = 'frojo';
					}
					if (id3!=0)
					{
						control = "id"+id3;
						document.getElementById(control).className = newClass;
						control = "tr"+id3;
						document.getElementById(control).className = 'frojo';
					}

				 } 
			}
} 

//document.onselectstart = new Function("return false");

function validate(op,id,idioma,fam,subfam)
{
	//alert("validate op="+op);
	doc=document.location.href.split("?");
	if (doc.length!=1)
	{
		document.formulario.action = doc[0];
	}
	
	if (op=='9') {document.formulario.action="index.php";}
	
	//alert(doc[0]);
	
	/*if (op=='7') document.formulario.action="index.php";
	if (op=='4') document.formulario.action="index.php";
	if (op=='8' && document.formulario.busqueda.value == "") return false;*/
	document.formulario.op.value = op;
	//alert(id);
	document.formulario.id.value = id;
	//alert(idioma);
	document.formulario.idioma.value = idioma;
	//alert(fam);
	document.formulario.fam.value = fam;
	//alert(subfam);
	document.formulario.subfam.value = subfam;
    
	//alert(op+" "+id);
	document.formulario.submit();
	//alert('fin');
}

function resetear()
{
	document.formulario.reset();
}


function pviiObjbg(obj, new_color) { //v2.1 by Project VII
	obj.style.backgroundColor=new_color;
}

function setfocus()
{
document.formulario.username.focus();
return;
}

//function changevaluecheck()
//{
//	//alert(document.formulario.disponible.value);
//	//if (document.formulario.disponible.value == "si" || document.formulario.disponible.value == "on")
//	//document.formulario.disponible.value = "no";
//	//else
//	//document.formulario.disponible.value = "si";
//	//alert(document.formulario.disponible.value);
//	alert(document.formulario.disponible.checked);
//	if (document.formulario.disponible.checked == true) document.formulario.disponible.value = "si";
//	if (document.formulario.disponible.checked == false) document.formulario.disponible.value = "no";
//	alert(document.formulario.disponible.value);
//
//}


//function abrir_ventana_foto(urlfoto,ref)
//{	
//	var img = new Image();
//	img.src = urlfoto;
//	ventana=window.open('','','width='+img.width+',height='+img.height+',scrollbars=no,resizable=0,toolbar=0');
//	ventana.document.write ('<html>\n');
//	ventana.document.write (' <head>\n');
//	ventana.document.write ('  <title>Inmueble Ref.: '+ref+'</title>\n');
	//ventana.document.write ('  <title>'Bercan'</title>\n');
//	ventana.document.write (' </head>\n');
//	ventana.document.write (' <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">\n');
//	ventana.document.write ('  <img src="' + urlfoto + '" height='+img.height+' width='+img.width+'>\n');
//	ventana.document.write (' </body>\n');
//	ventana.document.write ('</html>\n');
//}

function mostrar(ref) {
	//alert(_img_grande.width);
	//alert(_img_grande.height);
	
	if (_img_grande.width<20) 
	_img_grande.width = 300;
	if (_img_grande.height<20) 
	_img_grande.height = 400;
	
	//alert(_img_grande.width);
	//alert(_img_grande.height);
	var ops = "top=" + ((screen.height - _img_grande.height) / 2);
	ops += ",left=" + ((screen.width - _img_grande.width) / 2);
	ops += ",width=" + _img_grande.width + ",height=" + _img_grande.height;
	var contenido = "<html>\n<head>\n<title>Inmueble Ref.: "+ref+"</title>\n<body style='background-image: url(" + _img_grande.src + ")'></body></html>";
	var ventana = window.open("", "", ops);
	
	ventana.document.open();
	ventana.document.write(contenido);
	ventana.document.close();  //caricatos
}

function cargando(ref) {
	if (_img_grande.complete) mostrar(ref);
	else setTimeout("cargando()", 100);
}

function abrir(urlfoto,ref)	{
	_img_grande = new Image();
	_img_grande.src = urlfoto;
	cargando(ref);
}

function abrir_contactar()
{
var ventana;
ventana=window.open("/contacto.php","new","toolbars=no,scrollbars=no,directories=no,menubar=no,resizable=no,status=no,width=520,height=480,screenx=250,screeny=50,top=50,left=250");
}

function paginacion(pg,o)
{
	document.formulario._pagi_pg.value = pg;
	// ejemplo select
	//var miOpcion=document.formulario.vista.selectedIndex;
	//document.formulario.vista.options[miOpcion].value = v;
	document.formulario.op.value = o;
	document.formulario.submit();
	
}
function add_campo(num_camp)
{
	//alert(num_camp);
	num_camp++;
	document.formulario.num_camp.value = num_camp;
	//alert(document.formulario.num_camp.value);
	document.formulario.add.value = "1";
	document.formulario.submit();
}

function gen_cambiar_idioma(idioma)
{
	//alert(idioma);
	document.formulario.idioma.value = idioma;
	document.formulario.add.value = "1";
	document.formulario.submit();
}

function change(img)
{
	document.formulario.imagen.value = img;
	document.formulario.add.value = "1";
	document.formulario.cambio.value = "1";
	document.formulario.submit();
}

function change_corta(combo)
{
	document.formulario.plantilla_corta.value = combo;
	document.formulario.add.value = "1";
	document.formulario.submit();
}

function change_expand(combo)
{
	document.formulario.plantilla_expand.value = combo;
	document.formulario.add.value = "1";
	document.formulario.submit();
}

function contenedor(elem,variable)
{
	//alert(elem);
	//alert(variable);
	var visual = 'visual_'+elem;
	var encontrado = false;
	var i = 0;
	if(document.getElementById)
	{
		val = document.getElementById(visual).value.split('\n');
		while (i<val.length-1 && encontrado==false)
		{
			if (val[i]==variable) 
			{
				encontrado = true;
				val[i]='';
			}
			i++;
		}
	}
	
	if (encontrado) 
	{
		i=0;
		var result = '';
		var result2 = '';
		while (i<val.length-1)
		{
			if (val[i]!='') 
			{
				result = result + val[i] + '\n';
				result2 = result2 + val[i] + ',';
			}
			
			i++;
		}
		document.getElementById(visual).value = result;
		document.getElementById(elem).value = result2;
	}
	else 
	{
		document.getElementById(visual).value = document.getElementById(visual).value + variable + '\n';
		document.getElementById(elem).value = document.getElementById(elem).value + variable + ',';

	}
	
}

function asc_menu_categorias(elem,variable,menu)
{
	//alert(document.getElementById(elem).value);
	//alert(document.getElementById("final_ordenmenu").value);
	var visual = 'visual_'+elem;
	var encontrado = false;
	var encontrado2 = false;

	var i = 0;
	var j = 0;
	var pos = 0;
	if(document.getElementById)
	{
		val = document.getElementById(visual).value.split('\n');
		val2 = document.getElementById("final_ordenmenu").value.split(',');
		while (i<val.length-1 && encontrado==false)
		{
			if (val[i]==variable) 
			{
				encontrado = true;
				val[i]='';
				val2[i]='';
				if (i!=0) pos = i-1;
			}
			i++;
		}
	}
	//alert("elemento:"+variable+" en la pos:"+pos);
	i=0;
	var result = '';
	var result2 = '';
	var result3= '';
	while (i<val.length-1)
	{
		
		if (pos==i)
		{
			//alert("insertamos aki:"+i);
			result = result + variable + '\n';
			result2 = result2 + variable + ',';
			result3 = result3 + menu + ',';
			//alert(result2);
			//alert(result3);
		}
		if (val[i]!='') 
		{
			result = result + val[i] + '\n';
			result2 = result2 + val[i] + ',';
			result3 = result3 + val2[i] + ',';
			//alert(result2);
			//alert(result3);
		}		
		i++;
	}

	document.getElementById(visual).value = result;
	document.getElementById(elem).value = result2;
	document.getElementById("final_ordenmenu").value = result3;
	//alert(document.getElementById(elem).value);
	//alert(document.getElementById("final_ordenmenu").value);
}

function desc_menu_categorias(elem,variable,menu)
{
	//alert(document.getElementById(elem).value);
	//alert(document.getElementById("final_ordenmenu").value);
	var visual = 'visual_'+elem;
	var encontrado = false;
	var encontrado2 = false;

	var i = 0;
	var j = 0;
	var pos = 0;
	if(document.getElementById)
	{
		val = document.getElementById(visual).value.split('\n');
		val2 = document.getElementById("final_ordenmenu").value.split(',');
		while (i<val.length-1 && encontrado==false)
		{
			if (val[i]==variable) 
			{
				encontrado = true;
				val[i]='';
				val2[i]='';
				pos = i+1;
			}
			i++;
		}
	}
	//alert("elemento:"+variable+" en la pos:"+pos);
	i=0;
	var result = '';
	var result2 = '';
	var result3= '';
	encontrado = false;
	while (i<val.length-1)
	{
		if (val[i]!='') 
		{
			result = result + val[i] + '\n';
			result2 = result2 + val[i] + ',';
			result3 = result3 + val2[i] + ',';
			//alert(result2);
			//alert(result3);
		}
		if (pos==i)
		{
			//alert("insertamos aki:"+i);
			result = result + variable + '\n';
			result2 = result2 + variable + ',';
			result3 = result3 + menu + ',';
			//alert(result2);
			//alert(result3);
			encontrado = true;
		}
		i++;
	}
	
	if (encontrado==false)
	{
		result = result + variable + '\n';
		result2 = result2 + variable + ',';
		result3 = result3 + menu + ',';
	}

	document.getElementById(visual).value = result;
	document.getElementById(elem).value = result2;
	document.getElementById("final_ordenmenu").value = result3;
	//alert(document.getElementById(elem).value);
	//alert(document.getElementById("final_ordenmenu").value);
}

function pulsarTecla(e,op,idioma)
{
	var navegador = navigator.appName;
	if (navegador=="Netscape")
	{
		var TeclaN=e.which;
		var teclaReal = String.fromCharCode(TeclaN);
		//alert("Número:  "+ TeclaN + "\nReal:  " + teclaReal);
		if (TeclaN!=13)
		{
			return false;
		}
	}
	
	if (navegador=="Microsoft Internet Explorer")
	{
		var TeclaIE=e.keyCode;
		var teclaReal = String.fromCharCode(TeclaIE);
		//alert("Número:  "+ TeclaIE + "\nReal:  " + teclaReal);
		if (TeclaIE!=13)
		{
			//document.formulario.busqueda.value = document.formulario.busqueda.value+teclaReal;
			return false;
		}
	}
	
	//alert("pulsarTecla op="+op);
	if (document.formulario.busqueda.value=="" && op=="8")
	{
		alert("No palabra/as busqueda");
		return false;
	}
	document.formulario.op.value = op;
	document.formulario.idioma.value = idioma;
	document.formulario.submit();
}

function imprSelec(nombre,estilo)
{
  var ficha = document.getElementById(nombre);
  var ventimp = window.open(' ', 'popimpr');
  ventimp.document.write('<html><head><link href="'+estilo+'" rel="stylesheet" type="text/css"></head>'+ficha.innerHTML+'</html>' );
  ventimp.document.close();
  ventimp.print( );
  ventimp.close();
}

function validar_user(op,id_user)
{
	document.formulario.op.value = op;
	document.formulario.id_user.value = id_user;
	document.formulario.submit();
}

function comprobar(control)
{
	var nombre = document.getElementById(control).value;
	if (nombre !="")
	{document.formulario.submit();}
}

/*

Hi, I tried what you suggested by just returning false, but then the control worked in neither IE or Mozilla -- which is a shame, as your function was much more elegant.
So I tried incorporating the code from the link you posted (thanks for that), with the result that the function looks like this:

function restrict_to_regexp_onkeypress(event, element_id, regexp) {
key_char = get_key_char(event);
var element = document.getElementById(element_id);
var value = element.value;
value = value + key_char;
if (regexp.test(value)) {
return true;
} else {
event = (window.event) ? window.event : event;
if (event.returnValue) {
event.returnValue = false;
} else if (event.preventDefault) {
event.preventDefault();
} else {
return false;
}
}
}

Unfortunately, this has merely inversed my problem -- now the function works as designed in Mozilla, but not in IE. I *really* don't get it!
Cheers,
doug.
biot023
05-16-2006, 09:05 AM
After a bit of hacking about, I got the function working in both with:

function restrict_to_regexp_onkeypress(event, element_id, regexp) {
key_char = get_key_char(event);
var element = document.getElementById(element_id);
var value = element.value;
value = value + key_char;
if (regexp.test(value)) {
return true;
} else {
event = (window.event) ? window.event : event;
if (event.preventDefault) {
event.preventDefault();
} else {
event.returnValue = false;
return false;
}
}
}

*/

function pulsarTeclaGendinclass(e)
{
	var navegador = navigator.appName;
	var retroceder = false;
	var tRetroceso = 8;
    var tShitf     = 16;
	var teclaPulsada;
	var teclaReal;
	var longitud;
	
	if (navegador=="Netscape")
	{
	    //teclaPulsada=e.which;
		var charCode = e.charCode;
		if (charCode != 0)
		{
			if ((charCode < 48) || (charCode > 57 && charCode < 65) || (charCode > 90 && charCode < 97) || (charCode > 122))
			{
				alert('caracter no permitido');
				e.preventDefault();
			}
		}
	}
	
	if (navegador=="Microsoft Internet Explorer")
	{
		teclaPulsada=e.keyCode;
		teclaReal = String.fromCharCode(teclaPulsada);
		if (teclaPulsada==tRetroceso)
		retroceder = true;
			
		if ((!retroceder)&&(teclaPulsada!=tShitf))
		{   
			patron_letras = /[A-Z]/; 
			patron_numeros = /[0-9]/; 
			if (!patron_letras.test(teclaReal) && !patron_numeros.test(teclaReal))
			{
				alert('caracter no permitido');
				e.returnValue= false;
			}
		}
	}
} 

function aceptar_gendinclass()
{
	var protegida = false;
	for(i=0;i<document.formulario.length;i++)
	{
		if(document.formulario.elements[i].value=="desc" || document.formulario.elements[i].value=="id")
		{
			alert("palabra protegida")
			document.formulario.elements[i].focus()
			protegida = true;
			return false;
		}
	}
	if (protegida==false) document.formulario.submit();
}







function confirma()
{
   tria=confirm("Restore BD?");
   return tria;
}

function mostrar_imagen(url)
{
  document.formulario.imagen_gal.src = url;
  if(document.getElementById("capaimagen")!= undefined) //->2-06-06 NeCrOS , problema de llamada cuando no existe id pasado
   var capa = document.getElementById(capaimagen); 
}

///////// Funciones Script de Flash //////////

//Copyright 2006 Adobe Systems, Inc. All rights reserved.
function AC_AddExtension(src, ext)
{
  if (src.indexOf('?') != -1)
    return src.replace(/\?/, ext+'?'); 
  else
    return src + ext;
}

function AC_Generateobj(objAttrs, params, embedAttrs) 
{ 
  var str = '<object ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += '<embed ';
  for (var i in embedAttrs)
    str += i + '="' + embedAttrs[i] + '" ';
  str += ' ></embed></object>';

  document.write(str);
}

function AC_FL_RunContent(){
 if (parametrosFlash!="")  // Difernciamos por si modificaciones futuras en comportamiento.
  var ret = 
    AC_GetArgs
    (  arguments, ".swf?" + parametrosFlash, "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
 else	
	var ret = 
    AC_GetArgs
    (  arguments, ".swf", "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
     , "application/x-shockwave-flash"
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}

function AC_SW_RunContent(){
  var ret = 
    AC_GetArgs
    (  arguments, ".dcr", "src", "clsid:166B1BCA-3F9C-11CF-8075-444553540000"
     , null
    );
  AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}
function AC_GetArgs(args, ext, srcParamName, classid, mimeType){
  var ret = new Object();
  ret.embedAttrs = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){	
      case "classid":
        break;
      case "pluginspage":
        ret.embedAttrs[args[i]] = args[i+1];
        break;
      case "src":
      case "movie":	
        args[i+1] = AC_AddExtension(args[i+1], ext);
        ret.embedAttrs["src"] = args[i+1];
        ret.params[srcParamName] = args[i+1];
        break;
      case "onafterupdate":
      case "onbeforeupdate":
      case "onblur":
      case "oncellchange":
      case "onclick":
      case "ondblClick":
      case "ondrag":
      case "ondragend":
      case "ondragenter":
      case "ondragleave":
      case "ondragover":
      case "ondrop":
      case "onfinish":
      case "onfocus":
      case "onhelp":
      case "onmousedown":
      case "onmouseup":
      case "onmouseover":
      case "onmousemove":
      case "onmouseout":
      case "onkeypress":
      case "onkeydown":
      case "onkeyup":
      case "onload":
      case "onlosecapture":
      case "onpropertychange":
      case "onreadystatechange":
      case "onrowsdelete":
      case "onrowenter":
      case "onrowexit":
      case "onrowsinserted":
      case "onstart":
      case "onscroll":
      case "onbeforeeditfocus":
      case "onactivate":
      case "onbeforedeactivate":
      case "ondeactivate":
      case "type":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      case "width":
      case "height":
      case "align":
      case "vspace": 
      case "hspace":
      case "class":
      case "title":
      case "accesskey":
      case "name":
      case "id":
      case "tabindex":
        ret.embedAttrs[args[i]] = ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.embedAttrs[args[i]] = ret.params[args[i]] = args[i+1];
    }
  }
  ret.objAttrs["classid"] = classid;
  if (mimeType) ret.embedAttrs["type"] = mimeType;
  return ret;
}
//////////// Fin funciones de Flash //////////

function enviarform(archivo)
{
	//alert("enviando");
	document.formulario.action = "form/"+archivo+".php";
	document.formulario.submit();
}

function validarfechas(obj)
{
	var formatovalido=/^\d{1,2}\-\d{1,2}\-\d{4}$/
	var i
	
	for (i=0;i<=obj.length-1;i++)
	{
		//alert("iiiii:"+i);
		//alert("id:"+obj[i]);
		if (document.getElementById(obj[i])!=null)
		{
			var fecha = document.getElementById(obj[i]);
			//alert("valor:"+fecha.value);
			if (!formatovalido.test(fecha.value))
			{
				alert("aa-bb-cccc");
				fecha.focus();
				return false;
			}
		}
	}
	return true;
}
function ChangeClass_color(menu, newClass)
{ 
	  var navegador = navigator.appName;
	  var aux = "capa_color"+menu;
	  //alert(navegador);
		if (navegador=="Netscape")
		{
			 if (document.getElementById)
			 { 
				document.getElementById(aux).setAttribute("class",newClass);
				//document.getElementById(menu).class = newClass; 
			 } 
		}
		if (navegador=="Microsoft Internet Explorer")
		{
			 if (document.getElementById)
			 { 
				document.getElementById(aux).className = newClass;
			 } 
		}
} 

var colours = new Array("#FFFFFF", "#FFCCCC", "#FFCC99", "#FFFF99", "#FFFFCC", "#99FF99", "#99FFFF", "#CCFFFF", "#CCCCFF", "#FFCCFF", "#CCCCCC", "#FF6666", "#FF9966", "#FFFF66", "#FFFF33", "#66FF99", "#33FFFF", "#66FFFF", "#9999FF", "#FF99FF", "#C0C0C0", "#FF0000", "#FF9900", "#FFCC66", "#FFFF00", "#33FF33", "#66CCCC", "#33CCFF", "#6666CC", "#CC66CC", "#999999", "#CC0000", "#FF6600", "#FFCC33", "#FFCC00", "#33CC00", "#00CCCC", "#3366FF", "#6633FF", "#CC33CC", "#666666", "#990000", "#CC6600", "#CC9933", "#999900", "#009900", "#339999", "#3333FF", "#6600CC", "#993399", "#333333", "#660000", "#993300", "#996633", "#666600", "#006600", "#336666", "#000099", "#333399", "#663366", "#000000", "#330000", "#663300", "#663333", "#333300", "#003300", "#003333", "#000066", "#330099", "#330033");
var divPreview;
function mouseOver(el, Colour){
  divPreview.style.background = Colour;
  document.frmColour.ColorHex.value = Colour;
  el.style.borderColor = '#FFFFFF';
}
function mouseOver2(el, Colour,color){
  var aux2 = 'color'+color;
  document.getElementById(aux2).value = Colour;
}
function mouseOut(el){
  el.style.borderColor = '#666666';
}
function mouseDown(Colour){
 self.parent.setColor(Colour);
 self.parent.palette.style.visibility = 'hidden';
}
function init(){
    divPreview = Obj("divPreview");
}
function Obj(name) {
    return document[name]||(document.all && document.all[name])||(document.getElementById && document.getElementById(name));
}