function CloseWindowRedirectOpener(newURL)
{
	window.opener.location = newURL;
	this.close();
}

function showEventosAnteriores(objID)
{
	var obj = document.getElementById(objID);
	if(obj != null)
	{
		if(String(obj.style.display) == "none")
			obj.style.display = "block";
		else
			obj.style.display = "none";
	}
}

function showFoto(img, tit)
{	
	window.open("/imagePreview.aspx?srcImage="+escape(img)+"&title="+tit, "", "width=0,height=0,top=200,left=200,scrollbars=no");
}


function validateText(name, prompt, reg)
{
	var str = "";
	var obj = document.getElementsByName(name)[0];
	if(obj != null)
	{
		str = String(obj.value);
		str = str.replace(reg, "");
		if(str.length > 0)
			return true;
		obj.focus();	
		alert("Tem de preencher o campo "+prompt+".")
		return false;
	}
	return true;
}

function validateDate(name, prompt, reg)
{
	var str_day = "", str_month = "", str_year = "";
	var obj_day = document.getElementsByName(name+"_day")[0];
	var obj_month = document.getElementsByName(name+"_month")[0];
	var obj_year = document.getElementsByName(name+"_year")[0];
	if(obj_day != null && obj_month != null && obj_year != null)
	{
		str_day = String(obj_day.value);
		str_day = str_day.replace(reg, "");
		str_month = String(obj_month.value);
		str_month = str_month.replace(reg, "");
		str_year = String(obj_year.value);
		str_year = str_year.replace(reg, "");

		if(str_day.length > 0 && str_month.length > 0 && str_year.length > 0)
		{
			str_month = Number(str_month)-1;
			var date = new Date(str_year, str_month, str_day);
			
			//alert(str_year+", "+str_month+", "+str_day+"\n"+date.getFullYear()+", "+date.getMonth()+", "+date.getDate())
			if(Number(date.getFullYear()) == Number(str_year)
				&& Number(date.getMonth()) == Number(str_month)
				&& Number(date.getDate()) == Number(str_day))
					return true;
		}
		obj_day.focus();	
	}
	alert("A "+prompt+" não está correcta.")
	return false;
}

function validateAudition()
{
	var reg = new RegExp("(^\s)*|(\s$)*", "gi");

	if(!validateText("txt_name", "Nome", reg))
		return false;
	if(!validateText("txt_contact", "Contacto", reg))
		return false;
	if(!validateDate("dte_birthdate", "Data de Nascimento", reg))
		return false;
	if(!validateText("txt_habilitations", "Habilitações", reg))
		return false;
	if(!validateText("txt_instrument", "Instrumento / Voz", reg))
		return false;
	
	return true;
}


function validateMediaRoomRequest()
{
	var reg = new RegExp("^((\s)*)|((\s)*)$", "gi");

	if(!validateText("txt_name", "Nome / First Name", reg))
		return false;
	if(!validateText("txt_surname", "Apelido / Last Name", reg))
		return false;
	if(!validateText("txt_communication_social", "Orgão de Comunicação Social / Publication", reg))
		return false;
	if(!validateText("txt_address", "Morada / Address", reg))
		return false;
	if(!validateText("txt_town", "Cidade / Town", reg))
		return false;
	if(!validateText("txt_country", "País / Country", reg))
		return false;
	if(!validateText("txt_postal_code", "Cód. Postal / Postal Code", reg))
		return false;
	if(!validateText("txt_telephone", "Telefone / Phone", reg))
		return false;
	if(!validateText("txt_fax", "Fax", reg))
		return false;
	if(!validateText("txt_mobile", "Telemóvel / Mobile", reg))
		return false;
	if(!validateText("txt_email", "E-mail", reg))
		return false;
	if(!validateText("txt_subject", "Assunto", reg))
		return false;

	return true;
}

function NewWindow(mypage, myname, w, h, scroll) 
{
	var winl = (screen.width - w) / 2;
    var wint = (screen.height - h) / 2;
    var winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=no,location=no';
    var win = window.open(mypage, myname, winprops);
      
    if (parseInt(navigator.appVersion) >= 4 && win != null) 
    {
		if (win.window != null)
			win.window.focus(); 
	}
}

function ResizeWindow(id)
{
	var width = document.getElementById(id).clientWidth + 30;
	var height = document.getElementById(id).clientHeight + 40;
	
	window.resizeTo(width, height);
}

<!--StartFragment -->
/*function changeHeight()
{
	if (document.getElementById && !(document.all)) 
	{
		alert("NS");
		h = document.getElementById('iframeESRO').contentDocument.body.scrollHeight;
		document.getElementById('iframeESRO').height = h;
	}
	else if(document.all) 
	{ 
		alert("IE");
		var height = document.getElementById('iframeESRO').document.body.scrollHeight;
		document.all.iframeESRO.style.height = height;
	}
}*/

function VerifyEmail(email) {        

	var chk = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
	return (chk.test(email));
}

function ValidateOutlookForm()
{
	if (!VerifyEmail(document.getElementById("email").value))
	{
		alert("O endereço de email não é válido");
		return false;
	}
	document.getElementById("addToOutlookForm").submit();
	return true;
}

function ValidateEnviarAmigoForm()
{
	if(!ValidValue(document.getElementById("nameUSer").value))
	{
		alert("Campo de preenchimento obrigatório");
		document.getElementById("nameUSer").focus();
		return false;
	}
	
	if (!ValidValue(document.getElementById("emailUser").value))
	{
		alert("Campo de preenchimento obrigatório");
		document.getElementById("emailUser").focus();
		return false;
	}
	
	if (!VerifyEmail(document.getElementById("emailUser").value))
	{
		alert("E-mail inválido");
		document.getElementById("emailUser").focus();
		return false;
	}
	
	if(!ValidValue(document.getElementById("nameFriend").value))
	{
		alert("Campo de preenchimento obrigatório");
		document.getElementById("nameFriend").focus();
		return false;
	}
	
	if(!ValidValue(document.getElementById("emailFriend").value))
	{
		alert("Campo de preenchimento obrigatório");
		document.getElementById("emailFriend").focus();
		return false;
	}
	
	if(!VerifyEmail(document.getElementById("emailFriend").value))
	{
		alert("E-mail inválido");
		document.getElementById("emailFriend").focus();
		return false;
	}
		
	document.getElementById("sendFriendForm").submit();
	return true;
}

function ResetSendFriendForm()
{
	document.getElementById("sendFriendForm").reset();
	//document.getElementById("sendFriendForm").submit();
	return true;
}

function ValidValue(value)
{
	return value != null && value != "";
}

function Logout(uid)
{
	document.getElementById("loggedInDIV").style.display = "none";
	document.getElementById("loggedOutDIV").style.display = "block";
	document.getElementById("iframeESRO").src = "/eSRO/load_logout.asp?UID=" + uid;
}

function show_basket(nTickets)
{
	if (nTickets > 0)
	{
		document.getElementById("divBasket1").style.display = "none";
		document.getElementById("divBasket10").style.display = "none";
		document.getElementById("divBasket2").style.display = "block";
		document.getElementById("divBasket20").style.display = "block";
	}
}

function load_user(usTitle, usFirst, usLast, usCode)
{	
	if (document.getElementById("newUser").value = "0")
	{	
		document.getElementById("username").innerText = usFirst + " " + usLast;
		document.getElementById("loggedInDIV").style.display = "block";
		document.getElementById("loggedOutDIV").style.display = "none";
	}
}

function SetDiv(div1, div2)
{
	document.getElementById(div1).style.display = "none";
	document.getElementById(div2).style.display = "block";
}

function Register(uid, path)
{
	document.getElementById("iframeESRO").src = path + "/eSRO/com_interface.asp?UID=" + uid;		
}

function SetLogInControl(id, value)
{
	if (document.getElementById(id) != null)
		document.getElementById(id).value = value;
}


