/**
 * ShowAlert
 * 
 * Para correr la ventana de show alert al cargar una pagina
 */
window.addEvent('domready',function(){	
	/*
	var Cleaned = $('Cleaned');
	if(Cleaned){
		ShowAlert("All your notification setting have been unchecked","correct");
	}
	*/
	var Updated = $('Updated');
	if($('messageModalBox')){//Esto es para cuando hay que poner un alert en una pagina que ya contiene un campo con id="message". Hay que crear otro hidden para el mensaje del alert.
		var message = $('messageModalBox');
	}else{
		var message = $('message');
	}
	if(message && Updated){
		var oExtra={};
		if(iTime=Updated.getProperty('time')){
			oExtra = {'time':iTime};
		}
		switch (Updated.value){
			case "1":
				ShowAlert(message.value,"correct",oExtra);
				break;
			case "3"://cuando updated==3 significa que tenemos un URL al que queremos que redireccione despues de que aparezca el mensajito.
				var urlRedirect = $('urlRedirect');
				if(urlRedirect){
					var sUrl=urlRedirect.value;	
				}
				oExtra = {'url':sUrl};
				ShowAlert(message.value,"redirect",oExtra);
				break;
			case "4"://cuando updated==4 igual al 3 pero con 10 segs.
				var urlRedirect = $('urlRedirect');
				if(urlRedirect){
					var sUrl=urlRedirect.value;	
				}
				ShowAlert(message.value,"redirect",oExtra);
				break;
			default:
				ShowAlert(message.value,"error",oExtra);
				break;
		}
	}
	if($('sendVerification')) {
		// Aqui mandamos el mensaje de que si quiere reenviar su verificacion
		var verification = $('sendVerification');
		ShowSendVerificationWarning(verification.getAttribute('value'));
        }
});

function ShowSendVerificationWarning( sEmail ) {
	
	new newModal({
		title:'Account not verified',
		width: 250,
		titleSize: 16,
		contentURL:'/signin/verification.php?e=' + sEmail,
		method:'get',
		onContentLoaded: function(sHtml){
			if( $('sendEmailVerification') ) {
				var verification = $('sendEmailVerification');
				verification.removeEvent( );
				verification.addEvent( 'click', function(){
					$('sendEmailVerificationDiv').setHTML('<img id="loading-submit" src="/img/global/working.gif" class="button undisplay" style="margin-left: 10px; display: inline;"/>');
					new Ajax("/signin/verification.php?ev=" + this.sEmail,{
						method: "get",
						update: 'ssbox_content'
						/*onComplete: function(html) {
							$('ssbox_content').setHTML(html);
						}*/
					}).request(null);
					//cleanNewModal();
				}.bind({'sEmail': this.sEmail}));	
			}
		}.bind({'sEmail': sEmail})
	});

}

function ShowAlert(message,type,oExtra,oOptions){
	if(!oExtra){
		var oExtra={};
	}
	var Image="";
	var headerTitle = "";
	var background="";
	var path="/img/cpanel/settings/";
	if(type=="correct" || type=="redirect"){
		//Image="<img src='"+path+"updated_ok.gif' style='margin-right:10px;'>";
		Image='<span class="errorIcon"></span>';
		headerTitle='<span style="float:left;">Success</span>';
		background="#4c4c4c";
	}else if(type=="error" || type=="msg"){
		//Image="<img src='"+path+"updated_error.gif' style='margin-right:10px;'>";
		Image='<span class="errorIcon"></span>';
		headerTitle='<span style="float:left;">Error</span>';
		background="#df000a";
	}/*else if(type=="redirect"){//En este caso cuando se cumple pone la misma ventana que en correct
		Image="<img src='"+path+"updated_ok.gif' style='margin-right:10px;'>";
		background="#4c4c4c";
	}else if(type=="msg"){
		Image="<img src='"+path+"updated_error.gif' style='margin-right:10px;'>";
		background="#df000a";
	}*/
	oOptions = oOptions || {};  
	
	oOptions.bIsAlert = true;
	oOptions.bAlertType = type;
	oOptions.header = Image + headerTitle;
	oOptions.title = oOptions.title || message;
	oOptions.titleSize = oOptions.titleSize || '146px';
	oOptions.width = oOptions.width || '334px';
	oOptions.height = oOptions.height || '145px';
	oOptions.backgroundColor = oOptions.backgroundColor || background;
	            
	//var Alertwindow=new AlertMessage(oOptions);
	var Alertwindow=new newModal(oOptions);
	
	var time = typeof oExtra.time!='undefined'?oExtra.time:5;
	if (type=="redirect" && oExtra.url){
		Alertwindow.autoRedirect(time,oExtra.url);
	}else if(type=="msg"){
		var link = $('link');
		Alertwindow.linkDirect(link.name);
	}else if( time>0 ){
	    Alertwindow.autoClose(time);
	}
}

