// JavaScript Document
<!--
var langEspanol="spa";
var langIngles="eng";
var langPortugues="por";

function getCookie(name) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) && ( name != document.cookie.substring( 0, name.length ) ) ){
		return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
}

function getLangValue(){
	var lnge = getCookie('lnge');
	if (lnge==null)
		return 'spa';
	else
		return lnge;
}

function loadjscssfile(filename, filetype){
 if (filetype=="js"){ //if filename is a external JavaScript file
  var fileref=document.createElement('script');
  fileref.setAttribute("type","text/javascript");
  fileref.setAttribute("src", filename);
 }
 else if (filetype=="css"){ //if filename is an external CSS file
  var fileref=document.createElement("link");
  fileref.setAttribute("rel", "stylesheet");
  fileref.setAttribute("type", "text/css");
  fileref.setAttribute("href", filename);
 }
 if (typeof fileref!="undefined"){
  document.getElementsByTagName("head")[0].appendChild(fileref);
 }
}


function getRadioValue(idOrName) {
        var value = null;
        var element = document.getElementById(idOrName);
        var radioGroupName = null;  
        
        // if null, then the id must be the radio group name
        if (element == null) {
                radioGroupName = idOrName;
        } else {
                radioGroupName = element.name;     
        }
        if (radioGroupName == null) {
                return null;
        }
        var radios = document.getElementsByTagName('input');
        for (var i=0; i<radios.length; i++) {
                var input = radios[ i ];    
                if (input.type == 'radio' && input.name == radioGroupName && input.checked) {                          
                        value = input.value;
                        break;
                }
        }
        return value;
}

function setCheckedRadio(idOrName, value , checked) {
        var element = document.getElementById(idOrName);
        var radioGroupName = null;  
        
        // if null, then the id must be the radio group name
        if (element == null) {
                radioGroupName = idOrName;
        } else {
                radioGroupName = element.name;     
        }
        if (radioGroupName == null) {
                return false;
        }
        var radios = document.getElementsByTagName('input');
        for (var i=0; i<radios.length; i++) {
                var input = radios[i];                               
                if (input.type == 'radio' && input.name == radioGroupName && input.value == value) {                      
                        input.checked = checked;
                        break;                        
                }
        }
        return true;
}

function Trim(Str)
{
    return(LTrim(RTrim(Str)));
}

function RTrim( Str )
{
    var theLength = Str.length
    for(pos = 0; pos < theLength; pos++)
	    if( Str.charCodeAt(pos) != 32)
		    break
    return Str.substring(pos, theLength);
}

function LTrim( Str )
{
    var theLength = Str.length
    for(pos = theLength-1; pos >= 0; pos--)
	    if( Str.charCodeAt(pos) != 32)
		    break			
    return Str.substring(0, pos+1);
}

function esEmail(Str) {
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(Str)){    
    return (true);
  } else {
    return (false);
  }
}

function notCtr(key) {
  var pressedKey = String.fromCharCode(event.keyCode).toLowerCase();
  if (event.ctrlKey && pressedKey == key) {
    event.returnValue = false;
  }
}

function onlyNumberAndPoint(key)
{
	if ((key<48 || key>57))	
	  if (key!=46)
		key = 0;				
	return key;
}	

function allowInteger(e)
  {
   var key = window.event ? e.keyCode : e.which;
   var keychar = String.fromCharCode(key);
   var reg = new RegExp("^([0-9]+)$|^([0-9]+\.[0-9]+)$")
   if (key == 8)
   {
    keychar = String.fromCharCode(key);
   }
   if (key == 13)
   {
    key=8;
    keychar = String.fromCharCode(key);     
   }
   return reg.test(keychar);
} 
   
function validTwoDecimal(event, obj)
  {
    var code = (event.which) ? event.which : event.keyCode;
    var character = String.fromCharCode(code);
 
    if ((code >= 48 && code <= 57))
    { // check digits
      if (!isNaN(obj.value))
      {        
        if (obj.value > "0")
        {    
        	var tenth = String((obj.value / 0.1)); 
            if  (tenth.indexOf(".")>0){
          		var n = Number(tenth);
          		var s = n.toFixed(2);          		        	
          		return s.indexOf(".00")>0;
          	}
        }
      }
      return true;
    }
    else if (code == 46)
    { // Check dot
      if (obj.value.indexOf(".") < 0)
      {
        if (obj.value.length == 0)
         	obj.value = "0"; 
        return true;
      }
    }
    else if (code == 8 || code == 116)
    { // Allow backspace, F5
      return true;
    }
    else if (code >=37 && code <= 40)
    { // Allow directional arrows
      return true;
    }
 
    return false;
  }
 
  function validTwoDecimalField(obj)
  { // Remove dot if last character
    if (obj.value.indexOf(".") == obj.value.length-1)
    {
      obj.value = obj.value.substring(0, obj.value.length-1)
    } // Clear text box if not a number, incase user drags/drop letter into box
    else if (isNaN(obj.value))
    {
      obj.value = "";
    }   
  }

function alertConfirm(sText)
{
	var response = window.confirm(sText);
	return response;
}

function esLargoTC( t_tc, n_tc)
{
 var cards = new Array();
 var LengthValid = false;
 var lengths = new Array (); 
 
  cards [0] = {name: "1",  // VISA
               length: "13,16", 
               prefixes: "4",
               checkdigit: true};
  cards [1] = {name: "2",  //MASTERCARD
               length: "16", 
               prefixes: "51,52,53,54,55",
               checkdigit: true};
  cards [2] = {name: "5",   //DINNERCLUB
               length: "14,16", 
               prefixes: "300,301,302,303,304,305,36,38,55",
               checkdigit: true};
  cards [3] = {name: "3",   //AmEx
               length: "15", 
               prefixes: "34,37",
               checkdigit: true};
  cards [4] = {name: "4",  //Discover
               length: "16", 
               prefixes: "6011,65",
               checkdigit: true};
  
 var cardType = -1;

  for (var i=0; i<cards.length; i++) {
    if (t_tc == cards[i].name) {
      cardType = i;
      break;
    }
  }

  lengths = cards[cardType].length.split(",");
  for (j=0; j<lengths.length; j++) {
    if (n_tc.length == lengths[j]) {
	    LengthValid = true;
		break;
		}
  }
  
  if(LengthValid == false) {
	return false;
	}
	else{
		return true;
	}
}

function esBinOkTC( t_tc, n_tc)
{
 var cards = new Array();
 var PrefixValid = false; 
 var prefix = new Array (); 
 
  cards [0] = {name: "1",          //VISA
               length: "13,16", 
               prefixes: "4",
               checkdigit: true};
  cards [1] = {name: "2",           //MASTERCARD
               length: "16", 
               prefixes: "51,52,53,54,55",
               checkdigit: true};
  cards [2] = {name: "5",             //DINNERCLUB
               length: "14,16", 
               prefixes: "300,301,302,303,304,305,36,38,55",
               checkdigit: true};
  cards [3] = {name: "3",  //AmEx
               length: "15", 
               prefixes: "34,37",
               checkdigit: true};
  cards [4] = {name: "4",   //Discover
               length: "16", 
               prefixes: "6011,65",
               checkdigit: true};
  
 var cardType = -1;

  for (var i=0; i<cards.length; i++) {
    if (t_tc.toLowerCase () == cards[i].name.toLowerCase()) {
      cardType = i;
      break;
    }
  }

  prefix = cards[cardType].prefixes.split(",");
  
  for (j=0; j<prefix.length; j++) { 
    if (n_tc.substring(0,(prefix[j].length)) == prefix[j]) {
	    PrefixValid = true;
		break;
		}
  }
  
  if(PrefixValid == false) {
	return false;
	}
	else{
		return true;
	}
}

function esModule10TC( n_tc)
{
    var cardNo = n_tc

    var checksum = 0;                                
    var j = 1;                                       
  
    // Process each digit one by one starting at the right
    var calc;
    for (i = cardNo.length - 1; i >= 0; i--) {
    
      // Extract the next digit and multiply by 1 or 2 on alternative digits.
      calc = Number(cardNo.charAt(i)) * j;
    
      // If the result is in two digits add 1 to the checksum total
      if (calc > 9) {
        checksum = checksum + 1;
        calc = calc - 10;
      }
    
      // Add the units element to the checksum total
      checksum = checksum + calc;
    
      // Switch the value of j
      if (j ==1) {j = 2} else {j = 1};
    } 
  
    // All done - if checksum is divisible by 10, it is a valid modulus 10.
    // If not, report an error.
    if (checksum % 10 != 0)  {
     return false; 
    }
	else {
		return true;
	}
}

//----------------------------------------------
//----------------------------------------------
function ShowContrato() {
	contrato = document.getElementById('ScreenContrato');
	tarjeta = document.getElementById('ScreenTc');
	
	contrato.className = "open";
	tarjeta.className = "closed";
	   
	$('msgError').update('').hide();
	$('msgErrorContrato').update('').hide();
}

function ShowTc() {
	contrato = document.getElementById('ScreenContrato');
	tarjeta = document.getElementById('ScreenTc');
	
	contrato.className = "closed";
	tarjeta.className = "open";
	
	$('msgError').update('').hide();
	$('msgErrorContrato').update('').hide();
}

//----------------------------------------------
//----------------------------------------------


function esFecha( y, m, d)
{
	m--;
	fecha = new Date(y, m, d)
	if( Number(d) == Number(fecha.getDate()) &&
		Number(m) == Number(fecha.getMonth()) &&  
		Number(y) == Number(fecha.getFullYear()) )
		return true;
	else
		return false;
}

function esMayor18( y, m, d)
{
	df = new Date();
	
	if (y < df.getFullYear() - 18)
	{return true;}
	else
	{	if (y > df.getFullYear() - 18)
		{return false;}
		else
		{	if (m < df.getMonth() )
			{return true;}
			else
			{	if (m > df.getMonth() )
				{return false;}
				else
				{	if (d < df.getDay() )
					{return true;}
					else
					{	if (d > df.getDay() )
						{return false;}
						else
						{return true;}
					}
				}
			}
		}
	}	
}

function expiracionOk( y, m)
{
	d = new Date();
	
	if( y > d.getFullYear() )
	{
		return true;
	}
	else
	{
		if( y < d.getFullYear() )
		{ 
			return false;
		}
		else
		{ 
			if( (m-1) < d.getMonth() )
			{			
				return false;
			}
			else
			{
				return true;
			}
		}	
	}	
}

function decodeJS( Str, StrCompara, StrRespYes, StrRespNo )
{
	if (Str == StrCompara)
	{
		return (StrRespYes);
	}
	else
	{
		if (StrRespNo =='idem')
		{
			return (Str);
		}
		else
		{
			return (StrRespNo);
		}
	}
}

function IsNumber(Ky)
{
	if (Ky == 13)
		return;
	if (Ky <= 45 || Ky == 47 || Ky >= 58)
		event.returnValue = false;
}

function isNumberWpoint( Str )
{
    var theLength = Str.length
    var resp = 0
    for(pos = 0; pos < theLength; pos++)
	{ 
		if( (Str.charCodeAt(pos) > 47 & Str.charCodeAt(pos) < 58) || Str.charCodeAt(pos) == 46 ) {
			resp = resp;}
		else {
			resp = resp + 1;
			break;}
	}           
    if (resp == 0) {
        return (true);}
    else {
        return (false);}        
} 

function isNumberOletras( Str )
{
    var theLength = Str.length
    var resp = 0
    for(pos = 0; pos < theLength; pos++)
	{ 
		if( (Str.charCodeAt(pos) > 47 & Str.charCodeAt(pos) < 58) || Str.charCodeAt(pos) == 46 ) {
			resp = resp;}
		else {
				if( (Str.charCodeAt(pos) > 64 & Str.charCodeAt(pos) < 91) || (Str.charCodeAt(pos) > 96 & Str.charCodeAt(pos) < 123)){
				    resp = resp;}
				else {	
					resp = resp + 1;
					break;}
			}		
	}           
    if (resp == 0) {
        return (true);}
    else {
        return (false);}        
} 



function soloLetras( Str )
{
    var theLength = Str.length
    var resp = 0
    for(pos = 0; pos < theLength; pos++)
	{ 
		if( (Str.charCodeAt(pos) > 64 & Str.charCodeAt(pos) < 91) || (Str.charCodeAt(pos) > 96 & Str.charCodeAt(pos) < 123)){
		    resp = resp;}
		else {	
			resp = resp + 1;
			break;}
	}           
    if (resp == 0) {
        return (true);}
    else {
        return (false);}        
}

function soloLetrasYblancos( Str )
{
    var theLength = Str.length
    var resp = 0
    for(pos = 0; pos < theLength; pos++)
	{ 
		if( (Str.charCodeAt(pos) > 64 & Str.charCodeAt(pos) < 91) || (Str.charCodeAt(pos) > 96 & Str.charCodeAt(pos) < 123) || (Str.charCodeAt(pos) == 32) ){
		    resp = resp;}
		else {	
			resp = resp + 1;
			break;}
	}           
    if (resp == 0) {
        return (true);}
    else {
        return (false);}        
}


function decodeJS( Str, StrCompara, StrRespYes, StrRespNo )
{
	if (Str == StrCompara)
	{
		return (StrRespYes);
	}
	else
	{
		if  (StrRespNo =='idem')
		{
			return (Str);
		}
		else
		{
			return (StrRespNo);
		}
	}
}



function onlyNumber(key)
{

	if ((key<48 || key>57))	
		key = 0;				
	return key;
}
	


var Keys = {
      BACKSPACE: 8,            TAB: 9,                  ENTER: 13,            SHIFT: 16,
      CTRL: 17,                  ALT: 18,            PAUSE: 19,            CAPS: 20,
      ESC: 27,                   PAGEUP: 33,       PAGEDN: 34,       END: 35,
      HOME: 36,                  LEFT: 37,             UP: 38,             RIGHT: 39,
      DOWN: 40,                  INSERT: 45,       DELETE: 46,       
      n0: 48,      n1: 49, n2: 50, n3: 51, n4: 52, 
      n5: 53, n6: 54,      n7: 55,      n8: 56,      n9: 57,
      A:65, B:66, C:67, D:68, E:68, F:70, G:71, H:72, I:73, J:74, K:75,
      L:76, M:77, N:78, O:79, P:80, Q:81, R:82, S:83, T:84, U:85, V:86,
      W:87, X:88, Y:89, Z:90,
      WINLEFT: 91,             WINRIGHT: 92,      SELECT: 93,       NUM0: 96,
      NUM1: 97,                   NUM2: 98,             NUM3: 99,             NUM4: 100,
      NUM5: 101,                   NUM6: 102,             NUM7: 103,             NUM8: 104,
      NUM9: 105,                   MULTIPLY: 106,       ADD: 107,             SUBTRACT: 109,
      DECIMAL: 110,             DIVIDE: 111,       F1: 112,             F2: 113,
      F3: 114,                   F4: 115,            F5: 116,             F6: 117,
      F7: 118,                   F8: 119,             F9: 120,             F10: 121,
      F11: 122,                   F12: 123,             NUMLOCK: 144,       SCROLLLOCK: 145,
      SEMICOLON: 186,       EQUAL: 187,       COMMA: 188,       DASH: 189,
      PERIOD: 190,             FORWARDSLASH: 191,                         GRAVEACCENT: 192,
      OPENBRACKET: 219,       BACKSLASH: 220,                              CLOSEBRACKET: 221,
      QUOTE: 222
};

function KeyPressEvent(eventObj)
{
      this.eventHandler = null;     		//the event handler
      this.eventElement = null;     		//the element that caused the event
      this.elementTag = "";         		//the html tag that caused the event
      this.elementID = "";          		//the id of the element
      this.element = null;          		//the actual element
      this.keyCode = 0;             		//the keycode to capture
      this.arsOnlyNumber=null;				//the arguments function OnlyNumber
      this.arsOnlyNumberAndPoint=null;		//the arguments function OnlyNumberAndPoint
            
      if( document.all )
      {
            // IE
            this.eventHandler = eventObj;
            this.eventElement = eventObj.srcElement;
            this.elementTag = eventObj.srcElement.tagName;
            this.elementID = eventObj.srcElement.name;
            this.element = eventObj.srcElement;
            this.keyCode = eventObj.keyCode;
      }
      else
      {
            // Not IE
            this.eventHandler = eventObj;
            this.eventElement = eventObj.target.srcElement;
            this.elementTag = eventObj.target.tagName;
            this.elementID = eventObj.target.name;
            this.element = eventObj.target;
            this.keyCode = eventObj.which;
            
            // Safari bug workaround
            if (this.element.nodeType == 3) 
                  targ = targ.parentNode;
      }
}

function KeyHandler()
{

      //register for the event
      if ( document.addEventListener )
            document.addEventListener("keydown", this.keyDown.bind(this), false);
      else if ( document.attachEvent )
            document.attachEvent("onkeydown", this.keyDown.bind(this));
      else
            document.onkeydown = this.keyDown.bind(this);
            
      if (document.layers) document.captureEvents(Event.KEYDOWN);
      
      if ( document.addEventListener )
            document.addEventListener("keyup", this.keyUp.bind(this), false);
      else if ( document.attachEvent )
            document.attachEvent("onkeyup", this.keyUp.bind(this));
      else
            document.onkeyup = this.keyUp.bind(this);
            
      if (document.layers) document.captureEvents(Event.KEYUP);
      
      this.onKeyDown = function(e)  // e is a KeyPressEvent object
	  {
		if (this.arsOnlyNumberAndPoint!=null) {
		    for (i = 0;i < this.arsOnlyNumberAndPoint.length;i++){
			   	if (e.elementID == this.arsOnlyNumberAndPoint[i]  
			    	 && (e.keyCode < Keys.n0 || e.keyCode>Keys.n9)
			    	 && (e.keyCode < Keys.NUM0 || e.keyCode>Keys.NUM9)
			    	 && (e.keyCode != Keys.DELETE)
			    	 && (e.keyCode != Keys.BACKSPACE)    
			    	 && (e.keyCode != Keys.TAB)    
			    	 && (e.keyCode != Keys.RIGHT)    
			    	 && (e.keyCode != Keys.LEFT)
			    	 && (e.keyCode != Keys.PERIOD)
			    	 && (e.keyCode != Keys.DECIMAL))
			        return false; //cancel the press 
			 }
	 	}
	 	
	 	if (this.arsOnlyNumber!=null) {
		 	for (i = 0;i < this.arsOnlyNumber.length;i++){
			   	if (e.elementID == this.arsOnlyNumber[i]  
			    	 && (e.keyCode < Keys.n0 || e.keyCode>Keys.n9)
			    	 && (e.keyCode < Keys.NUM0 || e.keyCode>Keys.NUM9)
			    	 && (e.keyCode != Keys.DELETE)
			    	 && (e.keyCode != Keys.BACKSPACE)    
			    	 && (e.keyCode != Keys.TAB)    
			    	 && (e.keyCode != Keys.RIGHT)    
			    	 && (e.keyCode != Keys.LEFT))
			        return false; //cancel the press			        

			 }
		}
		
	    //more information available from e
	    //e.eventHandler     //the event handler
	    //e.eventElement      //the element that caused the event
	    //e.elementTag         //the html tag that caused the event
	    //e.elementID          //the id of the element
	    //e.element           //the actual element
	    //e.keyCode             //the keycode to capture
	
	    return true;
	}
	
	this.onKeyUp = function()
	{
	   //do nothing
	   return true;
	}
}

KeyHandler.prototype.onlyNumber = function onlyNumber() 
{
	this.arsOnlyNumber = arguments;
} 


KeyHandler.prototype.onlyNumberAndPoint = function onlyNumberAndPoint() 
{
	this.arsOnlyNumberAndPoint = arguments;   
} 

KeyHandler.prototype.keyDown = function(e)
{      
      if ( typeof(this.onKeyDown) != "undefined" )
      {
            if ( !e ) e = window.event;
            var r = this.onKeyDown( new KeyPressEvent(e) );
            
            if ( r == false )
            {
              if ( window.event ) window.event.cancelBubble = true;
              if ( window.event ) window.event.returnValue = false;
              if ( e.preventDefault ) e.preventDefault();
              return false;
            }
            else
            {
              if ( window.event ) window.event.cancelBubble = false;
              if ( window.event ) window.event.returnValue = true;
              return true;
            }
      }
      else
      {
            alert("No Key Press Event Handler Found!");
      }
};

KeyHandler.prototype.keyUp = function(e)
{      
      if ( typeof(this.onKeyUp) != "undefined" )
      {
            if ( !e ) e = window.event;
            var r = this.onKeyUp( new KeyPressEvent(e) );
            
            if ( r == false )
            {
                  if ( window.event ) window.event.cancelBubble = true;
              if ( window.event ) window.event.returnValue = false;
                  if ( e.preventDefault ) e.preventDefault();
                  if ( e.stopPropagation ) e.stopPropagation();
              return false;
            }
            else
            {
                  if ( window.event ) window.event.cancelBubble = false;
              if ( window.event ) window.event.returnValue = true;
                  return true;
            }
      }
      else
      {
            alert("No Key Press Event Handler Found!");
      }
};


/*
Useage:

var kh = new KeyHandler();
kh.onKeyDown = function(e)  // e is a KeyPressEvent object
{
    if ( e.eventElement == document.getElementById("textbox1") && e.keyCode == 45 )
        return false; //cancel the press
 
    //more information available from e
    e.eventHandler     //the event handler
    e.eventElement      //the element that caused the event
    e.elementTag         //the html tag that caused the event
    e.elementID          //the id of the element
    e.element           //the actual element
    e.keyCode             //the keycode to capture

    return true;
}

kh.onKeyUp = function()
{
   //do nothing
   return true;
}
*/
//-->
