//Clear text boxes on click, and return value if left null
function clearText(field){
   if (field.defaultValue == field.value) field.value = '';
   else if (field.value == '') field.value = field.defaultValue;
}

function DoNav(theUrl)
  {
  document.location.href = theUrl;
  }
//Nav drop down change classes
$(function() {
	$('.navdropdown').mouseover(function() {
		$('.navdrop').show();
		$('.navdropdown').addClass('selected');
	});
	$('.off').mouseover(function() {
		$('.navdrop').hide();
		$('.navdropdown').removeClass('selected');
	});
	$('#right, #number, #logo, #content, #left, #search').mouseover(function() {
		$('.navdrop').hide();
		$('.navdropdown').removeClass('selected');						   
	});
});
//Nav drop down
jQuery.fn.openMenu = function(id) {
	var box = document.getElementById('menu'+id);
	if(box.style.display == "none") {
		$('#menu'+id).show();
		$('#cat_heading'+id).addClass('caton');
	} else if(box.style.display == "block") {
		$('#menu'+id).hide();
		$('#cat_heading'+id).removeClass('caton');
	} else {
		$('#menu'+id).hide();
		$('#cat_heading'+id).removeClass('caton');
	}
};
//JCAROUSEL bind previous and next to existing links
function updatescarousellarge_initCallback(carousel) {
    jQuery('.ublock a').bind('click', function() {
        carousel.scroll(jQuery.jcarousel.intval(jQuery(this).text()));
        return false;
    });
};
/*function updatescarousel_initCallback(carousel) {
    jQuery('#right').bind('click', function() {
        carousel.next();
        return false;
    });

    jQuery('#left').bind('click', function() {
        carousel.prev();
        return false;
    });
};
//Jcarousel Settings
jQuery(document).ready(function() {
    jQuery('#updatescarousel').jcarousel({
        scroll: 1,
		auto: 5,
		initCallback: updatescarousel_initCallback,
		 // This tells jCarousel NOT to autobuild prev/next buttons
        buttonNextHTML: null,
        buttonPrevHTML: null,
		wrap: 'circular'
    });
});*/
jQuery(document).ready(function() {
	var hash = 1; 
	if (window.location.hash) {
		hash = parseInt(window.location.hash.slice(1));
	}
    jQuery('#updatescarousellarge').jcarousel({
		start: hash,
        scroll: 1,
		initCallback: updatescarousellarge_initCallback,
		wrap: 'circular'
    });
	jQuery('#partnerscarousel').jcarousel({
        scroll: 5,
		auto: 2,
		wrap: 'circular',
		buttonNextHTML: null,
        buttonPrevHTML: null
    });
});
$(document).ready(function() {
    $('#banner').cycle({
		fx: 'fade',
		speed:  2500 
	});
});
//Show IFRAME ONCE LOADED
$(document).ready(function(){ 
    $('.iframe').show(); 
});

//Form validation and submit
$(document).ready(function() {	 
	 $('.error').hide();
	//Enquiry Form 1
	$("form#enquiryform").submit(function() { 
	$('.error').hide();
     var name     = $('#name').attr('value');
	 if (name == "") {
      $("label#enquiryform_error").show();
      $("input#name").focus();
      return false;
    }
     var company     = $('#company').attr('value');
	 if (company == "") {
      $("label#enquiryform_error").show();
      $("input#company").focus();
      return false;
    }	 
	var telephone  = $('#telephone').attr('value');
	 var email     = $('#email').attr('value');  
	 $('.error').hide();
	 if (email == "") {
      $("label#enquiryform_error").show();
      $("input#email").focus();
      return false;
    }
	 var address     = $('#address').attr('value');  
	 $('.error').hide();
	 if (address == "") {
      $("label#enquiryform_error").show();
      $("input#address").focus();
      return false;
    }
	 var postcode     = $('#postcode').attr('value');  
	 $('.error').hide();
	 if (postcode == "") {
      $("label#enquiryform_error").show();
      $("input#postcode").focus();
      return false;
    }
     var enquirybox   = $('#enquirybox').attr('value');
	 $('.error').hide();
	var product = $('#product').attr('value');
	 $('.error').hide();
	 if (product == "none") {
      $("label#enquiryform_error").show();
      $("input#product").focus();
      return false;
    }	
	var robotest = $('#robotest').attr('value');
	var type = $('#type').attr('value');
     $.ajax({  
     type: "POST",  
     url: "includes/sendenquiryajax.php",  
     data: "name="+ name +"& company="+ company+ "& telephone="+ telephone+ "& email="+ email+ "& enquirybox="+ enquirybox+ "& address="+ address+ "& postcode="+ postcode+ "& product="+ product+ "& robotest="+ robotest+ "& type="+ type,  
     success: function(){
                 //$('form#enquiry').hide(function(){$('div.success').fadeIn();});
				if (type === "product") {
					var url = "product-enquiry-submitted";   
				} 
				else if(type === "technical") {
					var url = "technical-enquiry-submitted";
				}
				else if(type === "brochure") {
					var url = "brochure-request-submitted";   
				}
				else if(type === "promo") {
					var url = "promotional-gift-submitted";   
				}
				else if(type === "general") {
					var url = "enquiry-submitted";   
				}
				$(location).attr('href',url);
             }  
         });  
     return false;  
     }); 
});
