function ValidateForm2(form) {
	try {
		form = (!jsGetObject(form)) ? form : jsGetObject(form);
		
		var Icon = form.getAttribute("icon",2);
		if (!Icon) Icon = "alert.png";
		var onBeforeSubmit = form.getAttribute("onbeforesubmit",2);
		var onAfterSubmit = form.getAttribute("onaftersubmit",2);
		var returnSubmit = form.getAttribute("returnsubmit",2);
		if (!returnSubmit) returnSubmit = true;
		var ModalMsg = form.getAttribute("modalwindow",2);
		if (!ModalMsg) ModalMsg = true;
		ModalMsg = (jsIsString(ModalMsg) == true) ? (ModalMsg == "true") ? true : false : ModalMsg;
		
		if (onBeforeSubmit) {
			try {
				if (onBeforeSubmit.indexOf('(') < 0) {
					onBeforeSubmit += "(form);"
				}
				
				if (eval(onBeforeSubmit) == false) {
					return false;	
				}
			} catch(err) {
				jsShowErrors("ValidateForm:onBeforeSubmit", err);
			}
		}
		
		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;
					validation = (jsIsString(validation) == true) ? (validation == "true") ? true : false : validation;
					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[1];
						
						try {
							if (!eval(_validation_function)) {
								if (ModalMsg == false) {							
									alert(_validation_msg);
									if(__obj.type != "hidden" && jsGetStyle(__obj, 'display') != 'none' && 
									jsGetStyle(__obj, 'visibility') != 'hidden') {
										__obj.focus();
									}
								} else {
									parent.AlertWinMsg(_validation_msg, "error.png", 0, __obj, "error");
								}
								return false;
							}
						} catch(err) {
							jsShowErrors("ValidateForm:validation", err);
						}
					}
					
					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.";
							if (ModalMsg == false) {							
								alert(validationMsg);
								if(__obj.type != "hidden" && jsGetStyle(__obj, 'display') != 'none' && 
								jsGetStyle(__obj, 'visibility') != 'hidden') {
									__obj.focus();
								}
							} else {
								parent.AlertWinMsg(validationMsg, Icon, 0, __obj);
							}
							return false;
						}
					}
				}
			}
		}
		
		if (onAfterSubmit) {
			try {
				if (onAfterSubmit.indexOf('(') < 0) {
					onAfterSubmit += "(form);"
				}
				
				if (eval(onAfterSubmit) == false) {
					return false;	
				}
				//return eval(onAfterSubmit);
			} catch(err) {
				jsShowErrors("ValidateForm:onAfterSubmit", err);
			}
		}
		
		if (returnSubmit == true) {
			form.submit();
		}
		
		DisableFormElements(form);
		
		return false;	
	} catch(err) {
		jsShowErrors("ValidateForm", err);
	}
}


var __last_submit_button_caption;

function DisableFormElements(form) {
	try {
		form = (!jsGetObject(form)) ? form : jsGetObject(form);
		
		document.body.style.cursor = "wait";
		jsSetStyle("ProcesingData", "display", "block");
		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;
			}
		}
	} catch(err) {
		jsShowErrors("DisableFormElements", err);
	}
}

function EnableFormElements(form) {
	try {
		form = (!jsGetObject(form)) ? form : jsGetObject(form);
		
		document.body.style.cursor = "default";
		jsSetStyle("ProcesingData", "display", "none");
		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;
			}
		}
	} catch(err) {
		jsShowErrors("EnableFormElements", err);
	}
}

function DelRow2(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) UpdateTable2(obj, start_row, fila1_class, fila2_class);
	}
}

function DeleteData2(opt) {
	var obj = opt.obj || null;
	var elemid = opt.elemid || 0;
	var tabla = opt.tabla || '';
	var archivo = opt.archivo || '';
	var _msg = opt.msg || null;
	var _shift = opt.shift || 0;
	var start_row = opt.start_row || null;
	var fila1_class = opt.fila1_class || null;
	var fila2_class = opt.fila2_class || null;
	
	try {
		var MyFrameObj = (_jslib_isSafari) ? window.frames["IM_Iframe"] : window.frames[0];
		if (MyFrameObj) {
			if (jsIsString(obj)) obj = MyFrameObj.document.getElementById(obj);
			var ProcesingData = MyFrameObj.document.getElementById("ProcesingData");
			var PapeleraTotal = MyFrameObj.document.getElementById("papelera_total");
			var ButtonPapelera = MyFrameObj.document.getElementById("ButtonPapelera");
		} else {
			if (jsIsString(obj)) obj = jsGetObject(obj);
			var ProcesingData = jsGetObject("ProcesingData");
			var PapeleraTotal = jsGetObject("papelera_total");
			var ButtonPapelera = jsGetObject("ButtonPapelera");
		}
		
		if (obj) {
			_msg = (!_msg) ? true : confirm(_msg);
			_shift = (!_shift) ? 0 : _shift;
			
			if (_msg) {
				var del = new SetAjax();
				del.FilePath = __strMainDir + "includes/procesos/" + archivo;
				del.setVar = [["tabla", tabla], ["elemid", elemid], ["shift", _shift]];
				del.onLoading = function() {
					document.body.style.cursor = "wait";
					ProcesingData.style.display = "block";
				}
				del.onCompletion = function() {
					if (PapeleraTotal) {
						var total = parseInt(PapeleraTotal.value);
						if (_shift == 0) {
							total++;
						} else {
							total--;
						}
						if (total < 0) total = 0;
						PapeleraTotal.value = total;
						if (ButtonPapelera) {
							var icon_tag = ButtonPapelera.rows[0].cells[0].innerHTML;
							if (total > 0) {
								var plural = (total == 1) ? "registro" : "registros";
								ButtonPapelera.title = "La Papelera contiene " + total + " " + plural;
								icon_tag = icon_tag.replace("empty", "full");
							} else {
								ButtonPapelera.title = "La Papelera está vacía";
								icon_tag = icon_tag.replace("full", "empty");
							}
							
							ButtonPapelera.rows[0].cells[0].innerHTML = icon_tag;
						}
					}
					
					if (_shift == 1 || _shift == 0) {
						PlaySound("recycle");
					} else {
						PlaySound("restore");
					}
					
					document.body.style.cursor = "default";
					ProcesingData.style.display = "none";
					DelRow2(obj, "", start_row, fila1_class, fila2_class);
				}
				del.Execute();
				delete del;
			}
		}
		
		return false;
	} catch(err) {
		jsShowErrors("DeleteData2", err);
	}
}

function UpdateTable2(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) ? "AdminGridFila" : fila1_class;
	fila2_class = (!fila2_class) ? "AdminGridFila" : 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 OnClick(page){
	//tipo = (tipo == "" || tipo == null) ? 1 : tipo;
	if(page){
			document.location.href = __strMainDir + page;
	}
}

function menuOver(id) {
	var img1 = jsGetObject('img_td'+id+'_1');
	if (img1) img1.src = __strMainDir + 'images/menu_l_02.png';
	var img2 = jsGetObject('img_td'+id+'_2');
	if (img2) img2.style.backgroundImage = 'url('+__strMainDir+'images/menu_c_02.png)';
	var img3 = jsGetObject('img_td'+id+'_3');
	if (img3) img3.src = __strMainDir + 'images/menu_r_02.png';
	var txt3 = jsGetObject('txt_td'+id);
	if (txt3) txt3.style.color = '#6C6B6B';
}

function menuOut(id) {
	var img1 = jsGetObject('img_td'+id+'_1');
	if (img1) img1.src = __strMainDir + 'images/blank.gif';
	var img2 = jsGetObject('img_td'+id+'_2');
	if (img2) img2.style.backgroundImage = 'none';
	var img3 = jsGetObject('img_td'+id+'_3');
	if (img3) img3.src = __strMainDir + 'images/blank.gif';
	var txt3 = jsGetObject('txt_td'+id);
	if (txt3) txt3.style.color = '#6C6B6B';
}

function isInteger (s)
{
var i;

if (isEmpty(s))
if (isInteger.arguments.length == 1) return 0;
else return (isInteger.arguments[1] == true);

for (i = 0; i < s.length; i++)
{
var c = s.charAt(i);

if (!isDigit(c)) return false;
}

return true;
}

function isEmpty(s)
{
return ((s == null) || (s.length == 0))
}

function isDigit (c)
{
return ((c >= "0") && (c <= "9"))
} 

function MailingList(_titulo,_idioma) {
	Sexy.prompt('Ingrese su correo electrónico.','' , {
	  onComplete:
		function(returnvalue) {
		  if (returnvalue) {
			//alert(returnvalue);
			if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(returnvalue)){
				
				var mailing = new SetAjax();
				mailing.FilePath =__strMainDir + "includes/procesos/enviar_mailing_list.php";
				mailing.setVar = [["email", returnvalue]];
				mailing.onLoading = function() {
					document.body.style.cursor = "wait";
				}
				mailing.manageError = function(err,val) {
					document.body.style.cursor = "default";
					Sexy.alert('<h1>'+_titulo+'</h1><br><p>'+val+'.</p>');
				}
				mailing.onCompletion = function() {
					document.body.style.cursor = "default";
					Sexy.info('<h1>'+_titulo+'</h1><br><p>Gracias por suscribirse en Maxell Latin America.</p>');
				}
				mailing.Execute();
				delete mailing;
				
				return false;
				
			} else {
				Sexy.alert('<h1>'+_titulo+'</h1><br><p>Debe introducir un correo electronico.</p>');
				return false;
			}			
		  } else {
			if (returnvalue === false) { 
				return false;
			} else{
				MailingList();
			}
		  }
		}
	  });
}

function BuscadorDescarga() {
	var _nombre = jsGetObject('buscar_nombre');
	var _tipoDescarga = jsGetObject('codigo_tipo_descarga');
	var _codCategoria = jsGetObject('codigo_categoria');
	var _codProducto = jsGetObject('codigo_producto');
	
	var p = new SetAjax();
	p.FilePath = __strMainDir + "includes/procesos/cargar_centro_descarga.php";
	p.setVar = [["nombre", _nombre.value],["cod_tipo_descarga", _tipoDescarga.value],["cod_categoria", _codCategoria.value],["cod_producto", _codProducto.value]];
	p.Element = jsGetObject('ContentDescarga');
	p.ElementPlainText = false;
	p.onLoading = function() {
		jsSetStyle("LoadingBuscador", "display", "block");
		document.body.style.cursor = "wait";
	}
	p.onCompletion = function() {
		jsSetStyle("LoadingBuscador", "display", "none");
		document.body.style.cursor = "default";
	}
	p.Execute();
	delete p;
}

function PaginarBuscador(numPage,campoValue) {
	
	var p = new SetAjax();
	p.FilePath = __strMainDir + "includes/procesos/cargar_busc_producto.php";
	p.setVar = [["campo", campoValue],["pag", numPage]];
	p.Element = jsGetObject('ContentProductos');
	p.ElementPlainText = false;
	p.onLoading = function() {
		//jsSetStyle("LoadingProducto", "display", "block");
		document.body.style.cursor = "wait";
	}
	p.onCompletion = function() {
		//jsSetStyle("LoadingProducto", "display", "none");
		document.body.style.cursor = "default";
	}
	p.Execute();
	delete p;
}

function BuscarProducto(f) {
	if (f.buscar.value == '') {
		alert('Debe ingresar algún criterio de búsqueda.');
		f.buscar.focus();
		return false;
	}
	
	var p = new SetAjax();
	p.FilePath = __strMainDir + "includes/procesos/cargar_busc_producto.php";
	p.setVar = [["campo", f.buscar.value]];
	p.Element = jsGetObject('ContentProductos');
	p.ElementPlainText = false;
	p.onLoading = function() {
		//jsSetStyle("LoadingBuscador", "display", "block");
		document.body.style.cursor = "wait";
		//DisableFormElements(f);
	}
	p.onCompletion = function() {
		//jsSetStyle("LoadingBuscador", "display", "none");
		document.body.style.cursor = "default";
		EnableFormElements(f);
	}
	p.Execute();
	delete p;
}

/*------------------------------------------------------------------------------------------------------------\
	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 ;
}
