addEvent(window,'load',initForm);

var highlight_array=new Array();

function initForm(){
	initializeFocus();
	initAutoResize();
	ifInstructs();
	browserDetect();
}

function initializeFocus(){
	fields=getElementsByClassName(document,"*","field");
	for(i=0;i<fields.length;i++){
		if(fields[i].type=='radio'||fields[i].type=='checkbox'||fields[i].type=='file'){
			fields[i].onclick=function(){
				//habilitar(this.id);
				clearSafariRadios();
				var nodo;
				if (this.parentNode["nodeName"] == "FIELDSET") nodo = this.parentNode;
				else if (this.parentNode.parentNode["nodeName"] == "FIELDSET") nodo = this.parentNode.parentNode;
				else if (this.parentNode.parentNode.parentNode["nodeName"] == "FIELDSET") nodo = this.parentNode.parentNode.parentNode;
				else if (this.parentNode.parentNode.parentNode.parentNode["nodeName"] == "FIELDSET") nodo = this.parentNode.parentNode.parentNode.parentNode;
				addClassName(nodo,"focused",true)
			};
			fields[i].onfocus=function(){
				clearSafariRadios();
				var nodo;
				if (this.parentNode["nodeName"] == "FIELDSET") nodo = this.parentNode;
				else if (this.parentNode.parentNode["nodeName"] == "FIELDSET") nodo = this.parentNode.parentNode;
				else if (this.parentNode.parentNode.parentNode["nodeName"] == "FIELDSET") nodo = this.parentNode.parentNode.parentNode;
				else if (this.parentNode.parentNode.parentNode.parentNode["nodeName"] == "FIELDSET") nodo = this.parentNode.parentNode.parentNode.parentNode;
				addClassName(nodo,"focused",true)
			};
			highlight_array.splice(highlight_array.length,0,fields[i]);
		}
		else
		{
			fields[i].onfocus=function(){
				clearSafariRadios();
				var nodo;
				if (this.parentNode["nodeName"] == "FIELDSET") nodo = this.parentNode;
				else if (this.parentNode.parentNode["nodeName"] == "FIELDSET") nodo = this.parentNode.parentNode;
				else if (this.parentNode.parentNode.parentNode["nodeName"] == "FIELDSET") nodo = this.parentNode.parentNode.parentNode;
				else if (this.parentNode.parentNode.parentNode.parentNode["nodeName"] == "FIELDSET") nodo = this.parentNode.parentNode.parentNode.parentNode;
				addClassName(nodo,"focused",true)
			};
			fields[i].onblur=function(){
				var nodo;
				if (this.parentNode["nodeName"] == "FIELDSET") nodo = this.parentNode;
				else if (this.parentNode.parentNode["nodeName"] == "FIELDSET") nodo = this.parentNode.parentNode;
				else if (this.parentNode.parentNode.parentNode["nodeName"] == "FIELDSET") nodo = this.parentNode.parentNode.parentNode;
				else if (this.parentNode.parentNode.parentNode.parentNode["nodeName"] == "FIELDSET") nodo = this.parentNode.parentNode.parentNode.parentNode;
				removeClassName(nodo,"focused")
			};
		}
	}
}

function getElementsByClassName(oElm,strTagName,strClassName){
	var arrElements=(strTagName=="*"&&oElm.all)?oElm.all:oElm.getElementsByTagName(strTagName);
	var arrReturnElements=new Array();
	strClassName=strClassName.replace(/\-/g,"\\-");
	var oRegExp=new RegExp("(^|\\s)"+strClassName+"(\\s|$)");
	var oElement;
	for(var i=0;i<arrElements.length;i++){
		oElement=arrElements[i];
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}
	}

	return(arrReturnElements)
}

function clearSafariRadios(){
	for(var i=0;i<highlight_array.length;i++){
		if(highlight_array[i].parentNode){
			var nodo;
			if (highlight_array[i].parentNode["nodeName"] == "FIELDSET") nodo = highlight_array[i].parentNode;
			else if (highlight_array[i].parentNode.parentNode["nodeName"] == "FIELDSET") nodo = highlight_array[i].parentNode.parentNode;
			else if (highlight_array[i].parentNode.parentNode.parentNode["nodeName"] == "FIELDSET") nodo = highlight_array[i].parentNode.parentNode.parentNode;
			else if (highlight_array[i].parentNode.parentNode.parentNode.parentNode["nodeName"] == "FIELDSET") nodo = highlight_array[i].parentNode.parentNode.parentNode.parentNode;
			removeClassName(nodo,'focused');
		}
	}
}

function initAutoResize(){
}

function ifInstructs(){
	var container=document.getElementById('public');
	if(container){
		removeClassName(container,'noI');
		var instructs=getElementsByClassName(document,"*","instruct");
		if((container.offsetWidth<=450)||(instructs=='')){
			addClassName(container,'noI',true);
		}
	}
}

function browserDetect(){
	var detect=navigator.userAgent.toLowerCase();
	var container=document.getElementsByTagName('html');
	if(detect.indexOf('safari')+1){
		addClassName(container[0],'safari',true);
	}
	if(detect.indexOf('firefox')+1){
		addClassName(container[0],'firefox',true);
	}
}

function addClassName(objElement,strClass,blnMayAlreadyExist){
	if(objElement.className){
		var arrList=objElement.className.split(' ');
		if(blnMayAlreadyExist){
			var strClassUpper=strClass.toUpperCase();
			for(var i=0;i<arrList.length;i++){
				if(arrList[i].toUpperCase()==strClassUpper){
					arrList.splice(i,1);
					i--;
				}
			}
		}
		arrList[arrList.length]=strClass;
		objElement.className=arrList.join(' ');
	}
	else{
	objElement.className=strClass;
	}
}

function removeClassName(objElement,strClass){
	if(objElement.className){
		var arrList=objElement.className.split(' ');
		var strClassUpper=strClass.toUpperCase();
		for(var i=0;i<arrList.length;i++){
			if(arrList[i].toUpperCase()==strClassUpper){
				arrList.splice(i,1);
				i--;
			}
		}	
		objElement.className=arrList.join(' ');
	}
}

function addEvent(obj,type,fn){
	if(obj.attachEvent){
		obj["e"+type+fn]=fn;
		obj[type+fn]=function(){
		obj["e"+type+fn](window.event)};
		obj.attachEvent("on"+type,obj[type+fn]);
	}
	else{
		obj.addEventListener(type,fn,false);
	}
}

function valida_email(str)
{
	var reg_exp=new RegExp("^[a-zA-Z]+([\._\-]*[a-zA-Z0-9]+)*@[a-zA-Z]+([_\-][a-zA-Z0-9]+)*([\.][a-zA-Z0-9]+)+$");
	return reg_exp.test(str);
}