/******************************************************************************/
/***********************Hashmap Implementation for Javascript******************/
/******************************************************************************/

function Map()
{
    // members
    this.keyArray = new Array(); // Keys
    this.valArray = new Array(); // Values
        
    // methods
    this.put = put;
    this.get = get;
    this.size = size;  
    this.clear = clear;
    this.keySet = keySet;
    this.valSet = valSet;
    this.showMe = showMe;   // returns a string with all keys and values in map.
    this.findIt = findIt;
    this.remove = remove;
}

function put( key, val )
{
    var elementIndex = this.findIt( key );
    
    if( elementIndex == (-1) )
    {
        this.keyArray.push( key );
        this.valArray.push( val );
    }
    else
    {
        this.valArray[ elementIndex ] = val;
    }
}

function get( key )
{
    var result = null;
    var elementIndex = this.findIt( key );

    if( elementIndex != (-1) )
    {   
        result = this.valArray[ elementIndex ];
    }  
    
    return result;
}

function remove( key )
{
    var result = null;
    var elementIndex = this.findIt( key );

    if( elementIndex != (-1) )
    {
        this.keyArray = this.keyArray.removeAt(elementIndex);
        this.valArray = this.valArray.removeAt(elementIndex);
    }  
    
    return ;
}

function size()
{
    return (this.keyArray.length);  
}

function clear()
{
    for( var i = 0; i < this.keyArray.length; i++ )
    {
        this.keyArray.pop(); this.valArray.pop();   
    }
}

function keySet()
{
    return (this.keyArray);
}

function valSet()
{
    return (this.valArray);   
}

function showMe()
{
    var result = "";
    
    for( var i = 0; i < this.keyArray.length; i++ )
    {
        result += "Key: " + this.keyArray[ i ] + "\tValues: " + this.valArray[ i ] + "\n";
    }
    return result;
}

function findIt( key )
{
    var result = (-1);

    for( var i = 0; i < this.keyArray.length; i++ )
    {
        if( this.keyArray[ i ] == key )
        {
            result = i;
            break;
        }
    }
    return result;
}

function removeAt( index )
{
  var part1 = this.slice( 0, index);
  var part2 = this.slice( index+1 );

  return( part1.concat( part2 ) );
}
Array.prototype.removeAt = removeAt;
/******************************************************************************/

var errorCodes = new Map();
/*User errors*/
errorCodes.put("USR-030201","Please enter valid Credit Card Number or Expiration Date");

/*System errors*/
errorCodes.put("SYS-010201","Communication to one of our servers is timed out.Please try again later."); 

/* Application errors */
errorCodes.put("APP-INV-001","Application error encountered");

errorCodes.put("APP-REM-001","Application error encountered");

errorCodes.put("selfService.application.error","System is currently not available. We regret any inconvenience that this may have caused. Please try again later.");


errorCodes.put("USR-002","No Billing Address Exist.Please Select a different Account Id.");


errorCodes.put("APP-ACC-001","Application error encountered");


/* credit card validation */
errorCodes.put("USR-020201","Please enter Credit Card details.");
errorCodes.put("USR-020202","Please enter Credit Card details.");
errorCodes.put("USR-020203","Please enter a Valid Name on Credit Card.");
errorCodes.put("USR-020204","Please enter a valid Expiration Date(Month) of Credit Card.");
errorCodes.put("USR-020205","Please enter a valid Expiration Date of Credit Card.");
errorCodes.put("USR-020206","Please enter a valid Expiration Date(Year) of Credit Card.");
errorCodes.put("USR-020207","Please enter your Credit Card number.");
errorCodes.put("USR-020208","Please enter a valid Credit Card number.");
errorCodes.put("USR-020209","Please enter your Credit Card type.");
errorCodes.put("USR-020210","Please Select Valid Credit Card type.");
errorCodes.put("USR-020211","Please enter your CVV(or CID) code.");
errorCodes.put("USR-020212","Please enter a valid CVV(or CID) Code.");


errorCodes.put("USR-003","The Billing Address is not updated sucessfully, because of the Service Error. Please retry your request again later.")

errorCodes.put("USR-020301","Credit card charge amount is required.");
errorCodes.put("USR-020302","Credit card charge amount is invalid.");
errorCodes.put("USR-020303","Credit card charge amount is invalid.");
errorCodes.put("USR-020304","Please select Your Credit Card billing address(country).");
errorCodes.put("USR-020305","Please select valid Credit Card billing address(country).");

errorCodes.put("USR-020501","Please enter Credit Card billing address.");
errorCodes.put("USR-020502","Please enter Credit Card billing address(street name/number).");
errorCodes.put("USR-020503","Please enter Credit Card billing address(city).");
errorCodes.put("USR-020504","Please enter Credit Card billing address(state/province).");
errorCodes.put("USR-020505","Please enter your Credit Card billing address(zipcode).");
errorCodes.put("USR-020506","Please enter a valid Credit Card billing address(zipcode).");
errorCodes.put("USR-020507","Please enter Credit Card billing address(country).");
errorCodes.put("USR-020508","Please select valid Credit Card billing address(country).");
errorCodes.put("USR-020213","Please enter valid Credit Card number or Expiration Date.");
errorCodes.put("buyOnline.default.errormsg","Please enter valid information.");

errorCodes.put("USR-030205","Mandatory fields required");
errorCodes.put("USR-030209","Insufficient Funds");
errorCodes.put("USR-030215","Invalid Credit Card Type");
errorCodes.put("USR-030216","Invalid Credit Card expiration date");
errorCodes.put("USR-030217","Invalid Credit Card Number");
errorCodes.put("USR-030218","Invalid Credit Card Type or Number. ");
errorCodes.put("USR-030219","Invalid Amount. Amount should be greater than Zero.");
errorCodes.put("USR-030220","Invalid Credit Card number or expiry date");
errorCodes.put("USR-030221","We are sorry; Our online system does not support the currency and card type you have selected. We apologies for the inconvenience. Please contact support at 866-399-3239 to make payment.");






