/////////////////////////
/* Banner Functions */
/////////////////////////

  //JavaScript Rotating Banners
  //copyright daxassist, 2000-2004
  //visit http://www.daxassist.com for this and other javascripts with full tutorials.

  var delay = 5000;
  var maxiterations = 2;

// Customised the functions to have multiple banners on page

  function MyBannerChanger(from, bannertype) 
  {	
	// Only continue if iterations for current banner have not exceeded the max value
    //if(document.images && eval("baniterations_" + bannertype) <= maxiterations) 
	//{
		
      document.images[from].src = eval("banpics_"  + bannertype + "[currentimage_" + bannertype + "].src");
	  document.images[from].title = eval("bantitles_"  + bannertype + "[currentimage_" + bannertype + "]");

      eval("currentlink_" + bannertype + " = currentimage_" + bannertype);
	
	  //alert("for banner type : " + bannertype + " value is : " + eval("currentimage_" + bannertype));
	  
		if (eval("currentimage_" + bannertype) < eval("banpics_" + bannertype + ".length - 1")) 
		{
			eval("currentimage_" + bannertype + " = currentimage_" + bannertype + " + 1");
		}
		else 
		{
			eval("currentimage_" + bannertype + " = 0");
			//alert("before : " + eval("baniterations_" + bannertype));
			//alert("increasing iterations for banner type : " + bannertype);		
			// Increase the banner iteration for this banner type by 1
			//eval("baniterations_" + bannertype + "++");
			//alert("after : " + eval("baniterations_" + bannertype));
		}

      setTimeout("MyBannerChanger('" + from + "', " + bannertype + ")", delay);
    }
  //}	

  function MyFollowLink(bannertype) 
	{
    if(document.images) 
		{
		window.open(eval("banlinks_"+ bannertype + "[currentlink_" + bannertype + "]"), 'newwindow', '', false);			
	    }
   }


/////////////////////////
/* Validation Functions */
/////////////////////////

	var runme=true;

	// Form Functions
	// Used to check that mandatory textbox have a value
	function check_textbox(ThisField)
		{
	   if(document.getElementById(ThisField).value == ''){
				do_error(ThisField);
			}
	   }

	function check_radio(ThisField) {
		var MyRadio = document.getElementsByName(ThisField)
		var RadioChecked = false
			for(var i = 0; i < MyRadio.length; i++){
					if(MyRadio[i].checked) { RadioChecked=true ; } // yes one was ticked
				}
			if (RadioChecked == false) { do_error(ThisField); }
	}

	function do_error(ThisField) {
			var Error_colour  = "#cccccc";
			var TheMessage = 'Please enter a value for ' + ThisField;
			if (ThisField == 'Email') { TheMessage = 'Email address is not valid'; }
			alert(TheMessage);
			document.getElementById(ThisField).style.backgroundColor = Error_colour;
			document.getElementById(ThisField).focus();
			runme = false;
			}

	function check_Email(ThisField) { 
			var emailfmt= /^\w+([.-]\w+)*@\w+([.-]\w+)*\.\w{2,8}$/;
			if(!emailfmt.test(document.getElementById(ThisField).value))
				{ 
				do_error(ThisField); 
				runme = false
				}
		}

	function form_submit(ThisForm) { 
			if (runme == true) 
				{ 
				document.getElementById(ThisForm).submit(); 
				} 
			else {runme = true	} //reset the runme var; 
				}

   function getURLParam(name)
        {
          var regexS = "[\\?&]"+name+"=([^&#]*)";
                  //alert(regexS);
          var regex = new RegExp(regexS, "i");
          var tmpURL = window.location.href;
          var results = regex.exec( tmpURL );
          if( results == null )
            return "";
          else
            return results[1];
        }


/////////////////////////
/* Product Functions */
/////////////////////////


/***********************************************
	validate the input before adding to the shopping cart
	eg: colour, size, quantity
**************************************************/
function ValidateCart(ProductID)
{
	var AddToCart
	AddToCart = true;
	if (document.getElementById("QuanityInput"))
	{
		if (document.getElementById("QuanityInput").value == "")
		{
			AddToCart = false;
			alert("Please enter the quantity.");
		}
		else
		{
			if (isNaN(document.getElementById("QuanityInput").value))
			{
				AddToCart = false;
				alert("Quantity can not be non-numeric value.");
			}
			else
			{
				if (parseInt(document.getElementById("QuanityInput").value) <= 0)
				{
					AddToCart = false;
					alert("Quantity must be positive number.");
				}
			}
		}
	}

	if (document.getElementById("ColourSelector"))
	{
		if(document.getElementById("ColourSelector").value=="")
		{
			AddToCart = false;
			alert("Please Select Colour.");
		}
	}

	if (document.getElementById("SizeSelector"))
	{
		if(document.getElementById("SizeSelector").value=="")
		{
			AddToCart = false;
			alert("Please Select Size.");
		}
	}

	if (AddToCart == true)
	{
		if(document.getElementById("AddToCart_" + ProductID)) 
		{
			document.getElementById("AddToCart_" + ProductID).submit();
		}
		else
		{
			alert('shopping cart form not found');
		}
	}

}

function HandleMenuClick(parentid)
{
	if (document.getElementById("Menu_" + parentid))
	{
		if (document.getElementById("Menu_" + parentid).style.display == "none")
		{
			document.getElementById("Menu_" + parentid).style.display = "";
			return false;
		}
		else
		{
			return true;
		}		
	}
	else
	{
		return true;
	}
}

