// JavaScript Document
 jQuery.noConflict(); 
 
 jQuery(document).ready(function() {
	jQuery("#nav li:last a").css("background", "url(images/navBgRepeat.png) repeat-x").mouseenter(function () {  jQuery(this).css("background", "#EEE")} ).mouseout(function () { jQuery(this).css("background", "url(images/navBgRepeat.png) repeat-x") } );
	jQuery("#nav li:last #active_menu-nav").css("background", "#EEE");
	if (jQuery("#quickQuery").length > 0) {
		jQuery("#quickQuery").submit(function () { 
								return submitForm("quickQuery"); });
	}
	if (jQuery("#techquery").length > 0) {
		
		if (jQuery("#currentPage").length > 0) {
			jQuery("#currentPage").val(document.location.href);
		}
		
		jQuery("#techquery").submit(function () { 
								return submitForm("techquery"); });
	}
	/*
	if (jQuery("#imageRotate").length > 0) {
		jQuery("#imageRotate li:first").attr("class", "activeImage").css({"z-index": '3', "display": "block"}).animate({"dummy":"false"}, 4000, function() { nextImage(); });
	}
	*/
	
	if (jQuery("#homeBottom").length > 0) {
		if (jQuery("#homeBottom").children().length < 4) {
			
			jQuery("#homeBottom .moduletable:first").css({ width: "600px" });
		}
		
	}

	
	
});
  
function submitForm(formid) {
	var data = jQuery("#"+formid).serialize();
	
	var name = jQuery("#name").val();
	var email = jQuery("#email").val();
	var phone = jQuery("#phone").val();
	var company = jQuery("#company").val();
	var comments = jQuery("#query").val();
	if ((name == "") || (email == "") || (phone == "") || (company == "") || (comments == "")) {
		alert("Please fill out all fields");
	} else {
		
		if (validate_email(email) == false) {
			alert("Please enter a valid email address");
		} else {
		
			jQuery.post("/includes/contact.php", data, function (data) { 
				if (data == "DONE") {
					document.location.href = "/thanks";
					//jQuery("#"+formid+"Response").html("<p><strong>Thank you for your query</strong></p><p>A Technetics representative will be in contact soon</p>");
				} else {
					var response = data.split("^^^^");
					
					if (jQuery('.captchaCell img').length > 0) {
						jQuery('.captchaCell img').attr("src", '/securimage/securimage_show.php?'+Math.random());
						jQuery("#captcha_code").val("");
					}
					
					if (response[0] == "FAIL") {
						if (response[1] != "") {
							alert(response[1]);
						}
					}
					
				}
			
			});
		}
	}
	return false;
	
}

function validate_email(field) {
	
  		var apos = field.indexOf("@");
  		var dotpos = field.lastIndexOf(".");
  		if ( apos < 1 || dotpos-apos < 2){
			return false;
		} else {
			return true;
		}
  
}


function  nextImage() {
	var images = jQuery("#imageRotate li");
	var countImages = images.length;
	if (countImages > 1) {
		var active = jQuery(".activeImage");
		var next = jQuery(".activeImage").next("li");
		if (next.length == 0) {
			 next = jQuery("#imageRotate li:first");
		}
		
		next.css({"display":"block", "zIndex": 2});
		active.fadeOut(1000, function() {
			active.attr("class", "");
			next.attr("class", "activeImage").css("zIndex", countImages);
			jQuery("#homeImages li").not(next).css("zIndex", 1);	
			jQuery(".activeImage").animate({"dummy":"false"}, 4000, function() { nextImage(); });
		});
	
	}
}

