// JavaScript Document
function addTextClass() {
	var inputs = document.getElementsByTagName('input');
	for (var i=0; i < inputs.length; i++){
	if (inputs[i].getAttribute("type") == "button")
		inputs[i].setAttribute("className", "button", 0);
	}
}


function ajaxRequest(pagina,arrData,setup){
	function par_def(pname, def){ if(typeof setup[pname]=="undefined") {setup[pname]=def;}};
	par_def("async" ,true);
	par_def("method",'post');
	par_def("loading",defaultAjaxStateOne);
	par_def("loaded",defaultAjaxStateFour);
	par_def("okLoad",defaultAjaxStateFour200);
	
	var ajax=objAjax();
	ajax.open(setup.method,pagina,setup.async);
	ajax.onreadystatechange=function(){	
		if (ajax.readyState==1){//Loading
			setup.loading();
		}else if (ajax.readyState==4) {//Loaded
			setup.loaded();
			if(ajax.status==200){//OK response
				setup.okLoad(ajax.responseText);
			}else if(ajax.status==404){//Not URL found
				alert('ERROR:URL NO DISPONIBLE');
			}else{//Other error
	
			}
		}
	};
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(parseToAjaxSendString(arrData));
} 

function objAjax() {
  if(window.XMLHttpRequest)
    return new XMLHttpRequest(); 
  else if(window.ActiveXObject)
    return new ActiveXObject("Microsoft.XMLHTTP");
}

function parseToAjaxSendString(arrData){
	var qs="",index="";
	var objDate=new Date();
	var noCa=objDate.getHours()+objDate.getMinutes()+objDate.getSeconds()+objDate.getDay()+objDate.getMonth()+objDate.getYear();
	for(index in arrData)
		qs=qs+index+"="+encodeURIComponent(arrData[index])+"&";	
	qs=qs+"nocahe="+noCa;
	return qs;
}

//------------------------------>
function defaultAjaxStateOne(){

}
function defaultAjaxStateFour(){

}
function defaultAjaxStateFour200(datos){
	alert(datos);
}

//----------------------------->
function ge(idObject){
	var par,obj;
	(arguments.length>1)?(par=arguments[1]):(par=document);
	if(!par.getElementById || !(obj=par.getElementById(idObject))) return null;
	return obj;
}
function addEvent(object,even,exeFunction){
	if(object==null) alert('Unable To Add Event \n The Element Don\'t Exist');
	if(object.addEventListener) // Mozilla, Netscape, Firefox
		object.addEventListener(even, exeFunction, false);
	else  // IE
		object.attachEvent('on'+even, exeFunction);
}
function removeEvent(object,even,exeFunction){
	if(object==null) alert('Unable To Remove Event \n The Element Don\'t Exist');
	if(object.removeEventListener) // Mozilla, Netscape, Firefox
		object.removeEventListener(even, exeFunction, false);
	else  // IE
		object.detachEvent('on'+even, exeFunction);
}


function createHTML_OBJECT(idCon,element,idele){
	var obj=document.createElement(element);
	var cont=document.getElementById(idCon);
	obj.id=idele;
	cont.appendChild(obj);
	return obj;
}

function removeHTML_OBJECT(idEle){
	var obj=document.getElementById(idEle);
	obj.parentNode.removeChild(obj);
}

function getOnLayer(arrData,arrDataPost){
	var targetLayer=ge(arrData.idLayer),i,strEle="",sty,flClose=false;
	if(targetLayer==null){
		targetLayer=createHTML_OBJECT(document.forms[0].id,'div',arrData.idLayer);
		sty=targetLayer.style;
		sty.height="340px";
		sty.width="240px";
		sty.position="absolute";
		sty.left='10';
		sty.top='10';
		sty.overflow='auto';
		flClose=true;
	}
	if(typeof arrData['title']=='undefined') arrData['title']="Sin Titulo"; 
	arrDataPost.layerToLoad=arrData.idLayer;
	ajaxRequest(arrData.action,
		arrDataPost,{
		okLoad:function(datos){
			targetLayer.innerHTML="";
			if(flClose)
				targetLayer.innerHTML="<div class=\"titWindowLayer\">"+arrData['title']+"<img src=../utilidadesJS//"logos/cerrar.gif/" alt=\"Cerrar\" width=\"30\" height=\"30\" onClick=\"removeHTML_OBJECT('"+arrData.idLayer+"')\"/></div>";
			targetLayer.innerHTML +=datos;
		}
	});
}


