function ValidateForm(form, _return) {
	if (!_return) _return = true;
	form = (!jsGetObject(form)) ? form : jsGetObject(form);
	
	for(i=0; i<form.elements.length; i++) {
		var __obj = form.elements[i];
		if (__obj.type) {
			if(__obj.type != "button" && __obj.type != "submit") {
				validation = __obj.getAttribute("req",2);
				if (!validation) validation = true;
				validationMsg = __obj.getAttribute("msg",2);
				var _elem_type = __obj.type.toLowerCase();
					
				if (__obj.id == "" && __obj.name) {
					alert("El Objeto de tipo \"" + _elem_type + "\" debe tener un Id y un Nombre para identificarlo.");
					return false;
				}
				
				var _validation = __obj.getAttribute("validation",2);
				if (_validation) {
					var _validation_s = _validation.split("|");
					var _validation_function = _validation_s[0];
					_validation_function = _validation_function.replace("this", "'" + __obj.name + "'");
					var _validation_msg = _validation_s;
					
					if (!eval(_validation_function)) {
						alert(_validation_msg);
						if(__obj.type != "hidden") __obj.focus();
						return false;
					}
				}
				
				if (validation && validationMsg) {
					var wv = false;
					var _obj_array = jsGetObject(__obj.id);
					if (_obj_array && _obj_array.length) {
						for(j=0; j<_obj_array.length; j++) {
							if (_elem_type == "radio" || _elem_type == "checkbox") {
								if (_obj_array[j].checked == true) {
									wv = true;
									break;	
								}
							}
						}
					}
					
					_obj_array = document.getElementsByName(__obj.name);
					if (_obj_array.length == 1) {
						switch (_elem_type) {
							case "select-one":
								wv = (__obj.value.toString() == "0") ? false : true;
								break;
							case "radio", "checkbox":
								wv = (__obj.checked == false) ? false : true;
								break;
							default:
								wv = (__obj.value == "") ? false : true;
								break;
						}
					}
					
					if (wv == false) {
						if (validationMsg == "") validationMsg = "Campo Obligatorio.";
						alert(validationMsg);
						if(__obj.type != "hidden") __obj.focus();
						return false;
					}
				}
			}
		}
	}
	
	form.submit();
	
	DisableFormElements(form);
	
	return false;
}


var __last_submit_button_caption;

function DisableFormElements(form) {
	form = (!jsGetObject(form)) ? form : jsGetObject(form);
	
	document.body.style.cursor = "wait";
	jsSetStyle("ProcesingData", "visibility", "visible");
	var __fieldsets = document.getElementsByTagName("fieldset");
	if (__fieldsets.length) {
		for(i=0; i < __fieldsets.length; i++) {
			__fieldsets[i].style.cursor = "wait";
		}
	}
	
	for(i=0; i<form.elements.length; i++) {
		var __obj = form.elements[i];
		if (__obj.type) {
			if (__obj.type == "submit") {
				__last_submit_button_caption = __obj.value;
				__obj.value = "Espere...";
			}
			__obj.disabled = true;
		}
	}
}

function EnableFormElements(form) {
	form = (!jsGetObject(form)) ? form : jsGetObject(form);
	
	document.body.style.cursor = "default";
	jsSetStyle("ProcesingData", "visibility", "hidden");
	var __fieldsets = document.getElementsByTagName("fieldset");
	if (__fieldsets.length) {
		for(i=0; i < __fieldsets.length; i++) {
			__fieldsets[i].style.cursor = "default";
		}
	}
	
	for(i=0; i<form.elements.length; i++) {
		var __obj = form.elements[i];
		if (__obj.type) {
			if (__last_submit_button_caption == "") __last_submit_button_caption = "Guardar";
			if (__obj.type == "submit") __obj.value = __last_submit_button_caption;
			__obj.disabled = false;
		}
	}
}

function isEmail(obj) {
	obj = (!jsGetObject(obj)) ? obj : jsGetObject(obj);
	if (obj) {
		var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
		if (filter.test(obj.value)) {
			return true;
		} else {
			return false;
		}
	} else {
		return false;	
	}
}

function KeyAscii(e) {
	return (document.all) ? e.keyCode : e.which;
}

function openWin(eURL,eName,features) {
	window.open(eURL,eName,features);
}

function openCenterWin(eURL,eName,eFeatures,eWidth,eHeight) {
	var _features = "";
	_features = (eFeatures == "") ? "resizable=no,status=no,scrollbars=no" : eFeatures;
	_features += ",width="+eWidth+",height="+eHeight+",left="+((screen.width/2)-(eWidth/2))+",top="+((screen.height/2)-(eHeight/2));
	openWin(eURL,eName,_features);
}


function _CloseOnEsc(e) {
	if (KeyAscii(event) == 27) { window.close(); return; }
}

function InitESC() {
	document.body.onkeypress = _CloseOnEsc;
}

function ToggleDisplay(obj) {
	obj = (!jsGetObject(obj)) ? obj : jsGetObject(obj);
	if (obj) jsSetStyle2(obj, "display", (jsGetStyle2(obj, "display") == "none") ? "block" : "none")
}


/*------------------------------------------------------------------------------------------------------------\
	Date Created: 12-30-05
	Modified Date: 12-30-05
	Function Name: ClearHTML(sHTML)
	Porpouse: Limpia el código HTML.
		sHTML: HTML Tags a limpiar.
/-------------------------------------------------------------------------------------------------------------*/
function ClearHTML(sHTML) {
	sHTML = CleanWord(sHTML);
	sHTML = sHTML.replace(/<[^>]*>/gi, "");
	sHTML = sHTML.replace( /\n/gi, "") ;
	sHTML = sHTML.replace(/&nbsp;/gi, "");
	var RegX = new RegExp(String.fromCharCode(10), 'g');
	sHTML = sHTML.replace(RegX, "");
	RegX = new RegExp(String.fromCharCode(13), 'g');
	sHTML = sHTML.replace(RegX, "");
	return sHTML;
}


/*------------------------------------------------------------------------------------------------------------\
	Date Created: 12-30-05
	Modified Date: 12-30-05
	Function Name: CleanWord(html)
	Porpouse: Limpia el código HTML generado por Microsoft Word.
		html: HTML Tags a limpiar.
/-------------------------------------------------------------------------------------------------------------*/
function CleanWord(html) {
	html = html.replace(/<o:p>\s*<\/o:p>/g, "") ;
	html = html.replace(/<o:p>.*?<\/o:p>/g, "&nbsp;") ;
	
	// Remove mso-xxx styles.
	html = html.replace( /\s*mso-[^:]+:[^;"]+;?/gi, "" ) ;

	// Remove margin styles.
	html = html.replace( /\s*MARGIN: 0cm 0cm 0pt\s*;/gi, "" ) ;
	html = html.replace( /\s*MARGIN: 0cm 0cm 0pt\s*"/gi, "\"" ) ;

	html = html.replace( /\s*TEXT-INDENT: 0cm\s*;/gi, "" ) ;
	html = html.replace( /\s*TEXT-INDENT: 0cm\s*"/gi, "\"" ) ;

	html = html.replace( /\s*TEXT-ALIGN: [^\s;]+;?"/gi, "\"" ) ;

	html = html.replace( /\s*PAGE-BREAK-BEFORE: [^\s;]+;?"/gi, "\"" ) ;

	html = html.replace( /\s*FONT-VARIANT: [^\s;]+;?"/gi, "\"" ) ;

	html = html.replace( /\s*tab-stops:[^;"]*;?/gi, "" ) ;
	html = html.replace( /\s*tab-stops:[^"]*/gi, "" ) ;

	// Remove FONT face attributes.
	html = html.replace( /\s*face="[^"]*"/gi, "" ) ;
	html = html.replace( /\s*face=[^ >]*/gi, "" ) ;

	html = html.replace( /\s*FONT-FAMILY:[^;"]*;?/gi, "" ) ;
	
	// Remove Class attributes
	html = html.replace(/<(\w[^>]*) class=([^ |>]*)([^>]*)/gi, "<$1$3") ;

	// Remove styles.
	html = html.replace( /<(\w[^>]*) style="([^\"]*)"([^>]*)/gi, "<$1$3" ) ;

	// Remove empty styles.
	html =  html.replace( /\s*style="\s*"/gi, '' ) ;
	
	html = html.replace( /<SPAN\s*[^>]*>\s*&nbsp;\s*<\/SPAN>/gi, '&nbsp;' ) ;
	
	html = html.replace( /<SPAN\s*[^>]*><\/SPAN>/gi, '' ) ;
	
	// Remove Lang attributes
	html = html.replace(/<(\w[^>]*) lang=([^ |>]*)([^>]*)/gi, "<$1$3") ;
	
	html = html.replace( /<SPAN\s*>(.*?)<\/SPAN>/gi, '$1' ) ;
	
	html = html.replace( /<FONT\s*>(.*?)<\/FONT>/gi, '$1' ) ;

	// Remove XML elements and declarations
	html = html.replace(/<\\?\?xml[^>]*>/gi, "") ;
	
	// Remove Tags with XML namespace declarations: <o:p></o:p>
	html = html.replace(/<\/?\w+:[^>]*>/gi, "") ;
	
	html = html.replace( /<H\d>\s*<\/H\d>/gi, '' ) ;

	html = html.replace( /<H1([^>]*)>/gi, '<div$1><b><font size="6">' ) ;
	html = html.replace( /<H2([^>]*)>/gi, '<div$1><b><font size="5">' ) ;
	html = html.replace( /<H3([^>]*)>/gi, '<div$1><b><font size="4">' ) ;
	html = html.replace( /<H4([^>]*)>/gi, '<div$1><b><font size="3">' ) ;
	html = html.replace( /<H5([^>]*)>/gi, '<div$1><b><font size="2">' ) ;
	html = html.replace( /<H6([^>]*)>/gi, '<div$1><b><font size="1">' ) ;

	html = html.replace( /<\/H\d>/gi, '</font></b></div>' ) ;
	
	html = html.replace( /<(U|I|STRIKE)>&nbsp;<\/\1>/g, '&nbsp;' ) ;

	// Remove empty tags (three times, just to be sure).
	html = html.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
	html = html.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;
	html = html.replace( /<([^\s>]+)[^>]*>\s*<\/\1>/g, '' ) ;

	// Transform <P> to <DIV>
	var re = new RegExp("(<P)([^>]*>.*?)(<\/P>)","gi") ;	// Different because of a IE 5.0 error
	html = html.replace( re, "<div$2</div>" ) ;

	return html ;
}


function InputType(e, flag, _teclas) {
	var patron;
	var tecla = KeyAscii(e);
	var extrakey = -1;
	if (_teclas != "" && _teclas) {
		_teclas = _teclas.toString();
		extrakey = _teclas.indexOf(tecla.toString());
	}
	
	if (tecla == 8 || tecla == 13 || extrakey >= 0) return true; 
	//Tecla de retroceso (para poder borrar) y enter (para poder enviar)
	
	switch (flag) {
		case 0:
			patron = /[A-Za-z]/; //Solo acepta letras
			break;
		case 1:
			patron = /\D/; //No acepta números
			break;
		case 2:
			patron = /\w/; //Acepta números y letras
			break;
		default:
			patron = /\d/; //Solo acepta números
			break;
	}
	
	var key = String.fromCharCode(tecla);
	return patron.test(key);
}


function InputCheck(obj, flag) {
	obj = (!jsGetObject(obj)) ? obj : jsGetObject(obj);
	var patron;
	
	switch (flag) {
		case 0:
			patron = /[A-Za-z]/; //Solo acepta letras
			break;
		case 1:
			patron = /\D/; //No acepta números
			break;
		case 2:
			patron = /\w/g; //Acepta números y letras
			break;
		default:
			patron = /\d/; //Solo acepta números
			break;
	}
	
	return (obj.value != "") ? patron.test(obj.value) : true;
}


function ClearSelect(obj) {
	obj = (!jsGetObject(obj)) ? obj : jsGetObject(obj);
	obj.options.length = 0;	
}

function AddSelectOption(obj, txt, val, selected) {
	obj = (!jsGetObject(obj)) ? obj : jsGetObject(obj);
	
	selected = (selected == true) ? "defauldSelected" : "";
	var sub0 = new Option(txt, val, selected);
	obj.options[obj.options.length] = sub0;
}


function Log_Out() {
	ht = document.getElementsByTagName("body");
	ht[0].style.filter = "progid:DXImageTransform.Microsoft.BasicImage(grayscale=1)";
	if (confirm('¿Desea Cerrar su Sesión?')) {
		return true;
	} else {
		ht[0].style.filter = "";
		return false;
	}
}

/*------------------------------------------------------------------------------------------------------------\
	Date Created: 12-31-05
	Modified Date: 12-31-05
	Function Name: jsSetAttribute(obj, _name, _value)
	Porpouse: Asigna un atributo a un objeto o elemento.
		obj: Id del Objeto.
		_name: Nombre del atributo.
		_value: Valor del atributo.
/-------------------------------------------------------------------------------------------------------------*/
function jsSetAttribute(obj, _name, _value) {
	obj = (!jsGetObject(obj)) ? obj : jsGetObject(obj);
	obj.setAttribute(_name, _value);
}


function CargarSelect(obj1, obj2, parent_field, tabla, _default_txt) {
	if (obj1) {
		if (!_default_txt) _default_txt = "Seleccione";
		var obj_values = jsGetObject("txtcargar_select_elements");
		obj2 = jsGetObject(obj2);
		obj_values.value = "";
		
		var cargar = new SetAjax();
		cargar.FilePath = __strMainDir + "includes/procesos/cargar_select.php";
		cargar.setVar = [["tabla", tabla], ["parentid", obj1.value], ["parent_field", parent_field]];
		cargar.Element = obj_values;
		cargar.ElementAttribute = "value";
		cargar.onLoading = function() {
			document.body.style.cursor = "wait";
			obj1.disabled = true;
			obj2.disabled = true;
			ClearSelect(obj2);
			AddSelectOption(obj2, "Cargando...", "0");
		}
		cargar.onCompletion = function() {
			document.body.style.cursor = "default";
			obj1.disabled = false;
			ClearSelect(obj2);
			AddSelectOption(obj2, _default_txt, "0");
			
			var split1 = obj_values.value.split("[|]");
			for(i=0; i < split1.length; i++) {
				if (split1[i].length > 0) {
					var split2 = split1[i].split("[-]");
					AddSelectOption(obj2, split2[1], split2[0]);
				}
			}
			
			obj2.disabled = false;
		}
		cargar.Execute();
	}
}


document.write('<input type="hidden" name="txtcargar_select_elements" id="txtcargar_select_elements">');


function FixPNG(myImage)  {
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion);
	
    if ((version >= 5.5) && (version < 7) && (document.body.filters)) {
       var imgID = (myImage.id) ? "id='" + myImage.id + "' " : "";
	   var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : "";
	   var imgTitle = (myImage.title) ? "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' ";
	   var imgStyle = "display:inline-block;" + myImage.style.cssText;
	   var strNewHTML = "<span " + imgID + imgClass + imgTitle
                  + " style=\"" + "width:" + myImage.width 
                  + "px; height:" + myImage.height 
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>";
	   myImage.outerHTML = strNewHTML;
    }
}


function SetBgPNG(img_path) {
	var arVersion = navigator.appVersion.split("MSIE");
	var version = parseFloat(arVersion);
	var _style;
	if (_jslib_isIE && version >= 5.5 && version < 7) {
		_style = "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled=true, sizingMethod=scale src='" + img_path + "')";
	} else {
		_style = "background-image:url('" + img_path + "')";
	}
	
	return _style;
}

function DisplayPicture(src, w, h, _id) {
	var imgtags;
	_id = (!_id) ? "" : 'id="' + _id + '"';
	if (_jslib_isIE) {
		imgtags = "<div " + _id + " style=\"width:" + w + "px; height:" + h 
		+ "px; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src 
		+ "', sizingMethod='scale');\"></div>";
	} else {
		imgtags = '<img ' + _id + ' src="' + src + '" border="0" style="width:' + w + 'px; height:' + h + 'px;">';
	}
	
	return imgtags;
}


function ClickButton(page) {
	jsSetStyle("Msg", "display", "block");
	jsSetStyle("MasterContent", "visibility", "hidden");
	document.body.style.cursor = "wait";
	var IFrame = jsGetObject("MasterContent");
	if (IFrame) IFrame.src = __strMainDir + page;
}


function OnMouseOver(div, obj) {
	if (div != "") {
		T = 200;
		if (obj) {
			L = findPosX(obj);
			T = findPosY(obj);
			T = (_jslib_isIE) ? (T+27) : (T+25);
			jsSetStyle("Opc_" + div, "left", L);
			jsSetStyle("Opc_" + div, "top", T);
			obj.className = "MenuButtonOver";
		}
		jsSetStyle("Opc_" + div, "display", "block");
		DivSetVisible("Opc_" + div);
	}
}


function OnMouseOut(div, obj) {
	if (div != "") jsSetStyle("Opc_" + div, "display", "none");
	if (jsGetObject("DivShim")) jsSetStyle("DivShim", "display", "none");
	if (obj) obj.className = "MenuButtonOut";
}

function DivSetVisible(DivRef) {
	DivRef = (!jsGetObject(DivRef)) ? DivRef : jsGetObject(DivRef);
	var IfrRef = jsGetObject("DivShim");
	
	if (DivRef && IfrRef) {
		DivRef.style.display = "block";
		IfrRef.style.width = DivRef.offsetWidth;
		IfrRef.style.height = DivRef.offsetHeight;
		IfrRef.style.top = DivRef.style.top;
		IfrRef.style.left = DivRef.style.left;
		IfrRef.style.zIndex = DivRef.style.zIndex - 1;
		IfrRef.style.display = "block";
	}
}


function findPosX(obj) {
	obj = (!jsGetObject(obj)) ? obj : jsGetObject(obj);
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj) {
	obj = (!jsGetObject(obj)) ? obj : jsGetObject(obj);
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}
	else if (obj.y)
		curtop += obj.y;
	return (!_jslib_isSafari) ? curtop : (curtop + 30);
}



var aFinMes = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); 

function finMes(nMes, nAno){ 
	return aFinMes[nMes - 1] + (((nMes == 2) && (nAno % 4) == 0)? 1: 0); 
} 

function padNmb(nStr, nLen, sChr){ 
	var sRes = String(nStr); 
	for (var i = 0; i < nLen - String(nStr).length; i++) 
		sRes = sChr + sRes; 
	return sRes; 
} 

function makeDateFormat(nDay, nMonth, nYear){ 
	var sRes; 
	sRes = padNmb(nDay, 2, "0") + "/" + padNmb(nMonth, 2, "0") + "/" + padNmb(nYear, 4, "0"); 
	return sRes; 
} 

function incDate(sFec0){ 
	var nDia = parseInt(sFec0.substr(0, 2), 10); 
	var nMes = parseInt(sFec0.substr(3, 2), 10); 
	var nAno = parseInt(sFec0.substr(6, 4), 10); 
	nDia += 1; 
	if (nDia > finMes(nMes, nAno)){ 
		nDia = 1; 
		nMes += 1; 
		if (nMes == 13){ 
			nMes = 1; 
			nAno += 1; 
		}
	} 
	return makeDateFormat(nDia, nMes, nAno); 
} 

function decDate(sFec0){ 
	var nDia = Number(sFec0.substr(0, 2)); 
	var nMes = Number(sFec0.substr(3, 2)); 
	var nAno = Number(sFec0.substr(6, 4)); 
	nDia -= 1; 
	if (nDia == 0){ 
		nMes -= 1; 
		if (nMes == 0){ 
			nMes = 12; 
			nAno -= 1; 
		} 
		nDia = finMes(nMes, nAno); 
	} 
	return makeDateFormat(nDia, nMes, nAno); 
} 

function addToDate(sFec0, sInc){ 
	var nInc = Math.abs(parseInt(sInc)); 
	var sRes = sFec0; 
	if (parseInt(sInc) >= 0) 
		for (var i = 0; i < nInc; i++) sRes = incDate(sRes); 
	else 
		for (var i = 0; i < nInc; i++) sRes = decDate(sRes); 
	
	var nDia = sRes.substr(0, 2); 
	var nMes = sRes.substr(3, 2); 
	var nAno = sRes.substr(6, 4);
	
	return nMes + "/" + nDia + "/" + nAno; 
}


function ShowButton(strId, strCaption, strOnClick, strW, strHints) {
	strW = (!strW) ? 100 + 'px' : strW;
	strW = ' style="width:' + strW + '";';
	var btags = '<input type="button" id="' + strId + '" name="' + strId + '" value="' + strCaption + '" onclick="' + 
	strOnClick + '" class="BotonesMsgs" ' + strHints + strW + '>';
	return btags;
}

function ShowTableMsg(strMsg, strButton) {
	var t = ''
	t += '<table border="0" cellspacing="2" cellpadding="2" class="TablaSimple">';
	t += '<tr>';
	t += '<td align="center">' + strMsg + '</td>';
	t += '</tr>';
	if (strButton != "") {
		t += '<tr>';
		t += '<td align="center">' + strButton + '</td>';
		t += '</tr>';
	}
	t += '</table>';
	
	return t;
}


function ReplaceChars(sHTML, CharCode, sString) {
	var RegX = new RegExp(String.fromCharCode(CharCode), 'g');
	sHTML = sHTML.replace(RegX, sString);
	
	return sHTML;
}


function ReplaceEnters(sHTML, sString) {
	var RegX = new RegExp(String.fromCharCode(10), 'g');
	sHTML = sHTML.replace(RegX, sString);
	var RegX = new RegExp(String.fromCharCode(13), 'g');
	sHTML = sHTML.replace(RegX, sString);
	
	return sHTML;
}


function DelRow(row, msg, start_row, fila1_class, fila2_class) {
	msg = (!msg) ? "" : msg;
	var tmp = (msg != "") ? confirm(msg) : true;
	
	var tmp_val = row.nodeName.toLowerCase();
	while(tmp_val != "tr") {
		row = jsGetParent(row);
		tmp_val = row.nodeName.toLowerCase();
	}
	
	if (tmp == true) {
		obj = jsGetParent(jsGetParent(row));
		if (obj && row) obj.deleteRow(row.rowIndex);
		if (obj) UpdateTable(obj, start_row, fila1_class, fila2_class);
	}
}

function DeleteData(obj, elemid, tabla, _msg, _shift, start_row, fila1_class, fila2_class) {
	if (obj) {
		_msg = (!_msg) ? true : confirm(_msg);
		_shift = (!_shift) ? 0 : _shift;
		
		if (_msg) {
			var del = new SetAjax();
			del.FilePath = __strMainDir + "includes/procesos/eliminar_registro.php";
			del.setVar = [["tabla", tabla], ["elemid", elemid], ["shift", _shift]];
			del.onLoading = function() {
				document.body.style.cursor = "wait";
				jsSetStyle("ProcesingData", "visibility", "visible");
			}
			del.onCompletion = function() {
				document.body.style.cursor = "default";
				jsSetStyle("ProcesingData", "visibility", "hidden");
				DelRow(obj, "", start_row, fila1_class, fila2_class);
			}
			del.Execute();
		}
	}
	
	return false;
}


function UpdateTable(obj, start_row, fila1_class, fila2_class) {
	obj = (!jsGetObject(obj)) ? obj : jsGetObject(obj);
	
	var tmp = obj.nodeName.toLowerCase();
	while(tmp != "table") {
		obj = jsGetParent(obj);
		tmp = obj.nodeName.toLowerCase();
	}
	
	start_row = (!start_row) ? 1 : start_row;
	fila1_class = (!fila1_class) ? "Fila1" : fila1_class;
	fila2_class = (!fila2_class) ? "Fila2" : fila2_class;
	
	var flag = 1;
	for(i=start_row; i < obj.rows.length; i++) {
		if (flag == 1) {
			obj.rows[i].className = fila1_class;
			flag--;
		} else {
			obj.rows[i].className = fila2_class;
			flag++;
		}
	}
}

function IncreaseFont(obj, _default, _from, _to) {
	obj = (!jsGetObject(obj)) ? obj : jsGetObject(obj);
	if (!_default) _default = 12;
	if (!_from) _from = 10;
	if (!_to) _to = 16;
	
	var _current = jsGetStyle2(obj, "fontSize").replace("px", "");
	if (_current == "") _current = _default;
	if (_current > _to) _current = _from;
		
	jsSetStyle2(obj, "fontSize", String((parseInt(_current)+1)) + "px");
}

function FileExtension(__file) {
	__file = __file.toString();
	return __file.substr(__file.lastIndexOf('.')+1).toLowerCase();
}


function ValidarEncuesta(id,obj,msg) {
	var _checked = false;
	var _radio_value = 0;
	
	obj = document.getElementsByName(obj);
	if (!msg) msg = "Debe seleccionar una opción del sondeo.";
	
	if (obj) {
		for(i=0; i < obj.length; i++) {
			if (obj[i].checked == true) {
				_checked = true;
				_radio_value = obj[i].value;
				break;
			}
		}
		
		if (_checked == false) {
			alert(msg);
			return false;
		}
		
		var EncButton = jsGetObject("b_votar" + id);
		if (EncButton) EncButton.disabled = true;
		
		var Enc = new SetAjax();
		Enc.FilePath = __strMainDir + "includes/procesos/encuesta.php";
		Enc.Element = jsGetObject("TablEnc" + id);
		Enc.ElementPlainText = false;
		Enc.setVar = [["encuesta", id], ["opcion", _radio_value]];
		Enc.onLoading = function() {
			document.body.style.cursor = "wait";
		}
		Enc.onCompletion = function() {
			document.body.style.cursor = "default";
			alert("Gracias por Su Voto.");
		}
		Enc.Execute();
	}
}


function MaxResumen(obj, target, total) {
	obj = (!jsGetObject(obj)) ? obj : jsGetObject(obj);
	var label = (!jsGetObject(target)) ? target : jsGetObject(target);
	if (label && obj) {
		if (obj.value.length <= total) {
			label.innerHTML = total - obj.value.length;
		} else {
			if (obj.value.length <= total) {
				label.innerHTML = obj.value.length++;
			} else {
				obj.value = obj.value.substring(0, total);
				label.innerHTML = total-obj.value.length;
			}
		}
	}
}


function MM_jumpMenu(targ,selObj,restore) {
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


function zoom(nombre) {
	window.open(__strMainDir + "zoom.php?n=" + nombre,"_blank","width=600,height=550,resizable=yes,scrollbars=yes,toolbar=no,status=no");
}

function jsShowErrors(_func_name, _err) {
	var desc = (jsIsString(_err)) ? _err : _err.description;
	alert(_func_name + ": " + desc);
	return false;
}
function abrirSubCat(id,img){
	if(document.getElementById(id)){
		if(document.getElementById(id).style.display=="block"){
			document.getElementById(id).style.display="none";
			document.getElementById(img).src='images/pancanal_image_2.jpg';
		}else{
			document.getElementById(id).style.display="block"
			document.getElementById(img).src='images/pancanal_image_1.jpg';
		}
	}
}

function SearchBox(val){
	var tipo = (val == '1') ? 'propiedades.php' : 'proyectos.php';
	if(val==1){
		document.getElementById('d1').style.display="block";
		document.getElementById('d2').style.display="none";
		document.getElementById('search_propiedades').value = 1;
	}else{
		document.getElementById('d2').style.display="block";
		document.getElementById('d1').style.display="none";
		document.getElementById('search_proyectos').value = 2;
	}
	
}
var SearchBoxObj = null;
var IframeSearch = null;

function advanced_search() {	
		var tipo = document.getElementById('tipo');
		var categorias = document.getElementById('categorias');
		var banos = document.getElementById('banos');
		var camas = document.getElementById('camas');
		var distrito = document.getElementById('distrito');
		var provincia = document.getElementById('provincia');
		var nombrex = document.getElementById('nombrex');
		
		//alert(tipo.value);
		if (tipo.value != '2') {
			if(document.getElementById('d1').style.display=="block"){
				// BUSQUEDA POR PROPIEDAD
				//var pmenor = document.getElementsByName('pmenor')[1].value;
				//var pmayor = document.getElementsByName('pmayor')[1].value;
				var pmenor = document.getElementById('pmenor').value;
				var pmayor = document.getElementById('pmayor').value;
			}else{
				// BUSQUEDA POR PROYECTO
				var pmenor = document.getElementsByName('pmenor')[0].value;
				var pmayor = document.getElementsByName('pmayor')[0].value;
				//var pmenor = document.getElementById('pmenor').value;
				//var pmayor = document.getElementById('pmayor').value;
			}	
		} else {
			var pmenor = jsGetObject('pmenor2').value;
			var pmayor = jsGetObject('pmayor2').value;
			
		}	
		//alert(pmenor + ' ' + pmayor);
		var categorias_proyecto = document.getElementById('categorias_proyecto');
		var banos_proyecto = document.getElementById('banos_proyecto');
		var camas_proyecto = document.getElementById('camas_proyecto');
		var distrito_proyecto = document.getElementById('distrito_proyecto');
		var provincia_proyecto = document.getElementById('provincia_proyecto');
		var nombrex_proyecto = document.getElementById('nombrex_proyecto');
		
		if (document.getElementById('d1').style.display=="block") {
			var id = document.getElementsByName('referencia')[1];
			var area_const1 = document.getElementsByName('txtarea_const1')[1];
			var area_const2 = document.getElementsByName('txtarea_const2')[1];
			var area_const_medida = document.getElementsByName('area_const_medida')[1];
			document.location.href = "properties2.php?elemid=" + id.value + "&tipo=" + 
			tipo.value + "&categorias=" + categorias.value + "&banos=" +  banos.value + "&camas=" +  
			camas.value + "&distrito=" + distrito.value + "&provincia=" + provincia.value + "&pmenor=" + 
			pmenor + "&pmayor=" + pmayor + "&area_const1=" + area_const1.value + "&area_const2=" + 
			area_const2.value + "&area_const_medida=" + area_const_medida.value + "&nombrex=" + nombrex.value;
		} else {
			var id = document.getElementsByName('referencia')[0];
			var area_const1 = document.getElementsByName('txtarea_const1')[0];
			var area_const2 = document.getElementsByName('txtarea_const2')[0];
			var area_const_medida = document.getElementsByName('area_const_medida')[0];
			document.location.href = "projects.php?elemid=" + id.value + "&pmenor=" + 
			pmenor + "&pmayor=" + pmayor  + "&categorias=" +  categorias_proyecto.value + 
			"&distrito=" + distrito_proyecto.value + "&provincia=" + provincia_proyecto.value + "&banos=" +  
			banos_proyecto.value + "&camas=" +  camas_proyecto.value + "&area_const1=" + 
			area_const1.value + "&area_const2=" + area_const2.value + "&area_const_medida=" + area_const_medida.value + "&nombrex=" + nombrex_proyecto.value;
		}
		return false;
	}

function search_all(txt){
	if(txt!=""){
		document.location.href = "search_all.php?txt="+txt;
	}	
}

function ancora(oa){
	document.body.scrollTop=findPosY(oa);
}

function findPosY(obj) {
	obj = (!jsGetObject(obj)) ? obj : jsGetObject(obj);
	var iTop = 0;
    while(obj.tagName != "BODY") {
       	iTop += obj.offsetTop;
    	obj = obj.offsetParent;
 	}
	return iTop;
}

function findPosX(obj) {
	obj = (!jsGetObject(obj)) ? obj : jsGetObject(obj);
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}
	else if (obj.x)
	curleft += obj.x;
	return curleft;
}
	function ShowHideBox(show) {
		btrans = new BlendTransition();
		btrans.ObjId = SearchBoxObj;
		var obj = document.getElementsByName("search_in");
		obj.value = 0;
		
		if (show) {
			SearchBoxObj.style.display = "block";
			if (_jslib_isIE) IframeSearch.style.display = "block";
			btrans.opacStart = 1;
			btrans.opacEnd = 100;
		} else {
			btrans.opacStart = 100;
			btrans.opacEnd = 0;
		}
		
		btrans.milliSec = 300;
		btrans.onCompletion = function() {
			SearchBoxObj.style.display = "none";
			SearchBoxObj.innerHTML = '';
			if (_jslib_isIE) IframeSearch.style.display = "none";
		}
		btrans.opacity();
		delete btrans;
	}
	
	function CambiarPrecios(val) {
		if (val != '2') {
			jsGetObject('Precio1').style.display = 'block';
			jsGetObject('Precio2').style.display = 'none';
		} else {
			jsGetObject('Precio1').style.display = 'none';
			jsGetObject('Precio2').style.display = 'block';
		}
	}
function ent(e,txt){
	if(Key(e)==13){
		search_all(txt);
	}
}
function Key(e){    
	if(navigator.appName.indexOf("Netscape")!= -1){
	        return e.which;
	}else{
	        return e.keyCode;    
	}
}

function htmlEntities(texto){
    var i,carac,letra,novo='';
    for(i=0;i<texto.length;i++){
        carac = texto.charCodeAt(i);
        if( (carac > 47 && carac < 58) || (carac > 62 && carac < 127) ){
            novo += texto.charAt(i);
        }else{
            novo += "&#" + carac + ";";
        }
    }
    return novo;
}

function html_entity_decode(str) {
  var ta=document.createElement("textarea");
  ta.innerHTML=str.replace(/</g,"&lt;").replace(/>/g,"&gt;");
  return ta.value;
}
