var fldCount	= 0;
var isOpera		= self.opera;
var ie			= document.all && document.getElementById && !isOpera;
var ns6			= document.getElementById && !document.all;
var answArray	= new Array(); 

// Будем определять начальное значение fldCount
function initPollAddForm() {
	if(document.pollForm) {
		var fieldHtml ='';
		var fldArray = document.pollForm.elements;
		var el = document.getElementById('pollAddBlock');
		var iterator=0;
		//el.innerHTML = '';
		
		if(document.getElementById('BorderMustBeNone'))
			document.getElementById('BorderMustBeNone').style.border = "none";		
		
		for(i=0; i<fldArray.length; i++)
			if(fldArray[i].type == "radio") {
				
				fieldHtml += 
				'<table cellpadding=0 cellspacing=0 border=0>' +
					'<tr>' +
						'<td>' +
							'<input type="text" name="addField' + (++iterator) + '" value="'+ fldArray[i].value +'">' +
						'</td>' +
						'<td>' +
							'<input type="checkbox" name="addCBox' + iterator + '" checked>' +
						'</td>' +
					'</tr>' +
				'</table>';				
					
				++fldCount;
			}
		el.innerHTML = fieldHtml;
		//applyFieldChanges();
		
	} else if(el = document.getElementById('pollFldCount1')) {
		fldCount = parseInt(el.value);
	} else {
		fldCount = 0;	
	}
	//alert(fldCount);
}

function applyFieldChanges() {
	refreshFldList();
	var fldArray = document.addFieldForm.elements;
	var iterator = 1;
	var out = '<table cellpadding=0 cellspacing=0 border=0>';
	
	
	while(el = eval("fldArray.addField" + iterator)){
		out += '<tr><td>';
		out += '<input type="radio" name="poll1" value="'+ el.value +'">'+ el.value;
		out += '</td><td>';
		out += '<input type="button" value="Copy!" onclick="ClipBoard('+ iterator +')">';
		
		out += '</td></tr>';
		++iterator;
	}	
	
	out += '</table>';
	out += '<input name="pollFldCount" id="pollFldCount1" type="hidden" value="'+ (iterator-1) +'"">';
	
	pollForm1.innerHTML = out;
}

function chvw() {
	if(el = document.getElementById('pollDivAbs'))
		el.style.display = (el.style.display == "block") ? "none" : "block";
}

function addfield() {
	refreshFldList();
	var el = document.getElementById('pollAddBlock');
	
	var fieldHtml = 
			'<table cellpadding=0 cellspacing=0 border=0>' +
				'<tr>' +
					'<td>' +
						'<input type="text" name="addField' + (++fldCount) + '" value="Новое поле' + fldCount + '">' +
					'</td>' +
					'<td>' +
						'<input type="checkbox" name="addCBox' + fldCount + '" checked>' +
					'</td>' +
				'</tr>' +
			'</table>';
	
	
	el.innerHTML += fieldHtml;
	refreshFldList();
	//refreshCount();
}

function refreshCount() {
	var fldArray = document.addFieldForm.elements;
	var count;
	
	for(i=1; i<(fldArray.length-2); i+=2)
		if(fldArray[i].checked)
			++count;
	
	fldCount = count;
}

function refreshFldList() {
	var count = 0;
	var newFldHtml = '';
	var fldArray = document.addFieldForm.elements;	
	
	for(i=1; i<(fldArray.length-2); i+=2) {
		if(fldArray[i].checked) {
			++count;
			newFldHtml +=
			'<table cellpadding=0 cellspacing=0 border=0>' +
				'<tr>' +
					'<td>' +
						'<input type="text" name="addField' + count + '" value="'+ (fldArray[i-1].value) +'">' +
					'</td>' +
					'<td>' +
						'<input type="checkbox" name="addCBox' + count + '" checked>' +
					'</td>' +
				'</tr>' +
			'</table>';			
		}
	}
	
	fldCount = count;
	
	document.getElementById('pollAddBlock').innerHTML = newFldHtml;
}



if(ie || isOpera) {	
	window.attachEvent("onload", initPollAddForm);
} else {	
	window.addEventListener("load", initPollAddForm, true);
}


function ClipBoard(pN)
{
	el = document.getElementById('holdtext');
	el.innerText = pollForm1.poll1[pN-1].outerHTML + pollForm1.poll1[pN-1].value;
	
	Copied = el.createTextRange();
	Copied.execCommand("Copy");
}

/*
<SCRIPT LANGUAGE="JavaScript">

</SCRIPT>
*/