function XsAbrir(Url, Style, Width, Height, Position, WindowName){
	/*=======================================================
	Style
		1 - Ventana vacia sin controles (default)
		2 - Ventana normal con todos los controles
		3 - Ventana vacia sin controles pero redimensionable
		4 - Ventana con menu y redimensionable

	Position
		0 - TopLeft
		1 - Center (default)
	
	WindowName
		Define el nombre de referencia para la nueva ventana que se crea
	=========================================================*/

	var I, lWidth, lHeight, lPosition, lTop, lLeft, lStyle;
	var Properties

	// Defino los valores default para los argumentos
	lWidth = 640;
	lHeight = 480;
	if (Style==2)
		{lHeight = 420}
	lPosition = 1;
	lTop = 0;
	lLeft = 0;
	lStyle = 3;
	lWinName = "_blank"

	// Recupero los valores que me pasaron como argumentos
	for ( I = 0; I <=arguments.length-1; I++){
		if(arguments[I].toString().length > 0){
			switch (I) {
				case 1:
					lStyle = Style
					break
				case 2:
					lWidth = Width
					break
				case 3:
					lHeight = Height
					break
				case 4:
					lPosition = Position
					break
				case 5:
					lWinName = WindowName
					break
			}
		}
	}

	switch (lPosition) {
		// TopLeft
		case 0:
			lTop = 0
			lLeft = 0
			break
		// Center
		case 1:
			if(lStyle == 2){
				lTop = 	((screen.height - lHeight) / 2) - 148
			}else{
				lTop = 	((screen.height - lHeight) / 2) - 30
			}
			lLeft = (screen.width - lWidth) / 2
			break
	} 

	switch (lStyle){
		case 1:
			Properties = "toolbar=0,location=0,status=0,menubar=0,resizable=0"
			break
		case 2:
			Properties = "toolbar=1,location=1,status=1,menubar=1,resizable=1"
			break
		case 3:
			Properties = "toolbar=0,location=0,status=0,menubar=0,resizable=1"
			break
		case 4:
			Properties = "toolbar=0,location=0,status=0,menubar=1,resizable=1"
			break
	}
	
	if(navigator.appName != "Netscape") {
		eval("try { SetXsWinSetFocusXs() } catch (e){}")
	}
	window.open(Url, lWinName, Properties + ",scrollbars=1,top=" + lTop + ",left=" + lLeft + ",width=" + lWidth + ",height=" + lHeight);
	if(navigator.appName == "Netscape") {
		eval("SetXsWinSetFocusXs()")
	}
}

function GlobalReplace(Source, SearchText, ReplaceText, IgnoreCase){
	var Start, OldLen, NewLen
	var LSource

	//Check parameters
	// Lo cambie yo ' Leo - Mar 3 Jun 2003  - 5:15:15 p
	//if(Source == "" || SearchText == "" || ReplaceText == ""){
	if(Source == "" || SearchText == ""){
		return ""
	}
	
	//Get the string lengths
	OldLen = SearchText.length
	NewLen = ReplaceText.length
	
	//Should function respect case.
	if(IgnoreCase){
			SearchText = SearchText.toLowerCase()
			LSource = Source.toLowerCase()
	}
	else
			LSource = Source
	
	//Search for the first occurrence of searchtext
	Start = LSource.indexOf(SearchText)
	
	while (Start > 0){
			// replace searchtext with replacetext
			Source = Source.substring(0, Start) + ReplaceText + Source.substring(Start + OldLen, Source.length)
			if(IgnoreCase){
					SearchText = SearchText.toLowerCase()
					LSource = Source.toLowerCase()
			}
			else
					LSource = Source
			
			// find the next occurrence of searchtext
			Start = LSource.indexOf(SearchText, (Start + NewLen))
	}
	return Source
}

function setCookie(name, value, expires, path, domain, secure) {
	// name - name of the cookie
	// value - value of the cookie
	// [expires] - expiration date of the cookie
	// (defaults to end of current session)
	// [path] - path for which the cookie is valid
	// (defaults to path of calling document)
	// [domain] - domain for which the cookie is valid
	// (defaults to domain of calling document)
	// [secure] - Boolean value indicating if
	// the cookie transmission requires a secure transmission
	// * an argument defaults when it is assigned null as a placeholder
	// * a null placeholder is not required for trailing omitted arguments
	var caution = false
	
	var curCookie = name + "=" + escape(value) +
		 ((expires) ? "; expires=" + expires.toGMTString() : "") +
		 ((path) ? "; path=" + path : "") +
		 ((domain) ? "; domain=" + domain : "") +
		 ((secure) ? "; secure" : "")
	if (!caution || (name + "=" + escape(value)).length <= 4000)
		 document.cookie = curCookie
	else
		 if (confirm("Cookie exceeds 4KB and will be cut!"))
				document.cookie = curCookie
}

function getCookie(name) {
	// name - name of the cookie
	// * return string containing value
	// of specified cookie or null if cookie
	// does not exist
	var prefix = name + "="
	var cookieStartIndex = document.cookie.indexOf(prefix)
	if (cookieStartIndex == -1)
		 return null
	var cookieEndIndex = document.cookie.indexOf(";", cookieStartIndex + prefix.length)
	if (cookieEndIndex == -1)
		 cookieEndIndex = document.cookie.length
	return unescape(document.cookie.substring(cookieStartIndex + prefix.length, cookieEndIndex))
}

function deleteCookie(name, path, domain) {
	// name - name of the cookie
	// [path] - path of the cookie
	// (must be same as path used to create cookie)
	// [domain] - domain of the cookie
	// (must be same as domain used to create cookie)
	// * path and domain default if assigned
	// null or omitted if no explicit argument proceeds
	
	if (getCookie(name)) {
		 document.cookie = name + "=" +
		 ((path) ? "; path=" + path : "") +
		 ((domain) ? "; domain=" + domain : "") +
		 "; expires=Thu, 01-Jan-70 00:00:01 GMT"
	}
}

function fixDate(date) {
	// date - any instance of the Date object
	// * you should hand all instances of the
	// Date object to this function for "repairs"
	// * this function is taken from
	// Chapter 14, "Time and Date in JavaScript", in
	// "Learn Advanced JavaScript Programming"
	
	var base = new Date(0)
	var skew = base.getTime()
	if (skew > 0)
		 date.setTime(date.getTime() - skew)
}

function GetBrowser(){
	var Brs;
	var Done;
	Brs=navigator.appName+navigator.appVersion+navigator.userAgent;

		switch (navigator.appName){
		case "Netscape":
			if (Brs.indexOf("Opera 5",0) !=-1){return "OP5"}
			if (Brs.indexOf("Netscape4",0) !=-1){return "NN4"}
			if (Brs.indexOf("Netscape6",0) !=-1){return "NN6"}
			if (Brs.indexOf("Galeon",0) !=-1){return "GAL"}
			if (Brs.indexOf("Nautilus",0) !=-1){return "NAU"}
		break;
		case "Microsoft Internet Explorer":
			if (Brs.indexOf("Opera 5",0) !=-1){return "OP5"}
			if (Brs.indexOf("MSIE 7",0) !=-1){return "IE7"}
			if (Brs.indexOf("MSIE 6",0) !=-1){return "IE6"}
			if (Brs.indexOf("MSIE 5",0) !=-1){return "IE5"}
			if (Brs.indexOf("MSIE 4",0) !=-1){return "IE4"}
		break;
		case "Opera":
			if (Brs.indexOf("Opera/5",0) !=-1){return "OP5"}
		break;
		case "Konqueror":
		return "KO2";
		break;
		//case "Mozilla":
		//break;
		default: return "Other";
	}
}

function FillCombo(DefValue, HasBGColor, HasFontColor, strArr, DoClear, DoDisable, CtrlObj, CtrlType, ClearOnNotEmpty, UseActualValue){
	var lbl, id
	var ItemCount = 0
	var registro, i
	var Add, HasAddedOnce = false, HasRecords = false, ValorPadreEncontrado
	var StdArgs = 10
	var CantPadres = ((arguments.length) - StdArgs) / 2
	var aux
	var startOffset = 0
	var RegistroInicial = -1
	var middle
	var min
	var max
	var Ver = false;
	var CantidadElementosXDim;

	//document.body.style.cursor = 'wait'

	while (CtrlObj.options.length > 0){
		CtrlObj.options[0] = null
	}

	for(i=0;i < CantPadres;i++){
		if(arguments[2*i + StdArgs].selectedIndex == -1){
			SetNoData(CtrlObj);
			return;
		}
	}

	CantidadElementosXDim = CantPadres + 2;
	if(HasFontColor){
		CantidadElementosXDim += 1
	};
	if(HasBGColor){
		CantidadElementosXDim += 1
	};

	min = 0;
	max = strArr.length / (CantidadElementosXDim);

	if(CantPadres == 0){
		RegistroInicial = 0
	}
	else{
		// During the search, min <= target index <= max.
		while(min <= max){
			middle = Math.round((min + max) / 2);
			if(middle == 0){
				break;
			}
			RegistroStartIndex = (middle - 1) * (CantidadElementosXDim);

			// Busco los indices de mis padres
			i = 0
			ValorPadreEncontrado = true
			for(i=0;i < CantPadres;i++){
				// Verifico que el indice encontrado sea igual al de mis padres
				TargetValue = arguments[2*i + StdArgs].options[arguments[2*i + StdArgs].selectedIndex].value;

				var AuxTargetValue, AuxActualValue
				AuxTargetValue = TargetValue
				AuxActualValue = strArr[RegistroStartIndex + i];

				if(arguments[2*i + StdArgs + 1] == 'numeric'){
					AuxTargetValue = parseFloat(AuxTargetValue);
					AuxActualValue = parseFloat(AuxActualValue);
				} else {
					AuxTargetValue = AuxTargetValue.toString().toUpperCase();
					AuxActualValue = AuxActualValue.toString().toUpperCase();
        }

				if(AuxTargetValue < AuxActualValue){
					// Search the left half.
					max = middle - 1
					ValorPadreEncontrado = false
					break;
				}else if(AuxTargetValue > AuxActualValue){
					// Search the right half.
					min = middle + 1
					ValorPadreEncontrado = false
					break;
				}
			}
			if(ValorPadreEncontrado){
				// Buscar la primer ocurrencia a izquierda
				var j
				var HasFoundDifferent = false
				for(i=(middle - 1);i >=0 ;i--){
					for(j=0;j < CantPadres;j++){
						if(strArr[RegistroStartIndex + j] != strArr[(i * (CantidadElementosXDim)) + j]){
							RegistroInicial = (i + 1) * (CantidadElementosXDim)
							HasFoundDifferent = true
							break;
						}
					}
					if(HasFoundDifferent){
						break;
					}
				}
				// Si llego hasta el principio del array sin encontrar un valor distinto, entonces debe empezar desde la primera posicion
				if(i == -1){
					RegistroInicial = 0
				}
				break;
			}
		}
	}

	if(RegistroInicial == -1){
		SetNoData(CtrlObj);
		return false;
	}

	var AuxDefArr = DefValue.split(",");
	var defIndex;

	// Cargo el combo en base al array
	for(registro=RegistroInicial;registro < strArr.length-1 ;registro += (CantPadres + 2)){
		// Indice del label
		lbl = registro + CantPadres + 1
		// Indice del codigo
		id = registro + CantPadres

		// Recorro los argumentos pasados, verificando el filtro
		Add = true
		for(i=0;i < CantPadres;i++){
			if(arguments[2*i + StdArgs].selectedIndex > -1){
				if(strArr[registro + i] != arguments[2*i + StdArgs].options[arguments[2*i + StdArgs].selectedIndex].value){
					Add = false
				}
			}else{
				Add = false
			}
			if(!Add){
				break;
			}
		}

		if(Add){
			HasAddedOnce = true
		}else{
			if(HasAddedOnce){
				break;
			}
		}

		// Si corresponde, agrego el item al array
		if(Add){
			HasRecords = true;
			NewOption = new Option(strArr[lbl], strArr[id]);
			AddAttribute(NewOption, 'dbindex', ItemCount);
			CtrlObj.options[ItemCount] = NewOption
			if(GetBrowser().indexOf("NN", 0) == -1){
				aux = 0
				if(HasBGColor){
					CtrlObj.options[ItemCount].style.backgroundColor = strArr[id + 2]
					if(HasFontColor){
						aux = 1
					}
				}
				if(HasFontColor){
					CtrlObj.options[ItemCount].style.color = strArr[id + 2 + aux]
				}
				if(HasBGColor || HasFontColor){
					registro += 1 + aux
				}
			}
			for(defIndex=0;defIndex < AuxDefArr.length;defIndex++){
				if(strArr[id] == AuxDefArr[defIndex]){
					CtrlObj.options[ItemCount].selected = true
					DoClear = false
				}
			}
			ItemCount++
		}
	}
	
	if(!HasRecords){
		SetNoData(CtrlObj);
	}else{
		/*Esto lo saque porque sino se deshabilitaba siempre*/
		//CtrlObj.disabled = false
		/* Lo agregue para que se deshabilite cuando corresponde, y no siempre*/
		CtrlObj.disabled = DoDisable;
		
		if(UseActualValue == undefined){UseActualValue = false;}

		if(DoClear || !UseActualValue){
			CtrlObj.selectedIndex = -1;
		}
		if(!ClearOnNotEmpty && !UseActualValue){
			CtrlObj.selectedIndex = 0;
		}
		
	}
	//document.body.style.cursor = 'auto'

	if(CtrlObj.onchange != null && CantPadres > 0){
		try{
			CtrlObj.onchange();
		}catch (e){
		}
	}
}

function SetNoData(CtrlObj){
	var NewOption
	NewOption = new Option('(N/A)', '')
	CtrlObj.options[0] = NewOption
	CtrlObj.disabled = true
	//document.body.style.cursor = 'auto'
}

function CheckParent(Url){
	if(window.parent.frames.length > 0){
		window.parent.top.location.replace(Url);
	}
}

function CheckAll(ChkAllObj, ArrObj){
	var DoCheck = ChkAllObj.checked;
		
	for(i=0;i < ArrObj.length;i++){
		var ObjCtrl = document.all(ArrObj[i]);
		if(ObjCtrl){
			if(ObjCtrl.checked != DoCheck){
				ObjCtrl.click();
			}
		}
	}
}

function TriggerTinyMCESave() {
	try {
		tinyMCE.triggerSave()
	}
	catch (e) {}
}

function Type_Of(obj) {
	return typeof(obj)
}
