﻿	    /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        -
        - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
     	
		function handleSystemError( err , url , line)
	    {
		var strMensaje;
		var e;  			
    	    strMensaje  = 'Error \t: ' + err  + '\n';
    	    strMensaje += 'Line  \t: ' + line + '\n';
    	    strMensaje += 'URL   \t: ' + url  + '\n';
            e.description = err;
            e.line = line;
            e.url = url;
            handleError(e,"handleSystemError()", "hubo un error desconocido en el explorador del cliente", 1); 
            return true;

	    }
        
	    /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        -
        - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
		
       function handleError(e, strFuncion, strFrenddlyMessage, intShow)
       {
        
          var strFrameId = 'Top1_ifrError';
          var strUrl ='';
          var strDescription = '';
          var strLinea = '';
                if(typeof e.description != "undefined")
                {
                    strDescription = e.description;
                }
                if(typeof e.line != "undefined")
                {
                    strLinea = e.line;
                }
                if(typeof e.url != "undefined")
                {
                    strUrl = e.url;
                }
              
                var strBody =':::Hubo un error: ERROR:' + strFrenddlyMessage +  
                    '::: Descripción técnica: ' + strDescription +
                    '::: Página: ' + strUrl +
                    '::: Función: ' + strFuncion + 
                    '::: Línea: ' + strLinea;
                    parent.Top1_ifrError.location.href="/settings/handleError.aspx?totalError=" + strBody;
                  
                    if(intShow!=0)
                    {
                        alert(strFrenddlyMessage);
                    }
                   
       }
	    /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       -
        - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
     
       
       function messages(intTipoMessage, strMessage, objDivControl)
       {
            this.message = strMessage;
            this.showMessage = messages.showMessage(intTipoMessage, strMessage, objDivControl)
            
       }
	 
	 	/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        -
        - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
     
       messages.showMessage = messages_showMessage; 
       function messages_showMessage(intTipoMessage, strMessage, objDivControl)
       {
       var strHTMLMessage = "";
       if(objDivControl)
	   {
            switch(intTipoMessage)
            {
                case 0: //SI ESTA OK
                    strHTMLMessage = getHTMLMessageOK(strMessage, objDivControl.id);     
                    break;
                case 1: // SI ES ERROR
                    strHTMLMessage = getHTMLErrorCLIENT(strMessage, objDivControl.id);     
                    break;   
                case 2: // SI ES LOADING
                     strHTMLMessage = getLoading(strMessage);    
                    break;   
                default: // EN OTRO CASO
                    strHTMLMessage = "";     
                    break;
            }
	
            	objDivControl.innerHTML = strHTMLMessage;
		}
				
       }
       
       /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       -
        - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
      
       function getHTMLMessageOK(strMessage, strDiv)
       {
       
            var strHTML="";
                strHTML+= '<!-- mensaje de error-->' +
							'<table width="400" border="0" cellpadding="0" cellspacing="0">'+
										'<tr class="tr5">'+
										  '<td width="5">&nbsp;</td>'+
										  '<td>&nbsp;</td>'+
										  '<td width="5">&nbsp;</td>'+
										'</tr>'+
										'<tr>'+
										  '<td width="5">&nbsp;</td>'+
										  '<td><table width="100%" border="0" cellspacing="0" cellpadding="0">'+
											  '<tr>'+
												'<td><table width="100%" height="5" border="0" cellpadding="0" cellspacing="0">'+
													'<tr class="tr5">'+
													  '<td width="4" align="left" valign="top"><img src="/images/messageOkLeftTop.gif" /></td>'+
													  '<td valign="top"><img src="/images/messageOkLineHorizontal.gif" width="100%" height="1" /></td>'+
													  '<td width="4" align="right" valign="top"><img src="/images/messageOkRightTop.gif" /></td>'+
													'</tr>'+
												'</table></td>'+
											  '</tr>'+
											  '<tr>'+
												'<td><table width="100%" border="0" cellspacing="0" cellpadding="0">'+
													'<tr>'+
													  '<td width="1" background="/images/messageOkLineVertical.gif"><img src="/images/messageOkLineVertical.gif" width="1" height="5" /></td>'+
													  '<td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">'+
														  '<tr>'+
															'<td width="6">&nbsp;</td>'+
															'<td width="25" valign="top"><img src="/images/OKmessage.gif" hspace="5" vspace="5" /></td>'+
															'<td class="cssItext">' + strMessage + '</td>'+
															'<td width="10" align="right" valign="top"><a href="javascript:closeMessage(0,\'' + strDiv + '\');">'+
															  '<img src="/images/CerrarVentana.gif" width="10" height="9" hspace="5" vspace="5" border="0" />'+
															'</a>'+
															'</td>'+
														  '</tr>'+
													  '</table></td>'+
													  '<td width="1" align="right" background="/images/messageOkLineVertical.gif"><img src="/images/messageOkLineVertical.gif" width="1"/></td>'+
													'</tr>'+
												'</table></td>'+
											  '</tr>'+
											  '<tr>'+
												'<td valign="top"><table width="100%" height="5" border="0" cellpadding="0" cellspacing="0">'+
													'<tr class="tr5">'+
													  '<td width="4" align="left" valign="top"><img src="/images/messageOkLeftDown.gif" width="7" height="8" /></td>'+
													  '<td valign="baseline"><img src="/images/messageOkLineHorizontal.gif" width="100%" height="1" /></td>'+
													  '<td width="4" align="right" valign="top"><img src="/images/messageOkRightDown.gif" width="7" height="8" /></td>'+
													'</tr>'+
												'</table></td>'+
											  '</tr>'+
										  '</table></td>'+
										  '<td width="5">&nbsp;</td>'+
										'</tr>'+
										'<tr class="tr5">'+
										  '<td width="5">&nbsp;</td>'+
										  '<td>&nbsp;</td>'+
										  '<td width="5">&nbsp;</td>'+
										'</tr>'+
									  '</table>'+
									'<!-- end mensaje error-->';
                return strHTML;
       }
      
       /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       -
        - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
       function getHTMLErrorCLIENT(strMessage, strDiv)
       {
       var strHTML="";
                strHTML += '<!-- mensaje de error-->'+
							'<table width="400" border="0" cellpadding="0" cellspacing="0">'+
                                '<tr class="tr5">'+
                                  '<td width="5">&nbsp;</td>'+
                                  '<td>&nbsp;</td>'+
                                  '<td width="5">&nbsp;</td>'+
                            '</tr>'+
                                '<tr>'+
                                  '<td width="5">&nbsp;</td>'+
                                  '<td><table width="100%" border="0" cellspacing="0" cellpadding="0">'+
                                    '<tr>'+
                                      '<td><table width="100%" height="5" border="0" cellpadding="0" cellspacing="0">'+
                                        '<tr class="tr5">'+
                                          '<td width="4" align="left" valign="top"><img src="/images/messageErrorLeftTop.gif" /></td>'+
                                          '<td valign="top"><img src="/images/messageErrorLine.gif" width="100%" height="1" /></td>'+
                                          '<td width="4" align="right" valign="top"><img src="/images/messageErrorRightTop.gif" /></td>'+
                                        '</tr>'+
                                      '</table></td>'+
                                    '</tr>'+
                                    '<tr>'+
                                      '<td><table width="100%" border="0" cellspacing="0" cellpadding="0">'+
                                        '<tr>'+
                                          '<td width="1" background="/images/messageErrorVerticalLine.gif"><img src="/images/messageErrorVerticalLine.gif" width="1" /></td>'+
                                          '<td valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">'+
                                            '<tr>'+
                                              '<td width="20" valign="top"><img src="/images/ErrorPeq.gif" width="16" height="16" hspace="5" vspace="5" /></td>'+
                                              '<td class="cssItext">' + strMessage + '</td>'+
                                              '<td width="5" valign="top"><a href="javascript:closeMessage(0, \''+ strDiv +'\');">'+
                                                '<img src="/images/CerrarVentana.gif" hspace="5" vspace="5" border="0" />'+
                                              '</a>'+
                                              '</td>'+
                                            '</tr>'+
                                          '</table></td>'+
                                          '<td width="1" align="right" background="/images/messageErrorVerticalLine.gif"><img src="/images/messageErrorVerticalLine.gif" width="1"/></td>'+
                                        '</tr>'+
                                      '</table></td>'+
                                    '</tr>'+
                                    '<tr>'+
                                      '<td valign="top"><table width="100%" height="5" border="0" cellpadding="0" cellspacing="0">'+
                                        '<tr class="tr5">'+
                                          '<td width="4" align="left" valign="top"><img src="/images/messageErrorLeftDown.gif" /></td>'+
                                          '<td valign="baseline"><img src="/images/messageErrorLine.gif" width="100%" height="1" /></td>'+
                                          '<td width="4" align="right" valign="top"><img src="/images/messageErrorRightDown.gif" /></td>'+
                                        '</tr>'+
                                      '</table></td>'+
                                    '</tr>'+
                                  '</table></td>'+
                                  '<td width="5">&nbsp;</td>'+
                            '</tr>'+
                                '<tr class="tr5">'+
                                  '<td width="5">&nbsp;</td>'+
                                  '<td>&nbsp;</td>'+
                                  '<td width="5">&nbsp;</td>'+
                            '</tr>'+
                              '</table>'+
							         '<!-- end mensaje error-->';
            return strHTML;
       }

		/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        -
        - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
	   function closeMessage(intEstado, strDiv)
	   {
			if(this.document.getElementById(strDiv))
			{
				var objDiv = this.document.getElementById(strDiv);
		   		switch(intEstado)
		   		{
			   		case 0:
			   			objDiv.innerHTML = '';
			   		break;
			   	}
			}
	   }

		/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        -
        - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
	   
	   function getLoading(strMessage)
	   {
		var strHTML = '';
			if(strMessage=='')
			{
				strMessage = 'Cargando';
			}
			strHTML = '<img border="0" src="/images/loading.gif"> <font class="cssItext">' + strMessage + '</font>';
		return strHTML;
	   }
	   
	   /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       - CONVERSIONES
       - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
		
	   function formatNumber(strNumber, intDecimales, separador)
	   {
			var arrSplit;
			var strInitialNumber;
			var strLastNumber;
			var auxNumber = strNumber+'';
			var chrSeparator='';
			var i;
			var auxCeros='';
			var returnValue;
			var intDiferencial = 0;
				if(intDecimales==0)
				{
					separador = '';
					}
				if(auxNumber.indexOf('.')!=-1)
				{
					chrSeparator = '.';	
				}
				
				if(auxNumber.indexOf(',')!=-1)
				{
					chrSeparator = ',';	
				}
				
				if(chrSeparator=='')
				{
					for(i=0;i<intDecimales;i++)
					{
						auxCeros+= '0' + '';
						}
					return auxNumber + separador + auxCeros;
				}
				
				arrSplit = strNumber.split(chrSeparator);
				strInitialNumber = arrSplit[0];
				strLastNumber = arrSplit[1];
				
				if(strLastNumber.length<intDecimales)
				{
					intDiferencial = intDecimales - strLastNumber.length
					for(i=0;i<intDiferencial;i++)
					{
						strLastNumber += '0'; 
						}
				}
				strLastNumber = strLastNumber.substring(0, intDecimales);
				returnValue = strInitialNumber + separador + strLastNumber;
				return returnValue;
		
	   }
		/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       - CONVERSIONES
       - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
	    function replaceSubstring(inputString, fromString, toString) 
		{
		   var temp = inputString;
		   if (fromString == "") {
			  return inputString;
		   }
		   if (toString.indexOf(fromString) == -1) { 
			  while (temp.indexOf(fromString) != -1) {
				 var toTheLeft = temp.substring(0, temp.indexOf(fromString));
				 var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
				 temp = toTheLeft + toString + toTheRight;
		   }
		   } else {
			  var midStrings = new Array("~", "`", "_", "^", "#");
			  var midStringLen = 1;
			  var midString = "";
			  while (midString == "") {
				 for (var i=0; i < midStrings.length; i++) {
					var tempMidString = "";
					for (var j=0; j < midStringLen; j++) { tempMidString += midStrings[i]; }
					if (fromString.indexOf(tempMidString) == -1) {
					   midString = tempMidString;
					   i = midStrings.length + 1;
					}
				 }
			  } 
			  while (temp.indexOf(fromString) != -1) {
				 var toTheLeft = temp.substring(0, temp.indexOf(fromString));
				 var toTheRight = temp.substring(temp.indexOf(fromString)+fromString.length, temp.length);
				 temp = toTheLeft + midString + toTheRight;
			  }
			  while (temp.indexOf(midString) != -1) {
				var toTheLeft = temp.substring(0, temp.indexOf(midString));
				var toTheRight = temp.substring(temp.indexOf(midString)+midString.length, temp.length);
				temp = toTheLeft + toString + toTheRight;
				}
				}
			  return temp; 
				}

	function ValidarFloat(strFloat)
	{
		var reFloat =/^((\d+(\.\d*)?)|((\d*\.)?\d+))$/;
		if(!reFloat.test(strFloat))
		{ 
			return false;
		} 
		else 
		{
			return true;
		}
	}
	
	function IsInt (str)
	{
		var i = parseInt (str);
	
		if (isNaN (i))
			return false;
	
		i = i . toString ();
		if (i != str)
			return false;
	
		return true;
	}