function showhideelement(menuelement, clickaction) {

    if (!document.getElementById(menuelement))
    {
         return false;
    }
    if (!clickaction) {
        if (document.getElementById(menuelement).style.display == '') {
           document.getElementById(menuelement).style.display = 'none';
        } else {
           document.getElementById(menuelement).style.display = '';
        }
    } else {
        if (clickaction == 'show') {
           document.getElementById(menuelement).style.display = '';
        } else {
           document.getElementById(menuelement).style.display = 'none';
        }
    }
}

function SelectOption (obj, optval, optid, boldtext, smultiple)
{

	if (optid)
	{
		var obj = document.getElementById(optid);
	}

var tipo_objeto = obj.type.toLowerCase();
tipo_objeto = tipo_objeto.substr(0, 6);

        if (obj && tipo_objeto == 'select')
//        if (obj)
	{

        	for (var i=0; i<obj.options.length; i++) {

        		if (obj.options[i].value == optval)
        			{
        				obj.options[i].selected = true;
        				if (boldtext)
        				{
                                            obj.options[i].style.color = '#CC0000';
                                        }
        			}
        			else if (!smultiple)
        			{
        				obj.options[i].selected = false;			
        			}
        	}
	}
}

function RadioOption (obj, optval, optid)
{
        if (optid)
	{
		var obj = document.getElementById(optid);
	}
	if (obj)
	{
        	for (var i=0; i<obj.length; i++) {
    
        		if (obj[i].value == optval)
        			{
        				obj[i].checked = true;
        			}
        			else
        			{
        				obj[i].checked = false;
        			}
        	}
        }
}

function PopupWindow (url, popname, others)
{
//scrollbars=yes,resizable=yes,width=500,height=300
  popup = window.open('', popname, others);
  popup.document.writeln("<html><head><title></title><meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"></head>");
  popup.document.writeln("<frameset rows=\"*,28\" frameborder=\"NO\" border=\"0\" framespacing=\"0\">");
  popup.document.writeln("<frame src=\"" + url + "\" name=\"mainFrame\" scrolling=\"YES\">");
  popup.document.writeln("<frame src=\"public/html/popup/\" name=\"bottomFrame\" scrolling=\"NO\" noresize> <sc" + "ript language=\"javascript\">function execute_js (js) { env(js); } </scr" + "ipt>");

}


function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}

function ReplaceText (IDName, IDValue)
{

if (document.getElementById(IDName))
{
   document.getElementById(IDName).value = IDValue;
}

}

function get_random()
{
    var ranNum= Math.round(Math.random()*4);
    return ranNum;
}


function xmlhttpPost(strURL, strSubmit, strResultFunc) {
        //page, qry, func
        var xmlhttp=false;
        
        //if (@_jscript_version >= 5)
        // JScript gives us Conditional compilation, we can cope with old IE versions.
        // and security blocked creation of the objects.
        try {
            xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
        }catch (e) {
            try {
                xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }catch (E) {
                xmlhttp = false;
            }
        }

        if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
          xmlhttp = new XMLHttpRequest();
        }
        
        xmlhttp.open('POST', strURL, true);
        xmlhttp.setRequestHeader('Content-Type',
             'application/x-www-form-urlencoded');
        xmlhttp.onreadystatechange = function() {
                if (xmlhttp.readyState == 4) {
                    strResponse = xmlhttp.responseText;
                    switch (xmlhttp.status) {
                            // Page-not-found error
                            case 404:
                                    alert('Error: Not Found. The requested URL ' +
                                            strURL + ' could not be found.');
                                    break;
                            // Display results in a full window for server-side errors
                            case 500:
                                    handleErrFullPage(strResponse);
                                    break;
                            default:
                                    // Call JS alert for custom error or debug messages
                                    if (strResponse.indexOf('Error:') > -1 ||
                                            strResponse.indexOf('Debug:') > -1) {
                                            alert(strResponse);
                                    }
                                    // Call the desired result function
                                    else {
                                            eval(strResultFunc + '(strResponse);');
                                    }
                                    break;
                    }
            }
        }

        xmlhttp.send(strSubmit);


}

function handleErrFullPage(strIn) {

        var errorWin;

        // Create new window and display error
        try {
               errorWin = window.open('', 'errorWin');
               errorWin.document.body.innerHTML = strIn;
        }
        // If pop-up gets blocked, inform user
        catch(e) {
                alert('An error occurred, but the error message cannot be' +
                        ' displayed because of your browser\'s pop-up blocker.\n' +
                        'Please allow pop-ups from this Web site.');
        }
}

function ProcessAjaxResponse (response)
{

	if (response.substr(0, 14) == 'BNAjaxResponse')
	{
		var DataInfo = Array();
		
		DataInfo = response.split('//div//');

		return DataInfo;

	}
	else if (response.substr(0, 11) == 'BNAjaxError')
	{
		alert(response.substr(11))
		return false;
	}
	else
        {
           alert('No fue posible realizar la conección');
        }

}

function select_all(TheForm, TheMasterObject, TheObjectName) {

var formblock= TheForm;
var forminputs = formblock.getElementsByTagName('input');
	
for (i = 0; i < forminputs.length; i++) {
	// regex here to check name attribute
	var regex = new RegExp(TheObjectName, "i");
	if (regex.test(forminputs[i].getAttribute('name'))) {
	forminputs[i].checked = TheMasterObject.checked;
	}
}
}

function formatCurrency(num) {

        num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num))
	num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10)
	cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
//	num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
//	return (((sign)?'':'-') + '$' + num + '.' + cents);
	return (((sign)?'':'-') + num + '.' + cents);
}



/***********************************************
* Overlapping Content link- © Dynamic Drive (www.dynamicdrive.com)
* This notice must stay intact for legal use.
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function getposOffset(overlay, offsettype){
  var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
  var parentEl=overlay.offsetParent;
  while (parentEl!=null){
  totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
  parentEl=parentEl.offsetParent;
  }
  return totaloffset;
}

function overlay(curobj, subobj){
  if (document.getElementById){
  var subobj=document.getElementById(subobj)
  subobj.style.left=getposOffset(curobj, "left")+"px"
//  subobj.style.top=getposOffset(curobj, "top")+"px"
  subobj.style.top=getposOffset(curobj, "top") - subobj.style.height.replace(/px/g, "")+"px"
  subobj.style.display="block"
  return false
  }
  else
  return true
}

function overlayclose(subobj){
  document.getElementById(subobj).style.display="none"
}


/**********************************************
* Basic Validation
**********************************************/
function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
 
}


function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++)
      {
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1)
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
}

function IsEmpty(aTextField) {

   aTextField.replace(/ /g, "");
   if ((aTextField.length == '')) {
      return true;
   }
   else { return false; }
}


function BNValidateForm(ElementsData)
{
    var ElementList = new Array();
    var ErrorMsg = "";


    for (var i = 0; i < ElementsData.length; i++)
    {
        ElementList = ElementsData[i].split('|');


        if (ElementList[1] == 'email' && !isValidEmail(document.getElementById(ElementList[0]).value))
        {
            ErrorMsg = ErrorMsg + "- " + ElementList[2] + "\n\n";
        }
        else if (ElementList[1] == 'number'  && !IsNumeric(document.getElementById(ElementList[0]).value))
        {
            ErrorMsg = ErrorMsg + "- " + ElementList[2] + "\n\n";
        }
        else if(IsEmpty(document.getElementById(ElementList[0]).value))
        {
            ErrorMsg = ErrorMsg + "- " + ElementList[2] + "\n\n";
        }

    }
    
        if (ErrorMsg)
        {

            alert(ErrorMsg.substr(0, (ErrorMsg.length - 2)));
            return false;

        }
        else
        {
          return true;
        }


return true;

}

function BNToolTip (BNText, BNSize)
{
	if (BNText != "")
	{
            if (BNSize == "")
            {
                BNSize = 80;
            }
//  	      alert(BNText);
              stm(Array("", '<div style="padding:5px" align="center">' + BNText + '</div>'), Array("white","black","#999999","#F4F4F4","","","","","","","","","","",BNSize,"",1,0,10,10,"","","","",""));
        }

}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}