function check_form(f) {

  var error = "";
  var go = true;

  // not the best way to write this, but should be easy enough to understand and modify

  /*
    Shipping is required for payment by credit card orders due to the way netNet handles 
    gathering billing info. It's all done on thier site, but they DON'T collect specific shipping info
    So we'll have to make people enter shipping here, even if they then have to enter it again on NelNets side 
    as the billing info. Which is kind of lame, but I can't really think of another way
  */
  if (f.shipfirst.value == '') {
    error += "Please enter a shipping First name\n";
    go = false;
  }
  if (f.shiplast.value == '') {
    error += "Please enter  a shipping Last name\n";
    go = false;
  }
  if (f.shipaddress1.value == '') {
    error += "Please enter a shipping Address\n";
    go = false;
  } 
  if (f.shipcity.value == '') {
    error += "Please enter a shipping City\n";
    go = false;
  } 
  if (f.shipstate.value == '') {
    error += "Please enter a shipping State/Province or Region\n";
    go = false;
  }
  if (f.shipzip.value == '') {
    error += "Please enter a shipping Postal Code\n";
    go = false;
  }
  if (f.shipcn.value == '') {
    error += "Please enter a shipping Country\n";
    go = false;
  }


  if (go == false) {
    alert(error);
  }

  return go;

}

function swap_state_input (state_list) {

  /* 
  because we can now process international credit cards, we need to make some change in the addAddress form
  and get rid of the state pulldown for non-us orders. This accomplishes that
  */

  var index = document.f.shipcn.selectedIndex;
  var country = document.f.shipcn.options[index].value;

  if (country == 'United States') {
    state = document.getElementById('city_state');
    state.innerHTML = '<label for="shipcity">City/State</label><input type="text" id="shipcity" name="shipcity" size="15" maxlength="25" /><select id="shipstate" name="shipstate">'+ state_list + '</select>';
  } else {
    state = document.getElementById('city_state');
    state.innerHTML = '<label for="shipcity">City</label><input type="text" id="shipcity" name="shipcity" size="15" maxlength="25" /> <br /> <label for="shipstate">Province/Region</label> <input type="text" id="shipstate" name="shipstate" size="15" maxlength="25" />';
  }



}

  

/*
Start old POD javascript (I think we're not using any of this stuff anymore)
*/


// if all qtys are 0, don't submit update form AND revert the changed pull-down it's previous count

function formValidate( thisForm )
{
    var allOK = parseInt("0", 10);

    var ln = ( thisForm.elements.length - 1 );
                        
    for ( n = 0; n <= ln; n++ )
    {            
        var str = String( thisForm.elements[n].name );
        var pattern = /binding.*cnt/i;
        
        if ( str.match(pattern) ) 
        { 
            allOK =  allOK + parseInt(thisForm.elements[n].value, 10) ;
        } 
    }        

	if ( allOK == 0 )
	{
		/* if the select values are all zero, do nothing */
		return false;
    }
    else 
    { 
        return true;
    }
}

function getBindingCountsTotal( )
{
    var formCount = ( document.forms.length - 1 );
    var allOK = 0;
    var anchor = '';
        
    /* loop through all forms */
    for ( tform = 0; tform <= formCount; tform++ )
    {
        var thisFormOK = parseInt("0", 10);
                
        var ln = ( document.forms[tform].elements.length - 1 );
        
        /* examine update forms */
        if ( document.forms[tform].name == 'updateForm' )
        {
            for ( n = 0; n <= ln; n++ )
            {            
                    var str = String( document.forms[tform].elements[n].name );
                    var pattern = /binding.*cnt/i;
                    
                    if ( str.match(pattern) ) 
                    { 
                        thisFormOK =  thisFormOK + parseInt(document.forms[tform].elements[n].value, 10) ;
                        allOK =  allOK + parseInt(document.forms[tform].elements[n].value, 10) ;
                        anchor = document.forms[tform].elements.idno.value;
                    } 
            }
            
            /* Bail at the first occurrence of an "updateForm" set to all zeros */
            if ( thisFormOK == 0 ) 
            { 
                //alert( anchor );
                var returnArray = new Array( thisFormOK, anchor );
                return returnArray;
                break;
            }
            else
            {
                continue;
            }
        }
        /* skip other forms */
        else 
        { 
            continue; 
        }
    }
    
    /* none of the forms had zero sums */
    var toReturnArray = new Array( allOK, anchor );
    return toReturnArray;
}


function warnAboutPrintForm() 
{

     var input = confirm( "You are going to a print-only form intended for fax or postal mail.\nThis will terminate your order. Proceed?" )
     if ( input == true ) 
     { 
         return true; 
     }
     else 
     {
         return false;
     }

}


/* or the first name input so user doesn't fill out form then have to reload */
/* and the 'proceed' to buttons */
function checkBindingCounts()
{
    var resultArray = getBindingCountsTotal( );
    var  status = resultArray[0];
    var  anchor = resultArray[1] ;    
    
    if ( status == 0 ) 
    { 
        alert( "Warning: your quantities are set to zero.\nPlease set the number(s) for the desired binding(s).\n" );
        /* Safari/KHTML browsers reload on window.location.hash call */
        agent = navigator.userAgent.toLowerCase();
        
        var str = String( navigator.userAgent.toLowerCase() );
        var pattern = /khtml/;
        if ( str.match(pattern) ) 
        {
            return false;
        }
        /* non KHTML browsers: */
        else 
        {
            window.location.hash = anchor;
            return false;
        }
    }
    else
    {
        /* all updateForm forms total >= 1 */
        return true;
    }
}



function show(object) 
{
  if (document.getElementById) 
  {
    document.getElementById(object).style.visibility = 'visible';
  } 
  else if (document.layers && document.layers[object] != null) 
  {
    document.layers[object].visibility = 'show';
  } 
  else if (document.all) 
  {
    document.all[object].style.visibility = 'visible';
  }
}

function hide(object) 
{
  if (document.getElementById) 
  {
    document.getElementById(object).style.visibility = 'hidden';
  } 
  else if (document.layers && document.layers[object] != null) 
  {
    document.layers[object].visibility = 'hide';
  } 
  else if (document.all) 
  {
    document.all[object].style.visibility = 'hidden';
  }
}


