/*
  -------------------------------------------------------------------------
	                    JavaScript Form Validator 
                                Version 2.0.2
	Copyright 2003 JavaScript-coder.com. All rights reserved.
	You use this script in your Web pages, provided these opening credit
    lines are kept intact.
	The Form validation script is distributed free from JavaScript-Coder.com

	You may please add a link to JavaScript-Coder.com, 
	making it easy for others to find this script.
	Checkout the Give a link and Get a link page:
	http://www.javascript-coder.com/links/how-to-link.php

    You may not reprint or redistribute this code without permission from 
    JavaScript-Coder.com.
	
	JavaScript Coder
	It precisely codes what you imagine!
	Grab your copy here:
		http://www.javascript-coder.com/
    -------------------------------------------------------------------------  
*/
function Validator(frmname)
{	

  this.formobj=document.forms[frmname];
	if(!this.formobj)
	{
	  alert("BUG: couldnot get Form object "+frmname);
		return;
	}
	if(this.formobj.onsubmit)
	{
	 this.formobj.old_onsubmit = this.formobj.onsubmit;
	 this.formobj.onsubmit=null;
	}
	else
	{
	 this.formobj.old_onsubmit = null;
	}
	this.formobj.onsubmit=form_submit_handler;
	this.addValidation = add_validation;
	this.setAddnlValidationFunction=set_addnl_vfunction;
	this.clearAllValidations = clear_all_validations;
}
function set_addnl_vfunction(functionname)
{
  this.formobj.addnlvalidation = functionname;
}
function clear_all_validations()
{
	for(var itr=0;itr < this.formobj.elements.length;itr++)
	{
		this.formobj.elements[itr].validationset = null;
	}
}
function form_submit_handler()
{
	for(var itr=0;itr < this.elements.length;itr++)
	{
		if(this.elements[itr].validationset &&
	   !this.elements[itr].validationset.validate())
		{
		  return false;
		}
	}
	if(this.addnlvalidation)
	{
	  str =" var ret = "+this.addnlvalidation+"()";
	  eval(str);
    if(!ret) return ret;
	}
	return true;
}
function add_validation(itemname,descriptor,errstr)
{
  if(!this.formobj)
	{
	  alert("BUG: the form object is not set properly");
		return;
	}//if
	var itemobj = this.formobj[itemname];
  if(!itemobj)
	{
	  alert("BUG: Couldnot get the input object named: "+itemname);
		return;
	}
	if(!itemobj.validationset)
	{
	  itemobj.validationset = new ValidationSet(itemobj);
	}
  itemobj.validationset.add(descriptor,errstr);
}
function ValidationDesc(inputitem,desc,error)
{
  this.desc=desc;
	this.error=error;
	this.itemobj = inputitem;
	this.validate=vdesc_validate;
}
function vdesc_validate()
{
 if(!V2validateData(this.desc,this.itemobj,this.error))
 {
	if((this.itemobj.disabled == false)&&(this.itemobj.display != "hidden")&&(this.itemobj.type != "hidden")) {
		this.itemobj.focus();
		return false;
	}
	else{
		return false;		
	}
 }
 return true;
}
function ValidationSet(inputitem)
{
    this.vSet=new Array();
	this.add= add_validationdesc;
	this.validate= vset_validate;
	this.itemobj = inputitem;
}
function add_validationdesc(desc,error)
{
  this.vSet[this.vSet.length]= 
	  new ValidationDesc(this.itemobj,desc,error);
}
function vset_validate()
{
   for(var itr=0;itr<this.vSet.length;itr++)
	 {
	   if(!this.vSet[itr].validate())
		 {
		   return false;
		 }
	 }
	 return true;
}
function validateEmailv2(email)
{
// a very simple email validation checking. 
// you can add more complex email checking if it helps 
    if(email.length <= 0)
	{
	  return true;
	}
    var splitted = email.match("^(.+)@(.+)$");
    if(splitted == null) return false;
    if(splitted[1] != null )
    {
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null)
    {
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null) 
      {
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
return false;
}

function V2validateData(strValidateStr,objValue,strError) { 
	var error=0;
    texto="<img src='images/error.gif' alt='Enviando'><br /><br />Revise los campos que están en rojo.<br /><br /><button style='width:60px; height:18px; font-size:10px;' onClick='ocultaMensaje()' type='button'>Cerrar</button>";	
	divMensaje=document.getElementById("transparenciaMensaje");	
	divTransparente=document.getElementById("transparencia");	
    var epos = strValidateStr.search("="); 
    var  command  = ""; 
    var  cmdvalue = ""; 
    if(epos >= 0) 
    { 
     command  = strValidateStr.substring(0,epos); 
     cmdvalue = strValidateStr.substr(epos+1); 
    } 
    else 
    { 
     command = strValidateStr; 
    } 
    switch(command) 
    { 
		case "opciones":
		{
			sw = false;
			var opcion = objValue.length;	
			for (i=0;i<opcion;i++) {
				if (opcion.checked) {
					sw = true;
					break;
				}
			}
			if (!sw) {
				if(!strError || strError.length ==0)  { 
					strError = objValue.name + " : Campo obligatorio"; 
				} 
				//alert(strError);
				campoError(objValue);				
				error = 1;
				return false;
			}
		}
        case "req": 
        case "required": { 
           if(eval(objValue.value.length) == 0){ 
		   		if(objValue.type=="hidden" || objValue.disabled == true){
					if(!strError || strError.length ==0)  {
						strError = objValue.name + " : Campo obligatorio"; 
					}
					alert(strError);										
				}
				else{
					campoError(objValue);
				  	muestraMensaje(texto,strError);			  
				}
				error = 1;			  				
                return false; 
           }
           break;             
        }
        case "req1": { 
			if(document.getElementById("formapago").value == "Anual"){
			   if(eval(objValue.value.length) == 0){ 
					if(objValue.type=="hidden" || objValue.disabled == true){
						if(!strError || strError.length ==0)  {
							strError = objValue.name + " : Campo obligatorio"; 
						}
						alert(strError);										
					}
					else{
						campoError(objValue);
					  	muestraMensaje(texto,strError);			  
					}
					error = 1;			  				
					return false; 
			   }
			   break;             
			}
			else{
			   break;             				
			}
        }
		 
        case "maxlength": 
        case "maxlen": 
          { 
             if(eval(objValue.value.length) >  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = objValue.name + " : "+cmdvalue+" mximo de caracteres "; 
               }//if 
               //alert(strError + "\n[longitud actual = " + objValue.value.length + " ]"); 
 			   campoError(objValue);							   
			   error = 1;
               return false; 
             }//if 
             break; 
          }//case maxlen 
        case "minlength": 
        case "minlen": 
           { 
             if(eval(objValue.value.length) <  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = objValue.name + " : " + cmdvalue + " characters minimum  "; 
               }//if               
               //alert(strError + "\n[longitud actual = " + objValue.value.length + " ]"); 
 			   campoError(objValue);							   
   			   error = 1;
               return false;                 
             }
             break; 
            }//case minlen 
        case "alnum": 
        case "alphanumeric": 
           { 
              var charpos = objValue.value.search("[^A-Za-z0-9 ]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
               if(!strError || strError.length ==0) 
                { 
                 // strError = objValue.name+": Solo caracteres alpha-numericos son permitidos "; 
                }//if 
                //alert(strError + "\n [Posicin de caracter con error: " + eval(charpos+1)+"]"); 
				campoError(objValue);								
				error = 1;				
                return false; 
              }//if 
              break; 
           }//case alphanumeric 
        case "num": 
        case "numeric": 
           { 
              var charpos = objValue.value.search("[^0-9]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": Solo se permiten dgitos "; 
                }//if               
                //alert(strError + "\n [Posicin de caracter con error " + eval(charpos+1)+"]"); 
				campoError(objValue);								
				error = 1;				
                return false; 
              }//if 
              break;               
           }//numeric 
        case "alphabetic": 
        case "alpha": 
           { 
              var charpos = objValue.value.search("[^A-Za-z ]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) { 
				campoError(objValue);								
				error = 1;				
                return false; 
              }
              break; 
           }
		case "alnumhyphen":
			{
              var charpos = objValue.value.search("[^A-Za-z0-9\-_]"); 
              if(objValue.value.length > 0 &&  charpos >= 0) 
              { 
                  if(!strError || strError.length ==0) 
                { 
                  strError = objValue.name+": los caracteres permitidoss son A-Z,a-z,0-9,- y _"; 
                }//if                             
                //alert(strError + "\n [Posicin de caracter con error: " + eval(charpos+1)+"]");
				campoError(objValue);								
				error = 1;				
                return false; 
              }//if 			
			break;
			}
        case "email": 
          { 
               if(!validateEmailv2(objValue.value)) 
               { 
                 if(!strError || strError.length ==0) 
                 { 
                    strError = objValue.name+": Ingrese una dirección de email válida "; 
                 }//if                                               
                 //alert(strError);
				 muestraMensaje(texto,strError);	
				 campoError(objValue);								 
				 error = 1;				 
                 return false; 
               }//if 
           break; 
          }//case email 
        case "lt": 
        case "lessthan": 
         { 
            if(isNaN(objValue.value)) 
            { 
              //alert(objValue.name+": Debe ser un numero ");
 			  campoError(objValue);				
   			  error = 1;			  
              return false; 
            }//if 
            if(eval(objValue.value) >=  eval(cmdvalue)) 
            { 
              if(!strError || strError.length ==0) 
              { 
                strError = objValue.name + " : el valor debe ser menor de "+ cmdvalue; 
              }//if               
              //alert(strError); 
  			  campoError(objValue);				
 			  error = 1;
              return false;                 
             }//if             
            break; 
         }//case lessthan 
        case "gt": 
        case "greaterthan": 
         { 
            if(isNaN(objValue.value)) 
            { 
              alert(objValue.name+": Debe ser un nmero "); 
  			  campoError(objValue);				
  			  error = 1;			  
              return false; 
            }//if 
             if(eval(objValue.value) <=  eval(cmdvalue)) 
             { 
               if(!strError || strError.length ==0) 
               { 
                 strError = objValue.name + " : el valor debe ser mayor de "+ cmdvalue; 
               }//if               
               //alert(strError);
			   campoError(objValue);							   
 			   error = 1;			   
               return false;                 
             }//if             
            break; 
         }//case greaterthan 
        case "regexp": 
         { 
		 	if(objValue.value.length > 0)
			{
	            if(!objValue.value.match(cmdvalue)) 
	            { 
	              if(!strError || strError.length ==0) 
	              { 
	                strError = objValue.name+": Se econtraron caracteres invalidos "; 
	              }//if                                                               
	              //alert(strError); 
				  campoError(objValue);								  
	 			  error = 1;				  
	              return false;                   
	            }//if 
			}
           break; 
         }//case regexp 
        case "dontselect": 
         { 
            if(objValue.selectedIndex == null) 
            { 
              //alert("BUG: dontselect command for non-select Item");
			  campoError(objValue);							  
 			  error = 1;			  
              return false; 
            } 
            if(objValue.selectedIndex == eval(cmdvalue)) 
            { 
             if(!strError || strError.length ==0) 
              { 
				strError = objValue.name + ': Por favor seleccione una opcin'; 
              }//if                                                               
              //alert(strError); 
 			  campoError(objValue);				
 			  error = 1;			  
              return false;                                   
             } 
             break; 
         }//case dontselect 


		 case "igual": 
         { 
			 if(objValue.value != document.formRegistro.pass.value){
				//alert("La contrasea digitada no coincide!");
				document.formRegistro.pass.value = "";
				objValue.value = "";
				campoError(objValue);
	 			error = 1;				
				return false;
			 }
			 document.formRegistro.pass1.value=hex_md5(document.formRegistro.pass.value); 
             break; 
         }//case igual


		 case "valor": 
         { 
			 if((objValue.value == 0)||(objValue.value == '')){
				//alert("El valor del descuento debe ser mayor a 0!");
				objValue.focus();
				campoError(objValue);								
 			    error = 1;				
				return false;
			 }
			 else if(objValue.value > 200000){
				//alert("El valor del descuento no debe ser mayor a 200000!");
				objValue.focus();
				campoError(objValue);				
 			    error = 1;				
				return false;
			 }
             break; 
         }//case igual
		 case "repetido": { 
			 if(objValue.value == 1){
				objValue.focus();
				campoError(objValue);					
  			    error = 1;
				return false;
			 }
             break; 
         }
		 case "maxvalue":
		{ 
			if(eval(objValue.value) >  eval(cmdvalue)) { 
			   campoError(objValue);							   
			   error = 1;
			   return false; 
			}
			 break; 
		}
	
	
		case "minvalue":
		{ 
			if(eval(objValue.value) <  eval(cmdvalue)) { 
				campoError(objValue);							   
				error = 1;
				return false; 
			}		
			 break; 
		}
		case "contrasenya": 
        { 
			document.getElementById("pass1").value=hex_md5(document.getElementById("contrasenia").value); 
            break; 
        }
	}
	return true; 
}
/*
	Copyright 2007 JavaScript-coder.com. All rights reserved.
*/

//***********************************************************************************************************************************
//CDIGO MD5
/*
 * A JavaScript implementation of the RSA Data Security, Inc. MD5 Message
 * Digest Algorithm, as defined in RFC 1321.
 * Version 2.1 Copyright (C) Paul Johnston 1999 - 2002.
 * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet
 * Distributed under the BSD License
 * See http://pajhome.org.uk/crypt/md5 for more info.
 */

/*
 * Configurable variables. You may need to tweak these to be compatible with
 * the server-side, but the defaults work in most cases.
 */
var hexcase = 0;  /* hex output format. 0 - lowercase; 1 - uppercase        */
var b64pad  = ""; /* base-64 pad character. "=" for strict RFC compliance   */
var chrsz   = 8;  /* bits per input character. 8 - ASCII; 16 - Unicode      */

/*
 * These are the functions you'll usually want to call
 * They take string arguments and return either hex or base-64 encoded strings
 */
function hex_md5(s){ return binl2hex(core_md5(str2binl(s), s.length * chrsz));}
function b64_md5(s){ return binl2b64(core_md5(str2binl(s), s.length * chrsz));}
function str_md5(s){ return binl2str(core_md5(str2binl(s), s.length * chrsz));}
function hex_hmac_md5(key, data) { return binl2hex(core_hmac_md5(key, data)); }
function b64_hmac_md5(key, data) { return binl2b64(core_hmac_md5(key, data)); }
function str_hmac_md5(key, data) { return binl2str(core_hmac_md5(key, data)); }

/*
 * Perform a simple self-test to see if the VM is working
 */
function md5_vm_test()
{
  return hex_md5("abc") == "900150983cd24fb0d6963f7d28e17f72";
}

 /*
 * Calculate the MD5 of an array of little-endian words, and a bit length
 */
function core_md5(x, len)
{
  /* append padding */
  x[len >> 5] |= 0x80 << ((len) % 32);
  x[(((len + 64) >>> 9) << 4) + 14] = len;

  var a =  1732584193;
  var b = -271733879;
  var c = -1732584194;
  var d =  271733878;

  for(var i = 0; i < x.length; i += 16)
  {
    var olda = a;
    var oldb = b;
    var oldc = c;
    var oldd = d;

    a = md5_ff(a, b, c, d, x[i+ 0], 7 , -680876936);
    d = md5_ff(d, a, b, c, x[i+ 1], 12, -389564586);
    c = md5_ff(c, d, a, b, x[i+ 2], 17,  606105819);
    b = md5_ff(b, c, d, a, x[i+ 3], 22, -1044525330);
    a = md5_ff(a, b, c, d, x[i+ 4], 7 , -176418897);
    d = md5_ff(d, a, b, c, x[i+ 5], 12,  1200080426);
    c = md5_ff(c, d, a, b, x[i+ 6], 17, -1473231341);
    b = md5_ff(b, c, d, a, x[i+ 7], 22, -45705983);
    a = md5_ff(a, b, c, d, x[i+ 8], 7 ,  1770035416);
    d = md5_ff(d, a, b, c, x[i+ 9], 12, -1958414417);
    c = md5_ff(c, d, a, b, x[i+10], 17, -42063);
    b = md5_ff(b, c, d, a, x[i+11], 22, -1990404162);
    a = md5_ff(a, b, c, d, x[i+12], 7 ,  1804603682);
    d = md5_ff(d, a, b, c, x[i+13], 12, -40341101);
    c = md5_ff(c, d, a, b, x[i+14], 17, -1502002290);
    b = md5_ff(b, c, d, a, x[i+15], 22,  1236535329);

    a = md5_gg(a, b, c, d, x[i+ 1], 5 , -165796510);
    d = md5_gg(d, a, b, c, x[i+ 6], 9 , -1069501632);
    c = md5_gg(c, d, a, b, x[i+11], 14,  643717713);
    b = md5_gg(b, c, d, a, x[i+ 0], 20, -373897302);
    a = md5_gg(a, b, c, d, x[i+ 5], 5 , -701558691);
    d = md5_gg(d, a, b, c, x[i+10], 9 ,  38016083);
    c = md5_gg(c, d, a, b, x[i+15], 14, -660478335);
    b = md5_gg(b, c, d, a, x[i+ 4], 20, -405537848);
    a = md5_gg(a, b, c, d, x[i+ 9], 5 ,  568446438);
    d = md5_gg(d, a, b, c, x[i+14], 9 , -1019803690);
    c = md5_gg(c, d, a, b, x[i+ 3], 14, -187363961);
    b = md5_gg(b, c, d, a, x[i+ 8], 20,  1163531501);
    a = md5_gg(a, b, c, d, x[i+13], 5 , -1444681467);
    d = md5_gg(d, a, b, c, x[i+ 2], 9 , -51403784);
    c = md5_gg(c, d, a, b, x[i+ 7], 14,  1735328473);
    b = md5_gg(b, c, d, a, x[i+12], 20, -1926607734);

    a = md5_hh(a, b, c, d, x[i+ 5], 4 , -378558);
    d = md5_hh(d, a, b, c, x[i+ 8], 11, -2022574463);
    c = md5_hh(c, d, a, b, x[i+11], 16,  1839030562);
    b = md5_hh(b, c, d, a, x[i+14], 23, -35309556);
    a = md5_hh(a, b, c, d, x[i+ 1], 4 , -1530992060);
    d = md5_hh(d, a, b, c, x[i+ 4], 11,  1272893353);
    c = md5_hh(c, d, a, b, x[i+ 7], 16, -155497632);
    b = md5_hh(b, c, d, a, x[i+10], 23, -1094730640);
    a = md5_hh(a, b, c, d, x[i+13], 4 ,  681279174);
    d = md5_hh(d, a, b, c, x[i+ 0], 11, -358537222);
    c = md5_hh(c, d, a, b, x[i+ 3], 16, -722521979);
    b = md5_hh(b, c, d, a, x[i+ 6], 23,  76029189);
    a = md5_hh(a, b, c, d, x[i+ 9], 4 , -640364487);
    d = md5_hh(d, a, b, c, x[i+12], 11, -421815835);
    c = md5_hh(c, d, a, b, x[i+15], 16,  530742520);
    b = md5_hh(b, c, d, a, x[i+ 2], 23, -995338651);

    a = md5_ii(a, b, c, d, x[i+ 0], 6 , -198630844);
    d = md5_ii(d, a, b, c, x[i+ 7], 10,  1126891415);
    c = md5_ii(c, d, a, b, x[i+14], 15, -1416354905);
    b = md5_ii(b, c, d, a, x[i+ 5], 21, -57434055);
    a = md5_ii(a, b, c, d, x[i+12], 6 ,  1700485571);
    d = md5_ii(d, a, b, c, x[i+ 3], 10, -1894986606);
    c = md5_ii(c, d, a, b, x[i+10], 15, -1051523);
    b = md5_ii(b, c, d, a, x[i+ 1], 21, -2054922799);
    a = md5_ii(a, b, c, d, x[i+ 8], 6 ,  1873313359);
    d = md5_ii(d, a, b, c, x[i+15], 10, -30611744);
    c = md5_ii(c, d, a, b, x[i+ 6], 15, -1560198380);
    b = md5_ii(b, c, d, a, x[i+13], 21,  1309151649);
    a = md5_ii(a, b, c, d, x[i+ 4], 6 , -145523070);
    d = md5_ii(d, a, b, c, x[i+11], 10, -1120210379);
    c = md5_ii(c, d, a, b, x[i+ 2], 15,  718787259);
    b = md5_ii(b, c, d, a, x[i+ 9], 21, -343485551);

    a = safe_add(a, olda);
    b = safe_add(b, oldb);
    c = safe_add(c, oldc);
    d = safe_add(d, oldd);
  }
  return Array(a, b, c, d);

}

/*
 * These functions implement the four basic operations the algorithm uses.
 */
function md5_cmn(q, a, b, x, s, t)
{
  return safe_add(bit_rol(safe_add(safe_add(a, q), safe_add(x, t)), s),b);
}
function md5_ff(a, b, c, d, x, s, t)
{
  return md5_cmn((b & c) | ((~b) & d), a, b, x, s, t);
}
function md5_gg(a, b, c, d, x, s, t)
{
  return md5_cmn((b & d) | (c & (~d)), a, b, x, s, t);
}
function md5_hh(a, b, c, d, x, s, t)
{
  return md5_cmn(b ^ c ^ d, a, b, x, s, t);
}
function md5_ii(a, b, c, d, x, s, t)
{
  return md5_cmn(c ^ (b | (~d)), a, b, x, s, t);
}

/*
 * Calculate the HMAC-MD5, of a key and some data
 */
function core_hmac_md5(key, data)
{
  var bkey = str2binl(key);
  if(bkey.length > 16) bkey = core_md5(bkey, key.length * chrsz);

  var ipad = Array(16), opad = Array(16);
  for(var i = 0; i < 16; i++)
  {
    ipad[i] = bkey[i] ^ 0x36363636;
    opad[i] = bkey[i] ^ 0x5C5C5C5C;
  }

  var hash = core_md5(ipad.concat(str2binl(data)), 512 + data.length * chrsz);
  return core_md5(opad.concat(hash), 512 + 128);
}

/*
 * Add integers, wrapping at 2^32. This uses 16-bit operations internally
 * to work around bugs in some JS interpreters.
 */
function safe_add(x, y)
{
  var lsw = (x & 0xFFFF) + (y & 0xFFFF);
  var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
  return (msw << 16) | (lsw & 0xFFFF);
}

/*
 * Bitwise rotate a 32-bit number to the left.
 */
function bit_rol(num, cnt)
{
  return (num << cnt) | (num >>> (32 - cnt));
}

/*
 * Convert a string to an array of little-endian words
 * If chrsz is ASCII, characters >255 have their hi-byte silently ignored.
 */
function str2binl(str)
{
  var bin = Array();
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < str.length * chrsz; i += chrsz)
    bin[i>>5] |= (str.charCodeAt(i / chrsz) & mask) << (i%32);
  return bin;
}

/*
 * Convert an array of little-endian words to a string
 */
function binl2str(bin)
{
  var str = "";
  var mask = (1 << chrsz) - 1;
  for(var i = 0; i < bin.length * 32; i += chrsz)
    str += String.fromCharCode((bin[i>>5] >>> (i % 32)) & mask);
  return str;
}

/*
 * Convert an array of little-endian words to a hex string.
 */
function binl2hex(binarray)
{
  var hex_tab = hexcase ? "0123456789ABCDEF" : "0123456789abcdef";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i++)
  {
    str += hex_tab.charAt((binarray[i>>2] >> ((i%4)*8+4)) & 0xF) +
           hex_tab.charAt((binarray[i>>2] >> ((i%4)*8  )) & 0xF);
  }
  return str;
}

/*
 * Convert an array of little-endian words to a base-64 string
 */
function binl2b64(binarray)
{
  var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  var str = "";
  for(var i = 0; i < binarray.length * 4; i += 3)
  {
    var triplet = (((binarray[i   >> 2] >> 8 * ( i   %4)) & 0xFF) << 16)
                | (((binarray[i+1 >> 2] >> 8 * ((i+1)%4)) & 0xFF) << 8 )
                |  ((binarray[i+2 >> 2] >> 8 * ((i+2)%4)) & 0xFF);
    for(var j = 0; j < 4; j++)
    {
      if(i * 8 + j * 6 > binarray.length * 32) str += b64pad;
      else str += tab.charAt((triplet >> 6*(3-j)) & 0x3F);
    }
  }
  return str;
}
function mostrar(parametro){
	if(parametro == 1){
		mostrar1(document.getElementById("s_asesores"));
		ocultar(document.getElementById("s_otros"));	
		document.getElementById("texto").value = "Seleccione Asesor :";
	}
	else if(parametro == 2){
		ocultar(document.getElementById("s_asesores"));
		mostrar1(document.getElementById("s_otros"));			
		document.getElementById("texto").value = "Seleccione Caso :";
	}	
	document.getElementById("forma_contacto").value = parametro;
	document.getElementById("valor_contacto").value = '';
}
function mostrar1(campo){
	if (campo){
		campo.style.display="block";
		campo.style.visibility="visible";
	}
}
function ocultar(campo){
	if (campo){
		campo.style.visibility="hidden";
		campo.style.display="none";
	}
}


function cambiaTexto(pais){
	if(pais == 1){
		document.getElementById("departamento").disabled = false;		
	}
	else{
		document.getElementById("departamento").disabled = true;		
		document.getElementById("departamento").value = "";				
		document.getElementById("ciudad").value = "";						
	}
}

function actualiza_valor(valor){
	document.getElementById("valor_contacto").value = valor;		
}

function cambiar_forma_pago(valor){
	if(document.formRegistro.categoria[0].checked == true){
		mostrar1(document.getElementById("tabla_oculta"));
	}
	else{
		ocultar(document.getElementById("tabla_oculta"));
	}
}


function validadato(objeto){
	var objeto_o = objeto+"_o";
	var sw = objeto + "_sw";
	if(document.getElementById( sw ).value == 0){
		document.getElementById( objeto_o ).value = document.getElementById( objeto ).value.toUpperCase();
		document.getElementById( objeto ).value = "";
		document.getElementById( sw ).value = "1";	
		alert("Redigite el valor del campo " + objeto);
	}
}

function prueba(valor, campo){
	if(campo == 1)
		campo = "idplanes";
	if(campo == 7)
		campo = "pago";		
	document.getElementById(campo).value = valor;
}

function limpiar(){
	document.getElementById("formapago").value = '';
	document.getElementById("idplanes").value = '';
	document.getElementById("pago").value = '';	
}

function borrar(idControl){
	var imagen="<img src='images/loading.gif' /><small>Cargando formas de pago. Espere un momento por favor...</small>";
	document.getElementById( idControl ).innerHTML = imagen;
}

function resetear(categoria)
{	
	document.getElementById('idplanes').value='';
	document.getElementById('pago').value='';
	if (categoria=='Ocasional')
	{
		document.getElementById('idplanes').value=4;		
		document.getElementById('pago').value=4;
	}
	
}

//******************tooltip**************************************************************
onload=function() 
{	

	var obj = document.getElementById('jshabilitado');
	if (obj) obj.value='SI';
	
	cAyuda=document.getElementById("mensajesAyuda");

	cNombre=document.getElementById("ayudaTitulo");
	cTex=document.getElementById("ayudaTexto");
	form=document.getElementById("formRegistro");
	claseNormal="input";
	claseError="inputError";
	
	ayuda=new Array();
	ayuda["Nombre Empresa"]="Debe ingresar la razón social o el nombre de la persona natural. OBLIGATORIO.";	
	ayuda["Identificación"]="Debe ingresar el número de identificación de la empresa. Máximo 9 dígitos. Únicamente dígitos. No ingrese puntos. OBLIGATORIO.";		
	ayuda["Correo Electrónico"]="Debe ingresar mail de contacto de la empresa. Debe ser un mail válido. OBLIGATORIO.";			
	ayuda["Teléfono"]="Debe ingresar el número telefónico de la empresa. OBLIGATORIO.";
	ayuda["País"]="Seleccione el país. OBLIGATORIO.";
	ayuda["Departamento"]="Seleccione el departamento. OBLIGATORIO.";
	ayuda["Ciudad"]="Seleccione la ciudad desde donde se está inscribiendo. OBLIGATORIO.";
	ayuda["Usuario"]="Este campo es el usuario con el cual inciará sesión el administrador del sistema. No ingrese caracteres especiales. OBLIGATORIO.";
	ayuda["Password"]="Debe ser en minúscula. No ingrese caracteres especiales. OBLIGATORIO.";
	ayuda["Ingresar nuevamente Password"]="Debe ser exactamente igual al campo donde ingresó el password.  No ingrese caracteres especiales. OBLIGATORIO.";
	ayuda["Nombre Administrador"]="Nombre o nombres del usuario Administrador del Sistema. OBLIGATORIO.";
	ayuda["Apellido Administrador"]="Apellido o apellidos del usuario Admnistrador del Sistema. OBLIGATORIO.";	
	ayuda["Correo Electrónico Administrador"]="Correo electrónico de contacto del usuario Administrador del Sistema. Debe ser un mail válido . OBLIGATORIO.";		
	ayuda["Contacto"]="Debe seleccionar la forma como conoció a Servinformación. OBLIGATORIO.";		
	ayuda["Captcha"]="Este es un código de seguridad, para evitar el ingreso de mensajes duplicados. Tenga en cuenta Mayusculas y Minusculas. OBLIGATORIO.";	
	ayuda["Titular Cuenta"]="Debe ingresar el nombre de la persona responsable de la cuenta, desde la cual se va a hacer el descuento. OBLIGATORIO.";		
	ayuda["Identificación Titular"]="Debe ingresar el tipo y el número del documento de identificación. OBLIGATORIO.";			
	ayuda["Banco"]="Seleccione la Entidad Financiera. OBLIGATORIO.";
	ayuda["Número de Cuenta"]="Ingrese el número de la cuenta de la cuenta desde la cual se va a hacer el descuento.OBLIGATORIO.";
	ayuda["Valor del Descuento"]="Valor va a ser descontado del número de cuenta ingresado.OBLIGATORIO.";
	ayuda["Tipo Identificación"]="Tipo de Identificación del Cliente. OBLIGATORIO.";
	ayuda["Valor Crédito"]="Valor va a ser descontado de la tarjeta de crédito. El valor debe ser mayor a $9.999 y menor a $500.001. OBLIGATORIO.";
	ayuda["Identificación Usuario"]="Identificación del usuario titular de la tarjeta de crédito. OBLIGATORIO.";	
	ayuda["Nombre"]="Nombre del usuario titular de la tarjeta de crédito. OBLIGATORIO.";		
	ayuda["Correo Electrónico"]="Correo Electrónico del usuario titular de la tarjeta de crédito. Debe ser un mail válido. OBLIGATORIO.";	
	ayuda["Teléfono Usuario"]="Número Telefónico del usuario titular de la tarjeta de crédito. OBLIGATORIO.";
	ayuda["Su Nombre"]="Debe ingresar un nombre . OBLIGATORIO.";
	ayuda["Su Empresa"]="Debe ingresar el nombre de su empresa. OBLIGATORIO.";
	ayuda["Su email"]="Debe ingresar un email. OBLIGATORIO.";
	ayuda["Su ciudad"]="Debe ingresar la ciudad desde la cual está ingresando al portal. OBLIGATORIO.";	
	ayuda["Sector"]="Debe seleccionar el sector al que corresponde su empresa. OBLIGATORIO.";	
	
	
	
}

if(navigator.userAgent.indexOf("MSIE")>=0) navegador=0;
else navegador=1;

function muestraAyuda(event, campo){
	colocaAyuda(event);
	
	if(navegador==0) { 
		document.attachEvent("onmousemove", colocaAyuda); 
		document.attachEvent("onmouseout", ocultaAyuda); 
	}
	else {
		document.addEventListener("mousemove", colocaAyuda, true);
		document.addEventListener("mouseout", ocultaAyuda, true);
	}
	
	cNombre.innerHTML=campo;
	cTex.innerHTML=ayuda[campo];
	cAyuda.style.display="block";
}

function colocaAyuda(event){
	if(navegador==0){
		var corX=window.event.clientX+document.documentElement.scrollLeft;
		var corY=window.event.clientY+document.documentElement.scrollTop;
	}
	else
	{
		var corX=event.clientX+window.scrollX;
		var corY=event.clientY+window.scrollY;
	}
	cAyuda.style.top=corY+20+"px";
	cAyuda.style.left=corX+15+"px";
}

function ocultaAyuda(){
	cAyuda.style.display="none";
	if(navegador==0){
		document.detachEvent("onmousemove", colocaAyuda);
		document.detachEvent("onmouseout", ocultaAyuda);
	}
	else 
	{
		document.removeEventListener("mousemove", colocaAyuda, true);
		document.removeEventListener("mouseout", ocultaAyuda, true);
	}
}

function mostrarAyuda(imagen){
	document.getElementById( imagen ).style.display="block";
	document.getElementById( imagen ).style.visibility="visible";
}
function ocultarAyuda(imagen){
	document.getElementById( imagen ).style.display="none";
	document.getElementById( imagen ).style.visibility="hidden";
}
function campoError(campo){
	if((campo.disabled == false)&&(campo.type != "hidden")){
		campo.className=claseError;
		error=1;
	}
}
function muestraMensaje(mensaje,error){
	if(document.getElementById("pais")){
		document.getElementById("pais").style.visibility="hidden";
		document.getElementById("departamento").style.visibility="hidden";
		document.getElementById("ciudad").style.visibility="hidden";
		document.getElementById("tipoid").style.visibility="hidden";
	}
	if (divMensaje) divMensaje.innerHTML=mensaje;
	else alert(error);
	if (divTransparente) divTransparente.style.display="block";
}
function validarcamponumerico(e) {
	if(!e) var e = window.event;

	if (e.keyCode) 
		key  = e.keyCode;
	else if (e.which) 
		key = e.which;
	
	if (key != 13 && key != 8 && key != 9){
		if (key < 48 || key > 57){
			alert("Debe ingresar dígitos únicamente!");		
			return false;
		}
		if ((key == 8) || (key ==0) || (key ==13)){
			return true;
		}
  }
  return true;
}

function validartexto(e) {
	if(!e) var e = window.event;

	if (e.keyCode) 
		key  = e.keyCode;
	else if (e.which) 
		key = e.which;

	if ((key != 13)&(key != 32)&(key != 9)&(key != 225)&(key != 233)&(key != 237)&(key != 243)&(key != 250)){
	 if ((key <65 || key >90)&(key <97 || key >122)){
		 if(key < 48 || key > 57){
			alert("No ingrese caracteres especiales.");
			return (false);
		 }
	 }  
  }
  return true;
}

function ocultaMensaje(objValue){
	divTransparente.style.display="none";
	if(document.getElementById("pais")){
		document.getElementById("pais").style.visibility="visible";
		document.getElementById("departamento").style.visibility="visible";
		document.getElementById("ciudad").style.visibility="visible";
		document.getElementById("tipoid").style.visibility="visible";
	}
}
//******************fin tooltip**************************************************************
function digitoVerificacion(){
	nit =document.getElementById("identificacion").value;
    dv=0;
	if(document.getElementById("tipoid").value == 'NT'){
	   largo=nit.length;
	   j=0;
	   suma=0;
	   for(i=largo-1;i>=0;i--){
		  car=nit.substring(i,i+1);
		  if(j==0)
			 suma=suma+car*3;
		  else if(j==1)
			 suma=suma+car*7;
		  else if(j==2)
			 suma=suma+car*13;
		  else if(j==3)
			 suma=suma+car*17;
		  else if(j==4)
			 suma=suma+car*19;
		  else if(j==5)
			 suma=suma+car*23;
		  else if(j==6)
			 suma=suma+car*29;
		  else if(j==7)
			 suma=suma+car*37;
		  else if(j==8)
			 suma=suma+car*41;
		  else if(j==9)
			 suma=suma+car*43;
		  else if(j==10)
			 suma=suma+car*47;
		  else if(j==11)
			 suma=suma+car*53;
		  else if(j==12)
			 suma=suma+car*59;
		  else if(j==13)
			 suma=suma+car*67;
		  else if(j==14)
			 suma=suma+car*71;
		  j=j+1;
	   }
	   res=suma%11;
	   if(res==1)
		  dv=1;
	   else if(res!=0)
		  dv=11-res;
	   else dv=0;
	   document.getElementById("digver").value = dv;
	}
	else{
	   document.getElementById("digver").value = dv;
	}
}