// JavaScript Document
function getElem(id){
	return	document.getElementById(id);
}

// Mostrar a DIV de AJUDA
function mostrarDiv(){
	document.getElementById('dTexto').style.visibility = 'visible';
  
  pX = window.screen.width/2 - 200;
  pY = window.screen.height/2 - 150;
  
  
  document.getElementById('dTexto').style.left = pX + 'px';
  document.getElementById('dTexto').style.top = pY + 'px';
}

// Esconder a DIV de AJUDA
function esconderDiv(){
	document.getElementById('dTexto').style.visibility = 'hidden';
}

function replaceBR(str){

	//alert(str);
	n = (str.split("<br>")).length;
	for (i=0; i<n; i++ ){
		str = str.replace('<br>', "\r\n");
	}
	
	return str;
}


// VERIFICAR DADOS


//Verificar E-mail
function isReady(form, linguagem) {
    
    //if (isEmail(form.address.value) == false) {
		//val = form.
    
    switch (linguagem){
    	case 'pt':
      		mensagem = "P.f., introduza um e-mail válido.";
         break;
      case 'en':
      		mensagem = "Invalid Email.";
         break;
      case 'es':
      		mensagem = "Por favor, introduzca un e-mail válido.";
         break;
       
      	
    }
    
    
		if (isEmail(form.value) == false) {
        alert(mensagem);
        form.focus();
        return false;
    }
		/*
    if (isProper(form.username.value) == false) {
        alert("Please enter a valid username.");
        form.username.focus();
        return false;
    }
		*/
    return true;
}


function isEmail(string) {
    if (string.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
        return true;
    else
        return false;
}

function isProper(string) {
    if (string.search(/^\w+( \w+)?$/) != -1)
        return true;
    else
        return false;
}

function nl2br( str ) {
	return str.replace(/([^>])\n/g, '$1<br>\n');
}

function mudarInstrumento(inst){

	//alert(inst);
  url = 'instrumentos.php?instrumento=' + inst;
  sendRequest('GET', 'dInstrumentos', url);

}