// Author: J. Antonio Rodríguez Landeros, arlander@energia.gob.mx  rodriguez.antonio@gmail.com
// Copyright:  Secretaría de Energía, México; 
// Global Defs
_d=document;
_db=document.body;
_sc=screen;
_ie = (_d.all) ? 1 : 0;
// Begins :: Paths
_rgi="/webSener/img/";
_rg="/webSener/";
// Ends :: Paths
// Special FX
function fx_ce(_o,_s){ // Change Style
	var o=di_gE(_o);
	try{
		o.className=_s;
	} catch (e) {}
}
// User Interface
function ui_ci(_o,_s){ // Create image
	var o=di_gE(_o);
	o.innerHTML = "<img src='"+_rgi+_s+"' />";
}
function ui_rl(_s){ // Relocate URL
	window.location.href=_rg+_s;
}
// DOM Interface
function di_ad(_h,_o,_c){ // Add Div Tag
	var h=di_gE(_h);
	var nd=_d.createElement("DIV");
	try {
		nd.setAttribute("id",_o);	
		h.appendChild(nd);
		fx_ce(_o,_c);
	} catch (e) {alert("Client Error at DIV tag creation, with parameters : "+_h+", "+_o+", "+_c);}
}
function di_rc(_h,_o){ // Remove Content
	var h=di_gE(_h);
	var o=di_gE(_o);
	if(h!=null){
		if(o!=null){
			try{
				h.removeChild(o);
			} catch(e){}
		}
	}
}
function di_ih(_h,_t){ // set InnerHTML
	var h=di_gE(_h);
	try{
	 h.innerHTML=_t;
	} catch(e) {}
}
function di_aih(_h,_t){ // Appends InnerHTML
	var h=di_gE(_h);
	try{
		h.innerHTML=h.innerHTML+_t;
	} catch (e) {}
}
function di_gE(_o){ // get Element
	return _d.getElementById(_o);	
}
function di_sA(_o,_a,_v){ // Set Atributte
	var h=di_gE(_o);
	h.setAttribute(_a,_v);
}
function di_rSZ(_o,_x,_y){ // reSize
	di_sA(_o,"style","width:"+_x+"px;height:"+_y+"px;");
	var h=di_gE(_o);
	h.style.width=_x+"px";
	h.style.height=_y+"px";
}
function di_uL(_o,_x,_y){ // Ubicate Layer
    try {
	di_sA(_o,"style","left:"+_x+"px;top:"+_y+"px;");
	var h=di_gE(_o);
	h.style.left=_x+"px";
	h.style.top=_y+"px";
        } catch (e) {}
}
function di_mT(_o,_x,_y){ // Move To
    try {
	di_sA(_o,"style","left:"+_x+"px;top:"+_y+"px;");
	var h=di_gE(_o);	
	h.style.left=_x+"px";
	h.style.top=_y+"px";
        } catch (e){}
}
// IFrame DOM Interface
function di_gIF(_o){ // getIFrame
	if(_ie){
		return _d.frames(_o).document;	
	} else {	
		return di_gE(_o).contentDocument;		
	}
}
function di_getIFv(_o){ // get IFrame value 
	try{di_gE(_o).onclick();}catch(e){}	
	try{di_cIF(_o);}catch(e){}	
}

function di_sS(_o,_s){ // set Stylesheet
	di_gIF(_o).styleSheets[0].href = _rg + "styles/" + _s + ".css";
}
// Remote Sockets
function rs_cS(){ // Create Socket
	var C=null;
	if (window.XMLHttpRequest) { // Mozilla, Safari, IE7...
		C = new XMLHttpRequest();		
	} else if (window.ActiveXObject) { // IE 6 & 5		
		try {C=new ActiveXObject("Msxml3.XMLHTTP");}catch(e){
			try {C=new ActiveXObject("Msxml2.XMLHTTP");}catch(e){C=new ActiveXObject("Microsoft.XMLHTTP");} 
		}
	}
	return C;
}
function rs_gR(_h,_m,_r){ // get Resource
	var h=di_gE(_h);	
	fx_pl(true);
	var _s=rs_cS();	
	function rs_Bind(){
		if (_s.readyState==4){
			if (_s.status==200){					 
				h.innerHTML=_s.responseText;
				fx_pl(false);
			} else { h.innerHTML="1: No se ha podido contactar al servidor... <br><br>El servidor no ha encontrado el recurso que busca: "+_r;fx_pl(false);
			}
		}
	}
	if(_s){		
		_s.onreadystatechange=rs_Bind;
		if(!_ie) {
			_s.open("GET",_r,true);
		} else {
			_s.open("POST",_r,true);
		}
		_s.setRequestHeader("Cache-Control","no-cache, must-revalidate, max-age=0");
		_s.setRequestHeader("Expires","Mon, 06 Apr 1978 05:23:42 GMT");
		_s.setRequestHeader("Pragma","no-cache");		
		_s.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		_s.send(null);
	} else {
		h.innerHTML="2: No se ha podido contactar al servidor ... <br><br>El servidor no ha encontrado el recurso que busca: "+_r;fx_pl(false);
	}	
}
// System Interface - Particular System Implementation
function sys_gR(_r){ // System Get Resource
	fx_ce("SESSION","none");
	rs_gR("SESSION","POST",_rg+_r);
}
function sys_gR(_r,_h){ // System Get Resource
	fx_ce(_h,"none");
	rs_gR(_h,"POST",_rg+_r);
}
