var windowG;

function showRecommendForm(subject, id) {
	
	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() { loadRecommendForm(subject, '', '', '', '', '', 0, id); });
	
}

function loadRecommendForm(subject, sender, receiver, message, captcha, captchacrypt, send, id) {
	
	if(!subject) subject = "";
	if(!sender) sender = "";
	if(!receiver) receiver = "";
	if(!message) message = "";
	if(!captcha) captcha = "";
	if(!captchacrypt) captchacrypt = "";
	if(!send) send = 0;
	if(!id) id = 0;

	registerPositionStore = new Ext.data.JsonStore({
		url: '/?event=cmp.cst.documents.getrecommendform&random=' + Math.random(),
		root: 'DATA',
		autoLoad: true,
		fields: ['FORM', 'SUCCESSFULLYSENT'],
		baseParams: {
			subject: subject,
			sender: sender,
			receiver: receiver,			
			message: message,
			captcha: captcha,
			captchacrypt: captchacrypt,
			send: send,
			id: id
		},
		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 saveRecommendForm() {

	document.getElementById('submitbutton').disabled = "disabled";
	
	if(document.getElementById('captcha'))
		cap = document.getElementById('captcha').value;
	else
		cap = '';
	
	if(document.getElementById('captchacrypt'))
		capcr = document.getElementById('captchacrypt').value;
	else
		capcr = '';
	
	loadRecommendForm(
		document.getElementById('tsubject').value,
		document.getElementById('sender').value,
		document.getElementById('receiver').value,
		document.getElementById('message').value,
		cap,	
		capcr,
		1,
		document.getElementById('id').value
	);
		
}


function showContactForm(subject) {
	
	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() { loadContactForm(subject); });
	
}

function loadContactForm(subject, sender, message, captcha, captchacrypt, send) {
	
	if(!subject) subject = "";
	if(!sender) sender = "";
	if(!message) message = "";
	if(!captcha) captcha = "";
	if(!captchacrypt) captchacrypt = "";
	if(!send) send = 0;
	
	registerPositionStore = new Ext.data.JsonStore({
		url: '/?event=cmp.cst.documents.getcontactform&random=' + Math.random(),
		root: 'DATA',
		autoLoad: true,
		fields: ['FORM', 'SUCCESSFULLYSENT'],
		baseParams: {
			subject: subject,
			sender: sender,
			message: message,
			captcha: captcha,
			captchacrypt: captchacrypt,
			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 saveContactForm() {
	
	document.getElementById('submitbutton').disabled = "disabled";
	
	if(document.getElementById('captcha'))
		cap = document.getElementById('captcha').value;
	else
		cap = '';
	
	if(document.getElementById('captchacrypt'))
		capcr = document.getElementById('captchacrypt').value;
	else
		capcr = '';
	
	loadContactForm(
		document.getElementById('tsubject').value,
		document.getElementById('sender').value,
		document.getElementById('message').value,
		cap,	
		capcr,
		1
	);
		
}

function changeTab(id) {
	
	var all = Ext.get('tabheadchannel');
	arr = all.select('li', true);
	for(i=0; i<arr.elements.length; i++) {
		if(arr.elements[i].id == 'tabchannel' + id)
			arr.elements[i].addClass('active');
		else
			arr.elements[i].removeClass('active');
	}
	
	var all = Ext.get('tabbodychannel');
	arr = all.select('.innerbox', true);
	for(i=0; i<arr.elements.length; i++) {
		if(arr.elements[i].id == 'boxchannel' + id)
			arr.elements[i].applyStyles('display:block');
		else
			arr.elements[i].applyStyles('display:none');
	}
	
}




