// JavaScript Document

$(document).ready(function () {

	jQuery.preLoadImages("images/nav/about_f2.png", "images/nav/programs_f2.png", "images/nav/news_f2.png", "images/nav/shop_f2.png", "images/nav/contact_f2.png", "images/nav/home_f2.png", "images/pnav/afl_f2.png", "images/pnav/cricket_f2.png", "images/pnav/football_f2.png", "images/pnav/lifesaving_f2.png", "images/pnav/netball_f2.png", "images/pnav/surfing_f2.png", "images/pnav/tennis_f2.png", "images/pnav/hockey_f2.png", "images/pnav/basketball_f2.png");
	navSetup();
	$(".activeImage").animate({"dummy":"false"}, 4000, function() { nextImage(); });

	$(".navItem").each(function () {
		var current = $(this);
		var count = $(this).children("ul").length;
		if (count == 0) {
			current.mouseover(function() { $(".navItem ul").css({display: "none"}); });
		} else {
				current.children("a:first").mouseover(function() {
				$(".navItem ul").css({display: "none"});
			
				$(this).next("ul").css({display: "block"}).mouseleave(function () { 
					$(this).css({display: "none"}).unbind("mouseleave");
				});
			});
		}
	});
	
	
	//$("#accordion").accordion();
});


function navSetup() {
	var navs = Array("#nav a", "#programNav a");
	for (var i = 0; i < navs.length; i++) {
		$(navs[i]).each(function () {
			var img = jQuery("img", this);
			if (img.length > 0) {
				var src = img.attr("src");
				var pos = src.lastIndexOf(".");
				var str1 = src.substr(0, pos);
				var str2 = src.substr(pos, src.length);
				var roll = str1+"_f2"+str2;
				$(this).mouseover(function () { swapImage(img, roll) });
				$(this).mouseout(function () { swapImage(img, src); });
			}
		});
	}
}

function toggleFAQField(number)
{
	$('#faqdiv'+number).toggle();
}

function swapImage(image, src) {
	$(image).attr("src", src);
}

(function($) {
	var cache = [];
    $.preLoadImages = function() {
    	var args_len = arguments.length;
        for (var i = args_len; i--;) {
        	var cacheImage = document.createElement('img');
        	cacheImage.src = arguments[i];
        	cache.push(cacheImage);
        }
    }
})(jQuery);







function calcShopPrice(box, price, amount) {
	var orderVal = $("#"+box).val();
	var orderValInt = parseInt(orderVal);
	if (isNaN(orderValInt)) {
		$("#"+box).val("");
	} else {
		if (orderValInt > amount) {
			alert("Please note due to stock levels of this item there may be a delay in shipping");
			//$("#"+box).val("");	  
		} 
		var itemPrice = orderValInt*price;
		var tempPrice = $("#totalAmount").val();
		var tempPrice = parseInt(tempPrice);
		if (isNaN(tempPrice)) tempPrice = 0;			
			
		var totalPrice = tempPrice+itemPrice;
		$("#totalAmount").val(totalPrice);
		
	}
	
}


function validateShop() {
	var pass = true;	
	var reqArray = ["fname", "lname", "email", "servlocation"];
	
	for (var i = 0; i < reqArray.length; i++) {
		var field = reqArray[i];
		if ($("#"+field).val() == "") {
			pass = false;
			$("#"+field).css("backgroundColor", "#E8F2FA");
		} else {
			$("#"+field).css("backgroundColor", "#ffffff");
		}
	}
	if (pass == false) {
		alert("Please fill out all required fields");
	}
	return pass
	
}






function  nextImage() {
	var countImages = $("#scrolling img").length;
	if (countImages > 1) {
		var active = $(".activeImage");
		var aId = active.attr("id");
		aId = parseInt(aId.replace("image", ""));
		if (!isNaN(aId)) {
			if (aId == countImages) {
				var next = 1;
			} else {
				var next = aId+1;
			}
			$("#image"+next).css({"display":"block", "zIndex": 2});
			active.fadeOut(1000, function() {
				active.attr("class", "");
				$("#image"+next).attr("class", "activeImage").css("zIndex", countImages);
				$("#scrolling img").not("#image"+next).css("zIndex", 1);
				
				
				$(".activeImage").animate({"dummy":"false"}, 4000, function() { nextImage(); });
			});
		}	
	}
}




function validateExpressionForm(){

	

	

	if(check_fields("NameofSchool","NameofSchool_div"))

	  var NameofSchool = true;

	else

	  var NameofSchool = false;

	  

	 if(document.getElementById('TypeofSchool').checked == false && document.getElementById('TypeofSchool_1').checked ==false )

	 {

		document.getElementById('TypeofSchool_div').style.visibility = 'visible';

		document.getElementById('TypeofSchool_div').style.position = 'static';

		var TypeofSchool = false;

	 }

	 else

	 {

		  document.getElementById('TypeofSchool_div').style.visibility = 'hidden';

		  document.getElementById('TypeofSchool_div').style.position = 'absolute';

		  var TypeofSchool = true;

	 }

	

	 

	  if(check_fields("SchoolAddress","SchoolAddress_div"))

	   var SchoolAddress = true;

	 else

	   var SchoolAddress = false;

	   

	 if(check_fields("Suburb","Suburb_div"))

	   var	Suburb = true;

	 else

	   var Suburb = false;

	   

	   

	   if(check_fields("PostalAddress","PostalAddress_div"))

	   var	PostalAddress = true;

	 else

	   var PostalAddress = false;

	   

	   if(check_fields("Suburb_2","Suburb_2_div"))

	   var	Suburb_2 = true;

	 else

	   var Suburb_2 = false;

	   

	   if(check_fields("Postcode","Postcode_div"))

	   var	Postcode = true;

	 else

	   var Postcode = false;

	   

	   if(check_fields("ContactPerson","ContactPerson_div"))

	   var	ContactPerson = true;

	 else

	   var ContactPerson = false;

	   

	   if(check_fields("Position","Position_div"))

	   var	Position = true;

	 else

	   var Position = false;

	   

	   if(check_fields("PhoneNumberBH","PhoneNumberBH_div"))

	   var	PhoneNumberBH = true;

	 else

	   var PhoneNumberBH = false;



	 if(check_fields("Fax","Fax_div"))

	   var	Fax = true;

	 else

	   var Fax = false;

	   

	  if(checkmail("Email","Email_div"))

	   	 var Email = true;

	 else

	   	 var Email = false;

	   		

	  /*  if(document.getElementById('Wouldyouliketobecome').checked == false && document.getElementById('Wouldyouliketobecome_2').checked == false ){

				document.getElementById('Wouldyouliketobecome_div').style.visibility = 'visible';

				document.getElementById('Wouldyouliketobecome_div').style.position = 'static';

				var Would = false;

		}else{

			document.getElementById('Wouldyouliketobecome_div').style.visibility = 'hidden';

			document.getElementById('Wouldyouliketobecome_div').style.position = 'absolute';

			var Would = true;

		}

	   	 */

	   

	 if((NameofSchool == true) && (TypeofSchool==true) && (SchoolAddress==true) && (Suburb==true) && (PostalAddress==true) && (Suburb_2==true) && (Postcode==true) && (ContactPerson==true) && (Position==true) && (PhoneNumberBH==true) && (Fax==true) && (Email==true) ) 

	 {

		return true;

	 }

	 else

	 {

		return false;

	 }

}


function check_fields(field_id,span_name)

{	

	  if (document.getElementById(field_id).value.length != 0)

	  {

		document.getElementById(span_name).style.visibility = 'hidden';

		document.getElementById(span_name).style.position = 'absolute';	

		return true;

	  }

	  else

	  {

		document.getElementById(span_name).style.visibility = 'visible';

		document.getElementById(span_name).style.position = 'static';

		return false;

	  }

}

function checkmail(email_field,email_div)  

{  

var emailfilter=/^\w+[\+\.\w-]*@([\w-]+\.)*\w+[\w-]*\.([a-z]{2,4}|\d+)$/i  

var returnval=emailfilter.test(document.getElementById(email_field).value)  

if (returnval==false)  

{  

	document.getElementById(email_div).style.visibility = 'visible';  

	document.getElementById(email_div).style.position = 'static';  

	return false;  

}  

else  

{

	document.getElementById(email_div).style.visibility = 'hidden';  

	document.getElementById(email_div).style.position = 'absolute';  

	return true;  

}

} 


function check_apponline()

{

 if(check_dropdownfields("program","program_div") )

   var pg = true;

 else

   var pg = false;

   	

 if(check_dropdownfields("title","title_div") )

   var tl = true;

 else

   var tl  = false;

  

  if(check_fields("surname","surname_div") )

   var sn = true;

 else

   var sn  = false;

 

 if(check_fields("fname","fname_div") )

   var fn = true;

 else

   var fn  = false;

  

  if(check_fields("remail","remail_div") )

  {

   if( checkmail("remail","remail_div") )

	   var em = true;

	else

	   var em = false; 	

  }

  else

   var em  = false;

  

  if(check_fields("dob","dob_div") )

   var db = true;

 else

   var db  = false;

  

  if(check_fields("zip","zip_div") )

   var zp = true;

  else

   var zp  = false;

  

  if(check_fields("hphone","hphone_div") )

   var hp = true;

  else

   var hp  = false;

  

  if(check_fields("parent_name","parent_name_div") )

   var pm = true;

  else

   var pm = false;
   
   if(check_fields("parent_phone","parent_phone_div") )

   var pm = true;

  else

   var pm = false;

  

  if(check_fields("school","school_div") )

   var sh = true;

  else

   var sh = false;
   
   if(check_fields("comment1","comment1_div") )

   var c1 = true;

  else

   var c1 = false;
   
   
    if(check_fields("comment2","comment2_div") )

   var c2 = true;

  else

   var c2 = false;
   
   
   
    if(check_fields("comment3","comment3_div") )

   var c3 = true;

  else

   var c3 = false;
   
   
    if(check_fields("comment4","comment4_div") )

   var c4 = true;

  else

   var c4 = false;
   
   
    if(check_fields("comment5","comment5_div") )

   var c5 = true;

  else

   var c5 = false;
   
    if(check_fields("comment7","comment7_div") )

   var c7 = true;

  else

   var c7 = false;
   
    if(check_fields("comment8","comment8_div") )

   var c8 = true;

  else

   var c8 = false;
   
    if(check_fields("parent_email","parent_email_div") )

   var pe = true;

  else

   var pe = false;
   
   
   
   

  

  

   if( (pg == true) && (tl == true) && (sn == true) && (fn == true) && (em == true) && (db == true) && (zp == true) && (hp == true) && (pm == true) && (sh == true) && (c1 == true) && (c2 == true) && (c3 == true) && (c4 == true) && (c5 == true) && (c7 == true) && (c8 == true) && (pe == true)) {

   		return true;
   } else {
		alert("Please fill out all required fields");
		return false;
   }

	

}
function check_dropdownfields(field_id,span_name)

{

  if (document.getElementById(field_id).value != 0)

  {

	document.getElementById(span_name).style.visibility = 'hidden';

	document.getElementById(span_name).style.position = 'absolute';

	return true;

  }

  else

  {

	document.getElementById(span_name).style.visibility = 'visible';

	document.getElementById(span_name).style.position = 'static';

	return false;

  }

}


function calculatePrice(price,qty)
{
	//alert(price+'--'+qty);
	var qtyArr = document.getElementsByName('orderQty');
	var totSizes = document.getElementById('totalSizes').value;
	var netAmount = 0;
	for(var i=1; i <= totSizes; i++)
	{
		var qty   = document.getElementById('orderQty_'+i).value;	
		var price = document.getElementById('orderPrice_'+i).value;
		
		if(qty != 0 && qty != "" )
			netAmount += qty*price;
	}	
	
	document.getElementById('totalAmount').value = netAmount;
	/*st = "";
	for (var i in qtyArr)
	{if (st != "") st += "&";
	st = st + i + "=" + qtyArr[i]}*/
	//alert(st);
}

function check_out()
{
	
	if(check_fields("cName","cName_div") )
	   var cName = true;
	 else
	   var cName  = false;
		
	 if(check_fields("address1","address1_div") )
	   var address1 = true;
	 else
	   var address1  = false;
	   
	 	   
	   if((check_fields("postcode","city_div")) && (check_fields("city","city_div")) && (check_fields("state","city_div")))
	   var postcode = true;
	 else
	   var postcode  = false;
	
	 if(check_fields("phone","phone_div") )
	   var phone = true;
	 else
	   var phone  = false;
	   
	   

	
	if( document.getElementById("email").value!="")
	{
		 if(checkmail("email","email_div") )
		   var email = true;
		 else
		   var email  = false;
	}
	else
	  var email = true;
	   //delivery
	   if(check_fields("cName1","cName1_div") )
	   var cName1 = true;
	 else
	   var cName1  = false;
		
	 if(check_fields("address11","address11_div") )
	   var address11 = true;
	 else
	   var address11  = false;
	
	   
	if((check_fields("postcode1","city1_div")) && (check_fields("city1","city1_div")) && (check_fields("state1","city1_div")))
	   var postcode1 = true;
	 else
	   var postcode1  = false;
	
	  
	  
	   
	 if( (cName == true) && (address1 == true) &&  (postcode == true) && (phone == true) && (email == true) &&
		(cName1 == true) && (address11 == true) &&  (postcode1 == true) )
	     {
   		  return true;
		 }
     else
		return false;
	   
	
}
function check_product()
{
	if(check_dropdownfields('categories','pro_cat'))
		var category = true;
	else
		var category = false;
		
 	 if(check_fields("pName","pname_div"))
		var	pname = true;
	 else
	   var pname = false;

	 if(check_fields("pImage","pimg_div"))
	 {
		if(check_image('pImage'))
			var	img = true;
	 	else
	   		var img = false;
	 }  
	 else
	   var img = false;
	    
   if( (category == true) && (pname == true) && (img == true))
   		return true;
   else
		return false;
}



