// JavaScript Document

function extraApps(action)
{
	if (action == 'no')
	{
		document.form.submit();
	}
	else
	{		
		//increment our counter which is used to give each input field a unique number
		num++;
		document.getElementById('nameSet').style.display = 'block';
		adjustRows('nameSet','email');
	}
}

function insertEmailRow(isTable){
		
		
		index = document.getElementById(isTable).rows.length;
		
		nextRow =  document.getElementById(isTable).insertRow(index);
		isText0 = nextRow.insertCell(0);
		isText0.bgColor = '#003466';
		isText0.style.color = "#fff";
		isText0.style.fontWeight = "bold";
		isText0.setAttribute('colSpan','2');
		
		nextRow =  document.getElementById(isTable).insertRow(index+1);
		isText1 = nextRow.insertCell(0);
		txtArea1 = nextRow.insertCell(1);
		
		
		index = index.toString();
		
		nameStr1 = "email["+num+"]";		
		txtStr1 = "Email:";
		
		isText0.innerHTML = "New Applicant";
		isText1.innerHTML = txtStr1+'\n';
		
		idStr1 = "email"+num;
		var id = 'busy'+num;

		txtArea1.innerHTML = "<input name="+nameStr1+" id=\""+idStr1+"\" type='text' onkeydown=\"return preventSubmit(event)\" class='required validate-email' title='Enter email address.'>&nbsp;<input type=\"button\" name=\"next\" value=\"Next\" class=\"select\" onclick=\"checkEmail('"+idStr1+"','"+id+"');\"><img src='/imgs/indicator.gif' id='"+id+"' style='display:none;margin:5px 0 0 10px'>\n&nbsp;<input type=\"button\" name=\"cancel\" value=\"Cancel\" class=\"select\" onclick=\"removeThisApplicant(this);\">";
	}
	function preventSubmit(e){
		var code;
		if (!e){
			var e = window.event;
		}
		if (e.keyCode){ 
			code = e.keyCode;
		}else if (e.which){ 
			code = e.which;
		}
		if(code==13){
			return false;
		}
		return true;
	}
	function insertGrecRow(isTable){
		
		index = document.getElementById(isTable).rows.length;
		
		nextRow =  document.getElementById(isTable).insertRow(index);
		isText1 = nextRow.insertCell(0);
		txtArea1 = nextRow.insertCell(1);
		
		txtStr1 = "GREC:";
		nameStr1 = "grec["+num+"]";		
		
		idStr1 = "grec"+num;
		var id = 'busy_grec'+num;
		
		isText1.innerHTML = txtStr1+'\n';
		txtArea1.innerHTML = "<input name="+nameStr1+" id=\""+idStr1+"\" type='text' class='required' title='Enter a GREC number.'  onkeypress=\"return disableEnterKey(event)\" >&nbsp;<input type=\"button\" name=\"next\" value=\"Next\" class=\"select\" onclick=\"checkGrec('"+idStr1+"','"+id+"');\">&nbsp;&nbsp;<input type=\"button\" name=\"next\" value=\"No GREC\" class=\"select\" onclick=\"noCheckGrec('"+idStr1+"','"+id+"');\" /><img src='/imgs/indicator.gif' id='"+id+"' style='display:none;margin:5px 0 0 10px'>\n";
	}
	function insertNameRows(isTable){
		index = document.getElementById(isTable).rows.length;
		
		nextRow =  document.getElementById(isTable).insertRow(index);
		isText1 = nextRow.insertCell(0);
		txtArea1 = nextRow.insertCell(1);
		
		nextRow =  document.getElementById(isTable).insertRow(index+1);
		isText2 = nextRow.insertCell(0);
		txtArea2 = nextRow.insertCell(1)

		nextRow =  document.getElementById(isTable).insertRow(index+2);
		isText3 = nextRow.insertCell(0);
		txtArea3 = nextRow.insertCell(1)
		
		txtStr1 = "First Name:";
		txtStr2 = "Last Name:";
		txtStr3 = "Org Type:";
		
		nameStr1 = "first_name["+num+"]";
		nameStr2 = "last_name["+num+"]";
		nameStr3 = "app_type["+num+"]";	
		
		isText1.innerHTML = txtStr1+'\n';
		isText2.innerHTML = txtStr2+'\n';
		isText3.innerHTML = txtStr3+'\n';
		
		txtArea1.innerHTML = "<input name="+nameStr1+" type='text' class='required' title='Enter first name.'  onkeypress=\"return disableEnterKey(event)\" >\n";
		txtArea2.innerHTML = "<input name="+nameStr2+" type='text' class='required' title='Enter last name.'  onkeypress=\"return disableEnterKey(event)\" >\n"
		var select = "<select id=\"app_type\" class=\"required validate-alpha\" name="+nameStr3+">\n";
  		select += "<option selected value=\"0\">Select...</option>\n";
  		select += "<option value=\"realtor\">Realtor or Real Estate Agent</option>\n";
		select += "<option value=\"pro\">Community Association Manager</option>\n";
		select += "<option value=\"comm\">Community Association Board Member</option>\n";
		select += "<option value=\"other\">Other</option></select>\n";
		txtArea3.innerHTML = select;
	}
	
	function adjustRows(isTable,flag){
		
		currRows = document.getElementById(isTable).rows.length;

		if (flag == 'email')
		{
			insertEmailRow(isTable)
		}
		if (flag == 'grec')
		{
			insertGrecRow(isTable)
		}
		if (flag == 'names')
		{
			insertNameRows(isTable)
		}
	}
	function removeThisApplicant(elem){
		var table = document.getElementById('nameSet');
		for(var i=0;i<table.childNodes.length;i++){
			table.removeChild(table.childNodes[i]);
		}
	}
/*
function insertRows(isTable, num){
		
		
		index = document.getElementById(isTable).rows.length;
		
		nextRow =  document.getElementById(isTable).insertRow(index);
		isText0 = nextRow.insertCell(0);
		isText0.bgColor = '#003466';
		isText0.style.color = "#fff";
		isText0.style.fontWeight = "bold";
		isText0.setAttribute('colSpan','2');
		
		nextRow =  document.getElementById(isTable).insertRow(index+1);
		isText3 = nextRow.insertCell(0);
		txtArea3 = nextRow.insertCell(1);
		
		nextRow =  document.getElementById(isTable).insertRow(index+2);
		isText1 = nextRow.insertCell(0);
		txtArea1 = nextRow.insertCell(1)
		
		nextRow =  document.getElementById(isTable).insertRow(index+3);
		isText2 = nextRow.insertCell(0);
		txtArea2 = nextRow.insertCell(1);
		
		nextRow =  document.getElementById(isTable).insertRow(index+4);
		isText4 = nextRow.insertCell(0);
		txtArea4 = nextRow.insertCell(1);
		
		nextRow =  document.getElementById(isTable).insertRow(index+5);
		isText5 = nextRow.insertCell(0);
		txtArea5 = nextRow.insertCell(1);
		txtArea5.setAttribute('align','left');
		
		index = index.toString();
		num++;
		
		nameStr1 = "first_name["+num+"]";
		nameStr2 = "last_name["+num+"]";
		nameStr3 = "email["+num+"]";
		nameStr4 = "grec["+num+"]";
		nameStr5 = "use_info["+num+"]";
		
		txtStr1 = "First Name:";
		txtStr2 = "Last Name:";
		txtStr3 = "Email:";
		txtStr4 = "Licence No.:";
		txtStr5 = "Use your contact info for this applicant:";
		
		isText0.innerHTML = "New Applicant";
		isText1.innerHTML = txtStr1+'\n';
		isText2.innerHTML = txtStr2+'\n';
		isText3.innerHTML = txtStr3+'\n';
		isText4.innerHTML = txtStr4+'\n';
		isText5.innerHTML = txtStr5+'\n';
		
		idStr3 = "email"+num;
		idStr4 = "grec"+num;
		var id = 'busy'+num;
		var id_grec = 'busy_grec'+num; 
		
			
		txtArea1.innerHTML = "<input name="+nameStr1+" type='text' class='required' title='Enter first name.'>\n";
		
		
		txtArea2.innerHTML = "<input name="+nameStr2+" type='text' class='required' title='Enter last name.'>\n"
		txtArea3.innerHTML = "<input name="+nameStr3+" id=\""+idStr3+"\" onblur=\"checkEmail(this.value,'"+id+"')\" type='text' class='required validate-email' title='Enter email address.'><img src='imgs/indicator.gif' id='busy"+num+"' style='display:none;margin:5px 0 0 10px'>\n";
		txtArea4.innerHTML = "<input name="+nameStr4+" id=\""+idStr4+"\" type='text' onblur=\"checkGrec(this.value,'"+id_grec+"')\"><img src='imgs/indicator.gif' id='busy_grec"+num+"' style='display:none;margin:5px 0 0 10px'>\n";
		txtArea5.innerHTML = "<input name="+nameStr5+" type='checkbox'>\n";
		index++;
	}
	function adjustRows(isVal,isTable){
	
		currRows = document.getElementById(isTable).rows.length;
		newRows = isVal;
		if (currRows > 1)
		{
			for (i=0; i<currRows-1; i++)
			{
				document.getElementById(isTable).deleteRow(1)
			}
		}
		for (i=0; i<newRows; i++)
		{
			insertRows(isTable, i)
		}
	}
*/
