Event.observe(window, 'load', function() {
	// Preload images
	var index = 0;
	images = new Array("http://www.thewinecolours.com/img/bg/header00.jpg","http://www.thewinecolours.com/img/bg/header01.jpg","http://www.thewinecolours.com/img/bg/header02.jpg", "http://www.thewinecolours.com/img/bg/header03.jpg", "http://www.thewinecolours.com/img/bg/header04.jpg", "http://www.thewinecolours.com/img/bg/header05.jpg");
	var imageList = new Array();
	for(i=0;i<images.size();i++) {
		imageList[i] = new Image();
		imageList[i].src = images[i];
	}
	//Start sequence
		imageIndex = 0;
		setTimeout("loadHeaderImage()", 5000);
		
	if ($('tours')) {
		HSlideMenu("tours").setFirst(1).maxWidth(400).minWidth(120).build();        
	}
});

function loadHeaderImage() {
	imageIndex++;
	if (imageIndex == 6) imageIndex = 0;
	new Effect.Opacity('header-main', { from: 1, to: 0 });
    setTimeout("$('header-main').style.backgroundImage='url('+images[imageIndex]+')';new Effect.Opacity('header-main', { from: 0, to: 1 })", 1100);
	setTimeout("loadHeaderImage()", 10000);
}

function regActive(num)
{ 
for (i=1; i<166;i++){   
    var zone = "zone-" + i;
    
    if ($(zone)!=null) {
     $(zone).style.display='none';
    } 
    
    if (num==i) {
     $(zone).style.display='block'; 
    }     
    }          
 
  }
  
function displayNewsletter ()
{   
    var name =  $('nelname').value;
    var email =  $('nelemail').value;
    var group = $('group_id').value;
    
    var news = $('select-newslet').checked;
    
    if (news==true) { 	  
    	
	new Ajax.Request('http://www.thewinecolours.com/index.php?command=subscribe_user', {
					 method: 'post',
					 evalScripts: true,
					 encoding: 'iso-8859-1',
     				 parameters: {name: name, email: email, nl_group_id: group}	 
                    });
                          
     }
     document.getElementById('formenviar').submit();                     
}


function deleteContentName ()
{   
    var contentName = document.getElementById('nlname').value;
    
    if (contentName=='Nom' || contentName=='Nombre' || contentName=='Name') {
     document.getElementById('nlname').value='';
    }       
	}
	
function deleteContentEmail ()
{   
    var contentEmail = document.getElementById('nlemail').value;
    
     if (contentEmail=='e-mail') {
     document.getElementById('nlemail').value='';
    }		
	}
	
function deleteSearch ()
{   
    var search = document.getElementById('cerca').value;
    
     if (search=='Cerca' || search=='B\xFAsqueda' || search=='Search') {
     document.getElementById('cerca').value='';
    }		
}


function validaNewsletter(lang) {
    var e=true;
    
    if (lang=='ca') {
        e=validateEmail('nlemail', 'error-newsletter','msg-newsletter','L\'adre\xE7a indicada no \xE9s correcta', 'Si us plau, indiqui el seu e-mail'); 
    }
   else if (lang=='es') {
        e=validateEmail('nlemail', 'error-newsletter','msg-newsletter','La direcci\xF3n indicada no es correcta', 'Por favor, indique su email');
    }
     else if (lang=='en') {
        e=validateEmail('nlemail', 'error-newsletter','msg-newsletter','The indicated address isn\'t correct', 'Please, indicate your e-mail');
    }
   
    if (e!=false) e=true;
        
    if (e) {
        document.getElementById('newsletter').submit();
    }                 
} 

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



function showMsg (msgArea, msg, msgText,isError)
{
    displayArea = document.getElementById (msgArea);
    displayElement =  document.getElementById (msg);
    displayArea.style.display = "";
    if (isError) {
        displayArea.style.backgroundColor="#e6e6e6";
    }
    else {
        displayArea.style.backgroundColor="#e6e6e6";    
    }
    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 isDOMCompliant ()
{
        return (document.getElementsByTagName && document.createElement);
}

function validaRecomendar(lang)
{

    var n=true;
    var e2=true;    
    var m=true;
    
    if (lang=='ca') {
        n=validateField('nom1','msgerror','message','Si us plau, indiqueu el vostre nom', 'Si us plau, indiqueu el vostre nom');
        e2=validateEmail('email2', 'msgerror','message','L\'adre\xE7a indicada no \xE9s correcta', 'Si us plau, indiqueu el vostre e-mail'); 
    }else{
        n=validateField('nom1','msgerror','message','Por favor, indique su nombre', 'Por favor, indique su nombre');
        e2=validateEmail('email2', 'msgerror','message','La direcci\xF3n indicada no es correcta', 'Por favor, indique su email'); 
    }         
    
    if (n!=false) n=true;
    if (e2!=false) e2=true;
 
    
    if (n && e2) 
    {
        document.getElementById('formenviar').submit();
    }                 
}



function validaEnviarEs()
{
    var n=true;
    var e2=true;    
    var m=true;
    
    n=validateField('name','msgerror','message','Por favor, indique su nombre', 'Por favor, indique su nombre');
    e2=validateEmail('email2', 'msgerror','message','La direcci\363n de correo indicada no es v\xE1lida', 'Por favor, indique su direcci\363n de correo');
    m=validateTextarea('comment', 'msgerror','message','Por favor, escriba un mensaje', 'Por favor, escriba un mensaje');    
    
    if (n!=false) n=true;
    if (e2!=false) e2=true;
    if (m!=false) m=true;
 
    
    if (n && e2 && m) 
    {
        document.getElementById('formsend').submit();
    }                 
}

function validaComentarioEs()
{
    var n=true;
    var e=true;    
    
    n=validateField('name','msgerror','message','Por favor, indique su nombre', 'Por favor, indique su nombre');
    e=validateEmail('email','msgerror','message','La direcci\xF3n indicada no es correcta', 'Por favor, indique su email'); 
    
    if (n!=false) n=true;
    if (e!=false) e=true;
 
    
    if (n && e) 
    {
        document.getElementById('formsend').submit();
    }                 
}

function validaComentarioCa()
{   
    var n=true;
    var e=true;    
    
    n=validateField('name','msgerror','message','Si us plau, indiqueu el vostre nom', 'Si us plau, indiqueu el vostre nom');
    e=validateEmail('email','msgerror','message','L\'adre\xE7a indicada no \xE9s correcta', 'L\'adre\xE7a indicada no \xE9s correcta'); 
    
    if (n!=false) n=true;
    if (e!=false) e=true;
 
    
    if (n && e) 
    {
        document.getElementById('formsend').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 = "#9c1b36;";
        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_field (f)
{
    var field = trim(f);
    if (field.length == 0) {
        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 trim(str)
{
    return str.replace(/^\s*|\s*$/g,"");
}

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);
}























