var AddFormWindow=false;

function changeType()
{
	var el = document.getElementById('id_type');
	if (el != null && el != undefined) {

		var hide_all = [10,11,12,17,18,20];
		var show = [];
		show[1] = [];
		show[2] = [10];
		show[3] = [10];
		show[4] = [11,12,20];

		var tbl = getParentTag(el, 'TABLE');
		var old_attr = $(tbl).attr('id');
		$(tbl).attr('id', 'id_tbl_to_proc');

		// hide all dynamyc elements
		for (var i = 0; i < hide_all.length; i++) {
			$('#id_tbl_to_proc tr:eq(' + hide_all[i] + ')').hide();
		}

		// show relative to type
		show = show[el.value];
		if (show != null && show != 'undefined') {
			for (var i = 0; i < show.length; i++) {
				$('#id_tbl_to_proc tr:eq(' + show[i] + ')').show();
			}
		}

		var el2 = $('#education').get(0);
		if (el2.checked) {
			$('#id_tbl_to_proc tr:eq(17)').show();
			$('#id_tbl_to_proc tr:eq(18)').show();
		}

		$(tbl).attr('id', old_attr);
	}
}

function hideseoFields()
{
	var el = document.getElementById('id_type');
	if (el != null && el != undefined) {
		var tbl = getParentTag(el, 'TABLE');
		var old_attr = $(tbl).attr('id');
		$(tbl).attr('id', 'id_tbl_to_proc');
		var show = [5,6,7];
		for (var i = 0; i < show.length; i++) {
			$('#id_tbl_to_proc tr:eq(' + show[i] + ')').hide();
		}
		$(tbl).attr('id', old_attr);
	}
}

function showseoFields()
{
	var el = document.getElementById('id_type');
	if (el != null && el != undefined) {
		var tbl = getParentTag(el, 'TABLE');
		var old_attr = $(tbl).attr('id');
		$(tbl).attr('id', 'id_tbl_to_proc');
		var show = [5,6,7];
		for (var i = 0; i < show.length; i++) {
			$('#id_tbl_to_proc tr:eq(' + show[i] + ')').show();
		}
		$(tbl).attr('id', old_attr);
	}
}

function donewform(url)
{
	var width = 800;
	var height = 600;
	AddFormWindow = window.open(url, "AddFormWindow", "scrollbars=1;toolbar=0;width="+width+";height="+height) ;
	AddFormWindow.moveTo(100, 100);
	AddFormWindow.resizeTo(width, height);
	AddFormWindow.focus();
}

window.onfocus = function()
{
	if (typeof AddFormWindow.closed != "undefined" && !AddFormWindow.closed ){
		AddFormWindow.focus();
	} else {
	//alert(AddFormWindow.closed);
	}
	return true;
}

function addform(id,name)
{
	var formselect=document.getElementById('form_select');
	var newoption=document.createElement('option');
	newoption.text=name;
	newoption.value=id;
	try {formselect.add(newoption,null);} // standards compliant
	catch(ex) {formselect.add(newoption);} // IE only
	formselect.value=id;
}

function hideteaminfo()
{
	$('#newteam').parent().parent().hide();
	$('#exisitingteam').parent().parent().hide();
}

function showteaminfo()
{
	hideteaminfo();
	$('#'+document.getElementById('registertype').value).parent().parent().show();
}

function addanotheruser(button)
{
	var tbl = getParentTag(button, 'TABLE');
	row=tbl.insertRow(tbl.rows.length-2);
	row.className='anotheruser';
	labelCell=row.insertCell(0);
	labelCell.className='form_tbl_label';
	labelCell.innerHTML='Email';
	inputCell=row.insertCell(1);
	inputEmail=document.createElement('input');
	inputEmail.className='inp_width';
	inputEmail.name='anothermember_emails[]';
	inputCell.appendChild(inputEmail);
}

function setautocomplete()
{
	$("#member").autocomplete("admin/event/report?action=showmember&id_event="+id_event, {
		width: 300,
		selectFirst: true
	});
	$("#member").result(function(event, data, formatted) {
		if (data) $("#member_id").val(data[1]);
		if (data) $("input[name='amount']").val(data[2]);
	});
}

function getDOCInfo()
{
	if ($('#education').get(0).checked) {
		$('#doc_number + div').remove();
		$('#doc_number').after('<div>...<i>getting info</i>...</div>')
		$.post('admin/event', {action:'getDocInfo', docid: $('#doc_number').val()}, function(data){
			$('#doc_number + div').remove();
			docInfo=eval('('+data+')');
			var cAfterHTML='<div>CE Hours Approved: <b>'+docInfo.ce_hours;
			if (docInfo.renewal_date) cAfterHTML+='</b> Next Renewal Date: <b>'+docInfo.renewal_date;
			cAfterHTML+='</b></div>';
			$('#doc_number').after(cAfterHTML);
			$('tr.ce_credits input').val(docInfo.ce_hours);
		});
	}
}