var containerHeight;           
            
myEfect = function() {
    $('container').style.display='block';
    containerHeight = new fx.Height('container', {duration: 400});
}

window.onload = myEfect;
   
function showCategories(id)
{
    $(id + 'Select').style.display = 'block';
    $(id).style.display = 'none';
    
} 

function showNewCategories(id)
{
    $(id + 'Select').style.display = 'none';
    $(id).style.display = 'block';
    
}


function sendSome()
{
    var usuario = "fes-montjuic";
    var dominio = "xtec";
    var extension = "cat";
    var subject = "Info";

    emailCod=(usuario + '@' + dominio + '.' + extension + "?" + "subject" + "=" + subject);
    emailLabel=(usuario + '@' + dominio + '.' + extension);
    document.write('<a href="mailto:' + emailCod + '">' + emailLabel + '</a>');
}


function validaEnviar()
{
    var n=true;
    var e2=true;    
    var m=true;
    
    n=validateField('nom1','msgerror','message','Si us plau, indica el teu nom', 'Si us plau indica el teu nom');
    e2=validateEmail('email2', 'msgerror','message','El correu indicat no \xE9s v\xE0lid', 'Si us plau, indica el teu correu');
    m=validateTextarea('comentari', 'msgerror','message','Si us plau, escriu un missatge', 'Si us plau, escriu un missatge');    
    
    if (n!=false) n=true;
    if (e2!=false) e2=true;
    if (m!=false) m=true;
 
    
    if (n && e2 && m) 
    {
        document.getElementById('formenviar').submit();
    }                 
}

function validaEnviarEs()
{
    var n=true;
    var e2=true;    
    var m=true;
    
    n=validateField('nom1','msgerror','message','Por favor, indica tu nombre', 'Por favor, indica tu nombre');
    e2=validateEmail('email2', 'msgerror','message','El email indicado no es v\xE1lido', 'por favor indica tu email');
    m=validateTextarea('comentari', 'msgerror','message','Por favor, escribe un mensaje', 'Por favor, escribe un mensaje');    
    
    if (n!=false) n=true;
    if (e2!=false) e2=true;
    if (m!=false) m=true;
 
    
    if (n && e2 && m) 
    {
        document.getElementById('formenviar').submit();
    }                 
}


function validaEnviarContact()
{
    var n=true;
    var e1=true;  
    var m=true;
    
    n=validateField('nom1','msgerror','message','Si us plau, indica el teu nom', 'Si us plau indica el teu nom');
    e1=validateEmail('email1', 'msgerror','message','El correu indicat no \xE9s v\xE0lid', 'Si us plau, indica el teu correu');
    m=validateTextarea('comentari', 'msgerror','message','Si us plau, escriu un missatge', 'Si us plau, escriu un missatge');    
    
    if (n!=false) n=true;
    if (e1!=false) e1=true;
    if (m!=false) m=true;
 
    
    if (n && e1 && m) 
    {
        document.getElementById('formenviar').submit();
    }                 

}

function validaEnviarContactEs()
{
    var n=true;
    var e1=true;  
    var m=true;
    
    n=validateField('nom1','msgerror','message','Por favor, indica tu nombre', 'Por favor, indica tu nombre');
    e1=validateEmail('email1', 'msgerror','message','El email indicado no es v\xE1lido', 'por favor indica tu email');
    m=validateTextarea('comentari', 'msgerror','message','Por favor, escribe un mensaje', 'Por favor, escribe un mensaje');    
    
    if (n!=false) n=true;
    if (e1!=false) e1=true;
    if (m!=false) m=true;
 
    
    if (n && e1 && m) 
    {
        document.getElementById('formenviar').submit();
    }                 

}


function validaNewsletter() {
    var e=true;
    var n=true;
    e=validateEmail('nlemail', 'error-newsletter','msg-newsletter','E-mail inv\340lid', 'Indiqueu l\'e-mail');
    n=validateField('nlname','error-newsletter','msg-newsletter','Indiqueu el nom', 'Indiqueu el nom');
    if (e!=false) e=true;
    if (n!=false) n=true;
    
    if (e && n) {
        document.getElementById('subscribe').submit();
    }                 
} 

function validaNewsletterEs() {
    var e=true;
    var n=true;
    e=validateEmail('nlemail', 'error-newsletter','msg-newsletter','E-mail inv\xE1lido', 'Indicar el e-mail');
    n=validateField('nlname','error-newsletter','msg-newsletter','Indicar el nombre', 'Indicar el nombre');
    if (e!=false) e=true;
    if (n!=false) n=true;
    
    if (e && n) {
        document.getElementById('subscribe').submit();
    }                 
} 




function validateField(id,msgArea,msg,alertText,isError)
{
    field = document.getElementById(id);
    if(!check_field(field.value)){
        showMsg(msgArea, msg, alertText,isError);
        // change the color of text field
        field.style.borderColor = "red";
        field.focus();
        // make sure the form is not submitted
        return false;
    }
    else {
        return true;
    }
}

function validateEmail(id,msgArea,msg,alertText)
{
    // check the first email address ( the exclamation means "not" )
    field = document.getElementById (id);
    if(!check_email(field.value)){
        showMsg (msgArea,msg,alertText,true);
        // change the color of text field
        field.style.borderColor = "red";
        field.focus(); 
        // make sure the form is not submitted
        return false;
    }
    else {
        return true;
    }
}

function validateTextarea(id,msgArea,msg,alertText,isError)
{
    field = document.getElementById(id);
    if(!check_texta(field.value)){
    showMsg(msgArea, msg, alertText,isError);
    // change the color of text field
    field.style.borderColor = "red";
    field.focus();
    // make sure the form is not submitted
    return false;
    }
    else {
        return true;
    }
}

function check_texta(f)
{
    if (f) {
        var field = trim(f);
        if (field.length == 0) {
            return false;
        } else {
            return true;
        }
    } else {
        return false;
    }
}

function showMsg (msgArea, msg, msgText,isError)
{
    displayArea = document.getElementById (msgArea);
    displayElement =  document.getElementById (msg);
    displayArea.style.display = "";
    if (isError) {
        displayArea.style.backgroundColor="#ff6666";
    }
    else {
        displayArea.style.backgroundColor="#FFFF99";    
    }
    if (!isDOMCompliant) {
        alert (msgText);
    }
    else {
        
        changeElementText (displayElement,msgText);
        //document.location.href="#top";    
    }
}

function changeElementText (node,text) 
{
    while (node.hasChildNodes()) {
        node.removeChild(node.lastChild);
    }
    var textNode = document.createTextNode(text);
    node.appendChild(textNode );
}

function startList(){
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") {
				node.onmouseover=function() {
					this.className+=" over";
				}
				node.onmouseout=function() {
					this.className=this.className.replace(" over", "");
				}
			}
		}
	}
}

function check_field (f)
{
    var field = trim(f);
    if (field.length == 0) {
        return false;
    }
    else {
        return true;
    }
} 

function trim(str)
{
    return str.replace(/^\s*|\s*$/g,"");
}

function isDOMCompliant ()
{
        return (document.getElementsByTagName && document.createElement);
}

/**
* Function: Which button is pressed
**/

function wichButton(event)
{
	return event.keyCode;
}
/**
* Function: Verifies if the user has introduced the return key
* @param	keyCode
**/

function verifyCR (keyCode){
	if(keyCode == 13){
      document.getElementById('formacces').submit();
    }
    	
}


function check_email (emailAddress) {
    var re = /^(([^<>()[\]\\.,;:\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 re.test(emailAddress);
}


         
        
