/*var counter = 0;


function init() {
	document.getElementById('moreFields').onclick = moreFields();
	moreFields();
}

function moreFields() {
	counter++;
	var newFields = document.getElementById('readroot').cloneNode(true);
	newFields.id = '';
	newFields.style.display = 'block';
	var newField = newFields.childNodes;
	for (var i=0; i<newField.length; i++) {
		var theName = newField[i].name;
		if (theName)
			newField[i].name = theName + counter;
	}
	var insertHere = document.getElementById('writeroot');
	insertHere.parentNode.insertBefore(newFields,insertHere);
}
*/
var counter = 0;
var post_vars;

function initcounter(newcount)
{
	counter = newcount;
}

function clonefields(clonename,appendname)
{
	var e1=document.getElementById(clonename).cloneNode(true);
	e1.id =appendname + '_' + counter;
	e1.style.visibility = 'visible';
	e1.style.display = '';
	//var e1ch = e1.childNodes;
	var e1ch = e1.getElementsByTagName('*');
	for (var i = 0; i < e1ch.length; i++) {
		
		if (e1ch[i].id) {
			e1ch[i].id = e1ch[i].id + '_' + counter;
		}
		if (e1ch[i].type == "radio" || e1ch[i].type == "checkbox") {
			e1ch[i].name = e1ch[i].name + '_' + counter + '[]';
		}
		if (e1ch[i].className == 'display_cal') {
		//	e1ch[i].innerHTML = 'ifworks';
			var x2 = e1ch[i].title + '_' + counter;
			e1ch[i].title = '';
		//	var funccode = "displayCalendar(document.getElementById('" + e1ch[i].title + "'),'yyyy-mm-dd',this)";
			e1ch[i].onclick = function(q4){ return function() {displayCalendar(document.getElementById(q4),'yyyy-mm-dd',this);};}(x2);
		//	e1ch[i].title = 'yah';
		}
		if (e1ch[i].className == 'form_title') {
			e1ch[i].innerHTML = e1ch[i].innerHTML + (counter + 1);
		}
		if (e1ch[i].className == 'copy_form') {
			var cp1 = counter + 1;
			var x1 = counter;
			e1ch[i].value = "Copy Form " + counter + "'s Data to Form " + cp1;
			e1ch[i].onclick = function(){copyPreviousForm(x1);}
			e1ch[i].id = counter;
		}
	}
	document.getElementById(appendname).appendChild(e1);
	counter++;
	document.getElementById("submitted_form_count").value = counter;
}

function remove_by_ajax(){	
	xmlhttp= (window.XMLHttpRequest ? new XMLHttpRequest(): ((window.ActiveXObject) ? new ActiveXObject("Microsoft.XMLHTTP") : null) );
	//xmlhttp.onreadystatechange=state_change
	xmlhttp.open("POST",'./removelast.php',false);
	xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');

	var send_val = this.post_vars;
	//alert(send_val);	
	xmlhttp.send(send_val);
	//alert(xmlhttp.responseText);
	return (xmlhttp.responseText);	
}

function set_remove_vars() {
	hiddenid = 'hidden_id_' + counter;
	this.post_vars = '&draft_group=' + document.getElementById('draft_group').value + '&is_draft=1' + '&login_name=' + document.getElementById('login_name').value + '&id=' + document.getElementById(hiddenid).value;
}

function removefields(removename)
{
	counter--;
	hiddenid = 'hidden_id_' + counter;
	if (document.getElementById(hiddenid).value)
	{
		set_remove_vars();
		tempvar = remove_by_ajax();
	//	alert(tempvar);
	}
	var rn1 = removename + '_' + counter;
	var e1 = document.getElementById(rn1);
	e1.parentNode.removeChild(e1);
	document.getElementById("submitted_form_count").value = counter;
	//this.parentNode.parentNode.removeChild(this.parentNode);

}

function displayCalendar(calid, caldate, cal)
{
	alert(calid.id+caldate);
}

function copyPreviousForm(x15)
{
	alert(x15);
}


