// JavaScript Document
var testimonials;
$(document).ready(function() {

	$('#image_rotate').innerfade({   
         speed: 'slow',   
         timeout: 3000,   
         type: 'sequence',   
         containerheight: '140px'  
     });  
	
	if ($('#testimonials')) {
		$("p.test", this).hide();	
		testimonials=new Array();
		testimonials = $("p.test");
		selectTest();
	}	
});

function showForm() {
	$("#formdata").show();
}

function selectTest(jp) {
	var j = Math.floor( Math.random() * ( 4 + 1 ) );
	if (j == jp) {
		j = j+1;
	}
	for (i = 0; i < testimonials.length; i++) {
		$(testimonials[i]).hide();
	}
	if (testimonials[j] == "" || j == null) {
		$(testimonials[1]).animate({
	   opacity: 'show'
	 }, 1000);
	}
	else {
		$(testimonials[j]).animate({
	   opacity: 'show'
	 }, 1000);
	}
	var delay = setTimeout("selectTest(" + j + ")",10000)
}

function validate(thisform,referrer) {
	with (thisform) {
		if ($("#contactform")) {
			//check all form values completed
			$("input.val").each(function(i){
				if ($(this).attr("id") == "email") { 
					if (! validateEmail(this)) {
						$("~ span", this).show(); 
						$(this).css({ border: "1px solid #f00" });
						$("#errMess").show();
						this.focus();
						subfrm = 'false';
						return false;
					}
				}
				if (this.value == ""){ 
					$("~ span", this).show(); 
					$(this).css({ border: "1px solid #f00" });
					$("#errMess").show();
					this.focus();
					subfrm = 'false';
					return false;
				} else {
					$("~ span", this).hide();
					$("#errMess").hide();
					$(this).css({ border: "1px solid #CCC" });
					subfrm = 'true';
				}
			});
		}
		if (subfrm == 'false') {
			return false;
		}else{
			$("#formdata").hide();
			$("#feedback").append("<p class=center>Please wait, sending data<br><img src=i/ajax-loader.gif /></p>");
			var frmData = $("form").serialize();
			$.ajax({
			   type: "POST",
			   url: "http://www.petmates.com.au/mailer.php",
			  data: frmData,
			  
			   timeout: 1000,
				error: function(msg){
					$("#feedback > p").remove();
				 	$("#feedback").append("<h3>Thank you" + msg + "your information has been received</h3><p><a href='#' onclick='closeForm()'>You can now close this form</a></p>");
				},
			   success: function(msg){
				 $("#feedback > p").remove();
				 if (referrer == "contact") {
					 $("#feedback").append("<h3><span class='hlight'>Thank you" + msg + "your information has been received</span></h3><p><strong>We will be in contact with you very soon</strong></p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>");
					 return false;
				 }else {
				 	$("#feedback").append("<h3>Thank you" + msg + "your information has been received</h3><p><a href='#' onclick='closeForm()'>You can now close this form</a></p><p>&nbsp;</p><p>&nbsp;</p><p>&nbsp;</p>");
					return false;
				 }
			   }
			 });
			return false;
		}		
	}
 }
