function isEmail(email) {
	var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (filter.test(email)) {
		return true;
	} else {
		return false;
	}
}

/*------------------------------------------------------------------------------------------------------------\
	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 ValidarLogin(f) {
	if (f.email.value == "") {
		alert("Por favor, ingrese su correo electrónico.");
		f.email.focus();
		return false;
	}
	
	f.b_entrar.disabled = true;
	
	var chk_user = new SetAjax();
	chk_user.FilePath = "includes/conectar.php";
	chk_user.FileRedirect = "reportes.php";
	chk_user.setVar = [["email", f.email.value]];
	chk_user.manageError = function(err, val) {
		document.body.style.cursor = "default";
		f.b_entrar.disabled = false;
		f.b_entrar.value = 'Entrar';
		alert(val);
	}
	chk_user.onLoading = function() {
		document.body.style.cursor = "wait";
		f.b_entrar.value = 'Espere';
	}
	chk_user.onCompletion = function() {
		document.body.style.cursor = "default";
	}
	chk_user.Execute();
	
	return false;
}


function ValidarAdmin(f) {
	if (f.usuario.value == "") {
		alert("Por favor, ingrese su Usuario.");
		f.usuario.focus();
		return false;
	}
	
	if (f.clave.value == "") {
		alert("Por favor, ingrese su Contraseña.");
		f.clave.focus();
		return false;
	}
	
	f.b_entrar.disabled = true;
	
	var chk_user = new SetAjax();
	chk_user.FilePath = "conectar.php";
	chk_user.FileRedirect = "main.php";
	chk_user.setVar = [["u", f.usuario.value], ["c", f.clave.value]];
	chk_user.manageError = function(err, val) {
		document.body.style.cursor = "default";
		f.b_entrar.disabled = false;
		f.b_entrar.value = 'Entrar';
		alert(val);
	}
	chk_user.onLoading = function() {
		document.body.style.cursor = "wait";
		f.b_entrar.value = 'Espere';
	}
	chk_user.onCompletion = function() {
		document.body.style.cursor = "default";
	}
	chk_user.Execute();
	
	return false;
}

function LoadVendedor(id) {
	var Obj = jsGetObject('temp_data');
	var lv = new SetAjax();
	lv.FilePath = "includes/cargar_vendedor.php";
	lv.Element = Obj;
	lv.ElementPlainText = false;
	lv.setVar = [["id", id]];
	lv.onLoading = function() {
		jsSetStyle('ProblemaDiv','display','none');
		document.body.style.cursor = "wait";
		jsGetObject('Vendedor').innerHTML = '<img src="images/loading.gif" border="0"><br><br>Cargando...';
	}
	lv.onCompletion = function() {
		document.body.style.cursor = "default";
		var S = Obj.value.split('[PROBLEMA]');
		if (S.length > 1) {
			jsSetStyle('ProblemaDiv','display','block');
			jsGetObject('Problema').innerHTML = S[1];
		}
		jsGetObject('Vendedor').innerHTML = S[0];
	}
	lv.Execute();
}

document.write('<input type="hidden" name="temp_data" id="temp_data" />');


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 jsSetAttribute(obj, _name, _value) {
	obj = (!jsGetObject(obj)) ? obj : jsGetObject(obj);
	obj.setAttribute(_name, _value);
}

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;
	}
}