var tabsNotice = new Array();
tabsNotice[0] = 'MenuDetail';
tabsNotice[1] = 'MenuGuestlist';
tabsNotice[2] = 'MenuEventPage';
tabsNotice[3] = 'MenuSendInvite';

function NoticeCreationTab(part){
	var option = part - 1;
	var aPart = new Array();
	aPart[0] = 'create';
	aPart[1] = 'guestlist';
	aPart[2] = 'eventpage';
	aPart[3] = 'sendinvite';

	var url = '/eventcreator/notice/' + aPart[option] + '/index.cfm'; 

	new Ajax.Updater(
		'pageWrap', url, 
		{
			method: 'get',
			onComplete: function(){
				NoticeCreationActive(option);
			},evalScripts:true
		}
	);
}

function NoticeCreationActive(part){
	for(i = 0;i < tabsNotice.length;i++){
		if(i == part){
			$(tabsNotice[i]).className = "boxMenuActive";
			$('pageWrap').focus();
		}
		else{
			$(tabsNotice[i]).className = "boxMenu";
		}
	}

	if(part == 1){
		LoadEventContactList();	
	}else if(part == 0){
		ShowTemplates();
	}
}

function DesignType2(type){
	clearStyle2();

	if(type == 1){
		$('MyDesign').style.display = 'block';
		$('DindongDesign').style.display = 'none';

		$('create').removeClassName('createInvites');
		$('create').addClassName('createInvitesActive');
		$('design').removeClassName('ddInvitesActive');
		$('design').addClassName('ddInvites');

		$('createButton').removeClassName('btCreateInvites');
		$('createButton').addClassName('btCreateInvitesActive');
		$('designButton').removeClassName('btDdInvitesActive');
		$('designButton').addClassName('btDdInvites');

		$('desenhe_editBox').style.display = 'block';
		
		if( $('myImages').innerHTML == '' )MyDesignImageType(1);
	}else{
		$('MyDesign').style.display = 'none';
		$('DindongDesign').style.display = 'block';

		$('create').removeClassName('createInvitesActive');
		$('create').addClassName('createInvites');
		$('design').removeClassName('ddInvites');
		$('design').addClassName('ddInvitesActive');

		$('createButton').removeClassName('btCreateInvitesActive');
		$('createButton').addClassName('btCreateInvites');
		$('designButton').removeClassName('btDdInvites');
		$('designButton').addClassName('btDdInvitesActive');

		$('desenhe_editBox').style.display = 'none';
		
		ShowTemplates();
	}
}

function SetInviteText(){
	MessageField = $('event_message').value;
	
	if(MessageField != '')
		$('event_message1').innerHTML = MessageField;
	else
		$('event_message1').innerHTML = ' Texto do comunicado';
}

function SetInviteTemplate2(eventTemplate_id,operation){
	var pars = 'eventTemplate_id=' + eventTemplate_id + '&operation=' + operation;
	new Ajax.Request('/eventcreator/event/design/EventTemplateSet.cfm',
	{
		method:'get',
		parameters: pars,
		onComplete:function(r){
			SetInviteTemplateStyle2(r.responseText,operation);
		}
	});
}

function SetInviteTemplateStyle2(detail,operationType){
	var detail = detail.evalJSON();

	$('eventTemplate_id').value = detail.EVENTTEMPLATE_ID;
	$('event_inviteImage').value = '';

	/*	imagens	*/
	if(operationType == 1)
		imagePath = 'url(http://localhost:8500/picts/invite/template/original/' + detail.EVENTTEMPLATE_IMAGE + ')';
	else if(operationType == 2)
		imagePath = 'url(http://media.dindong.com.br/dev/picts/invite/template/original/' + detail.EVENTTEMPLATE_IMAGE + ')';
	else
		imagePath = 'url(http://media.dindong.com.br/prd/picts/invite/template/original/' + detail.EVENTTEMPLATE_IMAGE + ')';

	$('invite_image').src = '/images/eventcreator/img_transparent.png';

	$('preview_content').style.backgroundImage = imagePath;
	
	/*	divisores	*/
	if(detail.EVENT_INVITE_SHOWDIVIDERS == 1){
		$('headerBar').style.display = 'block';
		$('headerBar').style.height = '5px';
		$('headerBar').style.backgroundColor = detail.EVENT_INVITE_DIVIDERCOLOR;
		$('headerBar').style.width = '100%';

		$('footerBar').style.display = 'block';
		$('footerBar').style.height = '5px';
		$('footerBar').style.backgroundColor = detail.EVENT_INVITE_DIVIDERCOLOR;
		$('footerBar').style.width = '100%';
	}
	else{
		$('headerBar').style.display = 'none';
		$('headerBar').style.backgroundColor = '#000000';

		$('footerBar').style.display = 'none';
		$('footerBar').style.backgroundColor = '#000000';
	}

	/*	alinhamento */
	$('preview_info').style.textAlign = detail.EVENT_INVITEALIGN;

	/* color */	
	$('event_name_txt').style.color = detail.EVENT_INVITE_TITLECOLOR;
	$('event_message1').style.color = detail.EVENT_INVITE_TEXTCOLOR;

	/* font */
	$('event_name_txt').style.fontFamily = fonts[detail.EVENT_INVITE_TITLEFONT];
	$('event_message1').style.fontFamily = fonts[detail.EVENT_INVITE_TEXTFONT];

	/* size */
	$('event_name_txt').style.fontSize = detail.EVENT_INVITE_TITLESIZE;
	$('event_message1').style.fontSize = detail.EVENT_INVITE_TEXTSIZE;

	if(detail.EVENT_INVITE_TEXTBOLD == 1){
		$('event_message1').style.fontWeight = 'bold';
	}else{
		$('event_message1').style.fontWeight = 'normal';
	}

	if(detail.EVENT_INVITE_TITLEBOLD == 1){
		$('event_name_txt').style.fontWeight = 'bold';
	}else{
		$('event_name_txt').style.fontWeight = 'normal';
	}

	if(detail.EVENT_INVITE_TEXTITALIC == 1){
		$('event_message1').style.fontStyle = 'italic';
	}else{
		$('event_message1').style.fontStyle = 'normal';
	}

	if(detail.EVENT_INVITE_TITLEITALIC == 1){
		$('event_name_txt').style.fontStyle = 'italic';
	}else{
		$('event_name_txt').style.fontStyle = 'normal';
	}

}

function clearStyle2(){

	var clr = '#000000';

	/*	remove imagem	*/
	$('invite_image').src = '/images/eventcreator/img_event_default.jpg';

	/* background */
	$('preview_content').style.backgroundColor = '#FFFFFF';

	/*	remove rodapé	*/
	$('headerBar').style.display = 'block';
	$('headerBar').style.backgroundColor = clr;
	$('footerBar').style.display = 'block';
	$('footerBar').style.backgroundColor = clr;

	/*	background	*/
	$('preview_content').style.backgroundImage = '';
	$('preview_content').style.backgroundPosition = '0% 0%';

	/*	alinhamento */
	$('preview_info').style.textAlign = 'center';

	/* color */	
	$('event_name_txt').style.color = clr;
	$('event_message1').style.color = clr;

	/* font */
	$('event_name_txt').style.fontFamily = fonts[6];
	$('event_message1').style.fontFamily = fonts[6];

	/* size */
	$('event_name_txt').style.fontSize = '22pt';
	$('event_message1').style.fontSize = '12pt';
	
	/*	remoção de negrito	*/
	$('event_name_txt').style.fontWeight = 'normal';
	$('event_message1').style.fontWeight = 'normal';

	$('event_name_txt').style.fontStyle = 'normal';
	$('event_message1').style.fontStyle = 'normal';

	$('event_invite_backgroundColor').value = '';
	$('event_invite_textColor').value = '';
	$('event_invite_dividerColor').value = '';
	$('event_invite_titleColor').value = '';
	$('event_invite_showDividers').value = '';
}

function changeInviteColors2(){
	$('event_name_txt').style.color = $('event_invite_titleColor').value;
	$('event_message1').style.color = $('event_invite_textColor').value;

	$('headerBar').style.backgroundColor = $('event_invite_dividerColor').value;
	$('footerBar').style.backgroundColor = $('event_invite_dividerColor').value;
}

function changeInviteFontDetail2(){
	$('event_name_txt').style.fontFamily = $('event_invite_titleFont').options[$('event_invite_titleFont').selectedIndex].text;
	$('event_message1').style.fontFamily = $('event_invite_textFont').options[$('event_invite_textFont').selectedIndex].text;

	$('event_name_txt').style.fontSize = $('event_invite_titleSize').options[$('event_invite_titleSize').selectedIndex].value;
	$('event_message1').style.fontSize = $('event_invite_textSize').options[$('event_invite_textSize').selectedIndex].value;

	$('preview_info').style.textAlign = $RF('event_inviteAlign');
}

function changeInviteItemView2(){
	if ($('showDividers').checked == true){
		$('headerBar').style.display = 'block';
		$('footerBar').style.display = 'block';
		$('event_invite_showDividers').value = 1;
	}
	else{
		$('headerBar').style.display = 'none';
		$('footerBar').style.display = 'none';
		$('event_invite_showDividers').value = 0;	
	}
}

function CreateNoticeDetail(){
	var event_message = $('event_message').value;

	if(event_message == '')
		errorAlert('CreateNoticeDetailBlankFields','Preencha todos os campos marcados com *');
	else{
		$('frmNoticeDetail').request({
			onComplete: function(r){
				var response = r.responseText.evalJSON();
	
				if(response.STATUS == true)
					CreateNoticeDesign();
				else{
					if( response.LOGIN == 1 )
						showLogin(8,1);
					else
						errorAlert('CreateNoticeDetailError',response.MESSAGE);
				}
			},
			onFailure: function(){ errorAlert('CreateNoticeDetailError','Ocorreu um problema na edi&ccedil;&atilde;o dos detalhes do comunicado.'); }
		});
	}
}

function CreateNoticeDesign(){
	$('frmStyle').request({
		onComplete: function(transport){
			var response = transport.responseText.evalJSON();
			
			if(response.STATUS == true){
				NoticeCreationTab(2);
			}else{
				errorAlert('DesignCreateFalse',response.MESSAGE);
			}
		},
		onFailure: function(){ errorAlert('EventDetailCreateEvent','Ocorreu um problema ao salvar o design do comunicado.'); }
	});
}

function CreateNoticeGuestlist(){
	new Ajax.Request('/eventcreator/notice/guestlist/CreateSettings.cfm',
	{
		method:'get',
		onSuccess: function(r){
			var response = r.responseText.evalJSON();

			if(response.STATUS == true)
				NoticeCreationTab(3);
			else
				errorAlert('EventWarningError',response.MESSAGE);
		},
		onFailure: function(){
			errorAlert('EventWarningError','Ocorreu um problema na altera&ccedil;&atilde;o do passo atual.');
		}
	});
}

function CreateNoticePage(){
	$('event_information').value = editor.getData();

	if ($('event_information').value.length > 65000) {
		errorAlert('CreateEventPageExceed', 'O campo Informa&ccedil;&atilde;es excedeu o limite de 65000 caracteres.');
	}
	else {
		$('frmEventPage').request({
			onComplete: function(r){
				var response = r.responseText.evalJSON();
				
				if (response.STATUS == true) {
					NoticeCreationTab(4);
				}
				else {
					errorAlert('EventpageDetailError', 'Ocorreu um problema na edi&ccedil;&atilde;o dos detalhes da p&aacute;gina do comunicado.');
				}
			},
			onFailure: function(){
				errorAlert('EventpageDetailError', 'Ocorreu um problema na edi&ccedil;&atilde;o dos detalhes da p&aacute;gina do comunicado.');
			}
		});
	}
}

function SendNotice(formName){
	if(typeof(document.frmSendNotice.email_guestlistID) == 'undefined'){
		var email = false;
		var sms = false;
	}else{
		var email = isChecked(document.frmSendNotice.email_guestlistID);
		var sms = isChecked(document.frmSendNotice.sms_guestlistID);
	}

	if(email == false && sms == false)
		errorAlert('SendNoticeError','Nenhum convidado foi selecionado para o envio.');
	else{
		$('frmSendNotice').request({
		onComplete: function(r){
			var response = r.responseText.evalJSON();
			var rEmail = response.EMAIL.STATUS;
			var rSMS = response.SMS.STATUS;

			NoticePage = function(){ location.href = response.PAGE; }

			if(email == true && sms == true){//envio de e-mail e sms

				if(rEmail == 1 && rSMS == 1){
					successAlert('SendInviteSuccess','Os comunicados foram enviados com sucesso.<br>Voc&ecirc; ser&aacute; redirecionado para o Site do Comunicado dentro de alguns segundos.');					
					setTimeout('NoticePage()','4000');
				}else if(rEmail == 1 && rSMS == 2){
					errorAlert('SendNoticeAlert','Seu saldo de SMS se esgotou por&eacute;m alguns foram enviados os e-mails foram enviados com sucesso.<p>Caso voc&ecirc; deseje adquirir e-mails e SMS utilize o bot&atilde;o abaixo para compr&aacute;-los.</p>');
					LoadGuestlistCredit();
				}else if(rEmail == 1 && rSMS == 3){
					window.location.hash = 'credits';
					errorAlert('SendNoticeAlert','Seu saldo de SMS est&aacute; esgotado por&eacute;m os e-mails foram enviados.<p>Caso voc&ecirc; deseje adquirir e-mails e SMS utilize o bot&atilde;o abaixo para compr&aacute;-los.</p>');
				}else if(rEmail == 1 && rSMS == 4){
					var message = rSMS.MESSAGE + 'Os e-mails foram enviados com sucesso.';
					errorAlert('SendNoticeAlert',message);
				}else if(rEmail == 1 && rSMS == 5){
					errorAlert('SendNoticeAlert','Os e-mails foram enviados com sucesso por&eacute;m todos os contatos selecionados n&atilde;o possuem telefones cadastrados no Dindong.');
				}
				
				else if(rEmail == 2 && rSMS == 1){
					errorAlert('SendNoticeAlert','Seu saldo de e-mails se esgotou por&eacute;m alguns foram enviados e os SMS foram enviados com sucesso.<p>Caso voc&ecirc; deseje adquirir e-mails e SMS utilize o bot&atilde;o abaixo para compr&aacute;-los.</p>');
					LoadGuestlistCredit();
				}else if(rEmail == 2 && rSMS == 2){
					errorAlert('SendNoticeAlert','Seu saldo de e-mails e SMS se esgotou por&eacute;m alguns foram enviados.<p>Caso voc&ecirc; deseje adquirir e-mails e SMS utilize o bot&atilde;o abaixo para compr&aacute;-los.</p>');
					LoadGuestlistCredit();
				}else if(rEmail == 2 && rSMS == 3){
					errorAlert('SendNoticeAlert','Seu saldo de e-mails se esgotou por&eacute;m alguns foram enviados e o saldo de SMS est&aacute; esgotado.<p>Caso voc&ecirc; deseje adquirir e-mails e SMS utilize o bot&atilde;o abaixo para compr&aacute;-los.</p>');
					LoadGuestlistCredit();
				}else if(rEmail == 2 && rSMS == 4){
					var message = rSMS.MESSAGE + 'Seu saldo de e-mails se esgotou por&eacute;m alguns foram enviados.';
					errorAlert('SendNoticeAlert',message);
				}else if(rEmail == 2 && rSMS == 5){
					errorAlert('SendNoticeAlert','Seu saldo de e-mails se esgotou.<br>Todos os contatos selecionados n&atilde;o possuem telefones cadastrados no Dindong.');
				}

				else if(rEmail == 3 && rSMS == 1){
					window.location.hash = 'credits';
					errorAlert('SendNoticeAlert','Seu saldo de e-mails est&aacute; esgotado por&eacute;m os SMS foram enviados.<p>Caso voc&ecirc; deseje adquirir e-mails e SMS utilize o bot&atilde;o abaixo para compr&aacute;-los.</p>');
				}else if(rEmail == 3 && rSMS == 2){
					window.location.hash = 'credits';
					errorAlert('SendNoticeAlert','Seu saldo de e-mails est&aacute; esgotado e o saldo de SMS se esgotou por&eacute;m alguns SMS foram enviados.<p>Caso voc&ecirc; deseje adquirir e-mails e SMS utilize o bot&atilde;o abaixo para compr&aacute;-los.</p>');
				}else if(rEmail == 3 && rSMS == 3){
					window.location.hash = 'credits';
					errorAlert('SendNoticeAlert','Seu saldo de e-mails e SMS est&aacute; esgotado.<p>Caso voc&ecirc; deseje adquirir e-mails e SMS utilize o bot&atilde;o abaixo para compr&aacute;-los.</p>');
				}else if(rEmail == 3 && rSMS == 4){
					var message = 'Seu saldo de e-mails est&aacute; esgotado.' + rSMS.MESSAGE;
					errorAlert('SendNoticeAlert',message);
				}else if(rEmail == 3 && rSMS == 5){
					errorAlert('SendNoticeAlert','Seu saldo de e-mails est&aacute; esgotado.<br>Todos os contatos selecionados n&atilde;o possuem telefones cadastrados no Dindong.');
				}

				else if(rEmail == 4 && rSMS == 1){
					errorAlert('SendNoticeAlert','E-mails n&atilde;o enviados pois todos os convidados selecionados recusaram o recebimento.<br>OS SMS foram enviados com sucesso.');
				}else if(rEmail == 4 && rSMS == 2){
					errorAlert('SendNoticeAlert','E-mails n&atilde;o enviados pois todos os convidados selecionados recusaram o recebimento.<br>Seu saldo de SMS se esgotou por&eacute;m alguns foram enviados.');
				}else if(rEmail == 4 && rSMS == 3){
					errorAlert('SendNoticeAlert','E-mails n&atilde;o enviados pois todos os convidados selecionados recusaram o recebimento.<br>Seu saldo de SMS est&aacute; esgotado.');
				}else if(rEmail == 4 && rSMS == 4){
					errorAlert('SendNoticeAlert','E-mails n&atilde;o enviados pois todos os convidados selecionados recusaram o recebimento.<br>' + rSMS.MESSAGE);
				}else if(rEmail == 4 && rSMS == 5){
					errorAlert('SendNoticeAlert','E-mails n&atilde;o enviados pois todos os convidados selecionados recusaram o recebimento.<br>Todos os contatos selecionados n&atilde;o possuem telefones cadastrados no Dindong.');
				}

				else if(rEmail == 5 && rSMS == 1){
					errorAlert('SendNoticeAlert','Alguns e-mails n&atilde;o foram enviados pois os convidados recusaram o recebimento.<br>OS SMS foram enviados com sucesso.');
				}else if(rEmail == 5 && rSMS == 2){
					errorAlert('SendNoticeAlert','Alguns e-mails n&atilde;o foram enviados pois os convidados recusaram o recebimento.<br>Seu saldo de SMS se esgotou por&eacute;m alguns foram enviados.');
				}else if(rEmail == 5 && rSMS == 3){
					errorAlert('SendNoticeAlert','Alguns e-mails n&atilde;o foram enviados pois os convidados recusaram o recebimento.<br>Seu saldo de SMS est&aacute; esgotado.');
				}else if(rEmail == 5 && rSMS == 4){
					errorAlert('SendNoticeAlert','Alguns e-mails n&atilde;o foram enviados pois os convidados recusaram o recebimento.<br>' + rSMS.MESSAGE);
				}else if(rEmail == 5 && rSMS == 5){
					errorAlert('SendNoticeAlert','E-mails n&atilde;o enviados pois os convidados recusaram o recebimento.<br>Todos os contatos selecionados n&atilde;o possuem telefones cadastrados no Dindong.');
				}

			}else if(email == true && sms == false){//envio de e-mail

				if(rEmail == 1){
					successAlert('SendNoticeSuccess','Os comunicados foram enviados com sucesso.<br>Voc&ecirc; ser&aacute; redirecionado para o Site do Comunicado dentro de alguns segundos.');
					setTimeout('NoticePage()','4000');
				}else if(rEmail == 2){
					LoadGuestlistCredit();
					errorAlert('SendNoticeAlert','Seu saldo de e-mails se esgotou por&eacute;m alguns e-mails foram enviados.<p>Caso voc&ecirc; deseje adquirir e-mails e SMS utilize o bot&atilde;o abaixo para compr&aacute;-los.</p>');
				}else if(rEmail == 3){
					window.location.hash = 'credits';
					errorAlert('SendNoticeAlert','Seu saldo de e-mails est&aacute; esgotado.<p>Caso voc&ecirc; deseje adquirir e-mails e SMS utilize o bot&atilde;o abaixo para compr&aacute;-los.</p>');
				}else if(rEmail == 4){
					errorAlert('SendNoticeAlert','<p>E-mails n&atilde;o enviados pois todos os convidados selecionados recusaram o recebimento.</p>Enviei um e-mail contendo os endere&ccedil;os.');
				}else{
					errorAlert('SendNoticeAlert','<p>Alguns e-mails n&atilde;o foram enviados pois os convidados recusaram o recebimento.</p>Enviei um e-mail contendo os endere&ccedil;os.');
				}

			}else{//envio de sms

				if(rSMS == 1){
					successAlert('SendNoticeSuccess','Os comunicados via SMS foram enviados com sucesso.<br>Voc&ecirc; ser&aacute; redirecionado para o Site do Comunicado dentro de alguns segundos.');
					setTimeout('NoticePage()','4000');
				}else if(rSMS == 2){
					LoadGuestlistCredit();
					errorAlert('SendNoticeAlert','Seu saldo se esgotou por&eacute;m alguns SMS foram enviados.<p>Caso voc&ecirc; deseje adquirir e-mails e SMS utilize o bot&atilde;o abaixo para compr&aacute;-los.</p>');
				}else if(rSMS == 3){
					window.location.hash = 'credits';
					errorAlert('SendNoticeAlert','Seu saldo de SMS est&aacute; esgotado.<p>Caso voc&ecirc; deseje adquirir e-mails e SMS utilize o bot&atilde;o abaixo para compr&aacute;-los.</p>');
				}else if(rSMS == 4){
					errorAlert('SendNoticeAlert',rSMS.MESSAGE);
				}else
					errorAlert('SendNoticeAlert','Todos os contatos selecionados n&atilde;o possuem telefones cadastrados no Dindong.');

			}
		},
		onFailure: function(){ errorAlert('SendInviteError','Ocorreu um problema na edi&ccedil;&atilde;o dos detalhes da p&aacute;gina do evento.'); }
	});
	}
}
