/**
 * AreaMap module scripts for provider settings form
 *
 * @copyright (c) 2004-2007, SWsoft
 */
function refreshProvidersForm(radio) {
	var icqForm = self.document.getElementById('icqForm');
	var skypeForm = self.document.getElementById('skypeForm');

	switch (radio.value) {
		case 'icq':
			skypeForm.style.display = 'none';
			icqForm.style.display = 'block';
			break;

		case 'skype':
			skypeForm.style.display = 'block';
			icqForm.style.display = 'none';
			break;

		default:
			skypeForm.style.display = 'none';
			icqForm.style.display = 'block';
	}
	refreshPreviewForm();
}

function onSubmitProvidersForm() {
	self.sbPreloader.enable();
	var formObject = self.sbEditorObject.getFormObject();
	var radio = null;
	for (var i = 0; i < formObject.OnlineStatusIndicatorProvider.length; i++) {
		if (formObject.OnlineStatusIndicatorProvider[i].checked) {
			radio = formObject.OnlineStatusIndicatorProvider[i];
			break;
		}
	}

	var result = true;
	if (radio) {
		switch (radio.value) {
			case 'skype':
				result = validateField('SB_Validator.notEmpty', 'skypeName', 'EMPTY-SKYPE-NAME');
				break;

			case 'icq':
				result = validateField('SB_Validator.notEmpty', 'icqUin', 'EMPTY-ICQ-UIN');
				break;

			default:
				alert('internal SiteBuilder error: provider is not defined');
		}

	}
	return result;
}

function refreshPreviewForm() {
	var request = new SbAjaxRequest.ContainerUpdater(
		self.parent.baseUrl + '/Ajax/Wizard/Edit/Modules/OnlineStatusIndicator',
		getIndicatorRequestParams(),
		$('OnlineStatusIndicatorContainer'),
		{
			addOverlayText: false
		}
	);
}


function getIndicatorRequestParams() {
	var result = '';

	var formObject = self.sbEditorObject.getFormObject();
	var radio = null;
	for (var i = 0; i < formObject.OnlineStatusIndicatorProvider.length; i++) {
		if (formObject.OnlineStatusIndicatorProvider[i].checked) {
			radio = formObject.OnlineStatusIndicatorProvider[i];
			break;
		}
	}

	if (radio) {
		switch (radio.value) {
			case 'skype':
				result += 'type=skype&' + getSkypeRequestParams();
				break;

			case 'icq':
				result += 'type=icq&' + getIcqRequestParams();
				break;

			default:
				alert('internal SiteBuilder error: provider is not defined');
		}

	}
	return result;
}

function getIcqRequestParams() {
	var result = 'icqUin=' + encodeURIComponent($('icqUin').value);
	result += '&icqIcon=' + encodeURIComponent($('icqIcon').value);
	return result;
}

function getSkypeRequestParams() {
	var result = 'skypeName=' + encodeURIComponent($('skypeName').value);
	result += '&skypeIcon=' + encodeURIComponent($('skypeIcon').value);
	result += '&skypeCallByClick=' +
		(
			($('skypeCallByClick').checked)
			? 1
			: 0
		);
	return result;
}