function makeBackgroundActive( e )
{


    if (!e) {var e = window.event}

        if (e.target){
            targ = e.target
        }
        else if (e.srcElement){
          targ = e.srcElement
        }

        if (targ.nodeType == 3){ // defeat Safari bug
            targ = targ.parentNode;
        }

        var targ;
        var parentDivName;

        targ = targ.parentNode;
        parentDivName = targ.parentNode.id;  // traverse another parent node for input

        activateBackgroundColour( parentDivName );
}


function activateBackgroundColour( parentDivName ){

	
	 
     var rowLabel =  parentDivName.substring( 0, parentDivName.length -2);
	 	 
	 

     for( var loop=1; loop < 40; loop++ ){
         
		  		  
		  var label = rowLabel; 

		  
		  if ( loop < 10){
			label += "0";		  
		  }
		  
		  label+=loop;
	  
          var ele = document.getElementById(label);

		  //alert( ele + ' element for ' +  label) ;
		  
          if (ele != null){
              if (( label == parentDivName) ){
                  ele.style.backgroundColor= "#efefef" ;
                 
              }
              else{
                  ele.style.backgroundColor= "#ffffff";

              }
          }
      }
}

function getValidatingFields(){

  var validatingFields = new Array();

  validatingFields.push("name");
  validatingFields.push("info");

  return validatingFields;
}



function validateForm()
{

	
	
   var validate = false;


   var fEmail = document.getElementById('femail');
   var lEmail = document.getElementById('lemail');

   var basicFormFields  =   validateFormFieldValues();
   var emailValidate    =   validateEmail() ;
   var telValidate      =   validateTelephone();

   if ( basicFormFields && (emailValidate | telValidate )  ){
        validate = true;
   }

   displayFormMessage( validate);

   if(validate){
    var form  = document.getElementById("contactForm");
    form.action="http://www.halcyo.com/sendIt.php";

    document.forms[0].submit();
   }


}







function validateEmail( fEmail, lEmail ){

    var validateEmail = false;
    
    var formEmail = fEmail.value;

    var atPos = formEmail.indexOf("@");

    if ( atPos != -1 ){

     var restOfString = formEmail.substring(atPos+1, formEmail.length);

     if ( restOfString.indexOf(".")!= -1)
        validateEmail = true;
        resetStyleForm( lEmail, fEmail );
     }

     if(!validateEmail){
      errorStyleForm( lEmail, fEmail );
     }

     return validateEmail;
}



function focus(  objId ){

	document.getElementById( objId ).focus();


}


function validateTelephone(  ){

    var validateTel = false;

    var fTel = document.getElementById('fnumbers');
    var lTel = document.getElementById('lnumbers');

    if ( fTel.value.length > 6 ){
     validateTel = true;
     resetStyleForm( lTel, fTel );
    }
    else {
       errorStyleForm( lTel, fTel );
    }
   return validateTel;


}

function errorStyleForm( label, input ){
       label.style.color = "#cc3333";
       input.style.color = "#cc3333";
}

function resetStyleForm( label, input ){
       label.style.color = "#6F8247";
       input.style.color = "#666666";
}


function displayFormMessage( success ){


    var sendMessage = document.getElementById('sendMessage');

    if (success){
         sendMessage.style.color = "#000000";
         sendMessage.innerHTML = "<img src=\"images/checkmark.gif\" width=\"14\" height=\"13\" /> &nbsp;&nbsp;&nbsp;" + "Thanks for your enquiry, we'll contact you shortly";

    }
    else{
        sendMessage.style.color = "#000000";
       sendMessage.innerHTML =   "<img src=\"images/attention3_16x16.gif\" width=\"16\" height=\"16\" />  &nbsp;&nbsp;&nbsp;"  + "Oops .. We need you to amend the errors in <font color=\"#cc3333\">red</font>.";
    }
}



function redirect( page ){


	if ( page == 'eatOut'){
		location.href="eatingout.htm";

	}
	else if ( page == 'eatIn'){
		location.href="eatingin.htm";

	}
	else if ( page == 'veggie'){
		location.href="eatingoutveggie.htm";
	}
	else if ( page == 'vegan'){
		location.href="eatingoutvegan.htm";
	}
	else if ( page == 'home'){
		location.href="index.html";
	}

	else if ( page == 'search'){
		location.href="eatingout.htm";

	}
	else if ( page == 'clubs'){
		location.href="eatingout.htm";

	}
	else if ( page == 'recommend'){
		location.href="recommend.htm";
	}
	
}



