
$(document).ready(function(){
    $.defaultText({
           clearEvents: [
   {selector: '#contact .submit', type:'click'}
    ],
    css: 'title-style'
    });
    
      $('#slide-show').cycle({
		fx: 'fade',
                random: 1
	});
 
   $('.toggle').click(function(){
      $('.inner-ul').toggle('500');
      
   });
  
//  $('#prev').hide();
//     $.post('about_content.html',function(data){
//        $('#about-content').append(data);
//         });
//            $('#next').click(function(){
//                        $('#about-content').empty();
//                   $.post('about_content2.html',function(data){
//                $('#about-content').append(data); 
//                  });
//                $('#prev').show();
//                $('#next').hide();
//               });
//        $('#prev').click(function(){
//      $('#about-content').empty();
//      $.post('about_content.html',function(data){
//          $('#about-content').append(data); 
//          });
//         $('#prev').hide();
//          $('#next').show();
//       });

$('#customs').click(function(){
    window.location = $(this).find('a').attr('href');
    return false;
});

$('#customs').hover(
    function(){$('#customs').css({background: "url(images/customs-clearing2.jpg) no-repeat"})},
  function(){
     if(!$(this).hasClass('hover-sel')){ 
      $('#customs').css({background: "url(images/customs-clearing.jpg) no-repeat"});
     }
  }
);
  
  $('#forwarding').click(function(){
    window.location = $(this).find('a').attr('href');
    return false;
});

$('#forwarding').hover(
    function(){$('#forwarding').css({background: "url(images/forwarding_f2.jpg) no-repeat"})},
  function(){
      if(!$(this).hasClass('hover-sel')){ 
      $('#forwarding').css({background: "url(images/forwarding_f1.jpg) no-repeat"});
      }
  }
);
  
    $('#ship_agency').click(function(){
    window.location = $(this).find('a').attr('href');
    return false;
});

$('#ship_agency').hover(
    function(){$('#ship_agency').css({background: "url(images/ship-agency2.jpg) no-repeat"})},  
  function(){
      if(!$(this).hasClass('hover-sel')){ 
      $('#ship_agency').css({background: "url(images/ship-agency.jpg) no-repeat"});
  }
  }
);
  
      $('#warehousing').click(function(){
    window.location = $(this).find('a').attr('href');
    return false;
});

$('#warehousing').hover(
    function(){$('#warehousing').css({background: "url(images/warehousing-2.jpg) no-repeat"})},
  function(){
      if(!$(this).hasClass('hover-sel')){ 
      $('#warehousing').css({background: "url(images/warehousing-1.jpg) no-repeat"});
      }
  }
);
  
 $('#marine').click(function(){
    window.location = $(this).find('a').attr('href');
    return false;
});

$('#marine').hover(
    function(){$('#marine').css({background: "url(images/marine-insurance2.jpg) no-repeat"})},
  function(){
      if(!$(this).hasClass('hover-sel')){ 
      $('#marine').css({background: "url(images/marine-insurance.jpg) no-repeat"});
      }
  }
);


});


function trim(s)
{
  return s.replace(/^\s+|\s+$/, '');
}

function validateEmail(fld) {
    var error="";
    var tfld = trim(fld.value);                        // value of field with whitespace trimmed off
    var emailFilter = /^[^@]+@[^@.]+\.[^@]*\w\w$/ ;
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ ;
   
    if (fld.value == "") {
        fld.style.background = 'Yellow';
        error = "Please enter an email address.\n";
    } else if (!emailFilter.test(tfld)) {              //test email for illegal characters
        fld.style.background = 'Yellow';
        error = "Please enter a valid email address.\n";
    } else if (fld.value.match(illegalChars)) {
        fld.style.background = 'Yellow';
        error = "The email address contains illegal characters.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateName(fld) {
    var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "Please enter your name.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateMessage(fld){
	  var error = "";
    var illegalChars = /\W/; // allow letters, numbers, and underscores
 
    if (fld.value == "") {
        fld.style.background = 'Yellow'; 
        error = "Please enter a message.\n";
    } else {
        fld.style.background = 'White';
    }
    return error;
}

function validateCell(fld){
    	var error = "";
    var stripped = fld.value.replace(/[\(\)\.\-\ ]/g, '');    

    if(fld.value != ""){
    if (isNaN(parseInt(stripped))) {
        error = "The contact number contains illegal characters.\n";
        fld.style.background = 'Yellow';
    }
	}
    return error;
}


function validateFormOnSubmit(theForm) {
var reason = "";

  reason += validateName(theForm.name);
  reason += validateCell(theForm.tel);
  reason += validateEmail(theForm.email);
  reason += validateMessage(theForm.enquiry);
      
  if (reason != "") {
    alert("Some fields need correction:\n" + reason);
    return false;
  }else{
     theForm.submit(); 
  }

  return true;
}



