// JavaScript Document

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


function f_contact_validate(my_array){
	//get form object
	my_form = my_array['object'];
	if(my_form.elements.firstname.value==""){
		alert("Please fill out the FIRST NAME field");
		my_form.elements.firstname.focus();
		//return(false);
	}else if(my_form.elements.surname.value==""){
		alert("Please fill out the FAMILY NAME field");
		my_form.elements.surname.focus();
		//return(false);
	}else if(my_form.elements.phone.value=="" && my_form.elements.mobile.value==""){
		alert("Please fill out the PHONE or MOBILE field");
		my_form.elements.phone.focus();
		//return(false);
	}else if(my_form.elements.suburb.value==""){
		alert("Please fill out the SUBURB field");
		my_form.elements.suburb.focus();
		//return(false);
	}else if(my_form.elements.postcode.value==""){
		alert("Please fill out the POSTCODE field");
		my_form.elements.postcode.focus();
		//return(false);
	}else{
		//document.location = "http://www.gumleafgutterguard.com/cgi-bin/FormMail.cgi?recipient=jasjc@jasjc.com"
		my_form.submit();
		//return(true);
	}
}//end function f_contact_validate(my_array)
g_count = 0;
//handles photo gallery
function f_gallery(my_array){
	//detect type of control
	var my_data = my_array['data'];
	
	//get list of images
	var my_list = new Array();
	my_list[my_list.length] = {src:"../image/photogallery_img_001.jpg",label:"Gumleaf on Corrugated Valley"};
	my_list[my_list.length] = {src:"../image/photogallery_img_002.jpg",label:"Gumleaf on Corrugated Roof in Ironstone Blue"};
	my_list[my_list.length] = {src:"../image/photogallery_img_003.jpg",label:"Gumleaf on Cement Tile"};
	my_list[my_list.length] = {src:"../image/photogallery_img_004.jpg",label:"Gumleaf Helping when Bushfires Strike"};
	my_list[my_list.length] = {src:"../image/photogallery_img_005.jpg",label:"Gumleaf Gutter Protection on Flat Plastic Roof"};
	my_list[my_list.length] = {src:"../image/photogallery_img_006.jpg",label:"Gumleaf Gutter Protection on Clip Lock"};
	my_list[my_list.length] = {src:"../image/photogallery_img_007.jpg",label:"Our Home Demonstration Comes to You"};
	my_list[my_list.length] = {src:"../image/photogallery_img_008.jpg",label:"Gumleaf on Flat Cement Tile"};
	my_list[my_list.length] = {src:"../image/photogallery_img_009.jpg",label:"Bushfire Hazard"};
	my_list[my_list.length] = {src:"../image/photogallery_img_010.jpg",label:"Following ACC Procedures"};
	my_list[my_list.length] = {src:"../image/photogallery_img_011.jpg",label:"Final Result on Tile Roof"};
	my_list[my_list.length] = {src:"../image/photogallery_img_012.jpg",label:"Installation of Gumleaf on Tile Roof"};
	my_list[my_list.length] = {src:"../image/photogallery_img_013.jpg",label:"Gumleaf on Terricotta Tile"};
	my_list[my_list.length] = {src:"../image/photogallery_img_014.jpg",label:"Gumleaf Installed on Waterfront Home"};
	my_list[my_list.length] = {src:"../image/photogallery_img_015.jpg",label:"Highly Recommended by Water Tank Companies"};
	my_list[my_list.length] = {src:"../image/photogallery_img_016.jpg",label:"Woodland Grey on Corrugated Valley"};
	my_list[my_list.length] = {src:"../image/photogallery_img_017.jpg",label:"Toughest Gutter Guard"};
	my_list[my_list.length] = {src:"../image/photogallery_img_018.jpg",label:"Gumleaf on Stone Colorbond"};
	my_list[my_list.length] = {src:"../image/photogallery_img_019.jpg",label:"Gumleaf on Surfmist Colorbond"};
	my_list[my_list.length] = {src:"../image/photogallery_img_020.jpg",label:"Silted Gutters"};
	my_list[my_list.length] = {src:"../image/photogallery_img_021.jpg",label:"Trim Deck"};
	
	//get image count
	if(my_data=='prev'){
		g_count--;
	}else if(my_data=='next'){
		g_count++;
	}
	if(g_count==-1){g_count=my_list.length-1};
	if(g_count>my_list.length-1){g_count=0};
	/*
	g_count = Math.max(g_count,0);
	g_count = Math.min(g_count,my_list.length-1);
	*/
	
	//change image
	document.getElementById("image").innerHTML = "<img src='" + my_list[g_count]['src'] + "' width='292' height='219'>";
	//set label
	document.getElementById("image_label").innerHTML = my_list[g_count]['label'];
	
	//set navigation
	//id="gallery_nav_prev"
	/*
	if(g_count==0){
		var my_prev = "<img src=\"../image/photogallery_arr_prev_ds.gif\" name=\"prev\" width=\"12\" height=\"20\" border=\"0\" id=\"prev\">";
	}else{
		var my_prev = "<a href=\"javascript:f_gallery({data:'prev'});\" onMouseOver=\"MM_swapImage('prev','','../image/photogallery_arr_prev_ro.gif',1)\" onMouseOut=\"MM_swapImgRestore()\"><img src=\"../image/photogallery_arr_prev.gif\" name=\"prev\" width=\"12\" height=\"20\" border=\"0\" id=\"prev\"></a>";
	}
	if(g_count>=my_list.length-1){
		var my_next = "<img src=\"../image/photogallery_arr_next_ds.gif\" name=\"next\" width=\"12\" height=\"20\" border=\"0\" id=\"next\">";
	}else{
		var my_next = "<a href=\"javascript:f_gallery({data:'next'});\" onMouseOver=\"MM_swapImage('next','','../image/photogallery_arr_next_ro.gif',1)\" onMouseOut=\"MM_swapImgRestore()\"><img src=\"../image/photogallery_arr_next.gif\" name=\"next\" width=\"12\" height=\"20\" border=\"0\" id=\"next\"></a>";
	}
	document.getElementById("gallery_nav_prev").innerHTML = my_prev;
	document.getElementById("gallery_nav_next").innerHTML = my_next;
	*/
}

// This JavaScript will parse
// any search string
// and automatically declare
// all search parameters 
// as JavaScript variables
// with values.
// Feel free to use/abuse
// it any way you like.
// 
// Get the search string
// (without the leading "?"):
function f_URL_searchExtract(myArray){
	myURL=myArray['URL'];
	if(myURL.search.length > 0){
		//get search component
		mySearch = myURL.search;
		//eradicate ?
		mySearch = mySearch.substring(1);
		
		do{
			mySearch=mySearch.replace('%20',' ');
		}while(mySearch.indexOf("%20")>0)//end do
		
		//mySearch = mySearch.substring(mySearch.indexOf("=")+1);
		
		//alert("test: " + mySearch);
		
		// Split the string at each "&"
    	// and put the parts
    	// (name-value pairs) into an array:
		mySearch_array = mySearch.split("&");
		mySearch_array_2 = new Array();
		for (var i = 0; i <= mySearch_array.length - 1; i++) {
			// Get the left and right side
        	// of each part (name-value pair):
        	var left = mySearch_array[i].substring(0, mySearch_array[i].indexOf("="));
        	var right = mySearch_array[i].substring(mySearch_array[i].indexOf("=") + 1);
			if (isNaN(right)) {
				right = right + "";
            	//right = '"' + right + '"';
        	}//end if

			mySearch_array_2[left] = right;
			// Use the JavaScript eval()
        	// function to declare
        	// each part (name-value pair)
        	// as a JavaScript variable
        	// with a value assigned:
			//eval("var " + left + " = " + right);
			//myString="mySearch_array_2[\'" + left + "\']=" + right;
        	//eval(myString);
			
		}//end for
		
		return(mySearch_array_2);
	}//end if
}//end function

//handles detecting flash version info
function f_flash_detect(pm_array){
	//first check if navigator.plugins object exists
	if((navigator.plugins != null) && (navigator.plugins.length > 0)){
		//check if plugins object has info
		if(navigator.plugins["Shockwave Flash 2.0"] || navigator.plugins["Shockwave Flash"]){
			//check if shockwave flash entry has version append
			var my_flash_v2 = navigator.plugins["Shockwave Flash 2.0"] ? " 2.0" : "";
			//get flash info description
      		var my_flash_info = navigator.plugins["Shockwave Flash" + my_flash_v2].description;
			var my_flash_info_array = my_flash_info.split(" ");
			var my_array_major = my_flash_info_array[2].split(".");
			//get MAJOR version number
			var my_version_major = my_array_major[0];
			//get MINOR version number
			var my_version_minor = my_array_major[1];
			//get REVISION version number
			if(my_flash_info_array[3] != "" ){
				my_array_minor = my_flash_info_array[3].split("r");
			}else{
				my_array_minor = my_flash_info_array[4].split("r");
			}//end if
      		var my_version_revision = my_array_minor[1] > 0 ? my_array_minor[1] : 0;
			//assemble version number
            var my_flash_version = my_version_major + "." + my_version_minor + "." + my_version_revision;
			//return version number
			return(my_flash_version);
		}else{//plugins object has no info
			return(false);
		}//end if
	}//end if
	
	//second check for activeXObject
	//used for IE embeds
	//this methodology only works for IE6+
	//flashVersion = 9;
	for(var i=9; i>0; i--){
		flashVersion = 0;
		try{
			var flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash." + i);
			flashVersion = i;
			return(flashVersion);
		}catch(e){
		}
	}//end for
	
	//no detection object found
	return(false);
}//end function f_flash_detect

//handles writing flash object code
//to avoid IE active object security box issue
function f_flash_write(pm_array){
	//get required version of flash
	var my_flash_version_min = pm_array['flash'];
	
	//detect flash
	var my_flash_version = f_flash_detect();
	
	//check if flash version required is met
	//if not then look for and enact alt content
	if(parseInt(my_flash_version)<my_flash_version_min){
		//check for alt content
		var my_content_alt = pm_array['alt'];
		//write content found
		if(my_content_alt!=undefined && my_content_alt!=null){
			var my_html = "";
			//my_html = my_html + "<img src='../image/glgg_banner_alt.gif' />";
			my_html = my_html + my_content_alt;
			
			//write html to doc
			document.write(my_html);
		}//end if
		
		//feedback
		return(false);
	}//end if
	
	//get path to flash
	var my_flash_path = pm_array['path'];
	
	//get dimensions
	var my_flash_width = pm_array['width'];
	var my_flash_height = pm_array['height'];
	
	//construct html
	var my_html = "";
	my_html = my_html + "<object classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' codebase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0' width='" + my_flash_width + "' height='" + my_flash_height + "'>";
	my_html = my_html + "<param name='movie' value='" + my_flash_path + "'>";
	my_html = my_html + "<param name='quality' value='high'>";
	my_html = my_html + "<embed src='" + my_flash_path + "' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='" + my_flash_width + "' height='" + my_flash_height + "'></embed>";
	my_html = my_html + "</object>";
	
	//write html to doc
	document.write(my_html);
	
	//feedback
	return(true);
}//end function f_flash_write
