function addInputFiles(num_files)
{
    // I'm not sure which browsers this applies to
    // This try statement is so that this function works
    // ...in Mozilla browsers
    try{
        new_input_files.innerHTML = printNewInputFiles(num_files);
    }catch (e){
        try{
            // Do it the Mozilla way
            document.getElementById('new_input_files').innerHTML = printNewInputFiles(num_files);
        }catch (f){
            alert(f);
            // I think this applies to Opera & Netscape
            if (window['new_input_files'])
            {
                window['new_input_files'].innerHTML = printNewInputFiles(num_files);
            }
        }
    }
    return false;
}

function printNewInputFiles(num_files)
{
    output  = "<input type=hidden name='num_new_input_files' value='"+ num_files +"'>";
    
    for (index = 0; index < num_files; index++)
    {
        output += "<hr />";
        output += "<table class='outFile'>";
        
        output += "<tr>";
        output += "<td class='headerTD'>File "+ (index + 1) +" Caption:</td>";
        output += "<td>";
        output += "<input name='new_file_"+ index +"_caption' type='text' size='40' />";
        output += "</td></tr>";
        
        output += "<tr>";
        output += "<td class='headerTD'>File "+ (index + 1) +" Attachment:</td>";
        output += "<td>";
        output += "<input type=file name='new_file_"+ index +"_file' rows=6 cols=60 />";
        output += "</td></tr>";
        
        output += "</table>";
    }
    return output;
}


function newImage2(field)
{
    field = 'document.'+ field.form.name + '.is_new_'+ field.name;
    eval(field +'.value = 1');
}

function changeField(form_name, field_name, new_action)
{
	eval("document." + form_name + "." + field_name + ".value = '" + new_action + "'");
	return true;
}

function checkIfNew(form_name, drop_down_id)
{
    drop_down_val = eval("document."+ form_name +"." + drop_down_id + ".value");
    eval("new_field = document."+ form_name +".new_" + drop_down_id);
    if (drop_down_val == 'new')
    {
        new_field.setAttribute("type", "text");
        new_field.size = 20;
        new_field.setAttribute("value", "Enter new value!");
        new_field.focus();
    }
    else
    {
        new_field.setAttribute("type", "hidden");
    }
}

function checkIfNew2(field)
{
    form_name = field.form.name;
    field_name = field.name;
    eval("drop_down_val = field.value");
    eval("new_field = document."+ form_name +".new_" + field_name);
    if (drop_down_val == 'new')
    {
        new_field.setAttribute("type", "text");
        new_field.size = 20;
        new_field.setAttribute("value", "Enter new value!");
        new_field.focus();
    }
    else
    {
        new_field.setAttribute("type", "hidden");
    }
}
    
function confirm_delete(delete_string)
{
    var answer = confirm ('Are you sure you want to delete this record?')
    if (answer)
    {
        window.location= '?paction=Delete&id=' + delete_string;
    }
}

function setCajonPrice(priceField)
{
    // Since the type values are - "TYPE * PRICE"
    // ...where * is the character separating them to allow spliting
    temp = priceField.split('*');
    // First element of split array is type name
    type = temp[0];
    // Second element of split array is price for the selected size
    newPrice = temp[1];
    
    // Get the name of the design so that the name passed to paypal
    // ...can be created to be passed
    cajon_name = document.getElementById('design_name').value;
    // If the price is not -1, set price fields for display and
    // ...passing to paypal
    if (newPrice != -1)
    {
        // I'm not sure which browsers this applies to
        if (document.getElementById)
        {
            document.getElementById('amount').value    = newPrice;
            document.getElementById('item_name').value = cajon_name + " - " + type;
        }
    
        // I think this applies to Opera & Netscape
        else if (window["price"])
        {
            document.getElementById('amount').value = newPrice;
            document.getElementById('item_name').value = cajon_name + " - " + type;
        }
    }
    // No size is selected so reset all fields set before by above if-statement
    else
    {
        if (document.getElementById)
        {
            document.getElementById('amount').value = "";
            document.getElementById('item_name').value = apparel_name;
        }
        else if (window["price"])
        {
            window['price'].amount.value = "";
            window['item_name'].value = apparel_name;
        }
    }
}

function setApparelPrice(sizeid)
{
  // Get the name of the design so that the name passed to paypal
  // ...can be created to be passed
  apparel_name = document.getElementById('design_name').value;

  // If the price is not -1, set price fields for display and 
  // ...passing to paypal
  if (sizeid != -1)
  {
  	newPrice = sizePrices[sizeid];
	
    if (document.getElementById)
    {
      document.getElementById("price").innerHTML = '$' + newPrice;
      document.getElementById('amount').value    = newPrice;
      document.getElementById('item_name').value = apparel_name + " - " + sizeid;
    }
    else if (window["price"])
    {
      window["price"].innerHTML = '$' + newPrice;
      window['amount'].value = newPrice;
      window['item_name'].value = apparel_name + " - " + sizeid;
    }
  }
  // No size is selected so reset all fields set before by above if-statement
  else
  {
    if (document.getElementById)
    {
      document.getElementById("price").innerHTML = "";
      document.getElementById('amount').value = "";
      document.getElementById('item_name').value = apparel_name;
    }
    else if (window["price"])
    {
      window["price"].innerHTML = "";
      window['amount'].value = "";
      window['paypal_form'].item_name.value = apparel_name;
    }
  }
}

function checkApparelForm()
{
	// Every failed test will be added to the errorMsg
  	var errorMsg = "";
  
  	/*
  	 * Each 'if' statement tests one field's validity
  	 */
  
  	// Make sure a size has been selected
  	size = document.getElementById('sizes').value;
  	if (size == "-1")
  	{
    	errorMsg += "You must select a size!\n";
  	}
  
  	// If the error message is not empty, there are problems so...
  	// ...display it and return false
  	if (errorMsg != "")
  	{
    	alert(errorMsg);
    	return false;
  	}
  	else
	{
    	return true;
	}
}

