// JavaScript Document for /div/contact/litcritfeedback.html

//This javascript goes with feedback.html in /div/litcrit

//error handling code from W3Schools javascript tutorial
onerror=showJSError;
var err="";

function showJSError(msg,url,l)
{
	err="Error in javascript.\n\n";
	err+="Error: " + msg + "\n\n";
	err+="URL: " + url + "\n\n";
	err+="Line: " + l + "\n\n";
	err+="Please alert IPL staff if you see this message.\n\n";
	err+="Click OK to continue.\n\n";
	alert(err);
	return true;
}

// Mike Galloway 5/10/2006
//Based on code by Dustin Diaz from this site:
//http://www.dustindiaz.com/add-and-remove-html-elements-dynamically-with-javascript/
//Add and Remove HTML elements dynamically with Javascript - Filed under: D.O.M. , Usability - Monday, February 28th, 2005

var textboxnum = 2;

function addtextboxes()
{
var ni = document.getElementById('otroBox');
var numi = document.getElementById('otroValue');
var num = (document.getElementById("otroValue").value -1)+ 2;
numi.value = num;
var divIdName = "otro"+num+"Box";
var newdiv = document.createElement('div');
newdiv.setAttribute("id",divIdName);
//adding divides in QRC message view
newdiv.innerHTML = "<input type=\"hidden\" name=\"site"+textboxnum+"\" value=\"---------------\" />";
newdiv.innerHTML += "<div class=\"center\" style=\"border-top: 1px dotted black; width: 50%;\"><strong>Site Suggestion #"+textboxnum+".</strong></div> URL: <input type=\"text\" id=\"site"+textboxnum+"_url\" name=\"site"+textboxnum+"_url\" size=\"40\" />\n";
newdiv.innerHTML += "<div style=\"text-indent: 1em\">Choose one: <input type=\"radio\" name=\"site"+textboxnum+"_type\" value=\"new site\" />New Site? <input type=\"radio\" name=\"site"+textboxnum+"_type\" value=\"bad link\" />Bad Link?</div>";
newdiv.innerHTML += "<div style=\"text-indent: 1em\">What author, work, or period is this site about? <input type=\"text\" name=\"about"+textboxnum+"\" /> </div>";
newdiv.innerHTML += " <input type=\"button\" id=\"addasite"+textboxnum+"\" onclick=\"addtextboxes()\" value=\"Add another site\" /> <input type=\"button\" id=\"removeasite"+textboxnum+"\" onclick=\"rmTextboxes(\'"+divIdName+"\')\" value=\"Remove this entry\" />";

var textboxnumOld = textboxnum - 1;
//alert(textboxnumOld); //debugging
//to avoid snafus, best to limit user's functionality so they can only add or remove last set of fields
document.getElementById('addasite'+textboxnumOld).disabled=true;
// no first instance of the remove a site button, and the script will stop in error if it can't find it, so...
if (textboxnumOld > 1) {
	document.getElementById('removeasite'+textboxnumOld).disabled=true;
}

textboxnum++;
ni.appendChild(newdiv);
}

function rmTextboxes(divNum)
{
var d = document.getElementById('otroBox');
var olddiv = document.getElementById(divNum);

//we'll want to make sure the add or remove buttons are enabled for last set of fields
var textboxnumOld = textboxnum - 2;
//alert(textboxnumOld); //debugging
document.getElementById('addasite'+textboxnumOld).disabled=false;
// no first instance of the remove a site button, and the script will stop in error if it can't find it, so...
if (textboxnumOld > 1) {
	document.getElementById('removeasite'+textboxnumOld).disabled=false;
}


d.removeChild(olddiv);
textboxnum--;
}





