// JavaScript Document
/**
 * FUNCIONES JS: MENU, INPUT, ALTER_TABLE
 *	Programadas por Viktor Hugo Morales (http://vhmorales.wordpress.com)
 *	para Guiartdf.com SRL.
 *	
*/
menu = function() {
	_root = document.getElementById('nav');
	if (_root) {
		_child = _root.childNodes;
		for (i=0;i<_child.length;i++) {
			if (_child[i].nodeName == 'IMG') {
				if (_child[i].id) {
					_child[i].onmouseover = function() { this.className = 'over'; }
					_child[i].onclick = function() { 
						var _target = 'archivos';
						location.href='./?'+this.id;
					}
				}
			}
		}
	}
}
input = function() {
	var input = document.getElementsByTagName('input');
	if (input != null) {
		for (i=0;i<input.length;i++) {
			if (input[i].type == 'text' || input[i].type == 'password' || input[i].type == 'file') {
				if (input[i].className == 'opt') {
					input[i].onfocus = function() { this.className = 'opt_over'; }
					input[i].onblur = function() { this.className = 'opt'; }
				}
				else if (input[i].className == 'req') {
					input[i].onfocus = function() { this.className = 'req_over'; }
					input[i].onblur = function() { this.className = 'req'; }
				}
			}
		}
	}
	var textarea = document.getElementsByTagName('textarea');
	if (textarea != null) {
		for (i=0;i<textarea.length;i++) {
			if (textarea[i]) {
				if (textarea[i].className == '') {
					textarea[i].className = '';
					textarea[i].onfocus = function() { this.className = 'over'; }
					textarea[i].onblur = function() { this.className = ''; }
				}
				else {
					textarea[i].className = 'req';
					textarea[i].onfocus = function() { this.className = 'req_over'; }
					textarea[i].onblur = function() { this.className = 'req'; }
				}
			}
		}
	}
}
alter_table = function() {
	if (document.getElementsByTagName('TABLE')) {
		var _root = document.getElementsByTagName('TABLE');
		for (i=0;i<_root.length;i++) {
			if (_root[i].id == 'alter_table') {
				/*
				Algunos browsers indican que el nodo childNodes[0] es “#text” y otros “TBODY”, del mismo nodo.
				Para esa “falencia”, sin detectar navegadores ni versiones, aplico lo siguiente:
				*/
				if (_root[i].childNodes[0].nodeName == 'TBODY') { var _child = _root[i].childNodes[0].childNodes; }
				else { var _child = _root[i].childNodes[1].childNodes; }
				
				var num = 0;
				for (r=0;r<_child.length;r++) {
					
					if (_child[r].nodeName == 'TR') {
						//solo alternamos los TD
						if (_child[r].childNodes[0].nodeName == 'TD') {
							//verificamos si es par (1 = even) o impar (0 = odd)
							if (num == 0) { var isEven = true; var num = 1; }
							else { var isEven = false; var num = 0; }
							
							if (isEven) { _child[r].className = 'even'; } //si es par (1)
							else { _child[r].className = 'odd'; }//sino, debe ser impar (0)
							
							//efecto mouseover
							_child[r].onmouseover = function() {
								this.style.backgroundColor = '#ffffee';
							}
							_child[r].onmouseout = function() {
								this.style.backgroundColor = '';
							}
						}
					}
				}
			}
		}
	}
}

init = function() {
	menu();alter_table();input();
}

archivo = function(name, div) {
	cargando(name,div);
	return false;
}
cargando = function(url, target) {
  document.getElementById(target).innerHTML = ' Cargando información...';
  if (window.XMLHttpRequest) {
    req = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    req = new ActiveXObject("Microsoft.XMLHTTP");
  }
  if (req != undefined) {
    req.onreadystatechange = function() {cargado(url, target);};
    req.open("GET", url, true);
	//req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	//req.setRequestHeader("Accept-Charset", "iso-8859-1");
    req.send("");
  }
}
cargado = function(url, target) {
  if (req.readyState == 4) { // only if req is "loaded"
    if (req.status == 200) { // only if "OK"
      document.getElementById(target).innerHTML = req.responseText;
    } else {
      document.getElementById(target).innerHTML= ' Error '+ req.status + ': ' +req.statusText;
    }
  }
}
