	sfHover = function() {
		var sfEls = document.getElementById("nav").getElementsByTagName("LI");
		for (var i=0; i<sfEls.length; i++) {
			sfEls[i].onmouseover=function() {
				this.className+=" over";
			}
			sfEls[i].onmouseout=function() {
				this.className=this.className.replace(new RegExp(" over\\b"), "");
			}
		}
	}
	if (window.attachEvent) window.attachEvent("onload", sfHover);
	
String.prototype.trim = function() {
                return this.replace(/^\s+|\s+$/g,"");
}



function valid_email(email){
    var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    return reg.test(email)
}
function validate_question(){
                var firstname=document.getElementById("question_firstname").value.trim();
                var lastname=document.getElementById("question_lastname").value.trim();
                var email = document.getElementById("question_email").value.trim();
                var question= document.getElementById("question").value.trim();
                var message='The following errors have been found-\n\n';
                var flag=true;
                if(firstname == ""||firstname =="First Name"  ){
                    flag=false;
                    message=message+"\t- First name must be provided\n"
                }
                if(lastname == "" ||lastname == "Last Name" ){
                    flag=false;
                    message=message+"\t- Last name must be provided\n"
                }
                if(email == ""|| email=="Your Email"  ){
                    flag=false;
                    message=message+"\t- Email must be provided\n"
                }else{
                    if(!valid_email(email)){
                        flag=false;
                        message=message+"\t- Email must be a valid email address\n"
                    }
                }

                

                if(question == ""  ){
                    flag=false;
                    message=message+"\t- Question must be provided\n"
                }

                if (!flag){
                        alert(message);
                 }
                    return flag;
}
function validate_mailinglist(){
                var firstname=document.getElementById("firstname").value.trim();
                var lastname=document.getElementById("lastname").value.trim();
                var email = document.getElementById("email").value.trim();
                var message='The following errors have been found-\n\n';
                var flag=true;
                if(firstname == ""||firstname =="First Name"  ){
                    flag=false;
                    message=message+"\t- First name must be provided\n"
                }
                if(lastname == "" ||lastname == "Last Name" ){
                    flag=false;
                    message=message+"\t- Last name must be provided\n"
                }
                if(email == "" ||email=="Your Email"  ){
                    flag=false;
                    message=message+"\t- Email must be provided\n"
                }else{
                    if(!valid_email(email)){
                        flag=false;
                        message=message+"\t- Email must be a valid email address\n"
                    }
                }
                
                


                if (!flag){
                        alert(message);
                 }
                    return flag;
            }
$(document).ready(function(){
 
	var clearMePrevious = '';
	
	// clear input on focus
	$('.clearMeFocus').focus(function()
	{
		if($(this).val()==$(this).attr('title'))
		{
			clearMePrevious = $(this).val();
			$(this).val('');
		}
	});
	// if field is empty afterward, add text again
	$('.clearMeFocus').blur(function()
	{
		if($(this).val()=='')
		{
			$(this).val(clearMePrevious);
		}
	});
	
	$('#product_search_text').keyup(function()
	{
		var keyword=$(this).val();
		$.get("search_products.php?keyword="+keyword, function(data){
	  		$("#prod_search").html(data);
	  		$('#prod_search').show();
		});
		
	});
        $('#product_search_text').keyup(function()
	{
		var keyword=$(this).val();
		$.get("search_products.php?keyword="+keyword, function(data){
	  		$("#prod_search_div").html(data);
	  		$('#prod_search_div').show();
		});

	});

        $('#home_product_search_text').keyup(function()
	{
		var keyword=$(this).val();
		$.get("search_products.php?keyword="+keyword, function(data){
	  		$("#home_product_search_div").html(data);
	  		$('#home_product_search_div').show();
		});

	});

        $("#product_search").click(function(){
            $("#product_search_form").submit();
        });
        $("#home_product_search").click(function(){
            $("#home_product_search_form").submit();
        });
    	if ($('#map_canvas').length>0){
    		initializeGoogleMap();
    	}        
});
var geocoder;
var map;
var bounds=null;
var markers=new Array();
var markerImage;
function initializeGoogleMap() {
    geocoder = new google.maps.Geocoder();
    bounds = new google.maps.LatLngBounds();
    var latlng = new google.maps.LatLng(-28.5, 133);
    var myOptions = {
      zoom: 4,
      center: latlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
}


function putStockistsOnMap(stockists){
	
	 $.each(stockists, function(i,stockist)
			 {   
		 if (stockist.latitude!='' && stockist.longitude!=''){
			 
		 var point = new google.maps.LatLng(stockist.latitude, stockist.longitude);
		 marker = new google.maps.Marker({
	            map: map,
	            position: point,
	            //title: office.office_name,
	            //icon: 'images/bluemarker.png'
	        });		 
		 bounds.extend(point);
		 }
			 });

	 	 map.setCenter(bounds.getCenter());
		 map.fitBounds(bounds);
	 
	 //if only one office. zoom out.
	 
}
