document.createNamedElement = function(type, name) {
  var element;
  try {
    element = document.createElement('<'+type+' name="'+name+'">');
  } catch (e) { }
  if (!element || !element.name) { // Not in IE, then
    element = document.createElement(type)
    element.name = name;
  }
  return element;
}

function addVisitor(visitorinfos)   {     

var visitorcount = visitorinfos;
visitorcount++;   
var updateCount = document.getElementById('visitorcount');
updateCount.value = visitorcount;
//var sectionHdr = document.getElementById('sectionHDR');
//if (sectionHdr.firstChild.nodeType ==3) {
//sectionHdr.firstChild.nodeValue = "Visitor 1 Information";
//}  

var addVisitorLink = document.getElementById('addVisitorLink');
addVisitorLink.style.display = 'none';

var NewSectionHdr = document.getElementById('formTBL');
var DividerRow = NewSectionHdr.tBodies[0].appendChild(document.createElement('tr')); 
DividerRow.className = "gridSECTIONHDR";
var DividerCell = DividerRow.appendChild(document.createElement('td'));
DividerCell.className = "gridSECTIONTD";
DividerCell.style.fontWeight = "bold";
var DividerCellText = DividerCell.appendChild(document.createTextNode('Visitor ' + visitorcount + ' Information'));


//Visitor info table
var newVisitorRow = NewSectionHdr.tBodies[0].appendChild(document.createElement('tr')); 
var newVisitorCell = newVisitorRow.appendChild(document.createElement('td'));
newVisitorCell.colSpan = "2";
newVisitorCell.className="gridDATATBL";
var thetable = newVisitorCell.appendChild(document.createElement('table'));
thetable.width = "95%";
thetable.align = "center";
thetable.appendChild(document.createElement('tbody'));
//Row One= Name
var rowone = thetable.tBodies[0].appendChild(document.createElement('tr')); 
var namelabel = rowone.appendChild(document.createElement('td')); 
namelabel.className = "formLABEL";
var namerequired = namelabel.appendChild(document.createElement('span'));
namerequired.className = "red";
var namestar = namerequired.appendChild(document.createTextNode('*'));
var nametext = namelabel.appendChild(document.createTextNode('Visitor Name:'));
var inputnamecell = rowone.appendChild(document.createElement('td')); 
inputnamecell.className = "formINPUT";
var inputname = inputnamecell.appendChild(document.createElement('input'));
inputname.type = "text";
inputname.id = 'visitor_name' + visitorcount;
inputname.name = 'visitor_name' + visitorcount;
inputname.className = "formTEXT";
var errorcellname = rowone.appendChild(document.createElement('td')); 
errorcellname.width = "1";
errorcellname.appendChild(document.createTextNode(' '));

//Row Two= Email
var RowTwo = thetable.tBodies[0].appendChild(document.createElement('tr')); 
var emaillabel = RowTwo.appendChild(document.createElement('td')); 
emaillabel.className = "formLABEL";
var emailrequired = emaillabel.appendChild(document.createElement('span'));
emailrequired.className = "red";
var emailstar = emailrequired.appendChild(document.createTextNode('*'));
var emailtext = emaillabel.appendChild(document.createTextNode('E-mail:'));
var inputEmailCell = RowTwo.appendChild(document.createElement('td')); 
inputEmailCell.className = "formINPUT";
var inputEmail = inputEmailCell.appendChild(document.createElement('input'));
inputEmail.type = "text";
inputEmail.id = 'visitor_email' + visitorcount;
inputEmail.name = 'visitor_email' + visitorcount;
inputEmail.className = "formTEXT";
var errorCellEmail = RowTwo.appendChild(document.createElement('td')); 
errorCellEmail.width = "1";
errorCellEmail.appendChild(document.createTextNode(' '));

//Row Three= Work Phone
var RowThree = thetable.tBodies[0].appendChild(document.createElement('tr')); 
var phonelabel = RowThree.appendChild(document.createElement('td')); 
phonelabel.className = "formLABEL";
var phonerequired = phonelabel.appendChild(document.createElement('span'));
phonerequired.className = "red";
var phonestar = phonerequired.appendChild(document.createTextNode('*'));
var phonetext = phonelabel.appendChild(document.createTextNode('Work Phone:'));
var inputPhoneCell = RowThree.appendChild(document.createElement('td')); 
inputPhoneCell.className = "formINPUT";
var inputPhone = inputPhoneCell.appendChild(document.createElement('input'));
inputPhone.type = "text";
inputPhone.id = 'visitor_phone' + visitorcount;
inputPhone.name = 'visitor_phone' + visitorcount;
inputPhone.className = "formTEXT";
var errorCellPhone = RowThree.appendChild(document.createElement('td')); 
errorCellPhone.width = "1";
errorCellPhone.appendChild(document.createTextNode(' '));

//Row Four = Cell Phone
var RowFour = thetable.tBodies[0].appendChild(document.createElement('tr')); 
var cellphonelabel = RowFour.appendChild(document.createElement('td')); 
cellphonelabel.className = "formLABEL";
var cellphonetext = cellphonelabel.appendChild(document.createTextNode('Cell Phone:'));
var inputcellphoneCell = RowFour.appendChild(document.createElement('td')); 
inputcellphoneCell.className = "formINPUT";
var inputcellphone = inputcellphoneCell.appendChild(document.createElement('input'));
inputcellphone.type = "text";
inputcellphone.id = 'visitor_cell' + visitorcount;
inputcellphone.name = 'visitor_cell' + visitorcount;
inputcellphone.className = "formTEXT";
var errorCellcellphone = RowFour.appendChild(document.createElement('td')); 
errorCellcellphone.width = "1";
errorCellcellphone.appendChild(document.createTextNode(' '));
 
 
 //Row Five = newAddLink
var RowFive = thetable.tBodies[0].appendChild(document.createElement('tr')); 
var linkCell = RowFive.appendChild(document.createElement('td')); 
var linkdiv = linkCell.appendChild(document.createElement('div'));
linkdiv.id = 'addVisitorLink' + visitorcount;
var Visitorlink = linkdiv.appendChild(document.createElement('a'));
Visitorlink.setAttribute('href','javascript:void(0);');
Visitorlink.onclick= function()
{addVisitor(visitorcount);}
var Visitorlinktext = Visitorlink.appendChild(document.createTextNode('Add another Visitor'));
if (visitorcount ==3) {
			var Visitorlinkdiv = document.getElementById('addVisitorLink2');
			Visitorlinkdiv.style.display = 'none';
			}
if (visitorcount ==4) {
			var Visitorlinkdiv = document.getElementById('addVisitorLink3');
			Visitorlinkdiv.style.display = 'none';
			}
if (visitorcount ==5) {
			var Visitorlinkdiv = document.getElementById('addVisitorLink4');
			Visitorlinkdiv.style.display = 'none';
			}
}


function reload(Visitorsmod){
		if (Visitorsmod ==2) {
			var VisitorlinkdivMod1 = document.getElementById('addVisitorLink');
			VisitorlinkdivMod1.style.display = 'none';
			}
if (Visitorsmod ==3) {
			var VisitorlinkdivMod1 = document.getElementById('addVisitorLink');
			VisitorlinkdivMod1.style.display = 'none';
			}
if (Visitorsmod ==4) {
			var VisitorlinkdivMod3 = document.getElementById('addVisitorLink');
			VisitorlinkdivMod3.style.display = 'none';
			}
if (Visitorsmod ==5) {
			var VisitorlinkdivMod4 = document.getElementById('addVisitorLink');
			VisitorlinkdivMod4.style.display = 'none';
			}
		}