//ponemos los eventos de las imagenes
function makeImagesPop(id){
	var x = document.getElementById(id);
	if (!x) return;
	var y = x.getElementsByTagName('img');
	for (var i=0;i<y.length;i++){
		y[i].onclick = function(){window.open("/migal/verFoto.php?f="+this.src,"","toolbar=no, location=no, directories=no, status=no, menubar=no, resizable=yes ,width=320, height=240")};
	}
}

//ponemos los eventos de los enlaces
function makeULenlaces(){
	var x = document.getElementById('enlaces');
	if(!x) return;
	y = x.childNodes;
	for(var i=0; i<y.length; i++){
		if(y[i].nodeName == 'LI'){
			y[i].className = 'oculto';
			y[i].firstChild.onclick = function(){
				window.status = this.parentNode.nodeName+' - '+this.parentNode.className;
				if(this.parentNode.className != 'visible')
					this.parentNode.className = 'visible';
				else this.parentNode.className = 'oculto';
			}
		}
	}//fin del for
}

function empty(str){
	return (str == '');
}

function clearIfDefault(obj){
	if(obj.value == obj.getAttribute('dvalue')){
		obj.value = '';
		obj.className = 'edit';
	}
}

//y la validacion del formulario
function valContacto(){
	var x = document.forms.contacto;
	if(!x) return;
	x.onsubmit = function(){
		var ok = true;
		for(var i=0; i<this.elements.length; i++){
			xx = this.elements[i];
			dvalue = xx.getAttribute('dvalue');
			if(dvalue){
				//alert(xx.name+' -> '+dvalue);
				if(empty(xx.value) || (xx.value == dvalue)){
					ok = false;
					xx.value = dvalue;
					xx.onclick = function(){clearIfDefault(this)};
					xx.className += ' formerror';
				}//else xx.className = 'edit';
			}//else alert(xx.name+' no tiene dvalue : '+dvalue);
		}
		//alert(ok);
		return ok;
	}
}

function init(){
	if(screen.height > 768){
	   document.getElementById('cuerpo').style.height = '500px';
	}
	makeImagesPop('brazo');
	makeImagesPop('cuerpo');
	makeULenlaces();
	valContacto();
};

//lanzamos el init para los ie
if(!document.addEventListener){
	init();
}

