var windowG;

function showInviteMemberForm() {
	
	if (windowG) {
		windowG.destroy();
	}

	windowG = new Ext.Window({
		renderTo: Ext.getBody(),
		resizable:false,
		draggable: false,
		width: 880,
		cls: 'supportpopup',		
		minWidth: 300,
		minHeight: 200,
		bodyStyle:'',
		buttonAlign:'center',
		items: [{html:
			'<div id="supportcontainer"><img src="/js/libs/ext-2.3.0/resources/images/default/shared/blue-loading.gif" alt="loading" /></div>'			
		}],
		plain:false,
		floating:true,
		modal:true,
		closable: false,
		title:'',
		shadow:false
	});
	
	windowG.show(1, function() { loadInviteMemberForm('', '', '', '', '', '', 0, id); });
	
}

function loadInviteMemberForm(subject, receiver, message, send) {
	
	if(!subject) subject = "";
	if(!receiver) receiver = "";
	if(!message) message = "";
	if(!send) send = 0;

	registerPositionStore = new Ext.data.JsonStore({
		url: '/?event=cmp.cst.member.getinvitememberform&random=' + Math.random(),
		root: 'DATA',
		autoLoad: true,
		fields: ['FORM', 'SUCCESSFULLYSENT'],
		baseParams: {
			subject: subject,			
			receiver: receiver,			
			message: message,			
			send: send
		},
		listeners: {
			load: function(store, records) {
				for(var i=0;i<records.length; i++){					
					document.getElementById('supportcontainer').innerHTML = records[i].data.FORM;
					if(records[i].data.SUCCESSFULLYSENT.CODE) {
						windowG.close();
						Ext.Msg.show({
							title: records[i].data.SUCCESSFULLYSENT.TITLE,
							msg: records[i].data.SUCCESSFULLYSENT.MESSAGE,
							buttons: Ext.Msg.OK,						   
							animEl: 'elId',
							cls: 'msgbox'
						});
					}
				}	
				
				windowG.center();
			}			
		}
	});
	
}


function saveInviteMemberForm() {

	document.getElementById('submitbutton').disabled = "disabled";
	
	loadInviteMemberForm(
		document.getElementById('tsubject').value,
		document.getElementById('receiver').value,
		document.getElementById('message').value,
		1
	);
		
}
/* elNickname = id of nickname
 * txtNickname = default text in Nicknamefield
 * same for Password
 */
function clearDefaults(elNickname,txtNickname,elPassword,txtPassword){
	/* vars */
	var elN = document.getElementById(elNickname);
	var elP = document.getElementById(elPassword);
	
	if(elN != "null" && elN.value == txtNickname){
		elN.value = "";
	}
	
	if(elP != "null" && elP.value == txtPassword){
		elP.value = "";
	}
		
	return true;
}

