function m_copy(varname, value) {
	xhr('get','copypaste.php','do=copy&varname='+varname+'&value='+value,function(){},0);	
}

function m_paste(varname, callback, para) {
	xhr('get','copypaste.php','do=paste&varname='+varname,callback,(para ? para : 0));
}

function m_pasteIntoObj(obj, varname, nomessage) {
	var b = obj;
	m_paste(varname, function(xhrobj, c ) {
		if (c.type == 'checkbox' || c.type == 'radio') {
			c.oldchecked = c.checked;
			c.checked = (xhrobj.responseText != '' ? true : false);
		}
		else {
			c.oldvalue = c.value;
			c.value = xhrobj.responseText;
		}
		if (typeof c.onchange == 'function' && (c.oldvalue != c.value || c.oldchecked != c.checked)) {
			c.onchange();	
		}
		if (typeof nomessage == 'undefined') showMessage('Pasted successfully...');
		
	},b)
}

//name="format['.$row['id'].'][]" id="format_'.$row['id'].'_'.$c.'" 
//paste_checkboxes('.$row['id'].',\'format\');

function paste_checkboxes(entry_id, prefix) {
	var a = document.getElementsByName(prefix+'[' + entry_id + '][]');
	for (var i = 0, j=a.length; i<j; i++) {
		m_pasteIntoObj(a[i], prefix+'_'+i, true);
	}	
	showMessage('Pasted successfully...');
}

function _copy_checkboxes(listitem) {
	var a = listitem.getElementsByTagName('input');
	for (var i=0,j=a.length;i<j;i++) {
		if (a[i].type == 'checkbox') {
			m_copy(a[i].className,(a[i].checked ? a[i].value : ''), true);
		}
	}
}

function _paste_checkboxes(listitem) {
	var a = listitem.getElementsByTagName('input');
	for (var i=0,j=a.length;i<j;i++) {
		if (a[i].type == 'checkbox') {
			m_pasteIntoObj(a[i], a[i].className, true);
		}
	}
}

function copy_checkboxes(entry_id, prefix) {
	var a = document.getElementsByName(prefix+'[' + entry_id + '][]');
	for (var i = 0, j=a.length; i<j; i++) {
		m_copy(prefix+'_'+i,(a[i].checked ? a[i].value : ''));
	}	
	alert(j);
}


