/* 
	Nombre:			dhtmlapi.js
	Descripcion:	funciones javascript para abstraccion de navegadores. Prefijo API_
	Creación:		19/02/2001

	Ultima:			$Date: 22/01/09 12:23 $		($Author: Fjgomez $)

	ComuNET S.A.
*/
	function API_findObj(n, d) { //v4.0
		var p,i,x;  
		if(!d) d=document; 
		if((p=n.indexOf("?"))>0&&parent.frames.length)	{d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
		if(!(x=d[n])&&is_ie4up) 						{x=d.all[n];}
		
		if(is_nav5up)					{		// para echarle de comer aparte
			if (!x)	x=d.forms[n];
			if (!x) x=d.getElementById(n);
			if (!x)	{	
				var arrObj=d.getElementsByTagName('textarea');	
				if (arrObj.length>0)	 x=arrObj[n];
			}
			if (!x)	{	
				var arrObj=d.getElementsByTagName('img');	
				if (arrObj.length>0)	 x=arrObj[n];
			}
		}
		for (i=0;!x&&i<d.forms.length;i++) 				{x=d.forms[i][n];}
		for(i=0;!x&&is_nav4&&i<d.layers.length;i++) 	{x=API_findObj(n,d.layers[i].document); }
		return x;
	}

	// +*+ API dependiente de navegador
	function API_Wnd_Height(wnd,value) {
		var ht;
		if (wnd==null)		{wnd=window;}
		if (is_nav4up) 		{if (value) { wnd.innerHeight=value;	}				else {ht = wnd.innerHeight;}}
		else if (is_ie4up)	{if (value) { wnd.document.body.offsetHeight=value;	}	else {ht = wnd.document.body.offsetHeight;}}
		return ht;	
	}

	function API_Wnd_Width(wnd,value) {
		var wd;
		if (wnd==null)		{wnd=window;}
		if (is_nav4up) 		{if (value) { wnd.innerWidth=value;	}					else {wd = wnd.innerWidth;}}
		else if (is_ie4up)	{if (value) { wnd.document.body.offsetWidth=value;	}	else {wd = wnd.document.body.offsetWidth;}}
		return wd;	
	}

	function API_Ly_Left(objName,value) {

		var lft=0;		ly=API_findObj(objName);		if (!ly) {alert('API_Ly_Left Error: could not find : ' + objName); return 0;}
		if (is_nav4) 	{if (value) {ly.left=value;}			 else {lft = ly.left;}}
		if (is_ie4up)	{if (value) {ly.style.pixelLeft=value;} else {lft = ly.style.pixelLeft;}}
		if (is_nav5up)	{if (value) {ly.style.left=value+'px';} else {lft = ly.style.left.substr(0,ly.style.left.indexOf('px')); }}
		return lft;	
	}

	function API_Ly_Top(objName,value) {

		var tp=0;		ly=API_findObj(objName);		if (!ly) {alert('API_Ly_Top Error: could not find : ' + objName); return 0;}	
		if (is_nav4) 	{if (value) {ly.top=value;} 			else {tp = ly.top;}}
		if (is_ie4up)	{if (value) {ly.style.pixelTop=value;} 	else {tp = ly.style.pixelTop;}}
		if (is_nav5up)	{if (value) {ly.style.top=value+'px';} 	else {tp = ly.style.top.substr(0,ly.style.top.indexOf('px'));	 }}
		return tp;
	}
	
	function API_Ly_Height(objName,value) {

		var ht=0;		

		if (typeof(objName)!='object') 	{ ly=API_findObj(objName);}
		else							{ ly=objName;}
		if (!ly) {alert('API_Ly_Height Error: could not find : ' + objName); return 0;}
		if (is_nav4) 	{if (value) {ly.clip.height=value;}			else {ht = ly.clip.height;}}
		if (is_ie4up)	{if (value) {ly.style.pixelHeight=value;}	else {ht = ly.style.pixelHeight;}}
		if (is_nav5up)	{if (value) {ly.style.height=value+'px';} 	else {ht = ly.style.height.substr(0,ly.style.height.indexOf('px'));	 }}
		return ht;	
	}

	function API_Ly_Width(objName,value) {
		var wd=0;		
		if (typeof(objName)!='object') 	{ ly=API_findObj(objName);}
		else							{ ly=objName;}
		if (!ly) {alert('API_Ly_Width Error: could not find : ' + objName); return 0;}
		if (is_nav4)	{if (value) {ly.clip.width=value;}			else {wd = ly.clip.width;}}
		if (is_ie4up)	{if (value) {ly.style.pixelWidth=value;}	else {wd = ly.style.pixelWidth;}}
		if (is_nav5up)	{if (value) {ly.style.width=value+'px';} 	else {wd = ly.style.width.substr(0,ly.style.width.indexOf('px'));	 }}
		return wd;	
	}

	function API_Ly_BkColor(objName,value) {
		var bk=0;		

		if (typeof(objName)!='object') 	{ ly=API_findObj(objName);}
		else							{ ly=objName;}

		if (!ly) {alert('API_Ly_BkColor Error: could not find : ' + objName); return 0;}
		if (is_nav4) 			{if (value) {ly.document.bgColor=value; }		else {bk = ly.document.bgColor;}}
		if (is_ie4up || is_nav5up){if (value) {ly.style.backgroundColor=value;}	else {bk = ly.style.backgroundColor;}}
		return bk;	
	}

	function API_Ly_oLeft(objName) {

		var lft=0;		ly=API_findObj(objName);
		if (is_nav4) 				{lft = API_Ly_Left(objName);}
		if (is_ie4up || is_nav5up)	{lft = ly.offsetLeft;}
		return lft;	
	}

	function API_Ly_oTop(objName) {

		var tp=0;		ly=API_findObj(objName);
		if (is_nav4) 				{tp = API_Ly_Top(objName);}			
		if (is_ie4up || is_nav5up)	{tp = ly.offsetTop;}
		return tp;
	}

	function API_Ly_oWidth(objName) {

		var wd=0;		ly=API_findObj(objName);
		if (is_nav4) 				{wd = API_Ly_Width(objName);}	
		if (is_ie4up || is_nav5up)	{wd = ly.offsetWidth;}
		return wd;	
	}

	function API_Ly_oHeight(objName) {

		var ht=0;		ly=API_findObj(objName);
		if (is_nav4) 				{ht = API_Ly_Height(objName);}	
		if (is_ie4up || is_nav5up)	{ht = ly.offsetHeight;}
		return ht;
	}

	// Para propiedades que se llamen igual
	function API_Ly_Property(objName,property,value) {
		var vl=0;		

		if (typeof(objName)!='object') 	{ ly=API_findObj(objName);}
		else							{ ly=objName; }

		if (!ly) {alert('API_Ly_Property Error: could not find : ' + objName ); return 0;	}
		if (is_nav4) 				{if (value) {eval('ly.'+property+'='+value);}		else { vl = eval('ly.'+property);}}
		if (is_ie4up || is_nav5up)	{if (value) {eval('ly.style.'+property+'='+value);}	else { vl = eval('ly.style.'+property);}}
		return vl;	
	}

	function API_Ly_Property2(objArr,property,value) {
		for (var i=0;i<objArr.length;i++)	{
			if (typeof(objArr[i])!='object') 	{ ly=API_findObj(objArr[i]);}
			else								{ ly=objArr[i]; }

			if (ly) {
				if (is_nav4) 	{eval('ly.'+property+'='+value);}
				if (is_ie4up || is_nav5up)	{eval('ly.style.'+property+'='+value);}
			}
		}
	}	

	function API_Property2(objArr,property,value) {
		for (var i=0;i<objArr.length;i++)	{
			if (typeof(objArr[i])!='object') 	{ obj=API_findObj(objArr[i]);}
			else								{ obj=objArr[i]; }
			if (obj) {	eval('obj.'+property+'='+value);}
		}
	}	
	
	function API_ChgSize(d)	{
		if (d==null)	d=document;
		if (d.getElementsByTagName)	{
			el=d.getElementsByTagName("INPUT");
			for(i=0;i<el.length;i++)	{
				if (el[i].type=='password' || el[i].type=='text') el[i].size*=1.8;	
		}
			el=d.getElementsByTagName("TEXTAREA");
			for(i=0;i<el.length;i++)	el[i].cols*=1.8;
	
		}
	}
	function Refresh(nItem)	{
		if (is_nav4up)	location.reload();
		else			history.go(0);
	}

	function Ly_Refresh(capa,texto)	{
		var ly=API_findObj(capa);
		if (ly)
			if (is_nav4)	{
				ly.document.open();
				ly.document.write(texto);
				ly.document.close();
			}
			else	ly.innerHTML=texto;
	}

	function Open(sUrl,sTgt,sOpc)	{

		if (is_nav5up)	{ 
			if ( sTgt!=null && sTgt!='' && (sOpc==null || (sOpc && sOpc=='scrollbars=yes')))	{
				if (parent.frames[sTgt]) parent.frames[sTgt].location.href=sUrl;
				else					 
						if (parent.parent.frames[sTgt]) parent.parent.frames[sTgt].location.href=sUrl;
						else					 parent.parent.parent.frames[sTgt].location.href=sUrl;
			}
			else	{
				return window.openOriginal(sUrl,'',sOpc);
			}
		}
		else			return window.openOriginal(sUrl,sTgt,sOpc);
	}

	window.openOriginal=window.open
	window.open=Open;
	
	// fin de APi de navegador
	function Maximizar(miventana){
		miventana.parent.resizeTo(screen.availWidth,screen.availHeight); 
		miventana.parent.moveTo(0,0); 
	}
