function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

function a() {
	var combinado = '';
	for (var i = 0; i < arguments.length; i++) {
		combinado += arguments[i] + '::';
	}
	alert(combinado);
}


//Checa formularios

function checaForm(ref) {
	var cuantos = ref.parentNode.childNodes;
	var err = 0;
	for (var i = 0; i < cuantos.length; i++) {
		var tipo = cuantos[i].nodeName;
		if ((tipo == 'INPUT') || (tipo == 'TEXTAREA')) {
			var cual = $(cuantos[i]).value;
			if ((cual == $(cuantos[i]).title) && ($(cuantos[i]).className != 'opt')) {
				cuantos[i].style.borderColor = '#CF0C0C';
				++err;
			}
		}
	}
	if (err > 0){
		alert("Por favor llene todos los campos necesarios");
		return false;
	} else {
		ref.parentNode.submit();
		if ($('form').className =='comentarios') {
			comentarios();
		}
	}
}

//toggle enabled

function parentStyle(cual) {
	return cual.parentNode.style;
}


function init(){
	sombras();
	if ($('form')) {
		formElements = $('form').childNodes.length;
		for (i=0;i<formElements;++i) {
			var elem = $('form').childNodes[i];
				elem.onfocus = function() { if (this.value == this.title) { this.value = '';this.style.borderColor = "#444" } }
				elem.onblur = function() { if (this.value == '') { this.value = this.title; } }
		}
	}
}

function sombras() {
	dfoto = $('mainIMG');
	if ($('homeLink')) {
		$('homeLink').onclick = function() { location.href = '/index.php'; }
		$('homeLink').onmouseover = function() { $('homeAction').style.visibility='visible'; }
		$('homeLink').onmouseout = function() { $('homeAction').style.visibility='hidden'; }
	}
	
	if (!$('shadow')) {
		var shadow = document.createElement("div");
		shadow.setAttribute('id', 'shadow');
		shadow.innerHTML = "<div id=\"tl\" class=\"corner top\"></div><div id=\"tc\"></div><div id=\"tr\" class=\"corner top\"></div><div id=\"mid\"><div id=\"ml\"></div><div id=\"mr\"></div></div><div class=\"corner bottom\" id=\"bl\"></div><div id=\"bc\" class=\"bottom\"></div><div class=\"corner bottom\" id=\"br\"></div>";
		$('foto').appendChild(shadow);
		if (dfoto.width < dfoto.height){
			$('foto').style.right = (dfoto.width/4.5) + 'px';
			$('foto').style.top = -(dfoto.height/5)-10 + 'px';
			
		}
	}
	
	fotoW = eval(dfoto.width);
	fotoH = eval(dfoto.height);
	
	
	if (document.all) {
		$('shadow').style.width = fotoW+13 +'px';
		$('tc').style.width = fotoW-6 + 'px';
		$('bc').style.width = fotoW-6 + 'px';
		$('mid').style.height = fotoH-9 + 'px';
		$('shadow').style.height = fotoH+12 +'px';
	} else {
		$('shadow').style.width = fotoW+32 +'px';
		$('tc').style.width = fotoW+12 + 'px';
		$('bc').style.width = fotoW+12 + 'px';
		$('mid').style.height = fotoH+12 + 'px';
		$('shadow').style.height = fotoH+33 +'px';
	}
	//var fotoW = parseInt(getComputedStyle(foto, '').getPropertyValue('width'));
	//var fotoH = parseInt(getComputedStyle(foto, '').getPropertyValue('height'));
	//if (fotoH != 550);
}



function comentarios() {
	theLeft = window.innerWidth/2 - 480;
	attr = 'width=490, toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=yes, left=' + theLeft;
	window.open("/listado.php", "listado", attr);
}


window.onload = init;
