
natives = {
  get2d: function(aCadformats){
    var ret = new Array();
    for(i=0;i<aCadformats.length;i++){
      var item = aCadformats[i];
      if (item.cad=='2d' && item.type=='native'){
        ret.push(item);
      }
    }
    return ret;
  },
  
  get3d: function(aCadformats){
    var ret = new Array();
    for(i=0;i<aCadformats.length;i++){
      var item = aCadformats[i];
      if (item.cad=='3d' && item.type=='native'){
        ret.push(item);
      }
    }
    return ret;
  }
};

neutral = {
  get2d: function(aCadformats){
    var ret = new Array();
    for(i=0;i<aCadformats.length;i++){
      var item = aCadformats[i];
      if (item.cad=='2d' && item.type=='neutral'){
        ret.push(item);
      }
    }
    return ret;
  },
  
  get3d: function(aCadformats){
    var ret = new Array();
    for(i=0;i<aCadformats.length;i++){
      var item = aCadformats[i];
      if (item.cad=='3d' && item.type=='neutral'){
        ret.push(item);
      }
    }
    return ret;
  }
};


function displayOrderForm(sCompany, sEmail, sFirstname, sLastname, sStreet, sZipcode, sCity, sCountry, sState, sPhone, sFax, sUserDescription, sCadDescription, s3Ddescription, s2Ddescription, sNativeDesc, sNeutralDesc, sSavetext, sCancelText, sMessageMissing, sMessageFormats, sSavedMessage){

//   default values
  if (typeof sUserDescription=='undefined') { sUserDescription='enter User data';};
  if (typeof sCadDescription=='undefined')  { sCadDescription='CAD formats';};
  if (typeof s3Ddescription=='undefined')   { s3Ddescription='3D';};
  if (typeof s2Ddescription=='undefined')   { s2Ddescription='2D';};
  if (typeof sNativeDesc=='undefined')      { sNativeDesc='native';};
  if (typeof sNeutralDesc=='undefined')     { sNeutralDesc='neutral';};
  if (typeof sSavetext=='undefined')        { sSavetext='save';};
  if (typeof sCancelText=='undefined')      { sCancelText='cancel';};
  if (typeof sMessageMissing=='undefined')  { sMessageMissing='Please fill out all fields marked with the "*" sign.';};
  if (typeof sMessageFormats=='undefined')  { sMessageFormats='There are only 5 CAD formats at once allowed.'; };
  if (typeof sSavedMessage=='undefined')    { sSavedMessage='Saving successful.'; };
  
  if (typeof sCompany=='undefined')         { sCompany='company';};
  if (typeof sEmail=='undefined')           { sEmail='email';};
  if (typeof sFirstname=='undefined')       { sFirstname='firstname';};
  if (typeof sLastname=='undefined')        { sLastname='lastname';};
  if (typeof sStreet=='undefined')          { sStreet='street';};
  if (typeof sZipcode=='undefined')         { sZipcode='zip-/postcode';};
  if (typeof sCity=='undefined')            { sCity='city';};
  if (typeof sCountry=='undefined')         { sCountry='country';};
  if (typeof sState=='undefined')           { sState='state';};
  if (typeof sPhone=='undefined')           { sPhone='phone';};
  if (typeof sFax=='undefined')             { sFax='fax';};

  cleanupDiv('orderform');
  var target = $('orderform');
  
//     reading saved vals from cookie
    var company   = ReadCookieByName('cad_company');
    var email     = ReadCookieByName('cad_email');
    var firstname = ReadCookieByName('cad_firstname');
    var lastname  = ReadCookieByName('cad_lastname');
    var street    = ReadCookieByName('cad_street');
    var zipcode   = ReadCookieByName('cad_zipcode');
    var city      = ReadCookieByName('cad_city');
    var country   = ReadCookieByName('cad_country');
    var state     = ReadCookieByName('cad_state');
    var phone     = ReadCookieByName('cad_phone');
    var fax       = ReadCookieByName('cad_fax');
    
    sCompany += ' *';
    sEmail += ' *';
    sFirstname += ' *';
    sLastname += ' *';
    sZipcode += ' *';
    sCity += ' *';
    sCountry += ' *';

    var txt_company   = CreateTextDOM(sCompany,   'orderform_desc');
    var txt_email     = CreateTextDOM(sEmail,     'orderform_desc');
    var txt_firstname = CreateTextDOM(sFirstname, 'orderform_desc');
    var txt_lastname  = CreateTextDOM(sLastname,  'orderform_desc');
    var txt_street    = CreateTextDOM(sStreet,    'orderform_desc');
    var txt_zipcode   = CreateTextDOM(sZipcode,   'orderform_desc');
    var txt_city      = CreateTextDOM(sCity,      'orderform_desc');
    var txt_country   = CreateTextDOM(sCountry,   'orderform_desc');
    var txt_state     = CreateTextDOM(sState,     'orderform_desc');
    var txt_phone     = CreateTextDOM(sPhone,     'orderform_desc');
    var txt_fax       = CreateTextDOM(sFax,       'orderform_desc');
    
//     creating input fields
    var cad_company   = CreateInputDOM(company,   'cad_company',    'orderform_input');
    var cad_email     = CreateInputDOM(email,     'cad_email',      'orderform_input');
    var cad_firstname = CreateInputDOM(firstname, 'cad_firstname',  'orderform_input');
    var cad_lastname  = CreateInputDOM(lastname,  'cad_lastname',   'orderform_input');
    var cad_street    = CreateInputDOM(street,    'cad_street',     'orderform_input');
    var cad_zipcode   = CreateInputDOM(zipcode,   'cad_zipcode',    'orderform_input');
    var cad_city      = CreateInputDOM(city,      'cad_city',       'orderform_input');
    var cad_country   = CreateInputDOM(country,   'cad_country',    'orderform_input');
    var cad_state     = CreateInputDOM(state,     'cad_state',      'orderform_input');
    var cad_phone     = CreateInputDOM(phone,     'cad_phone',      'orderform_input');
    var cad_fax       = CreateInputDOM(fax,       'cad_fax',        'orderform_input');
    
    var table = document.createElement('table');
      modifyAttribute(table, 'class', 'orderform_table');
      var tbody = document.createElement('tbody');
      
        var row = document.createElement('tr');
          var cell = document.createElement('td');
            modifyAttribute(cell, 'colspan', '2');
            modifyAttribute(cell, 'class', 'orderform_head');
            cell.innerHTML = sUserDescription;
          row.appendChild(cell);
        tbody.appendChild(row);
        
        
        var row = document.createElement('tr');

//           company / email
          var cell = document.createElement('td');
            modifyAttribute(cell, 'class', 'orderform_td');
            cell.appendChild(txt_company);
            cell.appendChild(cad_company);
          row.appendChild(cell);
          
          var cell = document.createElement('td');
            modifyAttribute(cell, 'class', 'orderform_td');
            cell.appendChild(txt_email);
            cell.appendChild(cad_email);
          row.appendChild(cell);
        tbody.appendChild(row)
        
//         firstname / lastname
        var row = document.createElement('tr');

          var cell = document.createElement('td');
            modifyAttribute(cell, 'class', 'orderform_td');
            cell.appendChild(txt_firstname);
            cell.appendChild(cad_firstname);
          row.appendChild(cell);
          
          var cell = document.createElement('td');
            modifyAttribute(cell, 'class', 'orderform_td');
            cell.appendChild(txt_lastname);
            cell.appendChild(cad_lastname);
          row.appendChild(cell);
        tbody.appendChild(row)
        
//         street
        var row = document.createElement('tr');

          var cell = document.createElement('td');
            modifyAttribute(cell, 'class', 'orderform_td');
            cell.appendChild(txt_street);
            cell.appendChild(cad_street);
          row.appendChild(cell);
          
//           dummy??
//           var cell = document.createElement('td');
//             cell.appendChild(txt_email);
//             cell.appendChild(cad_email);
//           row.appendChild(cell);
        tbody.appendChild(row)
        
//         zip / city
        var row = document.createElement('tr');

          var cell = document.createElement('td');
            modifyAttribute(cell, 'class', 'orderform_td');
            cell.appendChild(txt_zipcode);
            cell.appendChild(cad_zipcode);
          row.appendChild(cell);
          
          var cell = document.createElement('td');
            modifyAttribute(cell, 'class', 'orderform_td');
            cell.appendChild(txt_city);
            cell.appendChild(cad_city);
          row.appendChild(cell);
        tbody.appendChild(row)
        
//         country / state
        var row = document.createElement('tr');

          var cell = document.createElement('td');
            modifyAttribute(cell, 'class', 'orderform_td');
            cell.appendChild(txt_country);
            cell.appendChild(cad_country);
          row.appendChild(cell);
          
          var cell = document.createElement('td');
            modifyAttribute(cell, 'class', 'orderform_td');
            cell.appendChild(txt_state);
            cell.appendChild(cad_state);
          row.appendChild(cell);
        tbody.appendChild(row)
        
//         phone / fax
        var row = document.createElement('tr');

          var cell = document.createElement('td');
            modifyAttribute(cell, 'class', 'orderform_td');
            cell.appendChild(txt_phone);
            cell.appendChild(cad_phone);
          row.appendChild(cell);
          
          var cell = document.createElement('td');
            modifyAttribute(cell, 'class', 'orderform_td');
            cell.appendChild(txt_fax);
            cell.appendChild(cad_fax);
          row.appendChild(cell);
        tbody.appendChild(row)
        
        
      table.appendChild(tbody);
    target.appendChild(table);
    

//     use cad.js to get all CAD formats licensed to 'ahp'
    var aCadformats = getCADformats('ahp');

//     group CAD formats by native / neutral, 2d / 3d
    var aNatives2d = natives.get2d(aCadformats);
    var aNatives3d = natives.get3d(aCadformats);

    var aNeutral2d = neutral.get2d(aCadformats);
    var aNeutral3d = neutral.get3d(aCadformats);

    
    var neutral2d;
    var neutral3d;
    var native2d;
    var native3d;
    
    var cadTable = document.createElement('table');
      modifyAttribute(cadTable, 'class', 'cadformat_table');
      var tbody = document.createElement('tbody');
//         arrangement
//         |-------------|-------------|
//         |             |             |
//         |  Neutral2d  |  Neutral3d  |
//         |             |             |
//         |             |             |
//         |-------------|-------------|
//         |             |             |
//         |             |             |
//         |  Native2d   |  Native3d   |
//         |             |             |
//         |-------------|-------------|
        
        var row = document.createElement('tr');
          var cell = document.createElement('td');
            modifyAttribute(cell, 'colspan', '2');
            modifyAttribute(cell, 'class', 'cadformat_head');
            cell.innerHTML = sCadDescription;
          row.appendChild(cell);
        tbody.appendChild(row);

        var row = document.createElement('tr');
          var txt = document.createElement('td');
            modifyAttribute(txt, 'class', 'neutral_head1');
            modifyAttribute(txt, 'colspan', '2');
            txt.innerHTML = sNeutralDesc;
          row.appendChild(txt);
        tbody.appendChild(row);

        var row = document.createElement('tr');
          var txt = document.createElement('td');
            modifyAttribute(txt, 'class', 'neutral_head2');
            txt.innerHTML = s2Ddescription;
          row.appendChild(txt);
          var txt = document.createElement('td');
            modifyAttribute(txt, 'class', 'neutral_head2');
            txt.innerHTML = s3Ddescription;
          row.appendChild(txt);
        tbody.appendChild(row);
        
        var row = document.createElement('tr');
          neutral2d = document.createElement('td');
          modifyAttribute(neutral2d, 'id', 'neutral2d');
          modifyAttribute(neutral2d, 'class', 'neutral2d');
          row.appendChild(neutral2d);

          neutral3d = document.createElement('td');
          modifyAttribute(neutral3d, 'id', 'neutral3d');
          modifyAttribute(neutral3d, 'class', 'neutral3d');
          row.appendChild(neutral3d);
        tbody.appendChild(row);


        var row = document.createElement('tr');
          var txt = document.createElement('td');
            modifyAttribute(txt, 'colspan', '2');
            modifyAttribute(txt, 'class', 'native_head1');
            txt.innerHTML = sNativeDesc;
          row.appendChild(txt);
        tbody.appendChild(row);

        var row = document.createElement('tr');
          var txt = document.createElement('td');
            modifyAttribute(txt, 'class', 'native_head2');
            txt.innerHTML = s2Ddescription;
          row.appendChild(txt);
          var txt = document.createElement('td');
            modifyAttribute(txt, 'class', 'native_head2');
            txt.innerHTML = s3Ddescription;
          row.appendChild(txt);
        tbody.appendChild(row);
        

        var row = document.createElement('tr');
          native2d = document.createElement('td');
          modifyAttribute(native2d, 'id', 'native2d');
          modifyAttribute(native2d, 'class', 'native2d');
          row.appendChild(native2d);

          native3d = document.createElement('td');
          modifyAttribute(native3d, 'id', 'native3d');
          modifyAttribute(native3d, 'class', 'native3d');
          row.appendChild(native3d);
        tbody.appendChild(row);

      cadTable.appendChild(tbody);
    target.appendChild(cadTable);
    
    
    
//     prepare neutral2d Table
//     ------------------------
    var neutral2dTable = document.createElement('table');
      modifyAttribute(neutral2dTable, 'id', 'neutral2dTable');
      modifyAttribute(neutral2dTable, 'class', 'neutral2dTable');
      var tbody = document.createElement('tbody');
        for (i=0; i<aNeutral2d.length; i++){
          var format = aNeutral2d[i];
          
          var row = document.createElement('tr');
            modifyAttribute(row, 'class', 'formattable_row');

            var desc = document.createElement('td');
              modifyAttribute(desc, 'class', 'formattable_desc');
              desc.innerHTML = format.name; // e.g. Metafile 3D (PS3)
            row.appendChild(desc);

            var value = document.createElement('td');
              modifyAttribute(value, 'class', 'formattable_value');
              var cbox = document.createElement('input');
//                 modifyAttribute(cbox, 'class', 'formattable_checkbox');
                modifyAttribute(cbox, 'type', 'checkbox');
                modifyAttribute(cbox, 'id', format.qualifier); // e.g. META3DV2
                modifyAttribute(cbox, 'value', format.qualifier); // e.g. META3DV2
              value.appendChild(cbox);
        
              if (format.version!=''){
                var versionDiv = document.createElement('span');
                  modifyAttribute(versionDiv, 'id', format.qualifier+'_version');
                  modifyAttribute(versionDiv, 'class', 'formattable_version');
                  versionDiv.innerHTML = format.version;
                value.appendChild(versionDiv);
              }
            row.appendChild(value);
              
              
          tbody.appendChild(row);
        }
      
      neutral2dTable.appendChild(tbody);

      neutral2d.appendChild(neutral2dTable);


//     prepare neutral3d Table
//     ------------------------
    var neutral3dTable = document.createElement('table');
      modifyAttribute(neutral3dTable, 'id', 'neutral3dTable');
      modifyAttribute(neutral3dTable, 'class', 'neutral3dTable');
      var tbody = document.createElement('tbody');
        for (i=0; i<aNeutral3d.length; i++){
          var format = aNeutral3d[i];
          
          var row = document.createElement('tr');
            modifyAttribute(row, 'class', 'formattable_row');

            var desc = document.createElement('td');
              modifyAttribute(desc, 'class', 'formattable_desc');
              desc.innerHTML = format.name; // e.g. Metafile 3D (PS3)
            row.appendChild(desc);

            var value = document.createElement('td');
              modifyAttribute(value, 'class', 'formattable_value');
              var cbox = document.createElement('input');
//                 modifyAttribute(cbox, 'class', 'formattable_checkbox');
                modifyAttribute(cbox, 'type', 'checkbox');
                modifyAttribute(cbox, 'id', format.qualifier); // e.g. META3DV2
                modifyAttribute(cbox, 'value', format.qualifier); // e.g. META3DV2
              value.appendChild(cbox);
        
              if (format.version!=''){
                var versionDiv = document.createElement('span');
                  modifyAttribute(versionDiv, 'id', format.qualifier+'_version');
                  modifyAttribute(versionDiv, 'class', 'formattable_version');
                  versionDiv.innerHTML = format.version;
                value.appendChild(versionDiv);
              }
            row.appendChild(value);
              
              
          tbody.appendChild(row);
        }
      
      neutral3dTable.appendChild(tbody);

      neutral3d.appendChild(neutral3dTable);








//     prepare native2d Table
//     ------------------------
    var native2dTable = document.createElement('table');
      modifyAttribute(native2dTable, 'id', 'native2dTable');
      modifyAttribute(native2dTable, 'class', 'native2dTable');
      var tbody = document.createElement('tbody');
        for (i=0; i<aNatives2d.length; i++){
          var format = aNatives2d[i];
          
          var row = document.createElement('tr');
            modifyAttribute(row, 'class', 'formattable_row');

            var desc = document.createElement('td');
              modifyAttribute(desc, 'class', 'formattable_desc');
              desc.innerHTML = format.name; // e.g. Metafile 3D (PS3)
            row.appendChild(desc);

            var value = document.createElement('td');
              modifyAttribute(value, 'class', 'formattable_value');
              var cbox = document.createElement('input');
//                 modifyAttribute(cbox, 'class', 'formattable_checkbox');
                modifyAttribute(cbox, 'type', 'checkbox');
                modifyAttribute(cbox, 'id', format.qualifier); // e.g. META3DV2
                modifyAttribute(cbox, 'value', format.qualifier); // e.g. META3DV2
              value.appendChild(cbox);
        
              if (format.version!=''){
                var versionDiv = document.createElement('span');
                  modifyAttribute(versionDiv, 'id', format.qualifier+'_version');
                  modifyAttribute(versionDiv, 'class', 'formattable_version');
                  versionDiv.innerHTML = format.version;
                value.appendChild(versionDiv);
              }
            row.appendChild(value);
              
              
          tbody.appendChild(row);
        }
      
      native2dTable.appendChild(tbody);

      native2d.appendChild(native2dTable);


//     prepare native3d Table
//     ------------------------
    var native3dTable = document.createElement('table');
      modifyAttribute(native3dTable, 'id', 'native3dTable');
      modifyAttribute(native3dTable, 'class', 'native3dTable');
      var tbody = document.createElement('tbody');
        for (i=0; i<aNatives3d.length; i++){
          var format = aNatives3d[i];
          
          var row = document.createElement('tr');
            modifyAttribute(row, 'class', 'formattable_row');

            var desc = document.createElement('td');
              modifyAttribute(desc, 'class', 'formattable_desc');
              desc.innerHTML = format.name; // e.g. Metafile 3D (PS3)
            row.appendChild(desc);

            var value = document.createElement('td');
              modifyAttribute(value, 'class', 'formattable_value');
              var cbox = document.createElement('input');
//                 modifyAttribute(cbox, 'class', 'formattable_checkbox');
                modifyAttribute(cbox, 'type', 'checkbox');
                modifyAttribute(cbox, 'id', format.qualifier); // e.g. META3DV2
                modifyAttribute(cbox, 'value', format.qualifier); // e.g. META3DV2
              value.appendChild(cbox);
        
              if (format.version!=''){
                var versionDiv = document.createElement('span');
                  modifyAttribute(versionDiv, 'id', format.qualifier+'_version');
                  modifyAttribute(versionDiv, 'class', 'formattable_version');
                  versionDiv.innerHTML = format.version;
                value.appendChild(versionDiv);
              }
            row.appendChild(value);
              
              
          tbody.appendChild(row);
        }
      
      native3dTable.appendChild(tbody);

      native3d.appendChild(native3dTable);

    var footerTable = document.createElement('table');
      modifyAttribute(footerTable, 'class', 'footer_table');
      var tbody = document.createElement('tbody');
        var row = document.createElement('tr');
//           modifyAttribute(row, 'class', 'footer_button_row');
          var cell = document.createElement('td');
            modifyAttribute(cell, 'class', 'footer_button');

            var btn = CreateButtonDOMJS(sCancelText, 'cancel();');
            cell.appendChild(btn);
            
            var spacer = document.createElement('span');
              spacer.innerHTML = convertHTML('&nbsp;');
            cell.appendChild(spacer);

            var btn = CreateButtonDOMJS(sSavetext, 'saveSettings(\'' +sMessageMissing+ '\', \'' +sMessageFormats+ '\', \'' +sSavedMessage+ '\');');
            cell.appendChild(btn);

            

          row.appendChild(cell);
        tbody.appendChild(row);
      footerTable.appendChild(tbody);
    target.appendChild(footerTable);
    
    
  document.getElementById('btn_send_cad').onclick = function() // override button event handler
  {
    if(saveSettings(sMessageMissing, sMessageFormats, sSavedMessage)) // save settings, and if user data is correct ..
    {
      
      // gsOrderCadDataFunction is defined within 'assistant_functions.js'
      // a value is assigned to this variable by the function addbasketOptionsButtons(...)
      
      eval(gsOrderCadDataFunction); // order cad data
      
    }
  }
  
  var aSelectedFormats = ReadCookieByName('cad_formats').split('|');
  for (i=0; i<aSelectedFormats.length; i++){
    var ele = aSelectedFormats[i];
    if (ele!=''){
      $(ele).checked=true;
    }
  }
  
  
}

function orderFormFilledCorrectly(){
  
  var val_company   = ReadCookieByName('cad_company');
  var val_email     = ReadCookieByName('cad_email');
  var val_firstname = ReadCookieByName('cad_firstname');
  var val_lastname  = ReadCookieByName('cad_lastname');
  var val_zipcode   = ReadCookieByName('cad_zipcode');
  var val_city      = ReadCookieByName('cad_city');
  var val_country   = ReadCookieByName('cad_country');
  var val_formats   = ReadCookieByName('cad_formats');
  
  if (val_company=='' || val_email=='' || val_firstname=='' || val_lastname=='' || val_zipcode=='' || val_city=='' || val_country=='' || val_formats==''){
    return false;
  }else{
    return true;
  }
}


function cancel()
{

  if ( orderFormFilledCorrectly() ) // if order form was filled in correctly
  {
    
    // gsOrderCadDataFunction is defined within 'assistant_functions.js'
    // a value is assigned to this variable by the function addbasketOptionsButtons(...)
    
    document.getElementById('btn_send_cad').onclick = function(){eval(gsOrderCadDataFunction);} // override button event handler
    
  }
  else
  {
    
    // gsEnterUserdataFunction is defined within 'assistant_functions.js'
    // a value is assigned to this variable by the function addbasketOptionsButtons(...)
    
    document.getElementById('btn_send_cad').onclick = function(){eval(gsEnterUserdataFunction);} // override button event handler
    
  }
  
  cleanupDiv('orderform');
  
}

function saveSettings(sMessage, sMessageFormats, sSavedMessage){
  if (typeof sMessage=='undefined')         { sMessage='Please fill out all fields marked with the "*" sign.'; };
  if (typeof sMessageFormats=='undefined')  { sMessageFormats='There are only 5 CAD formats at once allowed.'; };
  if (typeof sSavedMessage=='undefined')    { sSavedMessage='Saving successful.'; };
  
  
  
  var val_company   = $('cad_company').value;
  var val_email     = $('cad_email').value;
  var val_firstname = $('cad_firstname').value;
  var val_lastname  = $('cad_lastname').value;
  var val_street    = $('cad_street').value;
  var val_zipcode   = $('cad_zipcode').value;
  var val_city      = $('cad_city').value;
  var val_country   = $('cad_country').value;
  var val_state     = $('cad_state').value;
  var val_phone     = $('cad_phone').value;
  var val_fax       = $('cad_fax').value;
  
  if (val_company=='' || val_email=='' || val_firstname=='' || val_lastname=='' || val_zipcode=='' || val_city=='' || val_country==''){
    alert(sMessage);
    return(false); // return no success (userdata incomplete)
  }

  if (cookieWriteAllowed()==true){
    WriteCookie('cad_company', val_company, ExpirationTime);
    WriteCookie('cad_email', val_email, ExpirationTime);
    WriteCookie('cad_firstname', val_firstname, ExpirationTime);
    WriteCookie('cad_lastname', val_lastname, ExpirationTime);
    WriteCookie('cad_street', val_street, ExpirationTime);
    WriteCookie('cad_zipcode', val_zipcode, ExpirationTime);
    WriteCookie('cad_city', val_city, ExpirationTime);
    WriteCookie('cad_country', val_country, ExpirationTime);
    WriteCookie('cad_state', val_state, ExpirationTime);
    WriteCookie('cad_phone', val_phone, ExpirationTime);
    WriteCookie('cad_fax', val_fax, ExpirationTime);
  }else{
    writeCookiePopup('cad_company', val_company, ExpirationTime);
    writeCookiePopup('cad_email', val_email, ExpirationTime);
    writeCookiePopup('cad_firstname', val_firstname, ExpirationTime);
    writeCookiePopup('cad_lastname', val_lastname, ExpirationTime);
    writeCookiePopup('cad_street', val_street, ExpirationTime);
    writeCookiePopup('cad_zipcode', val_zipcode, ExpirationTime);
    writeCookiePopup('cad_city', val_city, ExpirationTime);
    writeCookiePopup('cad_country', val_country, ExpirationTime);
    writeCookiePopup('cad_state', val_state, ExpirationTime);
    writeCookiePopup('cad_phone', val_phone, ExpirationTime);
    writeCookiePopup('cad_fax', val_fax, ExpirationTime);
  }

  var cBoxes = document.getElementsByTagName('input');
  var aSelectedFormats = new Array();
  for (i=0; i<cBoxes.length; i++){
    var ele = cBoxes[i];
    if (ele.getAttribute('type') == 'checkbox' && ele.checked==true){
        aSelectedFormats.push( ele.getAttribute('value') );
    }
  }
  
//   check the number of selected CAD formats
  if((aSelectedFormats.length>5)||(aSelectedFormats.length<1))
  {
    alert(sMessageFormats);
    return(false); // return no success (not enough / too many cad formats selected)
  }
  
  var sFormatsCookie = aSelectedFormats.join('|');
  
  if (cookieWriteAllowed()==true){
    WriteCookie('cad_formats', sFormatsCookie, ExpirationTime);
  }else{
    writeCookiePopup('cad_formats', sFormatsCookie, ExpirationTime);
  }
  alert(sSavedMessage);
  
  
  // gsOrderCadDataFunction is defined within 'assistant_functions.js'
  // a value is assigned to this variable by the function addbasketOptionsButtons(...)
  
  document.getElementById('btn_send_cad').onclick = function(){eval(gsOrderCadDataFunction);} // override button event handler
  
  
  cleanupDiv('orderform');
  return(true); // success (cad data may be ordered)
  
}




