
function fillCategory(){ 
 // this function is used to fill the category list on load
addOption(document.Orderform.Model, "Orhy", "Orhy", "");
addOption(document.Orderform.Model, "Ascain", "Ascain", "");
addOption(document.Orderform.Model, "Marixu", "Marixu", "");
addOption(document.Orderform.Model, "Maitena", "Maitena", "");
addOption(document.Orderform.Model, "Marion", "Marion", "");
addOption(document.Orderform.Model, "Kiva", "Kiva", "");
}

//This section for creating new order line

function addLoadEvent(func) {
//alert("wombats")
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

addLoadEvent(addUser);




// kick things off when user clicks button #add-user
function addUser(){
	var addOrderButton = document.getElementById('add-user');	
	addOrderButton.onclick = addNewOrder;
//	alert(addOrderButton)
//        alert("spheres")	
}



// set fieldcount to be used in incrementing names, below
fieldcount = 1;

function addNewOrder() {
	
	// grab panel & fieldset that contain form fields to clone
	var addUserPanel = document.getElementById('add-user-panel');
	var firstUserFieldset = document.getElementById('new-user');

//		alert("addUserPanel is " + addUserPanel)
//		alert("firstUserFieldset is " + firstUserFieldset)
	
	//clone #new-user
	var newUserFieldset = firstUserFieldset.cloneNode(true);	
	
	//append number to each id and for
	newUserFieldset.id = 'new-user' + fieldcount;

//	alert("fieldcount is " + fieldcount)	
	
	addNumberToAttribute('label',newUserFieldset);
	addNumberToAttribute('input',newUserFieldset);
	addNumberToAttribute('select',newUserFieldset);
	// note: if you're cloning other form field types like select, add them here

	
	//insert new cloned, incremented elements into page	
	addUserPanel.appendChild(newUserFieldset);	
	
	fieldcount++; //increment field count for next time
	return false; // block default behavior of submit button
}




function addNumberToAttribute(element, newUserFieldset){ 

		elementList = newUserFieldset.getElementsByTagName(element);
		for (i = 0; i < elementList.length; i++){
			numberAttribute(elementList[i], fieldcount);
		}
}

//add number to each new form field, to keep IDs unique
function numberAttribute(currentNode, numToUse) {
	
		if(currentNode.nodeType == 1 && currentNode.getAttribute('for')){
			var currentFor = currentNode.getAttribute('for');
			currentNode.setAttribute('for', (currentFor + '--' + numToUse)) ;				
		}

		if((currentNode.nodeType == 1) && currentNode.getAttribute('name')){
				var currentId = currentNode.getAttribute('name');
				currentNode.setAttribute('name', (currentId  + numToUse )) ;			
		}	
		
		
		// note: if you added other form field types like select above, repeat the argument for these
	
}







function SelectSubCat(){
// ON selection of category this function will work
//var wombat = "document.Orderform.Model.selectedIndex"
//alert(wombat)
alert("fieldcount is " + fieldcount)
switch(fieldcount){

case 1:
alert("fieldcount is " + fieldcount)
//Colour

removeAllOptions(document.Orderform.Colour);
addOption(document.Orderform.Colour, "Colour", "Colour", "");
if(document.Orderform.Model.selectedIndex < 6){
	addOption(document.Orderform.Colour,"Marine", "Marine");
	addOption(document.Orderform.Colour,"Black", "Black");
	addOption(document.Orderform.Colour,"Jeans Marine", "Jeans Marine");
	addOption(document.Orderform.Colour,"Emerald", "Emerald");
	addOption(document.Orderform.Colour,"Cream", "Cream");
	addOption(document.Orderform.Colour,"Red", "Red");
	addOption(document.Orderform.Colour,"White", "White");
	addOption(document.Orderform.Colour,"Chocolate", "Chocolate");
	addOption(document.Orderform.Colour,"Turquoise", "Turquoise");
	addOption(document.Orderform.Colour,"Sand", "Sand");
	addOption(document.Orderform.Colour,"Yellow", "Yellow");
	addOption(document.Orderform.Colour,"Violet", "Violet");
	addOption(document.Orderform.Colour,"Jeans washed", "Jeans washed");
	addOption(document.Orderform.Colour,"Olive", "Olive");
	addOption(document.Orderform.Colour,"Indian", "Indian");
	addOption(document.Orderform.Colour,"Indigo", "Indigo");
	addOption(document.Orderform.Colour,"Jeans black", "Jeans black");
	addOption(document.Orderform.Colour,"Bordeaux", "Bordeaux");
	addOption(document.Orderform.Colour,"Pervenche", "Pervenche");
	addOption(document.Orderform.Colour,"Malabar", "Malabar");
	addOption(document.Orderform.Colour,"Bamboo", "Bamboo");
	
}

//Kiva
if(document.Orderform.Model.selectedIndex == 6){
	addOption(document.Orderform.Colour,"Marine", "Marine");
	addOption(document.Orderform.Colour,"Black", "Black");
	addOption(document.Orderform.Colour,"Jeans Marine", "Jeans Marine");
	addOption(document.Orderform.Colour,"Sand", "Sand");
	
}

//Size
//Orhy
removeAllOptions(document.Orderform.Shoesize);
addOption(document.Orderform.Shoesize, "0", "0");
if(document.Orderform.Model.selectedIndex < 2){
	addOption(document.Orderform.Shoesize,"23", "23");
	addOption(document.Orderform.Shoesize,"24", "24");
	addOption(document.Orderform.Shoesize,"25", "25");
	addOption(document.Orderform.Shoesize,"26", "26");
	addOption(document.Orderform.Shoesize,"27", "27");
	addOption(document.Orderform.Shoesize,"28", "28");
	addOption(document.Orderform.Shoesize,"29", "29");
	addOption(document.Orderform.Shoesize,"30", "30");
	addOption(document.Orderform.Shoesize,"31", "31");
	addOption(document.Orderform.Shoesize,"32", "32");
	addOption(document.Orderform.Shoesize,"33", "33");
	addOption(document.Orderform.Shoesize,"34", "34");
	addOption(document.Orderform.Shoesize,"35", "35");
	addOption(document.Orderform.Shoesize,"36", "36");
	addOption(document.Orderform.Shoesize,"37", "37");
	addOption(document.Orderform.Shoesize,"38", "38");
	addOption(document.Orderform.Shoesize,"39", "39");
	addOption(document.Orderform.Shoesize,"40", "40");
	addOption(document.Orderform.Shoesize,"41", "41");
	addOption(document.Orderform.Shoesize,"42", "42");
	addOption(document.Orderform.Shoesize,"43", "43");
	addOption(document.Orderform.Shoesize,"44", "44");
	addOption(document.Orderform.Shoesize,"45", "45");
	addOption(document.Orderform.Shoesize,"46", "46");
	addOption(document.Orderform.Shoesize,"47", "47");
	

}
//Ascain
if(document.Orderform.Model.selectedIndex == 2){
	addOption(document.Orderform.Shoesize,"34", "34");
	addOption(document.Orderform.Shoesize,"35", "35");
	addOption(document.Orderform.Shoesize,"36", "36");
	addOption(document.Orderform.Shoesize,"37", "37");
	addOption(document.Orderform.Shoesize,"38", "38");
	addOption(document.Orderform.Shoesize,"39", "39");
	addOption(document.Orderform.Shoesize,"40", "40");
	addOption(document.Orderform.Shoesize,"41", "41");
	addOption(document.Orderform.Shoesize,"42", "42");
	addOption(document.Orderform.Shoesize,"43", "43");
	addOption(document.Orderform.Shoesize,"44", "44");
	addOption(document.Orderform.Shoesize,"45", "45");
	addOption(document.Orderform.Shoesize,"46", "46");
	addOption(document.Orderform.Shoesize,"47", "47");
	

}
//Marixu
if(document.Orderform.Model.selectedIndex == 3){
	addOption(document.Orderform.Shoesize,"35", "35");
	addOption(document.Orderform.Shoesize,"36", "36");
	addOption(document.Orderform.Shoesize,"37", "37");
	addOption(document.Orderform.Shoesize,"38", "38");
	addOption(document.Orderform.Shoesize,"39", "39");
	addOption(document.Orderform.Shoesize,"40", "40");
	addOption(document.Orderform.Shoesize,"41", "41");
	addOption(document.Orderform.Shoesize,"42", "42");
	addOption(document.Orderform.Shoesize,"43", "43");
	addOption(document.Orderform.Shoesize,"44", "44");
	addOption(document.Orderform.Shoesize,"45", "45");
	addOption(document.Orderform.Shoesize,"46", "46");
	

}
// Maitena and Marion
if(document.Orderform.Model.selectedIndex == 4 || document.Orderform.Model.selectedIndex == 5){
	addOption(document.Orderform.Shoesize,"35", "35");
	addOption(document.Orderform.Shoesize,"36", "36");
	addOption(document.Orderform.Shoesize,"37", "37");
	addOption(document.Orderform.Shoesize,"38", "38");
	addOption(document.Orderform.Shoesize,"39", "39");
	addOption(document.Orderform.Shoesize,"40", "40");
	addOption(document.Orderform.Shoesize,"41", "41");
	

}
//Kiva
if(document.Orderform.Model.selectedIndex == 6){
	addOption(document.Orderform.Shoesize,"39", "39");
	addOption(document.Orderform.Shoesize,"40", "40");
	addOption(document.Orderform.Shoesize,"41", "41");
	addOption(document.Orderform.Shoesize,"42", "42");
	addOption(document.Orderform.Shoesize,"43", "43");
	addOption(document.Orderform.Shoesize,"44", "44");
	addOption(document.Orderform.Shoesize,"45", "45");
	addOption(document.Orderform.Shoesize,"46", "46");
	

}
break;

case 2:
alert("fieldcount is " + fieldcount)
//Colour
removeAllOptions(document.Orderform.Colour1);
if(document.Orderform.Model1.selectedIndex < 6){
	addOption(document.Orderform.Colour1,"Marine", "Marine");
	addOption(document.Orderform.Colour1,"Black", "Black");
	addOption(document.Orderform.Colour1,"Jeans Marine", "Jeans Marine");
	addOption(document.Orderform.Colour1,"Emerald", "Emerald");
	addOption(document.Orderform.Colour1,"Cream", "Cream");
	addOption(document.Orderform.Colour1,"Red", "Red");
	addOption(document.Orderform.Colour1,"White", "White");
	addOption(document.Orderform.Colour1,"Chocolate", "Chocolate");
	addOption(document.Orderform.Colour1,"Turquoise", "Turquoise");
	addOption(document.Orderform.Colour1,"Sand", "Sand");
	addOption(document.Orderform.Colour1,"Yellow", "Yellow");
	addOption(document.Orderform.Colour1,"Violet", "Violet");
	addOption(document.Orderform.Colour1,"Jeans washed", "Jeans washed");
	addOption(document.Orderform.Colour1,"Olive", "Olive");
	addOption(document.Orderform.Colour1,"Indian", "Indian");
	addOption(document.Orderform.Colour1,"Indigo", "Indigo");
	addOption(document.Orderform.Colour1,"Jeans black", "Jeans black");
	addOption(document.Orderform.Colour1,"Bordeaux", "Bordeaux");
	addOption(document.Orderform.Colour1,"Pervenche", "Pervenche");
	addOption(document.Orderform.Colour1,"Malabar", "Malabar");
	addOption(document.Orderform.Colour1,"Bamboo", "Bamboo");
	
}

//Kiva
if(document.Orderform.Model1.selectedIndex == 6){
	addOption(document.Orderform.Colour1,"Marine", "Marine");
	addOption(document.Orderform.Colour1,"Black", "Black");
	addOption(document.Orderform.Colour1,"Jeans Marine", "Jeans Marine");
	addOption(document.Orderform.Colour1,"Sand", "Sand");
	
}

//Size
//Orhy
removeAllOptions(document.Orderform.Shoesize1);
addOption(document.Orderform.Shoesize1, "0", "0");
if(document.Orderform.Model1.selectedIndex < 2){
	addOption(document.Orderform.Shoesize1,"23", "23");
	addOption(document.Orderform.Shoesize1,"24", "24");
	addOption(document.Orderform.Shoesize1,"25", "25");
	addOption(document.Orderform.Shoesize1,"26", "26");
	addOption(document.Orderform.Shoesize1,"27", "27");
	addOption(document.Orderform.Shoesize1,"28", "28");
	addOption(document.Orderform.Shoesize1,"29", "29");
	addOption(document.Orderform.Shoesize1,"30", "30");
	addOption(document.Orderform.Shoesize1,"31", "31");
	addOption(document.Orderform.Shoesize1,"32", "32");
	addOption(document.Orderform.Shoesize1,"33", "33");
	addOption(document.Orderform.Shoesize1,"34", "34");
	addOption(document.Orderform.Shoesize1,"35", "35");
	addOption(document.Orderform.Shoesize1,"36", "36");
	addOption(document.Orderform.Shoesize1,"37", "37");
	addOption(document.Orderform.Shoesize1,"38", "38");
	addOption(document.Orderform.Shoesize1,"39", "39");
	addOption(document.Orderform.Shoesize1,"40", "40");
	addOption(document.Orderform.Shoesize1,"41", "41");
	addOption(document.Orderform.Shoesize1,"42", "42");
	addOption(document.Orderform.Shoesize1,"43", "43");
	addOption(document.Orderform.Shoesize1,"44", "44");
	addOption(document.Orderform.Shoesize1,"45", "45");
	addOption(document.Orderform.Shoesize1,"46", "46");
	addOption(document.Orderform.Shoesize1,"47", "47");
	

}
//Ascain
if(document.Orderform.Model1.selectedIndex == 2){
	addOption(document.Orderform.Shoesize1,"34", "34");
	addOption(document.Orderform.Shoesize1,"35", "35");
	addOption(document.Orderform.Shoesize1,"36", "36");
	addOption(document.Orderform.Shoesize1,"37", "37");
	addOption(document.Orderform.Shoesize1,"38", "38");
	addOption(document.Orderform.Shoesize1,"39", "39");
	addOption(document.Orderform.Shoesize1,"40", "40");
	addOption(document.Orderform.Shoesize1,"41", "41");
	addOption(document.Orderform.Shoesize1,"42", "42");
	addOption(document.Orderform.Shoesize1,"43", "43");
	addOption(document.Orderform.Shoesize1,"44", "44");
	addOption(document.Orderform.Shoesize1,"45", "45");
	addOption(document.Orderform.Shoesize1,"46", "46");
	addOption(document.Orderform.Shoesize1,"47", "47");
	

}
//Marixu
if(document.Orderform.Model1.selectedIndex == 3){
	addOption(document.Orderform.Shoesize1,"35", "35");
	addOption(document.Orderform.Shoesize1,"36", "36");
	addOption(document.Orderform.Shoesize1,"37", "37");
	addOption(document.Orderform.Shoesize1,"38", "38");
	addOption(document.Orderform.Shoesize1,"39", "39");
	addOption(document.Orderform.Shoesize1,"40", "40");
	addOption(document.Orderform.Shoesize1,"41", "41");
	addOption(document.Orderform.Shoesize1,"42", "42");
	addOption(document.Orderform.Shoesize1,"43", "43");
	addOption(document.Orderform.Shoesize1,"44", "44");
	addOption(document.Orderform.Shoesize1,"45", "45");
	addOption(document.Orderform.Shoesize1,"46", "46");
	

}
// Maitena and Marion
if(document.Orderform.Model1.selectedIndex == 4 || document.Orderform.Model.selectedIndex == 5){
	addOption(document.Orderform.Shoesize1,"35", "35");
	addOption(document.Orderform.Shoesize1,"36", "36");
	addOption(document.Orderform.Shoesize1,"37", "37");
	addOption(document.Orderform.Shoesize1,"38", "38");
	addOption(document.Orderform.Shoesize1,"39", "39");
	addOption(document.Orderform.Shoesize1,"40", "40");
	addOption(document.Orderform.Shoesize1,"41", "41");
	

}
//Kiva
if(document.Orderform.Model1.selectedIndex == 6){
	addOption(document.Orderform.Shoesize1,"39", "39");
	addOption(document.Orderform.Shoesize1,"40", "40");
	addOption(document.Orderform.Shoesize1,"41", "41");
	addOption(document.Orderform.Shoesize1,"42", "42");
	addOption(document.Orderform.Shoesize1,"43", "43");
	addOption(document.Orderform.Shoesize1,"44", "44");
	addOption(document.Orderform.Shoesize1,"45", "45");
	addOption(document.Orderform.Shoesize1,"46", "46");
	

}

break;



}




}


/*

*/







function removeAllOptions(selectbox)
{
	var i;
	for(i=selectbox.options.length-1;i>=0;i--)
	{
		//selectbox.options.remove(i);
		selectbox.remove(i);
	}
}


function addOption(selectbox, value, text )
{
	var optn = document.createElement("OPTION");
	optn.text = text;
	optn.value = value;

	selectbox.options.add(optn);
}

