/* add attribute values as classnames (general) */
function letsAddAttr() {
	attrToClass('a','rel','external');
	attrToClass('input','type','text');
	attrToClass('input','type','password');
	attrToClass('input','type','radio');
	attrToClass('input','type','checkbox');
	attrToClass('input','type','file');
}

addLoadEvent(letsAddAttr);



/* adds on hover action to a list (navigation) */
function startList() {
if (document.all && document.getElementById) {
//navRoot = document.getElementById("nav");
navRoot = $('nav');
for (i=0; i<navRoot.childNodes.length; i++) {
  node = navRoot.childNodes[i];
  if (node.nodeName=="LI") {
  node.onmouseover=function() {
  //this.className+=" over";
  addClass(this,'over')
    }
  node.onmouseout=function() {
  this.className=this.className.replace
      (" over", "");
   }
   }
  }
 }
}

addLoadEvent(startList);



/* delete all function */
function deleteall(){
	var el = getElementsByClass('delete',$('content'),'a');
	for(var i=0; i < el.length; i++){
		el[i].onclick = function(){
			return confirm('¿Está seguro que desea eliminar los items seleccionados?');
		}
	}
}



/* if images is selected, go to step2 and change the button */
function imagesStep(){
	var img = $('img_step');
	var mybutton = $('submitButton');
	img.onclick = function() {
		if (this.checked == true) {
			mybutton.firstChild.nodeValue = 'Siguiente';
		} else {
			mybutton.firstChild.nodeValue = 'Guardar';
		}
	}
}
	
	

/* searches for a link with a className, and adds a trigger to open it in a new window */
function h4toggles() {
	var h4s = getElementsByClass('toggle',$('content'),'h4');
	for (i=0; i<h4s.length; i++) {
		h4s[i].style.cursor = 'pointer'; 
		h4s[i].onclick = function() {
			toggle(this.parentNode.getElementsByTagName('div')[0]);
			this.className = (this.className != 'toggle toggle2' ? 'toggle toggle2' : 'toggle');
		}
	}
	//alert(externals.length);
}



/* searches for a th with a className, and adds a trigger to sort its table */
function sortme() {
	var th = getElementsByClass('sort',$('content'),'th');
	for (i=0; i<th.length; i++) {
		var span = document.createElement('span');
		span.setAttribute('class','sortarrow');
		
		th[i].style.cursor = 'pointer';
		th[i].appendChild(span);
		th[i].onclick = function() {
			ts_resortTable(this, 1);
			return false;
		}
	}
}
addLoadEvent(sortme);

/*
function sortdate() {
	var th = getElementsByClass('sortdate',$('content'),'th');
	for (i=0; i<th.length; i++) {
		var span = document.createElement('span');
		span.style.border = '1px solid red';
		span.setAttribute('class','sortarrow');
		
		th[i].style.cursor = 'pointer';
		th[i].appendChild(span);
		th[i].onclick = function() {
			ts_resortTable(this, 3);
			return false;
		}
	}
}
addLoadEvent(sortdate);
*/
