/*
--------------------------------------------------------------------------------
Main JavaScript validation 
---------------------------------------------------------------------------------
   Version        	Date        Name      	Desc
      1.0         	17/05/2006  AEK       	First version to include ExtractCrap()
      1.1	  		28/05/2006  AEK			Extract ExtractCrap(), Add MouseOver & MouseOut
      1.2			24/10/2007  AEK			Add Order functions (temp hard coded)
 ---------------------------------------------------------------------------------
*/

var ColB = '#ffffff';
var ColA = '#aaaaaa';

var Products = {
"DogNest or CatNest" : [ 'Small 26" circular £24.95 (cover with zip)', 'Small 26" circular £44.95 (Complete)', 'Small 21" x 30" £29.95 (cover with zip)', 'Small 21" x 30" £54.95 (Complete)', 'Medium 28" x 42" £48.95 (cover with zip)', 'Medium 28" x 42" £87.95 (Complete)', 'Large 33" x 44" £58.95 (cover with zip)', 'Large 33" x 44" £97.95 (Complete)', 'Larger 37" x 52" £64.95 (cover with zip)', 'Larger 37" x 52" £107.95 (Complete)', 'Giant 39" x 62" £66.95 (cover with zip)', 'Giant 39" x 62" £120.95 (Complete)'], 
"Dry Dog Bags" : [ 'Small £33.95', '30" x 20" £41.95', '40" x 24" £52.95', '48" x 28" £55.95', '54" x 34" £61.95'],
"Waterproof Load Liner" : [ '60" x 60" £54.95']};

var Fabrics = {
"DogNest or CatNest" : [ '05 Tough green twill', '06 Tough brown twill', '08 Brown cord', '09 Green cord', '11 Purple cord', '10 Red tartan', '04 Blue Tartan', '01 Paisley', '02 Brown floral cord', '07 Blue floral cord', '11 Tough camouflage material', '12 Herringbone', '13 Pink cord' ],
"Dry Dog Bags" : [ 'Terry Tuft towelling - double sided' ],
"Waterproof Load Liner" : [ 'Waterproof Blue Plastic Load Liner' ]};
/* */
var Fabric_images = new Array("galleryimages/Fabric_Swatches/Thumb_5-tough_green_twill.jpg","galleryimages/Fabric_Swatches/Thumb_6-Tough_brown_twill.jpg","galleryimages/Fabric_Swatches/Thumb_8-Brown_Cord.jpg","galleryimages/Fabric_Swatches/Thumb_9-Green_Cord.jpg","galleryimages/Fabric_Swatches/Thumb_11-Purple_cord.jpg","galleryimages/Fabric_Swatches/Thumb_10-Red_Tartan.jpg","galleryimages/Fabric_Swatches/Thumb_4-Blue_tartan.jpg","galleryimages/Fabric_Swatches/Thumb_1-Paisley.jpg","galleryimages/Fabric_Swatches/Thumb_2-Brown_floral_cord.jpg","galleryimages/Fabric_Swatches/Thumb_7-Blue_floral_cord.jpg","galleryimages/Fabric_Swatches/Thumb_camouflage_material.jpg","galleryimages/Fabric_Swatches/Thumb_Herringbone.jpg","galleryimages/Fabric_Swatches/Thumb_pink.jpg");

function lstFabrics_OnChange() {

  var lstFabrics = document.getElementById("lstFabrics");
  var imgFabric = document.getElementById("imgChosenFabric");
   			for(i=0; i<lstFabrics.length; i++) {
    			if( lstFabrics.options[i].selected ) {
 						imgFabric.src = Fabric_images[i];
    			}
  			}
}

function selectAll(listName, selected) {
  var listBox = document.getElementById(listName);
  for(i=0; i<listBox.length; i++) {
    listBox.options[i].selected=selected;
  }
  if( listBox.onchange ) {
    listBox.onchange();
  }
}



function lstDogNestProducts_OnChange(blnFromOnLoad) {
var listBox = document.getElementById("lstDogNestProducts");
var subListBox = document.getElementById("lstSizes");
var subListBox1 = document.getElementById("lstFabrics");
var OriginatingFile = getQueryVariable("GalleryName");
var ArtPieceID = getQueryVariable("ArtpieceID");
var SelectedNest = -1;
var SelectedSize = -1;
var SelectedFabric = -1;

if (listBox) {   //test for the existence of the lstDogNestProducts
  	//alert("blnFromOnLoad = " + blnFromOnLoad);
  	if (blnFromOnLoad=='false') {                        //called from within order form by selection using a drop-down
		subListBox.options.length=0;
		subListBox1.options.length=0;
  		for(i=0; i<listBox.length; i++) {
    		if( listBox.options[i].selected ) {
    			var key = listBox.options[i].text;
    			var imgFabric = document.getElementById("imgChosenFabric");
    			if (i==0) {
  					imgFabric.src = Fabric_images[0]; //"galleryimages/Fabric_Swatches/dog_bag_100.jpg";
    			}
    			if(Products[key]) {
    			   	for(j=0; j<Products[key].length; j++) {
    			    	subListBox.options.add(new Option(Products[key][j],Products[key][j]));
					}
    			}
    			if(Fabrics[key]) {
    			   	for(j=0; j<Fabrics[key].length; j++) {
    			    	subListBox1.options.add(new Option(Fabrics[key][j],Fabrics[key][j]));
    			  	}
    			  	
    			}
     			if (i==1) {
  					imgFabric.src = "galleryimages/Fabric_Swatches/dog_bag_100.jpg";
  					subListBox1.options[0].selected=true;
    			}
    			if (i==2) {
  					imgFabric.src = "galleryimages/Fabric_Swatches/car_liner_100.jpg";
  					subListBox.options[0].selected=true;
  					subListBox1.options[0].selected=true;  					  					
    			}   			
    		}
  		}
  	} else {                                                      //called from outside order form
  		listBox.options.add(new Option("DogNest or CatNest", "DogNest or CatNest"));
  	    listBox.options.add(new Option("Dry Dog Bags", "Dry Dog Bags"));
  	    listBox.options.add(new Option("Waterproof Load Liner", "Waterproof Load Liner"));
  		var queryS = window.location.search.substring(1);
  		//alert("qS = >" + queryS + "<");
  		if (queryS == "") {
  			SelectedNest = -1;
  			//listBox.options[0].selected=true;
  		} else {

   			if  (OriginatingFile == "Fabric_Swatches")  {
        		SelectedNest = 0;
        		SelectedFabric = parseInt(ArtPieceID);
        	} else {
    			if (OriginatingFile == "Dognest_products")  {
        			SelectedNest = 0;
        			SelectedSize = (parseInt(ArtPieceID) * 2)  + 1;
        		} else { 	
        			if (OriginatingFile == "Catnest_products")  {
        				SelectedNest = 0;
        				SelectedSize = (parseInt(ArtPieceID) * 2)  + 1;
        			} else {
    					if (OriginatingFile == "drydogbag")  {
        					SelectedNest = 1;
        					//SelectedSize = 0;
        				} else {
    						if (OriginatingFile == "loadliner")  {       
        						SelectedNest = 2;
        						SelectedSize = 0;  
    						}  
  						}
  					}
  				}
  			}
		
  		}	
  	 //alert("From Outside: SelectedNest = " + SelectedNest + ",   SelectedSize = " + SelectedSize + ",   SelectedFabric = " + SelectedFabric);
  	    //listBox.options.add(new Option("DogNest or CatNest", "DogNest or CatNest"));
  	    //listBox.options.add(new Option("Dry Dog Bags", "Dry Dog Bags"));
  	    //listBox.options.add(new Option("Waterproof Load Liner", "Waterproof Load Liner"));
  	    var imgFabric = document.getElementById("imgChosenFabric");
  		if (SelectedNest == -1) {
  			listBox.options[0].selected=true;
  			imgFabric.src = Fabric_images[0];
  		} else {
  			listBox.options[SelectedNest].selected=true;
  			if (SelectedNest==0) {
  				imgFabric.src = Fabric_images[0];
  			} else {
  				 if (SelectedNest==1) {
  					imgFabric.src = imgFabric.src = "galleryimages/Fabric_Swatches/dog_bag_100.jpg";
  					//subListBox1.options[0].selected=true;
  				} else {
  					if (SelectedNest==2) {
  						imgFabric.src = imgFabric.src = "galleryimages/Fabric_Swatches/car_liner_100.jpg";
  						//subListBox1.options[0].selected=true;
  					}
  				}
  			}
  		}

  		 			  	 		
  		for(i=0; i<listBox.length; i++) {
  			//alert("key = " + listBox.options[i].text);
    		if( listBox.options[i].selected ) {
    			var key = listBox.options[i].text;
    			//alert("key = " + key);
    			if(Products[key]) {
    			   	for(j=0; j<Products[key].length; j++) {
    			    	subListBox.options.add(new Option(Products[key][j],Products[key][j]));
					}
    			}
    			if(Fabrics[key]) {
    			   	for(j=0; j<Fabrics[key].length; j++) {
    			    	subListBox1.options.add(new Option(Fabrics[key][j],Fabrics[key][j]));
    			  	}
    			}
    		}
  		} 
   		if (SelectedSize != -1) {
  			subListBox.options[SelectedSize].selected=true;
  		} 	
  		
  
 		if (SelectedFabric != -1)  {
  			subListBox1.options[SelectedFabric].selected=true;
  			var imgFabric = document.getElementById("imgChosenFabric");
  			imgFabric.src = Fabric_images[SelectedFabric];
  		} else {
  			if (SelectedNest==1 || SelectedNest==2) {
  				subListBox1.options[0].selected=true;
  			}
  		}
  	}
}  	
//alert("length = " + listBox.length);  	
}

function getQueryVariable(variable) {
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
	var pair = vars[i].split("=");
	if (pair[0] == variable) {
		return pair[1];
	}
}

}


function MouseOver(id)  {
	var el = document.getElementById(id);
 	el.style.backgroundColor = ColA;
}      
 
function MouseOut(id)  {
	var el = document.getElementById(id);
	el.style.backgroundColor = ColB;
}      
