// JavaScript Document
var LastDivOpened;

function NewMessage(MsgType,GroupId)
{
		switch (MsgType)
		{
			case 'A':
				DivName = "AssignmentDiv";
			break;
			case 'Q':
				DivName = "QuickMsgDiv";
			break;
			case 'R':
				DivName = "ReminderDiv";
			break;
			case 'E':
				DivName = "RealAssignmentDiv";
			break;
		}
	
	CloseDiv();
	DivObj = document.getElementById(DivName);
	if(GroupId)
		UrlStr = "&GroupId="+GroupId;
	else
		UrlStr="";
	Url = "/messages/index.php?Ajax=1&MsgType="+MsgType+UrlStr;
	
	RefreshAjaxDiv(DivName,Url);
	DivObj.style.display = "inline";
}

function NewReminder(MessageId)
{
	CloseDiv();
	
	RemDivObj = document.getElementById("RemDiv");
	if(RemDivObj)
		DivName = "RemDiv";
	else
		DivName = "ReminderDiv";
	
	Url = "/messages/index.php?Ajax=1&SubmittedAjax=1&MsgId="+MessageId+"&MsgType=R";
	RefreshAjaxDiv(DivName,Url);
}

function ShowMessage(MessageId,MessageDiv,Reminder)
{
	CloseDiv();
	LastDivOpened = MessageDiv;
	MessageDivObj = document.getElementById(MessageDiv);
	if(Reminder)
		RemStr = "&Reminder=1";
	else
		RemStr = "";
	Url = "/messages/index.php?Ajax=1&MessageId="+MessageId+RemStr;
	RefreshAjaxDiv(MessageDiv,Url);
	MessageDivObj.style.display = "inline";
}

function CloseDiv(Type,DivName)
{
	if(LastDivOpened)
	{
		LastDivObj = document.getElementById(LastDivOpened);
		LastDivObj.style.display='none';
	}
	
	if(!DivName)
	{
		switch (Type)
		{
			case 'A':
				DivName = "AssignmentDiv";
			break;
			case 'Q':
				DivName = "QuickMsgDiv";
			break;
			case 'R':
				DivName = "ReminderDiv";
			break;
			case 'E':
				DivName = "RealAssignmentDiv";
			break;
		}
	}
	
	if(DivName)
	{
		DivObj = document.getElementById(DivName);
		DivObj.style.display = "none";
	}
}

function SendForm(FormName,Type)
{
	Error = 0;
	FormObj = document.forms[FormName];
	if(Type=="A")
	{
		DueDate = FormObj["DueDate"].value;
		Title = FormObj["Description"].value;
		if(DueDate=="" || Title=="")
			Error = 1;
	}
	
	if(Type=="Q")
	{
		ToUser = FormObj["ToUserName"].value;
		Title = FormObj["Description"].value;
		if(ToUser=="" || Title=="")
			Error = 1;
	}
	
	if(Error==0)
	{
		alert("llegó");
		FormObj.submit();
		CloseDiv(Type);
	}
	else
		alert("You must complete all required fields.");
	
}

<!-- Attach the datepicker to duedate after document is ready -->
function CallCalendar(FormName,FormField,Lang)
{
	if(Lang=="Spa")
	{
		/* Inicialización en español para la extensión 'UI date picker' para jQuery. */
		/* Traducido por Vester (xvester@gmail.com). */
		jQuery(function($){
			$.datepicker.regional['es'] = {clearText: 'Limpiar', clearStatus: '',
			closeText: 'Cerrar', closeStatus: '',
			prevText: '&lt;Ant', prevStatus: '',
			nextText: 'Sig&gt;', nextStatus: '',
			currentText: 'Hoy', currentStatus: '',
			monthNames: ['Enero','Febrero','Marzo','Abril','Mayo','Junio',
				'Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre'],
			monthNamesShort: ['Ene','Feb','Mar','Abr','May','Jun',
				'Jul','Ago','Sep','Oct','Nov','Dic'],
			monthStatus: '', yearStatus: '',
			weekHeader: 'Sm', weekStatus: '',
			dayNames: ['Domingo','Lunes','Martes','Mi&eacute;rcoles','Jueves','Viernes','S&aacute;dabo'],
			dayNamesShort: ['Dom','Lun','Mar','Mi&eacute;','Juv','Vie','S&aacute;b'],
			dayNamesMin: ['Do','Lu','Ma','Mi','Ju','Vi','S&aacute;'],
			dayStatus: 'DD', dateStatus: 'D, M d',
			dateFormat: 'dd/mm/yy', firstDay: 0, 
			initStatus: '', isRTL: false};
			$.datepicker.setDefaults($.datepicker.regional['es']);
			});
	}
	
	jQuery(function($){$("#"+FormField).datepicker();});
	DateObj = document.forms[FormName][FormField];
	DateObj.focus();
}

function Notes4Quiz()
{
	QuizId = document.forms["Notes"]["QuizId"].value;
	GroupId = document.forms["Notes"]["GroupId"].value;
	
	Url = "/users/home.php?Ajax=1&QuizId="+QuizId+"&GroupId="+GroupId+"&JSArray=1";
    if (QuizId!=0)
        $("#NotesDiv").css({opacity:'1'});
    else
        $("#NotesDiv").css({opacity:'0.5'});

	RefreshAjaxDiv("ScriptDiv",Url);
    
    //console.log("QuizId: "+QuizId);
}

function ValEmail(InputName,FormName)
{
	FormObj = document.forms[FormName];
	InputObj = FormObj[InputName];
	
	var Email = InputObj.value;
	var filter=/^[A-Za-z][A-Za-z0-9_]*@[A-Za-z0-9_]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	if (Email.length == 0 )
	{
		alert("You must enter a valid e-mail address.");
		return false;
	}
	
	if (filter.test(Email))
	{
		FormObj.submit();
		return true;
	}
	else
	{
		alert("You must enter a valid e-mail address.");
		return false;
	}
}

function ShowSendForm()
{
	MailDivObj = document.getElementById('MailDiv');
	MailDivObj.style.display = "inline";
	LastDivOpened = "MailDiv";
	RefreshAjaxDiv('MailDiv','/history/index.php?Ajax=1');
}

function DelMessage(DivName,MessageId,GroupId,MType)
{
	if(GroupId)
		Url = "/messages/index.php?Ajax=1&Delete=1&MessageId="+MessageId+"&GroupId="+GroupId+"&MType="+MType;
	else
		Url = "/messages/index.php?Ajax=1&Delete=1&MessageId="+MessageId+"&MType="+MType;
	//alert(Url);
	//alert(DivName);
	if(confirm("Do you want to delete this message?")) 
	{	
		//alert(Url);
		RefreshAjaxDiv(DivName,Url);
	}
}

function GetAllNotes(PupilId, GroupId)
{
	Url = "/users/home.php?Ajax=1&PupilId="+PupilId+"&GroupId="+GroupId;
	DivName = "AllNotesDiv";
	RefreshAjaxDiv(DivName,Url);
	document.getElementById(DivName).style.display = "inline";
}

function DelRelation(DivName,ContentId,GroupId)
{
	Url = "/teacherfiles/adm.php?Ajax=1&GroupId="+GroupId+"&ContentId="+ContentId+"&Action=DelRel";
	if(confirm("Do you really want to do this?")) 
	{	
		//alert(Url);
		RefreshAjaxDiv(DivName,Url);
	}
}

function ChangeTextColor()
{
	PObj = document.getElementById("LogOutAlert");
	
	if(PObj.style.color=="red")
		PObj.style.color = "black";
	else
		PObj.style.color = "red"
		
	tout = setTimeout('ChangeTextColor();',1000);
}
/****************** Teatro ***************/

function NewsSuscribe(DivName)
{
	Email = document.forms.NewsForm.Email.value;
	Url = "/teatro/newsletter/index.php?Email="+Email;
	RefreshAjaxDiv(DivName, Url);
	return false;
}

/***************** Rotativo Horizontal *********************/

var LayerWidth = new Number(0);
var Stop = new Number(0);
var Speed = new Number(1);
var Pixeles = new Number(4);

function initLayers(LayerName)
{
	Layer = document.getElementById(LayerName);
	
	if (Layer)
	{
		LayerWidth = new Number(Layer.offsetWidth);
		Layer.style.left = 1;
	}
}

function ChangePosition(LayerName,Left)
{
	Layer  = document.getElementById(LayerName);
	Px = new String(Layer.style.left);
	Px = Px.replace('px','');
	Px = new Number(Px);
	
	if(Left==1)
		Layer.style.left = Px - Pixeles;
	else
		Layer.style.left = Px + Pixeles;
}

function MoveContinuousLeft(LayerName,Init)
{
	Layer  = document.getElementById(LayerName);
	LeftPx = new String(Layer.style.left);
	LeftPx = LeftPx.replace('px','');
	LeftPx = LeftPx.replace('pt','');
	LeftPx = new Number(LeftPx);
	
	if(Init)
		Stop=0;
	
	if(Stop!=1 && LeftPx < 0)
	{
		ChangePosition(LayerName);
		movedown = setTimeout("MoveContinuousLeft('"+LayerName+"',0)",Speed);
	}
}

function SetStop()
{
	Stop=1;	
}

function MoveContinuousRight(LayerName,Init)
{
	Layer  = document.getElementById(LayerName);
	LeftPx = new String(Layer.style.left);
	LeftPx = LeftPx.replace('px','');
	LeftPx = LeftPx.replace('pt','');
	LeftPx = new Number(LeftPx);
	
	if(Init==1)
		Stop=0;
	
	if(Stop!=1 && LeftPx > -(LayerWidth))
	{
		ChangePosition(LayerName,'1');
		movedown = setTimeout("MoveContinuousRight('"+LayerName+"',0)",Speed);
	}
}