
// Global Variables
if ( typeof App        == 'undefined' ) { App        = ''; }
if ( typeof DefaultKey == 'undefined' ) { DefaultKey = 'VDM software copyright 2002'; }
// Login
function SaveLogin() {
  aDate = new Date();  aDate.setDate( aDate.getDate() + 365 );   
  F = document.forms[ 'cart_form' ]; 
  if ( F != undefined ) {
    V = F.elements[ 'Cart_ID'    ].value;  if ( V == undefined ) { V = '0'; }  document.cookie='Cart_ID='    + V + '; expires=' + aDate;
    V = F.elements[ 'Cart_OID'   ].value;  if ( V == undefined ) { V = '0'; }  document.cookie='Cart_OID='   + V + '; expires=' + aDate;
    V = F.elements[ 'Cart_PWD'   ].value;  if ( V == undefined ) { V = '';  }  document.cookie='Cart_PWD='   + V + '; expires=' + aDate;
    V = F.elements[ 'Cart_eMail' ].value;  if ( V == undefined ) { V = '';  } 
    if ( V.indexOf( '@' ) == - 1 ) { V = ''; }  document.cookie='Cart_eMail=' + V + '; expires=' + aDate; 
    A = F.elements[ 'EMAIL' ];  
    if ( A != undefined ) {
      V = A.value;  if ( V == undefined ) { V = '';  } 
      if ( V.indexOf( '@' ) == - 1 ) { V = ''; }  document.cookie='Alt_eMail=' + V + '; expires=' + aDate;
    } 
    A = F.elements[ 'Buy_DIV' ];  
    if ( A != undefined ) {
      V = A.value;  if ( V == undefined ) { V = '';  }  document.cookie='Buy_DIV='  + V + '; expires=' + aDate;
    }  
    A = F.elements[ 'Buy_DIV' ];  
    if ( A != undefined ) {
      V = A.value;  if ( V == undefined ) { V = '';  }  document.cookie='Buy_FIND=' + V + '; expires=' + aDate;
    }
  }
}
function ClearLogin() {
  aDate = new Date();  aDate.setDate( aDate.getDate() + 365 );   
  document.cookie='Cart_ID=0;   expires=' + aDate;
  document.cookie='Cart_OID=0;  expires=' + aDate;
  document.cookie='Cart_eMail=; expires=' + aDate;
  document.cookie='Cart_PWD=;   expires=' + aDate;
//  document.cookie='Buy_DIV=;    expires=' + aDate;
//  document.cookie='Buy_FIND=;   expires=' + aDate;
}
function CheckLogin( Event ) { 
  if ( Event.keyCode == 13 ) { // Event.keyCode = 0;  
    SaveLogin();  window.navigate( App + 'cart.php' ); }
}
// Find 
function Find() {
  SaveLogin();    
  S = document.forms[ 'buy_form' ].elements[ 'FIND' ].value;
  S = App + 'cart.php?FIND=' + S;
  document.getElementById( 'cart' ).innerHTML = '<h3 align="center">Processing your request...</h3>';  window.location.href = S;
}
function FindKey( Event ) {
  if ( Event.keyCode == 13 ) { Event.keyCode = 0;  Find(); }
}
// Delete
function DelCart( ID ) {
  SaveLogin();  
  if ( confirm( 'Empty All Items' ) ) { 
    ClearLogin();
//  S = App + 'SQL.php?SQL=delete Orders where ID=' + ID + '&URL=' + App + 'cart.php';
    S = App + 'DelOrder.php?ID=' + ID + '&URL=' + App + 'cart.php';
    document.getElementById( 'cart' ).innerHTML = '<h3 align="center">Processing your request...</h3>';  
    window.location.href = S;
  }
}
function DelRow( ID ) {
  if ( confirm( 'Delete this Item' ) ) { 
//  S = App + 'SQL.php?SQL=delete OrderItems where ID=' + ID + '&URL=' + App + 'cart.php';
    S = App + 'DelRow.php?ID=' + ID + '&URL=' + App + 'cart.php';
    document.getElementById( 'cart' ).innerHTML = '<h3 align="center">Processing your request...</h3>';  
    window.location.href = S;
  }
}
// Add and update Row
function AddRow( ID ) {
  SaveLogin();    
//  F = document.forms[ 'cart_form' ];
//  if ( F != undefined ) { V = F.elements[ 'QTY_' + ID ].value; }  
  $Q = Math.round( document.getElementById( 'QTY_'   + ID ).value );
  $N =             document.getElementById( 'NAME_'  + ID ).innerText;
  $P = Math.round( document.getElementById( 'PRICE_' + ID ).innerText );
  if ( $Q == undefined || $Q == '' || $Q == $P ) { $Q = 1; } 
  if( $Q < 10 || confirm( 'Confirm Order of ' + $Q + ' ' + $N ) ) {
    $S = App + 'row_add.php?ID=' + ID + '&QTY=' + $Q + '&URL=' + App + 'cart.php';
    document.getElementById( 'cart' ).innerHTML = '<h3 align="center">Processing your request...</h3>';
    window.location.href = $S;
} }
function AddRowKey( Event, ID ) {
  if ( Event.keyCode == 13 ) { //Event.keyCode = 0;  
    AddRow( ID );  
  }
}
function UpdRow( ID ) { 
//S = "update OrderItems set Quantity=" + document.forms[ 'cart_form' ].elements[ 'QUANTITY_' + ID ].value + " where ID=" + ID;
//S = App + 'SQL.php?SQL=' + S + '&URL=' + App + 'cart.php';
  Qty = document.forms[ 'cart_form' ].elements[ 'QUANTITY_' + ID ].value;
  S = App + 'UpdRow.php?ID=' + ID + '&QTY=' + Qty + '&URL=' + App + 'cart.php';
  document.getElementById( 'cart' ).innerHTML = '<h3 align="center">Processing your request...</h3>';  window.location.href = S;
}
function UpdRowKey( Event, ID, Name ) { 
  if ( Event.keyCode == 13 ) { 
    S = document.forms[ 'cart_form' ].elements[ Name + '_' + ID ].value;
//  if ( Name == 'QUANTITY' ) { S = "update OrderItems set Quantity="      + S +  " where ID=" + ID; }
//                       else { S = "update OrderItems set " + Name + "='" + S + "' where ID=" + ID; }  
//  S = App + 'SQL.php?SQL=' + S + '&URL=' + App + 'cart.php';
    if ( Name == 'QUANTITY' ) { S = " set Quantity="      + S;       }  
                         else { S = " set " + Name + "='" + S + "'"; }
    S = App + 'UpdOrderItems.php?ID=' + ID + '&SQL=' + S + '&URL=' + App + 'cart.php';
    document.getElementById( 'cart' ).innerHTML = '<h3 align="center">Processing your request...</h3>';  
    window.location.href = S;
  }
}
// Forms and Grids
function EnterToTab( Event, Element, Skip ) {
  if ( Event.keyCode == 13 ) { 
    F = Element.form;  // Event.keyCode = 0; 
    if ( F != undefined ) {
      for ( i = 0; i < F.elements.length; i++ ) {
        if ( F.elements[ i ] == Element ) {
          if ( i < F.elements.length - Skip ) { F.elements[ i + Skip ].focus();  return; }  // Down
        }                                                                                    
      }
    }
  }
}
function Orders_EMAIL( Value ) {
  aDate = new Date();  aDate.setDate( aDate.getDate() + 365 );   
  document.cookie = 'VDM_eMail=' + Value + '; expires=' + aDate; 
}
function Orders_PASSWORD2( Value ) {
  aDate = new Date();  aDate.setDate( aDate.getDate() + 365 );   
  document.cookie = 'VDM_PWD=' + Value + '; expires=' + aDate; 
}
function UpdField( Event, Table, ID, Name, Value ) {
//S = "update " + Table + " set " + Name + "="  + Value +  " where ID=" + ID;   
//S = App + 'SQL.php?SQL=' + S + '&URL=' + document.URL.replace( '?', '<<q>>' ).replace( '&', '<<a>>' );
  S = " set " + Name + "="  + Value; 
  S = App + 'Upd' + Table + '.php?ID=' + ID + '&SQL=' + S + '&URL=' + document.URL.replace( '?', '<<q>>' ).replace( '&', '<<a>>' );
  document.getElementById( 'cart' ).innerHTML = '<h3 align="center">Processing your request...</h3>';  window.location.href = S;
}
function UpdateCell( Event, Element ) {
  if ( Event.keyCode == 13 ) {
    ID   = Element.name.substring( Element.name.lastIndexOf( '_' ) + 1 ); 
    Name = Element.name.substring( 0, Element.name.lastIndexOf( '_' ) );
    E = Element.form.elements[ 'Grid_Required' ];  if ( E != undefined ) { Required = ',' + E.value + ','; } else { Required = ' '; }
    E = Element.form.elements[ 'Grid_NoQuotes' ];  if ( E != undefined ) { NoQuotes = ',' + E.value + ','; } else { NoQuotes = ' '; }
    if ( Required.indexOf( ',' + Name + ',' ) != - 1 && ( Element.value == '' || Element.value == 'enter a required value' ) ) {
      Element.style.color = 'red';  Element.value = 'enter a required value';  Element.focus();  Element.select();  return;
      }
    else {
      Table = Element.form.elements[ 'Grid_Table' ].value;  
      try { eval( Table + '_' + Name + '("' + Element.value + '")' ); } catch( Err ) { }  // execute any custom code for that table_field
//      S = "update " + Table;
      if ( NoQuotes.indexOf( ',' + Name + ',' ) == - 1 ) 
             { S = " set " + Name + "='" + Element.value + "'"; }
        else { S = " set " + Name + "="  + Element.value;       }
//           { S = S + " set " + Name + "='" + Element.value + "' where ID=" + ID; }
//      else { S = S + " set " + Name + "="  + Element.value +  " where ID=" + ID; }
//    S = App + 'SQL.php?SQL=' + S + '&URL=' + document.URL.replace( '?', '<<q>>' ).replace( '&', '<<a>>' );
      S = App + 'Upd' + Table + '.php?ID=' + ID + '&SQL=' + S + 
                                    '&URL=' + document.URL.replace( '?', '<<q>>' ).replace( '&', '<<a>>' );
      document.getElementById( 'cart' ).innerHTML = '<h3 align="center">Processing your request...</h3>';  window.location.href = S;
    }
  }
}
function UpdateRow( ID ) {
  for ( i = 0; i < document.forms.length; i++ ) {
    F = document.forms[ i ];  Found = false;
    for ( j = 0; j < F.elements.length; j++ ) {
      E = F.elements[ j ];
      if ( E.name.substring( E.name.lastIndexOf( '_' ) + 1 ) == ID ) {
        Name = E.name.substring( 0, E.name.lastIndexOf( '_' ) );
        if ( ! Found ) { 
          Found = true;
          EE = F.elements[ 'Grid_Required' ];  if ( EE != undefined ) { Required = ',' + EE.value + ','; } else { Required = ' '; }
          EE = F.elements[ 'Grid_NoQuotes' ];  if ( EE != undefined ) { NoQuotes = ',' + EE.value + ','; } else { NoQuotes = ' '; }
          Table = F.elements[ 'Grid_Table' ].value;  S = ' set '; //S = 'update ' + Table + ' set '; 
        }
        if ( Found ) {
          if ( Required.indexOf( ',' + Name + ',' ) != - 1 && ( E.value == '' || E.value == 'enter a required value' ) ) {
            E.value = 'enter a required value';  E.focus();  E.select();  return;
            }
          else {
            if ( E.type != 'hidden' && ( E.type != 'radio' || E.checked ) ) { 
              S = S + "[" + Name + "]="; 
              if ( E.tagName == 'SELECT' ) { V = E.options[ E.selectedIndex ].text; } else { V = E.value; }
              try { eval( Table + '_' + Name + '("' + V + '")' ); } catch( Err ) { }  // execute any custom code for that table_field
              if ( NoQuotes.indexOf( ',' + Name + ',' ) == - 1 ) { S = S + "'" + V + "',"; }
                                                            else { S = S       + V +  ","; }
            }
          }
        }
      }
    }
    if ( Found ) { 
      S = S.substring( 0, S.length - 1 ); // + ' where ID=' + ID;  
//    S = App + 'SQL.php?SQL=' + S + '&URL=' + document.URL.replace( '?', '<<q>>' ).replace( '&', '<<a>>' );
      S = App + 'UpdateRow.php?ID=' + ID + '&SQL=' + S + 
                              '&URL=' + document.URL.replace( '?', '<<q>>' ).replace( '&', '<<a>>' );
      document.getElementById( 'cart' ).innerHTML = '<h3 align="center">Processing your request...</h3>';  window.location.href = S;
      return;
    }
  }
}
function UpdFieldByName( Name ) {
  for ( i = 0; i < document.forms.length; i++ ) {
    F = document.forms[ i ];  Found = false;
    for ( j = 0; j < F.elements.length; j++ ) {
      E = F.elements[ j ];  if ( E.name == Name ) { UpdateField( null, E );  return; }
    }
  }
}
function UpdateField( Event, Element ) {
  if ( Event == null || Event.keyCode == 13 ) { 
    E = Element.form.elements[ 'Form_Required' ];  if ( E != undefined ) { Required = ',' + E.value + ','; } else { Required = ' '; }
    E = Element.form.elements[ 'Form_NoQuotes' ];  if ( E != undefined ) { NoQuotes = ',' + E.value + ','; } else { NoQuotes = ' '; }
    if ( Required.indexOf( ',' + Element.name + ',' ) != - 1 && ( Element.value == '' || Element.value == 'enter a required value' ) ) {
      Element.style.color = 'red';  Element.value = 'enter a required value';  Element.focus();  Element.select();  return;
      }
    else {
      Table = Element.form.elements[ 'Form_Table' ].value;  
      try { eval( Table + '_' + Element.name + '("' + Element.value + '")' ); } catch( Err ) { }  // execute any custom code for that table_field
      ID = Element.form.elements[ 'Form_ID' ].value;  //    S = "update " + Table;
      if ( NoQuotes.indexOf( ',' + Element.name + ',' ) == - 1 ) 
             { S = " set " + Element.name + "='" + Element.value + "'"; }
        else { S = " set " + Element.name + "="  + Element.value;       }
//           { S = S + " set " + Element.name + "='" + Element.value + "' where ID=" + Element.form.elements[ 'Form_ID' ].value; }
//      else { S = S + " set " + Element.name + "="  + Element.value +  " where ID=" + Element.form.elements[ 'Form_ID' ].value; }
//    S = App + 'SQL.php?SQL=' + S + '&URL=' + document.URL.replace( '?', '<<q>>' ).replace( '&', '<<a>>' );
      S = App + 'Upd' + Table + '.php?ID=' + ID + '&SQL=' + S + 
                                    '&URL=' + document.URL.replace( '?', '<<q>>' ).replace( '&', '<<a>>' );
      document.getElementById( 'cart' ).innerHTML = '<h3 align="center">Processing your request...</h3>';  window.location.href = S;
    }
  }
}
function UpdateForm( Name, URL ) {
  F = document.forms[ Name ];  if ( URL == '' ) { URL = document.URL; } 
  if ( F == undefined ) { alert( Name + 'form not found' ); }
  else { 
    E = F.elements[ 'Form_Required' ];  if ( E != undefined ) { Required = ',' + E.value + ','; } else { Required = ' '; }
    E = F.elements[ 'Form_Excluded' ];  if ( E != undefined ) { Excluded = ',' + E.value + ','; } else { Excluded = ' '; }
    E = F.elements[ 'Form_NoQuotes' ];  if ( E != undefined ) { NoQuotes = ',' + E.value + ','; } else { NoQuotes = ' '; }
    Table = F.elements[ 'Form_Table' ].value;  S = '';  isChecked = false;     
    for ( i = 0; i < F.elements.length; i++ ) {
      E = F.elements[ i ];
      if ( E.tagName == 'SELECT' ) { V = E.options[ E.selectedIndex ].text; } else { V = E.value; }
           if( E.tagName == 'SELECT' ) { V = E.options[ E.selectedIndex ].text;  isChecked = false; } //else { V = E.value; } 
      else if( E.type == 'radio' ) {
             if( E.checked ) { V = E.value;  isChecked = true; }  // save checked value in SQL
        else if( isChecked ) { continue; }                        // ignore unchecked options if one is checked
        else {                                                    // else scan the series to see if one is checked 
          for( j = i + 1; j < F.elements.length; j++ ) {      
                 if( F.elements[ j ].name != E.name ) { break; }
            else if( F.elements[ j ].checked ) { isChecked = true;  break; } 
          } 
          if( isChecked ) { continue; } else { V = ''; }          // if none were checked flag as empty
        } 
//        if( isChecked ) alert( E.name + ' = ' + E.value ); else alert( E.name ); 
        }         
      else { V = E.value;  isChecked = false; }                   // non radio types always turn off the isCheked flag   
      if ( E.name.substring( 0, 9 ) == '_CONFIRM_' ) { 
        EE = F.elements[ E.name.substring( 9 ) ];  
        if ( E.value != EE.value ) { E.select();  E.focus();  return; } else { continue; }
      }
      if( Excluded.indexOf( ',' + E.name + ',' ) != - 1 ) { continue; } 
      if( Required.indexOf( ',' + E.name + ',' ) != - 1 && ( V == '' ) ) {
        E.parentNode.style.border = '1px solid red';  E.focus();  return;
        }
      else if( E.className == 'Required' && ( V == '' ) ) {
        E.parentNode.style.border = '1px solid red';  E.focus();  return;
        }
      else {
        E.parentNode.style.border = ''; 
        if ( ! E.readOnly && E.type != 'hidden' && ( E.type != 'radio' || E.checked ) && ( E.type != 'text' || E.defaultValue != E.value ) ) {
          S = S + "[" + E.name + "]=";  // if (  E.type == 'text' ) { alert( E.name + ' ' + E.defaultValue + '=' + E.value ); }
          try { eval( Table + '_' + E.name + '("' + V + '")' ); } catch( Err ) { }  // execute any custom code for that table_field
          V = escape( V.replace( /'/g, "''" ) );  
//        V = V.replace( /'/g, "''" );  
 //       V = V.replace( /'/g, "'+char(39)+" );  V = V.replace( /+char(39)+/g, "+char(39)+'" );
          if ( NoQuotes.indexOf( ',' + E.name + ',' ) == - 1 ) { S = S + "'" + V + "',"; }
                                                          else { S = S       + V +  ","; }
        }
      }
    }
//  if ( S != '' ) { S = 'update ' + Table + ' set ' + S.substring( 0, S.length - 1 ) + ' where ID=' + F.elements[ 'Form_ID' ].value; } 
//  S = App + 'SQL.php?SQL=' + S + '&URL=' + URL.replace( '?', '<<q>>' ).replace( '&', '<<a>>' );  
    if ( S != '' ) { 
      S = ' set ' + S.substring( 0, S.length - 1 );  ID = F.elements[ 'Form_ID' ].value; 
      S = App + 'Upd' + Table + '.php?ID=' + ID + '&SQL=' + S + 
                                    '&URL=' + URL.replace( '?', '<<q>>' ).replace( '&', '<<a>>' );  
      document.getElementById( 'cart' ).innerHTML = '<h3 align="center">Processing your request...</h3>';  
      window.location.href = S;
    }
  }
} 
function EditRowContact( ID, Index ) {
  SaveLogin();
  S = App + 'row_contact.php?LID=' + ID + '&Index=' + Index;  
  document.getElementById( 'cart' ).innerHTML = '<h3 align="center">Processing your request...</h3>';  window.location.href = S;
}
function EditRowContact2( ID, Index, Code ) {
  SaveLogin(); 
       if ( Code.indexOf( '-PROC'  ) != - 1 ) { S = App + 'row_contact1.php?LID=' + ID + '&Index=' + Index; } 
  else if ( Code.indexOf( '-ACCOM' ) != - 1 ) { S = App + 'row_contact2.php?LID=' + ID + '&Index=' + Index; } 
                                         else { S = App + 'row_contact.php?LID='  + ID + '&Index=' + Index; } 
  document.getElementById( 'cart' ).innerHTML = '<h3 align="center">Processing your request...</h3>';  window.location.href = S;
}
function UpdCheckout( Name ) {
  SaveLogin();
  F = document.forms[ 'cart_form' ];
  S = F.elements[ 'Cart_ID' ].value + '|' + F.elements[ 'Cart_OID' ].value + '|' + F.elements[ 'Cart_eMail' ].value + '|' + F.elements[ 'Cart_PWD' ].value;  
  S = 'https://cashin.ca/' + App + 'checkout.php?UID=' + S; //Encrypt64( S );  
  document.getElementById( 'cart' ).innerHTML = '<h3 align="center">Processing your request...</h3>';
  UpdateForm( Name, S ); 
}
function Checkout() {
  SaveLogin();
  F = document.forms[ 'cart_form' ];
  S = F.elements[ 'Cart_ID' ].value + '|' + F.elements[ 'Cart_OID' ].value + '|' + F.elements[ 'Cart_eMail' ].value + '|' + F.elements[ 'Cart_PWD' ].value;  
  S = 'https://cashin.ca/' + App + 'checkout.php?UID=' + S; //Encrypt64( S );  
  document.getElementById( 'cart' ).innerHTML = '<h3 align="center">Processing your request...</h3>';  window.location.href = S;
}
function UpdCheckout_ACI( Name ) {
  SaveLogin();  S = App + 'checkout.php';
  document.getElementById( 'cart' ).innerHTML = '<h3 align="center">Processing your request...</h3>';
  UpdateForm( Name, S ); 
}
function Checkout_ACI() {
  SaveLogin();  S = App + 'checkout.php';
  document.getElementById( 'cart' ).innerHTML = '<h3 align="center">Processing your request...</h3>';  window.location.href = S;
}
function Submit_SH() {
  F = document.forms[ 'cart_form' ];  if ( F != undefined ) { F.submit; }
}
function AutoSubmit_SH() {
  F = document.forms[ 'cart_form' ]; 
//  if ( F != undefined && F.elements[ 'AutoSubmit' ].value == 'T' ) { F.submit; }
}
function GetOrder() {
  SaveLogin();
  F = document.forms[ 'cart_form' ];  S = F.elements[ 'Order_ID' ].value;  
  S = 'http://clearware.net/' + App + 'order.php?OID=' + S;  
  document.getElementById( 'cart' ).innerHTML = '<h3 align="center">Processing your request...</h3>';  window.location.href = S;
}
function GetOrderKey( Event ) {
  if ( Event.keyCode == 13 ) { GetOrder(); }
}
// Obsolete
function UpdOrderKey( Event, ID, Name ) { 
  if ( Event.keyCode == 13 ) {
    if ( Name == 'DATE_START' || Name == 'DATE_STOP' ) {
      E = document.forms[ 'cart_form' ].elements[ 'o' + Name ];  Old = E.value;
 
      }
    else {    
      E = document.forms[ 'cart_form' ].elements[ Name ];  S = E.value;
      if ( E.tagName == 'SELECT' ) { S = E.options[ E.selectedIndex ].text; }   
      if ( Name == 'CARD_NUMBER' ) {
        if ( S.indexOf( '{{' ) != - 1 && S.indexOf( '}}' ) != - 1 ) { return; }  alert( '1234 5678 9012=' + Encrypt64( '1234 5678 9012' ) );
        T = '****************************************';  //S = DigitsOnly( S );
        S = T.substring( 0, S.length - 4 ) + S.substring( S.length - 4, S.length ) + '  ' + 
            String.fromCharCode( 13 ) + String.fromCharCode( 10 ) + '{{' + Encrypt64( S ) + '}}'; 
      }    
      if ( Name == 'CARD_EXPIRY' ) {
        if ( S.indexOf( '{{' ) != - 1 && S.indexOf( '}}' ) != - 1 ) { return; }     
        S = '{{' + Encrypt64( S ) + '}}';  
      }    
      if ( Name == 'CARD_CODE' ) {
        if ( S.indexOf( '{{' ) != - 1 && S.indexOf( '}}' ) != - 1 ) { return; }     
        S = '{{' + Encrypt64( S ) + '}}'; 
      }    
//    S = "update Orders set " + Name + "='" + S + "' where Contact_ID=" + ID;  
//    S = App + 'SQL.php?SQL=' + S + '&URL=' + document.URL.replace( '?', '<<q>>' ).replace( '&', '<<a>>' );
      S = " set " + Name + "='" + S + "'"; 
      S = App + 'UpdOrders.php?ID=' + ID + '&SQL=' + S + 
                             '&URL=' + document.URL.replace( '?', '<<q>>' ).replace( '&', '<<a>>' );
    }
    document.getElementById( 'cart' ).innerHTML = '<h3 align="center">Processing your request...</h3>';  window.location.href = S;
  }  
}
function UpdContact( Event, ID, Name ) {
  if ( Event.keyCode == 13 ) { 
    E = document.forms[ 'cart_form' ].elements[ Name ];  S = E.value;
    aDate = new Date();  aDate.setDate( aDate.getDate() + 365 );   
    if ( Name == 'EMAIL'     ) { document.cookie='VDM_eMail=' + S + '; expires=' + aDate; }
    if ( Name == 'PASSWORD2' ) { document.cookie='VDM_PWD='   + S + '; expires=' + aDate; }
//  S = "update Contacts set " + Name + "='" + S + "' where ID=" + ID;  
//  S = App + 'SQL.php?SQL=' + S + '&URL=' + document.URL.replace( '?', '<<q>>' ).replace( '&', '<<a>>' );
//    S = S.replace( "'", "' + char(39) + '")
    S = " set " + Name + "='" + S + "'"; 
    S = App + 'UpdContacts.php?ID=' + ID + '&SQL=' + S + 
                             '&URL=' + document.URL.replace( '?', '<<q>>' ).replace( '&', '<<a>>' );
    document.getElementById( 'cart' ).innerHTML = '<h3 align="center">Processing your request...</h3>';  window.location.href = S;
  }
}
function UpdForm( Table, ID ) {
  F = document.forms[ 'cart_form' ];  S = ' set '; //  S = 'update ' + Table + ' set ';  
  for ( i = 0; i < F.elements.length; i++ ) {
    E = F.elements[ i ];  
    if ( E.type != 'hidden' && ( E.type != 'radio' || E.checked ) ) { 
      S = S + "[" + E.name + "]="; 
      if ( E.tagName == 'SELECT' ) { S = S + "'" + E.options[ E.selectedIndex ].text + "',"; }   
                              else { S = S + "'" + E.value                           + "',"; }
    }
  }
//S = S.substring( 0, S.length - 1 ) + ' where ID=' + ID;  
//S = App + 'SQL.php?SQL=' + S + '&URL=' + document.URL.replace( '?', '<<q>>' ).replace( '&', '<<a>>' );
  S = S.substring( 0, S.length - 1 );
  S = App + 'Upd' + Table + '.php?ID=' + ID + '&SQL=' + S + 
                                '&URL=' + document.URL.replace( '?', '<<q>>' ).replace( '&', '<<a>>' );
  document.getElementById( 'cart' ).innerHTML = '<h3 align="center">Processing your request...</h3>';  window.location.href = S;
} 
// Library
function Trim( Data ) {
  while ( Data.length > 0 && Data.charAt( 0               ) == ' ' ) { Data = Data.substring( 1                  ); }
  while ( Data.length > 0 && Data.charAt( Data.length - 1 ) == ' ' ) { Data = Data.substring( 0, Data.length - 1 ); }
  return Data;
}
function DigitsOnly( Data ) {
  S = '';  
  for ( i = 0; i < Data.length; i++ ) {
    C = Data.substring( i, i + 1 );  if ( ( C >= '0' ) && ( C <= '9' ) ) { S = S + C; } 
  }
  return S;
}
// Encryption
function Encode64( Data ) {  
  S = '';  Extra = 3 - ( Data.length % 3 );  if ( Extra == 3 ) { Extra = 0 ; }
  for( i = 1; i <= Extra; i++ ) { Data = Data + '0'; }  
  Data = Data + '00' + Extra;  
  for( i = 0; i < Data.length; i = i + 3 ) {
    C = Data.substring( i, i + 3 );
    S = S + 
         String.fromCharCode( 64 + Math.floor( C.charCodeAt( 0 ) /  4 ) ) +    // first top 6 bits
         String.fromCharCode( 64 +           ( C.charCodeAt( 0 ) %  4 ) * 16 + // bottom 2 + top 4
                                   Math.floor( C.charCodeAt( 1 ) / 16 ) ) +   
         String.fromCharCode( 64 +           ( C.charCodeAt( 1 ) % 16 ) *  4 + // bottom 4 + top 2
                                   Math.floor( C.charCodeAt( 2 ) / 64 ) ) +    
         String.fromCharCode( 64 +           ( C.charCodeAt( 2 ) % 64 ) );     // bottom 6                              
  }                    
  return S;
}
function Decode64( Data ) {
  S = '';  
  for( i = 0; i < Data.length; i = i + 4 ) {
    C = Data.substring( i, i + 4 ); 
    S = S + 
         String.fromCharCode(             ( C.charCodeAt( 0 ) - 64 ) * 4 +        // first 6 bits +
                              Math.floor( ( C.charCodeAt( 1 ) - 64 ) / 16 ) )   + // then next 2 
         String.fromCharCode(             ( C.charCodeAt( 1 ) - 64 ) % 16 * 16  + // first 4 +
                              Math.floor( ( C.charCodeAt( 2 ) - 64 ) /  4 ) )   + // then next 4
         String.fromCharCode(             ( C.charCodeAt( 2 ) - 64 ) %  4 * 64  + // first 2 +
                                          ( C.charCodeAt( 3 ) - 64 ) );           // then next 6 
  }
  S = S.substr( 0, S.length - 3 - S.substr( S.length - 1 ) );  
  return S;
}
function Encrypt64a( Data, Key ) {
  Data = Encode64( Data );  
  if ( Key == '' || typeof Key == 'undefined' ) { Key = DefaultKey; }
  while ( Key.length < 16 ) { i = Math.floor( Key.length / 3 );  Key = Key + Key.substring( i, i + 1 ); }
  k = Math.floor( Key.length / 2 );  
  for ( i = 0; i < Key.length; i++ ) {  // repeat a minimum 16 times
    S = '';  
    for ( j = 0; j < Data.length; j++ ) {
      BitLen = Math.floor( ( Key.charCodeAt( k ) % 32 ) / 8 ) + 1;  
      P1 = Math.pow( 2, BitLen );  P2 = Math.pow( 2, 6 - BitLen ); 
      k = k + Key.charCodeAt( ( k + j ) % Key.length );  k = k % Key.length;
      S = S + String.fromCharCode( 64 + ( Data.charCodeAt( j ) % 64 ) / P1 +     // move Bitlen Right
                                      ( ( Data.charCodeAt( j ) % P1 ) * P2 ) );  // move 6 - Bitlen Left
    }
    Data = S;
  }
  return S;
}
function Decrypt64a( Data, Key ) {
  if ( Key == '' || typeof Key == 'undefined' ) { Key = DefaultKey; }
  while ( Key.length < 16 ) { i = Math.floor( Key.length / 3 );  Key = Key + Key.substring( i, i + 1 ); }
  k = Math.floor( Key.length / 2 );  
  for ( i = 0; i < Key.length; i++ ) {  // repeat a minimum 16 times
    S = '';  
    for ( j = 0; j < Data.length; j++ ) {
      BitLen = Math.floor( ( Key.charCodeAt( k ) % 32 ) / 8 ) + 1;  
      P1 = Math.pow( 2, BitLen );  P2 = Math.pow( 2, 6 - BitLen ); 
      k = k + Key.charCodeAt( ( k + j ) % Key.length );  k = k % Key.length;
      S = S + String.fromCharCode( 64 + ( Data.charCodeAt( j ) % 64 ) / P2 +     // move Bitlen Right
                                      ( ( Data.charCodeAt( j ) % P2 ) * P1 ) );  // move Bitlen Left
    }
    Data = S;
  }
  return Decode64( S );
}
function Encrypt64( Data ) {
  Data = Encode64( Data ); 
  S = '';  Key = 'VDM software copyright 2002';  k = Math.floor( Key.length / 2 );  
  for ( i = 0; i < Data.length; i++ ) {
    BitLen = Math.floor( ( Key.charCodeAt( k ) % 32 ) / 8 ) + 1;  
    P1 = Math.pow( 2, BitLen );  P2 = Math.pow( 2, 6 - BitLen ); 
    k = k + Key.charCodeAt( ( k + i ) % Key.length );  k = k % Key.length;
    S = S + String.fromCharCode( 64 + ( Data.charCodeAt( i ) % 64 ) / P1 +     // move Bitlen Right
                                    ( ( Data.charCodeAt( i ) % P1 ) * P2 ) );  // move 6 - Bitlen Left
  }
  return S;
}
function Decrypt64( Data ) {
  S = '';  Key = 'VDM software copyright 2002';  k = Math.floor( Key.length / 2 );  
  for ( i = 0; i < Data.length; i++ ) {
    BitLen = Math.floor( ( Key.charCodeAt( k ) % 32 ) / 8 ) + 1;  
    P1 = Math.pow( 2, BitLen );  P2 = Math.pow( 2, 6 - BitLen );
    k = k + Key.charCodeAt( ( k + i ) % Key.length );  k = k % Key.length;
    S = S + String.fromCharCode( 64 + ( Data.charCodeAt( i ) % 64 ) / P2 +     // move Bitlen Right
                                    ( ( Data.charCodeAt( i ) % P2 ) * P1 ) );  // move Bitlen Left
  }
  return Decode64( S );
}

