// JavaScript Document
//var latestId = 1;
function addNewItem(totalnum) {
var numi = document.getElementById('theValue').value;
if(numi < totalnum ){
	appendElement("container1", "category" + latestId, "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"5\"><tr><td width=\"35%\" align=\"right\"></td><td><select name=\"subcatid"+latestId+"\" id=\"subcatid"+latestId+"\" onchange=\"getSubcategory(this,'biz','divSubCat"+latestId+"',"+latestId+");getRestaurant(this);getDetail(this); processField(this);\" title=\"please select a business category.\" class=\"required\"><option value=\"\"> -choose business category- </option>"+cat_listbox+"</select></td></tr><tr><td align=\"right\">&nbsp;</td><td><div id=\"divSubCat"+latestId+"\" style=\"display:inline;\"><select name=\"sscid"+latestId+"\" id=\"sscid"+latestId+"\" onChange=\"processField(this);\" disabled=\"disabled\"><option value=\"\"> -choose business sub-category- </option></select></div> <br /><a href=\"javascript:removeItem(" + latestId + ")\">[delete]</a></td></tr></table>");
	appendElement("container2", "category" + latestId, "<span id=\"prev_subcatid"+latestId+"\"></span><span id=\"cap_sscid"+latestId+"\" class=\"field_cap\"> /</span><br /><span id=\"prev_sscid"+latestId+"\"></span>");

	latestId++;
	num = parseInt(numi)+1;
	document.getElementById('theValue').value = num;
	document.getElementById('totalCategory').value = latestId;
	if(numi == parseInt(totalnum)-1) {
	//document.getElementById('addanotherdept').style.display = 'none';
	}
}
}
function removeItem(idNumber) {
	removeElement("container1", "category" + idNumber);
	removeElement("container2", "category" + idNumber);
	var numi = document.getElementById('theValue').value;
	num = parseInt(numi)-1;
	document.getElementById('theValue').value = num;
	//document.getElementById('addanotherdept').style.display = 'block';
}


function addNewItemVacancy(totalnum) {
var numi = document.getElementById('theValue').value;
if(numi < totalnum ){
	appendElement("vacancycontainer", "vacancy" + latestId, "<table width=\"350\" border=\"0\" cellspacing=\"1\" cellpadding=\"3\"><tr><td width=\"160\" align=\"left\"><input type=\"text\" name=\"vacancydate" + latestId + "\" id=\"vacancydate" + latestId + "\" size=\"20\" maxlength=\"10\" class=\"date-pick dp-applied field-short\" readonly=\"true\"><a href=\"#\" title=\"event start date\" style=\"float:left; \"></a></td><td width=\"160\" align=\"left\" valign=\"top\"><input type=\"text\" name=\"vacancyrooms" + latestId + "\" id=\"vacancyrooms" + latestId + "\" size=\"20\" maxlength=\"10\" class=\"field-short\">&nbsp;&nbsp;<a href=\"javascript:removeItemVacancy(" + latestId + ")\"><img src=\"/maestro/images/icon_delete.png\" alt=\"delete\" align=\"absmiddle\"></a></td></tr></table>");
	latestId++;
	num = parseInt(numi)+1;
	document.getElementById('theValue').value = num;
	document.getElementById('totalVacancy').value = latestId;
	if(numi == parseInt(totalnum)-1) {
	document.getElementById('addanothervacancy').innerHTML = '';
	}
}
jQuery('.date-pick').datePicker({clickInput:true})
}
function removeItemVacancy(idNumber) {
	removeElement("vacancycontainer", "vacancy" + idNumber);
	var numi = document.getElementById('theValue').value;
	num = parseInt(numi)-1;
	document.getElementById('theValue').value = num;
	document.getElementById('addanothervacancy').innerHTML = '<b>+ add new date</b>';
}

function addNewItemcustomrepeat(totalnum) {
var numi = document.getElementById('theValue').value;
if(numi < totalnum ){
	var ctimeInfo = "'ctimeInfo" + latestId+ "'"
	var csformat = "'csformat" + latestId + "'"
	var ceformat = "'ceformat" + latestId + "'"
	var prev_csformat = "'prev_csformat" + latestId + "1'"
	var prev_ceformat = "'prev_ceformat" + latestId + "1'"
	var csmin = "'csmin" + latestId + "'"
	var cemin = "'cemin" + latestId + "'"
	var cshour = "'cshour" + latestId + "'"
	var cehour = "'cehour" + latestId + "'"

	
appendElement("container3", "customrepeat" + latestId, '<table width="100%" border="0" cellspacing="1" cellpadding="2"><tr><td bgcolor="#F9F9F9" width="23%" align="center"><input type="text" name="csdate'+latestId+'" id="csdate'+latestId+'" class="date-pick dp-applied field-date enddate-limit" readonly="true" onclick="setEnddate();"> <a href="#" title="event start date" style="float:left; "></a></td><td width="64%" bgcolor="#F9F9F9"><table border="0" cellspacing="0" cellpadding="2"><tr><td><div id="ctimeInfo'+latestId+'" style="display:block; "><table width="100%" border="0" cellspacing="0" cellpadding="2" align="center"><tr><td width="5%" align="right">Start</td><td width="1%" align="right"><input name="cshour'+latestId+'" type="text" id="cshour'+latestId+'" maxlength="2" class="field-time" onkeypress="return noNumbers(event,this,12)" onkeyup="processField(this);processField1(document.getElementById('+csformat+'),'+prev_csformat+'); processField3(document.getElementById('+cshour+'),document.getElementById('+csmin+'),document.getElementById('+csformat+'));"/></td><td width="1%">:</td><td width="1%"><input name="csmin'+latestId+'" type="text" id="csmin'+latestId+'" maxlength="2" class="field-time" onkeypress="return noNumbers(event,this,59)" onkeyup="processField(this); processField1(document.getElementById('+csformat+'),'+prev_csformat+'); processField3(document.getElementById('+cshour+'),document.getElementById('+csmin+'),document.getElementById('+csformat+'));"/></td><td width="1%" align="left"><select name="csformat'+latestId+'" id="csformat'+latestId+'" class="field-dropdown" onChange="changeForamt('+ceformat+',this);processField1(this,'+prev_csformat+');"><option selected="selected" value="am">am</option><option value="pm">pm</option></select></td><td rowspan="2" nowrap="nowrap"></td></tr><tr><td align="right">End</td><td align="right"><input name="cehour'+latestId+'" type="text" id="cehour'+latestId+'" maxlength="2" class="field-time" onkeypress="return noNumbers(event,this,12)" onkeyup="processField(this); processField1(document.getElementById('+ceformat+'),'+prev_ceformat+'); processField3(document.getElementById('+cehour+'),document.getElementById('+cemin+'),document.getElementById('+ceformat+'));"/></td><td width="1%">:</td><td><input name="cemin'+latestId+'" type="text" id="cemin'+latestId+'" maxlength="2" class="field-time" onkeypress="return noNumbers(event,this,59)" onkeyup="processField(this); processField1(document.getElementById('+ceformat+'),'+prev_ceformat+'); processField3(document.getElementById('+cehour+'),document.getElementById('+cemin+'),document.getElementById('+ceformat+'));"/></td><td width="1%" align="left"><select name="ceformat'+latestId+'" id="ceformat'+latestId+'" class="field-dropdown" onChange="changeForamt1('+csformat+',this);processField1(this,'+prev_ceformat+');"><option selected="selected" value="am">am</option><option value="pm">pm</option></select></td></tr></table></div><td valign="middle"><input type="checkbox" name="callday'+latestId+'" value="yes" id="callday'+latestId+'" onclick="toggleLayer1('+ctimeInfo+');"/> All day</td></tr></table></td><td width="13%" bgcolor="#F9F9F9" align="center"><a href="javascript:removeItemcustomrepeat(' + latestId + ')"><img src="/maestro/images/icon-x.png" alt="delete" border="0" /></a></td></tr></table>');

appendElement("container4", "prev_customrepeat" + latestId, '<table width="100%" border="0" cellspacing="1" cellpadding="3"><tr class="preview_dates_body"><td width="39%" ><div align="center" id="prev_csdate'+latestId+'"></div></td><td width="38%"><div align="center" id="prev_ctimeInfo'+latestId+'"><span id="prev_cshour'+latestId+'"></span><span id="cap_csmin'+latestId+'" class="field_cap">:</span><span id="prev_csmin'+latestId+'"></span><span id="prev_csformat'+latestId+'1"></span> - <span id="prev_cehour'+latestId+'"></span><span id="cap_cemin'+latestId+'" class="field_cap">:</span><span id="prev_cemin'+latestId+'"></span><span id="prev_ceformat'+latestId+'1"></span></div><div align="center" id="prevall_ctimeInfo'+latestId+'" style="display:none; ">All Day</div></td><td width="23%" nowrap="nowrap"><div align="center"><table width="100%" border="0" cellspacing="0" cellpadding="3"><tr><td class="preview_addicons_sm"><a href="#"><img alt="icon" src="/images/ico-add.gif" /></a><a href="#">faves</a></td><td class="preview_addicons_sm"><a href="#"><img alt="icon" src="/images/ico-add.gif" /></a><a href="#">trip</a></td></tr></table></div></td></tr></table>');
	
	latestId++;
	num = parseInt(numi)+1;
	document.getElementById('theValue').value = num;
	document.getElementById('totalCategory').value = latestId;
	if(numi == parseInt(totalnum)-1) {
	//document.getElementById('addanotherdept').style.display = 'none';
	}
}
jQuery('.date-pick').datePicker({clickInput:true})
}



function removeItemcustomrepeat(idNumber) {
	removeElement("container3", "customrepeat" + idNumber);
	removeElement("container4", "prev_customrepeat" + idNumber);
	var numi = document.getElementById('theValue').value;
	num = parseInt(numi)-1;
	document.getElementById('theValue').value = num;
	//document.getElementById('addanotherdept').style.display = 'block';
}


function removeElement(parentId, elementId) {
	//Get a reference to the element containgint the element we are removing
  	var parentElement = document.getElementById(parentId);
  	//Get a reference to the element we are removing
  	var childElement = document.getElementById(elementId);
	//remove the 
  	parentElement.removeChild(childElement);
}
function appendElement(containerId, newElementId, newElementContent) {
	//First, we need to create a new DIV element
  	var newElement=document.createElement("div");
	//New we will give it the specified ID so we can manage it later if necessary
	newElement.setAttribute("id", newElementId);
	//Insert the HTML content into the new element
  	newElement.innerHTML=newElementContent;
	//Get a reference to the element that will contain the new element
 	var container = document.getElementById(containerId);
	//Now we just need to insert our new element into the containing element
  	container.appendChild(newElement, container);
}
