function nl2br(inputan){
	while (inputan.indexOf(String.fromCharCode(10)) != -1) {
		inputan = inputan.replace(String.fromCharCode(10), '<br />');
	}
	return inputan;
}

function closeCmp(componentName) {
	Ext.getCmp(componentName).setVisible(false);
}

function clearFormContact() {
	document.getElementById('inputan-n').value = '';
	document.getElementById('inputan-e').value = '';
	document.getElementById('inputan-s').value = '';
	document.getElementById('inputan-c').value = '';
	document.getElementById('inputan-code').value = '';
}

function sendMail() {
	Ext.Ajax.request({
		url: '/modules/contact/mail-contact.php',
		params: {
			task: 'sendmail',
			nama: document.getElementById('inputan-n').value,
			email: document.getElementById('inputan-e').value,
			subject: document.getElementById('inputan-s').value,
			content: document.getElementById('inputan-c').value,
			code: document.getElementById('inputan-code').value
		},
		callback: function(o,p,r) {
			switch(r.responseText) {
				case '1':
					Ext.Msg.alert('Perhatian', 'Pesan telah terkirim. Terima kasih telah menghubungi kami!');
					document.getElementById('siimage').src = 'modules/contact/securimage_show.php?sid=' + Math.random();
					break;
				case '2':
					Ext.Msg.alert('Perhatian', 'Maaf pesan Anda tidak terkirim karena adanya gangguan pada server kami. Silakan coba lagi nanti!');
					document.getElementById('siimage').src = 'modules/contact/securimage_show.php?sid=' + Math.random();
					break;
				case '3':
					Ext.Msg.alert('Perhatian', 'Kode yang Anda masukkan tidak sah! Harap masukkan kode yang benar!');
					break;
			}
			Ext.get('contactcontainer').unmask();
			clearFormContact();
		}
	});
}