<!--
// Version 2002-05-22 copyright Com. Visual Arkipo

// UtilCalc(fnum)
// UtilValue(id)
// UtilSearch (nKey)
// UtilSwapImage(id, onFile)
// UtilStripFilePath(file)
// UtilCheckFileType(file, type1, type2, ..., typeN)
// UtilPopWindow()
// UtilHTML(func [load/get],id,file,nestref)
// UtilServerCall(myUrl)
// UtilServerResponse(msg)


// history:
//
// 2002-05-22 UtilSetDiv Checks if id exists
// 2002-04-21 UtilSearch string unescaped
// 2002-04-08 UtilHTML * DELETED *
// 2002-04-08 IE=(IE4||IE5)
// 2002-03-21 UtilSearch(nKey, myUrl) url new parameter
// 2002-03-01 UtilStripFilePath MacIntosh ':' separators
// 2002-02-05 UtilSwapImage(id, onFile)
// 2002-01-17 UtilStripFilePath now strips search parameters
// 2002-01-15 UtilSearch() returns false if nkey not found, positioning error corrected
// 2002-01-15 UtilCheckFileType
// 2002-01-11 UtilStripFilePath , UtilPopWindow()
// 2002-01-02 UtilSearch nKey = ''  returns all the string
// 2001-12-17 UtilSwapImage(id)

IE4=(document.all && !document.getElementById)
IE5=(document.all && document.getElementById)
NS4=document.layers;
var NS6=(!document.all&&document.getElementById), NS=(NS4||NS6), IE=(IE4||IE5);
Opera = (navigator.userAgent.indexOf('Opera') !=-1)
IEWin50 = ((navigator.platform.indexOf("Win") != -1) && (navigator.appVersion.indexOf("MSIE 5.0") != -1));

function UtilCalc(fString)
{
	temp = parseInt(eval(fString));
	return(temp);
}

function UtilValue(id)
{
	d = document;
	if (IE)
	{
		return(parseFloat(document.all[id].value));
	}
	else if (NS6) 
	{
		return(parseFloat(document.getElementById(id).value));
	}
}

function UtilSetDiv(id,val,text)
{
	if (!text) text ='';
	if (IE) {if (document.all[id]) document.all[id].innerHTML = val + text;}
	else if (NS6) 
		{
		if (document.getElementById(id)) document.getElementById(id).innerHTML = val + text;
	}
	else if (NS4)
	{
		with(document.layers[id].document)
		{
      		open();
      		write(val+text);
      		close();
		} 
	}
}

function UtilSetVal(id,val)
{
	d = document;
	if (IE) document.all[id].value = val;
	else if (NS4) document.layers[id].value = val;
	else if (NS6) document.getElementById(id).value = val;
}

// UtilSearch Busca la variable nKey en el texto despues de la interogación ? en una URL
function UtilSearch (nKey, myUrl)
{
	if (!myUrl) var mySearch = unescape(window.location.search);
	else mySearch = myUrl;
	
	if (!mySearch) return (false);
	if (!nKey)  return (mySearch);
		
	var pos = mySearch.indexOf(nKey);
	if (pos != -1)
	{
		var pos1 = mySearch.indexOf("=", pos);
		if (pos1 != (pos + nKey.length)) return (false);
		var pos2 = mySearch.indexOf("&", pos);
		if (pos2 == -1) pos2 = mySearch.length;
		return(unescape(mySearch.substring(pos1+1,pos2)));
	}
	else return (false);
}


// Cambia la imagen en src creando 'onSrc' con 'onFile' como URL a una imagen
function UtilSwapImage(id, onFile)
{
	if (IE) {if (document.all(id)) docimg = document.all(id);}
	else if (NS4) {if (document.images(id)) docimg = document.images(id);}
	else if (NS6) {if (document.getElementById(id)) docimg = document.getElementById(id);}
	else return(false);

	if (!docimg.onSrc)
	{
		if (!onFile) return(false);
		docimg.onSrc = onFile;	 
	}

	temp = docimg.src;
	docimg.src = docimg.onSrc;
	docimg.onSrc = temp;
}

function UtilStripFilePath(file) 
{ 
	if ((file) && (file != ""))
	{
 		pos = file.lastIndexOf("\\");
		if (pos == -1) pos = file.lastIndexOf("/");
		if (pos == -1) pos = file.lastIndexOf(":");
		name = file.substr(pos+1);
		pos = name.indexOf('?');
		if (pos > -1) name = name.substr(0,pos)
		return (name);
	}
	return("");
}


function UtilCheckFileType() 
{ 
	returnvalue = false;
	args = UtilCheckFileType.arguments;
	file = args[0];
	
	if ((file) && (file != ""))
	{
 		pos = file.lastIndexOf(".");
		ext = file.substr(pos+1).toLowerCase();
	}
	
	for (i=1;i<args.length;i++)
	{
		if (ext == args[i]) 
		{
			returnvalue = true;
			break;
		}
	}
	return returnvalue;
}

function UtilPopWindow(path,name,width,height) 
{
	var remote=null;

	remote = window.open(path,name,"toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=0,resizable=0,width="+width+",height="+height);

	if (remote != null) 
	{
    	if (remote.opener == null)
      		remote.opener = self;
		remote.focus();
	}
}

var UtilServerBufferArray = new Array();


function UtilServerBuffer(myUrl, mode, destination)
{
	this.myUrl = myUrl+ ((myUrl.indexOf('?')!=-1)?"&":"?")+'rpc='+UtilServerBufferArray.length;
	this.mode = (mode ? mode:'alert');
	this.destination = destination;
	
	this.id = (this.mode == 'load') ? destination : 'RPC' + UtilServerBufferArray.length;
	this.obj = null;
	this.doc = null;
	this.inUse = false;
	this.content = null;
 }

// Para comptibilidad con NS4 se tiene crear un <layer name="RPC0"><iframe id="RPC0"></iframe></layer>
function UtilServerCall(myUrl, mode, destination)
{
	var miBuffer; // our IFrame object
	loading = false;

	//if (!document.createElement) {return true};
	
  	if (myUrl && (mode != 'repeat'))
	{
		dl = document.location;
		urltemp = dl.pathname.replace(/\\/g,'/');
		urltemp = urltemp.slice(0,urltemp.lastIndexOf('/')+1);
		myUrl = dl.protocol + '//' + dl.host + urltemp + myUrl;
		//miBuffer = null;
		for(i=0;i<UtilServerBufferArray.length;i++)
		{
			if (!UtilServerBufferArray[i].inUse) 
			{

				miBuffer = UtilServerBufferArray[i];
				miBuffer.myUrl = myUrl+ ((myUrl.indexOf('?')!=-1)?"&":"?")+'rpc='+i;
				miBuffer.mode = (mode ? mode:'alert');
				miBuffer.destination = destination;
				miBuffer.id = (miBuffer.mode == 'load')? miBuffer.destination:miBuffer.id;
				break;
			}
		}

 	
		if (!miBuffer) 
		{
  			UtilServerBufferArray[UtilServerBufferArray.length] = new UtilServerBuffer(myUrl, mode, destination);
			miBuffer = UtilServerBufferArray[UtilServerBufferArray.length-1];
		}
		if (miBuffer.mode != 'load') miBuffer.inUse = true;


			if (NS4)
			{
				if (!document.layers[miBuffer.id]) { return true; }
				miBuffer.obj = document.layers[miBuffer.id];
			}
			else if (IE4 || IEWin50 || Opera)
			{
				if (document.frames[miBuffer.id]) miBuffer.obj = document.frames[miBuffer.id];
			}
			else if (NS6)
			{
				if (document.getElementById(miBuffer.id)) miBuffer.obj = document.getElementById(miBuffer.id);	
			}	
		//}
		
		if (!miBuffer.obj) 
		{
			if (IE4 || IEWin50 || Opera)
			{
				document.body.innerHTML += '<iframe id="'+miBuffer.id+'" width="0" height="0" frameborder="0" src="'+miBuffer.myUrl+'"></iframe>';
				loading = true;
				miBuffer.obj = document.frames[miBuffer.id];
			}
			else if (document.createElement)
			{
   				// create the IFrame 
				// this will only happen the first time 
				// the function is called
				var tempIFrame=document.createElement('iframe');

				tempIFrame.setAttribute('id',miBuffer.id);
   				tempIFrame.style.border='0px';
   				tempIFrame.style.width='0px';
   				tempIFrame.style.height='0px';
				miBuffer.obj = document.body.appendChild(tempIFrame);
				if (((document.frames) && (navigator.platform.indexOf("Mac")!= -1)) || IE4 || IEWin50) 
				{
					miBuffer.obj = document.frames[miBuffer.id];
				}
			}
		}
	}
	else miBuffer = UtilServerBufferArray[myUrl];
	
	if (navigator.userAgent.indexOf('Gecko') !=-1 && !miBuffer.obj.contentDocument) 
	{
    	// we have to give NS6 a fraction of a second
    	// to recognize the new IFrame
		temp = parseInt(miBuffer.id.substring(3)); 
		setTimeout('UtilServerCall(temp,"repeat")',1000);		
		//if (miBuffer.id =="RPC0" ) setTimeout('UtilServerCall(0,"repeat")',500);
		//else if (miBuffer.id =="RPC1" ) setTimeout('UtilServerCall(1,"repeat")',500);
    	return false;
	}
  
	if (!Opera && miBuffer.obj.contentDocument) 
	{
    	// For NS6
		miBuffer.doc = miBuffer.obj.contentDocument; 
	}
	else if (!Opera && miBuffer.obj.contentWindow) 
	{
    	// For IE5.5 and IE6
    	miBuffer.doc = miBuffer.obj.contentWindow.document;
  	}
	else if (miBuffer.obj.document) 
	{
    	// For IE4&5
    	miBuffer.doc = miBuffer.obj.document;
  	}
	else if (NS4)
	{
		miBuffer.obj.load(miBuffer.myUrl, miBuffer.obj.clip.width);
	}
	else 
	{
    	return true;
	}
	//if (!NS4 && !loading) miBuffer.doc.location.replace(miBuffer.myUrl);
	if (!NS4 && !loading) document.getElementById(miBuffer.id).src = miBuffer.myUrl;
	//debugger;
	//window.document.miBuffer.id.src = miBuffer.myUrl;
	//document.getElementById(miBuffer.id).src = miBuffer.myUrl;
	else loading = false;
	return false;
}

function UtilServerResponse(call, source, destination)
{
	var whatRPC = UtilSearch("rpc", call);
	var magicWord = 'free';
	//debugger;
	if (whatRPC)
	{
		if (UtilServerBufferArray.length > whatRPC) whatBuffer = UtilServerBufferArray[whatRPC];
		else return;
		
	if (parent.frames && !NS6)
	{
		if (parent.frames[whatBuffer.id].document.body) whatBuffer.doc = parent.frames[whatBuffer.id].document;
		else return;
	}
	else if (document.getElementById)
	{
		// For NS6
		if (document.getElementById(whatBuffer.id).contentDocument)
			whatBuffer.doc = document.getElementById(whatBuffer.id).contentDocument; 
		// For IE5.5 and IE6
		else if (document.getElementById(whatBuffer.id).contentWindow)
		    	whatBuffer.doc = document.getElementById(whatBuffer.id).contentWindow.document;
	}

			
		
		if ((!source) || (source == 'body'))
		{
			if (whatBuffer.doc && whatBuffer.doc.body) whatBuffer.content = whatBuffer.doc.body.innerHTML;
		}
		else if (source == magicWord) 
		{
			whatBuffer.inUse = false;
			return;
		}
		else
		{
			if (IE4) whatBuffer.content = whatBuffer.doc.all(source).innerHTML;		
			else if (whatBuffer.doc.body) whatBuffer.content = whatBuffer.doc.getElementById(source).innerHTML;
		}

		if (destination) 
		{
			if (destination != magicWord) whatBuffer.destination = destination;
			else whatBuffer.inUse = false;
		}	
		
		if (whatBuffer.mode == 'alert')
		{
		 	alert(whatBuffer.content);
		}
		else if (whatBuffer.mode == 'buffer')
		{
		
			if (whatBuffer.destination)
			{ 
				if (whatBuffer.destination == 'return') return (whatBuffer.content);
				if (IE4) document.all(whatBuffer.destination).innerHTML = whatBuffer.content;
				else document.getElementById(whatBuffer.destination).innerHTML = whatBuffer.content;
			}
		}
	}
}
//-->

