function addField(form){
 var ni = document.getElementById('myDiv');
 var numi = document.getElementById('theValue');
 var num = (document.getElementById("theValue").value -1)+ 2;
 numi.value = num;
 var divIdName = "my"+num+"Div";
 var newdiv = document.createElement('div');
 newdiv.setAttribute("id", divIdName);
 switch(form){
 case 'dirs':
 newdiv.innerHTML = "<p><label for=\"dir"+num+"\">Director "+num+"</label> <a href=\"javascript:;\" onclick=\"removeEvent(\'"+divIdName+"\',\'"+num+"\')\">Remove</a><br /><input type=\"text\" name=\"director[]\" id=\"dir"+num+"\" size=\"30\" /></p><p><label for=\"inst"+num+"\">Institution "+num+"</label><br /><textarea cols=\"60\" rows=\"3\" name=\"inst[]\" id=\"inst"+num+"\"></textarea></p>";
 break;
 case 'cats':
 newdiv.innerHTML = "<p><input type=\"text\" name=\"categories[]\" id=\"categories"+num+"\" size=\"30\" /> <a href=\"javascript:;\" onclick=\"removeEvent(\'"+divIdName+"\',\'"+num+"\')\">Remove</a></p>";
 break;
 case 'merch':
 newdiv.innerHTML = "<table cellpadding=\"0\"><tr><td colspan=\"2\" style=\"border-bottom:1px solid #999;background:#eee;\"><p class=\"r\"><a href=\"javascript:;\" onclick=\"removeEvent(\'"+divIdName+"\',\'"+num+"\')\">Remove</a></p></td></tr><th style=\"background:#ddd;font-weight:600;\">CART VARIABLES</th><td>&nbsp</td></tr><tr><th>Item Title *</th><td><input class=\"text\" type=\"text\" name=\"item_title[]\" id=\"item_title"+num+"\" value=\"\" size=\"70\" /></td></tr><tr><th>Item sku *</th><td><input class=\"text\" type=\"text\" name=\"item_sku[]\" id=\"item_sku"+num+"\" value=\"\" size=\"20\" /></td></tr><tr><th>Description *</th><td><input class=\"text\" type=\"text\" name=\"item_desc[]\" id=\"item_desc"+num+"\" value=\"\" size=\"60\" /></td></tr><tr><th>Price * $</th><td><input class=\"text\" type=\"text\" name=\"bprice[]\" id=\"bprice"+num+"\" value=\"\" size=\"10\" /></td><tr><tr><tr><th style=\"background:#ddd;font-weight:600;\">PAGE OPTIONS</th><td>The heading appears above this product or grouping of products.</td></tr><tr><th>Heading (optional)</th><td><input class=\"text\" type=\"text\" name=\"heading[]\" id=\"heading"+num+"\" value=\"\" size=\"60\" /></td></tr><tr><th>Product Name *</th><td><input class=\"text\" type=\"text\" name=\"prod_name[]\" id=\"prod_name"+num+"\" value=\"\" size=\"60\" /></td></tr><th>Price Increase Date</th><td><input onfocus=\"showCalendarControl(this);\" class=\"text\" type=\"text\" name=\"idate[]\" id=\"idate"+num+"\" size=\"10\" value=\"\" /></td></tr><tr><th>Price After $</th><td><input class=\"text\" type=\"text\" name=\"aprice[]\" id=\"aprice"+num+"\" value=\"\" size=\"10\" /></td></tr><tr><td colspan=\"2\" style=\"border-top:1px solid #999;background:#eee;\"><p><a href=\"javascript:;\" onclick=\"addField('merch');\">Add More Items</a></p></td></table>";
 break;
 case 'authors':
 newdiv.innerHTML = "<p><label for=\"author"+num+"\">Author "+num+"</label> <strong><a href=\"javascript:;\" onclick=\"removeEvent(\'"+divIdName+"\',\'"+num+"\')\">Remove</a></strong><br /><input class=\"txt\" type=\"text\" name=\"author[]\" id=\"author"+num+"\" size=\"40\" /><br /><label for=\"inst"+num+"\">Institution "+num+"</label><br /><textarea class=\"txt\" cols=\"40\" rows=\"2\" name=\"inst[]\" id=\"inst"+num+"\"></textarea></p>";
 break;
 }
 ni.appendChild(newdiv);
}


function removeEvent(divNum, x){
 var d = document.getElementById('myDiv');
 var olddiv = document.getElementById(divNum);
 d.removeChild(olddiv);
 var numi = document.getElementById('theValue');
 numi.value = x-1;
}



//addLoadListener(hideFeature);
//addLoadListener(init_featured);

function init_featured(){
 if(document.getElementById('featureText')){
  feature = document.getElementById('featureText');
  feature.className = "hidden";
  if(document.forms['mf']['param6']){
   var onhp = document.forms['mf']['param6'];
   onhp.onclick = function(){
    if(onhp.checked){
     showFeature();
     onhp.checked = true;
    } 
    else{
     hideFeature();
     onhp.checked = false;
    }
   };
  }
 }
}

function showFeature(){
  var feature = document.getElementById("featureText");
  feature.className = "";
  return true;
}

function hideFeature(){
  var feature = document.getElementById("featureText");
  feature.className = "hidden";
  return true;
}

function toggleBilling(){
	if (document.forms[0].sameAddress){
		if (document.forms[0].sameAddress.checked){
			document.getElementById('optional').className = 'hidden';
		}
		else{
			document.getElementById('optional').className = '';
		}
	}
}


function addLoadListener(fn){
        if(typeof window.addEventListener != 'undefined'){
                window.addEventListener('load', fn, false);
        }
        else if (typeof document.addEventListener != 'undefined'){
                document.attachEventListener('load', fn, false);
        }
        else if (typeof window.attachEvent != 'undefined'){
                window.attachEvent('onload', fn);
        }
        else{
                var oldfn = window.onload;
                if(typeof window.onload != 'function'){
                        window.onload = fn;
                }
                else{
                        window.onload = function(){
                        oldfn();
                        fn();
                        };
                }
        }
}
function makePleaseWaitButton(){
    document.absForm.submitter.disabled = true;
    document.absForm.submitter.backgroundColor = "#fff";
    document.absForm.submitter.value = "Please Wait...";
    return true;
}
