/*

CUSTOM FORM ELEMENTS

Created by Ryan Fait
www.ryanfait.com

The only thing you need to change in this file is the following
variables: checkboxHeight, radioHeight and selectWidth.

Replace the first two numbers with the height of the checkbox and
radio button. The actual height of both the checkbox and radio
images should be 4 times the height of these two variables. The
selectWidth value should be the width of your select list image.

You may need to adjust your images a bit if there is a slight
vertical movement during the different stages of the button
activation.

Visit http://ryanfait.com/ for more information.

*/

var checkboxHeight = "20";
var radioHeight = "20";
var selectSortBy = "104";
var selectReason = "180";
var selectSize = "180";
var selectDegree = "180";

/* No need to change anything after this */


document.write('<style type="text/css">input.styled_sortby { display: none; } select.styled_sortby { position: relative; width: ' + selectSortBy + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; }</style><br />');
document.write('<style type="text/css">input.select_reason { display: none; } select.select_reason { position: relative; width: ' + selectReason + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; }</style>');
document.write('<style type="text/css">input.super-attribute-select{ display: none; } select.super-attribute-select{ position: relative; width: ' + selectSize + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; }</style>');
document.write('<style type="text/css">input.select_degree{ display: none; } select.DegreeListBox{ position: relative; width: ' + selectDegree + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; }</style>');
document.write('<style type="text/css">input.garment { display: none; } select.sel_garment { position: relative; width: ' + selectSize + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; }</style>');
document.write('<style type="text/css">input.colour { display: none; } select.sel_colour { position: relative; width: ' + selectSize + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; }</style>');
document.write('<style type="text/css">input.size { display: none; } select.sel_size { position: relative; width: ' + selectSize + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; }</style>');
document.write('<style type="text/css">input.clubname { display: none; } select.sel_clubname { position: relative; width: ' + selectSize + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; }</style>');
document.write('<style type="text/css">input.lstDegreeFace { display: none; } select.sel_lstDegreeFace { position: relative; width: ' + selectDegree + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; }</style>');

var Custom = {
	
	initialize: function(parentId, currentId) {

		// also initialize xfade2.js here for club tops
		if(document.getElementById('garment') != null){
			init();
		}
		var inputs = null;
		if (parentId == null || typeof parentId != 'string')
		{
			inputs = document.getElementsByTagName("input");
		}
		else
		{
			if (currentId != null && document.getElementById(currentId) != null)
			{
				return;
			}

			if (document.getElementById(parentId) == null)
			{
				return;
			}
			inputs = document.getElementById(parentId).getElementsByTagName("input");
		}
		var span = Array(), textnode, option, active;

		inputs = document.getElementsByTagName("select");

		for(a = 0; a < inputs.length; a++) {
			//alert(inputs[a].className.indexOf("sel_ChooseDegreeListBox"));
			//return false;
			if(inputs[a].className.indexOf("styled_sortby") != -1 || 
				inputs[a].className.indexOf("select_reason") != -1 || 
				inputs[a].className.indexOf("super-attribute-select") != -1 || 
				inputs[a].className.indexOf("DegreeListBox") != -1 ||
				inputs[a].className.indexOf("sel_garment") != -1	||
				inputs[a].className.indexOf("sel_colour") != -1 ||
				inputs[a].className.indexOf("sel_size") != -1 ||
				inputs[a].className.indexOf("sel_clubname") != -1 ||
				inputs[a].className.indexOf("sel_lstDegreeFace") != -1) {
				option = inputs[a].getElementsByTagName("option");
				active = option[0].childNodes[0].nodeValue;
				textnode = document.createTextNode(active);
				for(b = 0; b < option.length; b++) {
					if(option[b].selected == true) {
						textnode = document.createTextNode(option[b].childNodes[0].nodeValue);
					}
				}
				span[a] = document.createElement("span");
				span[a].className = "select";
				span[a].id = "select" + inputs[a].id;
				span[a].appendChild(textnode);
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = Custom.choose;
			}
		}
	},
	
	choose: function() {
		option = this.getElementsByTagName("option");
		for(d = 0; d < option.length; d++) {
			if(option[d].selected == true) {
				document.getElementById("select" + this.id).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
				if(this.id == 'sortby'){
					setLocation(this.value);
				}
				if (this.id == 'garment' && this.value != '')
				{
					populateColours(garmentUrl, this.value);
				}
				if (this.id == 'colour' && this.value != '')
				{
					populateSize(colourUrl, this.value, document.getElementById('garment').value);
				}
				if (this.id == 'size')
				{
					checkProduct(checkProdUrl, document.getElementById('garment').value, document.getElementById('colour').value, document.getElementById('size').value);
				}
			}
		}
	}
}

window.onload = Custom.initialize;
