function insertFlash(id,src,width,height,wmode,menu,flashVars,title,flashVersion) {
  var pidObject = (id==null)? "" : 'id="'+id+'"';
  var pidEmbed = (id==null)? "" : 'name="'+id+'"'; 
  var pwmode = (wmode==null)? "" : wmode;
  var pmenu = (menu==null)? true : false;
  var pflashVars = (flashVars==null)? "" : flashVars;
  var ptitle = (title==null)? "" : title; 
  var pflashVersion = (flashVersion==null)? "6,0,29,0" : flashVersion;

  document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+pflashVersion+' " width="'+width+'" height="'+height+'" pidObject  title="'+ptitle+'">');
  document.write('<param name="movie" value="'+src+'">');
  document.write ('<param name="quality" value="high">');
  document.write('<param name="flashVars" value="'+pflashVars+'">');
  document.write('<param name="wmode" value="'+pwmode+'">'); 
  document.write('<param name="menu" value="'+pmenu+'">');
  document.write('<embed src="'+src+'" quality="high" pidEmbed menu="'+pmenu+'"  wmode="'+pwmode+'" flashvars="'+pflashVars+'" pluginspage=" http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'"></embed>');
  document.write('</object>');

}

//-----------------
  function insertFlashChart(id,src,width,height,wmode,menu,flashVars,title,flashVersion,bg_color) {
  var pidObject = (id==null)? "" : 'id="'+id+'"';
  var pidEmbed = (id==null)? "" : 'name="'+id+'"'; 
  var pwmode = (wmode==null)? "" : wmode;
  var pmenu = (menu==null)? true : false;
  var pflashVars = (flashVars==null)? "" : flashVars;
  var ptitle = (title==null)? "" : title; 
  var pflashVersion = (flashVersion==null)? "8,0,0,0" : flashVersion;
  var bg_color = (bg_color==null)? "FFFFFF" : bg_color;

  document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+pflashVersion+' " width="'+width+'" height="'+height+'" pidObject  title="'+ptitle+'">');
  document.write('<param name="movie" value="'+src+'">');
  document.write ('<param name="quality" value="high">');
  document.write('<param name="flashVars" value="'+pflashVars+'">');
  document.write('<param name="wmode" value="'+pwmode+'">'); 
  document.write('<param name="menu" value="'+pmenu+'">');
  document.write('<PARAM NAME=bgcolor VALUE="#'+bg_color+'">');
  document.write('<embed src="'+src+'" quality="high" pidEmbed menu="'+pmenu+'"  wmode="'+pwmode+'" flashvars="'+pflashVars+'" pluginspage=" http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" ALIGN="" swLiveConnect="true" NAME="charts" bgcolor="#'+bg_color+'"></embed>');
  document.write('</object>');

 }
//-----------------
/*
  function insertFlashChart2(id,src,width,height,wmode,menu,flashVars,title,flashVersion,bg_color,destino) {
  var pidObject = (id==null)? "" : 'id="'+id+'"';
  var pidEmbed = (id==null)? "" : 'name="'+id+'"'; 
  var pwmode = (wmode==null)? "" : wmode;
  var pmenu = (menu==null)? true : false;
  var pflashVars = (flashVars==null)? "" : flashVars;
  var ptitle = (title==null)? "" : title; 
  var pflashVersion = (flashVersion==null)? "8,0,0,0" : flashVersion;
  var bg_color = (bg_color==null)? "FFFFFF" : bg_color;
  var html = '';

  html += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+pflashVersion+' " width="'+width+'" height="'+height+'" pidObject  title="'+ptitle+'">';
  html += '<param name="movie" value="'+src+'">';
  html += '<param name="quality" value="high">';
  html += '<param name="flashVars" value="'+pflashVars+'">';
  html += '<param name="wmode" value="'+pwmode+'">'; 
  html += '<param name="menu" value="'+pmenu+'">';
  html += '<PARAM NAME=bgcolor VALUE="#'+bg_color+'">';
  html += '<embed src="'+src+'" quality="high" pidEmbed menu="'+pmenu+'"  wmode="'+pwmode+'" flashvars="'+pflashVars+'" pluginspage=" http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+width+'" height="'+height+'" ALIGN="" swLiveConnect="true" NAME="charts" bgcolor="#'+bg_color+'"></embed>';
  html += '</object>';
  
  document.getElementById(destino).innerHTML += html;

 }
 */
//----------------------

function validaEmail(campo,email,ididm){
	var reEmail1 = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	var msg = [];
	if(email != ""){
	    if (!reEmail1.test(email)) {
            msg[1] = " no es una dirección válida de e-mail!";
            msg[2] = " não é um endereço válido de e-mail!";
            msg[3] = " is not a valid e-mail!";
            alert('"' + email + '"' + msg[ididm]);
		    campo.value = "";
		    campo.focus();
		    return false;
	    }else{
	        return true;
	    }
    }
    return false;
}

function PopupCentralizado(pagina,nome,width,height,parametros) {
	largura = screen.width;
	altura = screen.height;
	posX = (largura - width) / 2;
	posY = (altura - height) / 2;
	var janela = null;
	if (parametros=='') {
		janela = window.open(pagina, nome,'left='+posX+',top='+posY+',height='+height+',width='+width);
	} else {
		janela = window.open(pagina, nome,parametros+',left='+posX+',top='+posY+',height='+height+',width='+width);
	}
	janela.focus();
	return false;
}

function TeclaInteiro(e){
	var key;
	var keychar;
	var reg;
	
	if(window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		key = e.keyCode; 
	}
	else if(e.which) {
		// netscape or firefox
		key = e.which; 
	}
	else {
		// no event, so pass through
		return true;
	}
	if((key > 47 && key < 58) || (key == 8)) // numeros de 0 a 9 OU BACKSPACE
		return true;
	else {
		return false;
	}
}

function TeclaDecimal(e){
	var key;
	var keychar;
	var reg;
	
	if(window.event) {
		// for IE, e.keyCode or window.event.keyCode can be used
		key = e.keyCode; 
	}
	else if(e.which) {
		// netscape or firefox
		key = e.which; 
	}
	else {
		// no event, so pass through
		return true;
	}
	if(key > 47 && key < 58) // numeros de 0 a 9
		return true;
	else {
		if (key == 8 || key == 44 || key == 46) // backspace / , / .
			return true;
		else
			return false;
	}
}

function countChars(num_chars, obj_mostrador, obj_texto, msg) {
	campo=obj_texto.value;
	obj_mostrador.value=campo.length;
	if (campo.length>parseInt(num_chars)) {
		alert(msg+" "+num_chars+" caracteres.");
		obj_texto.value=campo.substring(0,parseInt(num_chars));
		obj_mostrador.value=num_chars;
		return false;
	}
	return true;
}

function getElementsByClass(searchClass,node,tag) {

	var classElements = new Array();
	if (node == null)
		node = document;
	if (tag == null)
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
	var j = 0;
	for (i = 0; i < elsLen; i++) {
		if (pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

function getNowString(){
		var now = new Date();
		var ano = now.getFullYear();
		var mes = now.getMonth() + 1;
		if(mes<10) mes = "0" + mes;
		var dia = now.getDate();
		if(dia<10) dia = "0" + dia;
		var hora = now.getHours();
		if(hora<10) hora = "0" + hora;
		var minuto = now.getMinutes();
		if(minuto<10) minuto = "0" + minuto;
		var segundo = now.getSeconds();
		if(segundo<10) segundo = "0" + segundo;
		var agora = ano + "" + mes + "" + dia + "" + hora + "" + minuto + "" + segundo;
		return agora;
}

function FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.
 
	RETVAL:
		The formatted number!
 **********************************************************************/
{ 
        if (isNaN(parseInt(num))) return "NaN";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;		// Return our formatted string!
}

function FormatDate(fecha_in){
	if(fecha_in.length==10){
		fecha_out = fecha_in.substring(6,10) + "" + fecha_in.substring(3,5) + "" + fecha_in.substring(0,2);
	}else{
		fecha_out =  fecha_in.substring(6,8)+ "/" + fecha_in.substring(4,6) + "/" + fecha_in.substring(0,4);
	}
	return fecha_out;
}

//---------------------------------------------------------------
Array.prototype.in_array = function(p_val) {
	for(var i = 0, l = this.length; i < l; i++) {
		if(this[i] == p_val) {
			return true;
		}
	}
	return false;
}
//---------------------------------------------------------------
function IsNumeric(strString)
   //  check for valid numeric strings	
   {
   var strValidChars = "0123456789.-";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   //  test strString consists of valid characters listed above
   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }
