/*

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 = "25";
var radioHeight = "25";
var selectWidth = "204";
var selectWidth1 = "70";
var selectWidth2 = "147";
var selectWidth3 = "344";
var selectWidth4 = "70";
var selectWidth5 = "147";
var selectWidth6 = "118";
var selectWidth7 = "147";
var selectWidth8 = "57";
var selectWidth9 = "204";

/* No need to change anything after this */
//Modified by tattoo
document.write('<style type="text/css">input.styled { display: none; } select.styled { position: relative; width: ' + selectWidth + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } input.styled1 { display: none; } select.styled1 { position: relative; width: ' + selectWidth1 + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } input.styled2 { display: none; } select.styled2 { position: relative; width: ' + selectWidth2 + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } input.styled3 { display: none; } select.styled3 { position: relative; width: ' + selectWidth3 + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } input.styled4 { display: none; } select.styled4 { position: relative; width: ' + selectWidth4 + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } input.styled5 { display: none; } select.styled5 { position: relative; width: ' + selectWidth5 + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } input.styled6 { display: none; } select.styled6 { position: relative; width: ' + selectWidth6 + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } input.styled7 { display: none; } select.styled7 { position: relative; width: ' + selectWidth7 + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } input.styled8 { display: none; } select.styled8 { position: relative; width: ' + selectWidth8 + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; } input.styled9 { display: none; } select.styled9 { position: relative; width: ' + selectWidth9 + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; }</style>');
//document.write('<style type="text/css">input.styled { display: none; } select.styled { position: relative; width: ' + selectWidth + 'px; opacity: 0; filter: alpha(opacity=0); z-index: 5; }</style>');
//Modified by tattoo

var Custom = {
	init: function() {
		var inputs = document.getElementsByTagName("input"), span = Array(), textnode, option, active;
		for(a = 0; a < inputs.length; a++) {
			if((inputs[a].type == "checkbox" || inputs[a].type == "radio") && inputs[a].className == "styled") {
				span[a] = document.createElement("span");
				span[a].className = inputs[a].type;

				if(inputs[a].checked == true) {
					if(inputs[a].type == "checkbox") {
						position = "0 -" + (checkboxHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					} else {
						position = "0 -" + (radioHeight*2) + "px";
						span[a].style.backgroundPosition = position;
					}
				}
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				inputs[a].onchange = Custom.clear;
				span[a].onmousedown = Custom.pushed;
				span[a].onmouseup = Custom.check;
				document.onmouseup = Custom.clear;
			}
		}
		inputs = document.getElementsByTagName("select");
				
		for(a = 0; a < inputs.length; a++) {			
			//Modified by tattoo
			if((inputs[a].className == "styled") || (inputs[a].className == "styled1") || (inputs[a].className == "styled2") || (inputs[a].className == "styled3") || (inputs[a].className == "styled4") || (inputs[a].className == "styled5") || (inputs[a].className == "styled6") || (inputs[a].className == "styled7") || (inputs[a].className == "styled8") || (inputs[a].className == "styled9")) {
			//if(inputs[a].className == "styled") {
			//Modified by tattoo
				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");				
				//Modified by tattoo				
				if (inputs[a].id=="id_lang") {
					span[a].className = "select1";
				} else if (inputs[a].id=="select_country") {
					span[a].className = "select2";
				} else if (inputs[a].id=="select_city") {
					span[a].className = "select3";
				} else if (inputs[a].id=="cu_title") {
					span[a].className = "select4";
				} else if (inputs[a].id=="cu_country") {
					span[a].className = "select5";
				} else if (inputs[a].id=="cu_category") {
					span[a].className = "select6";
				} else if ((inputs[a].id=="group_type") || (inputs[a].id=="trip_type") || (inputs[a].id=="connecting_flight") || (inputs[a].id=="traveling_from") || (inputs[a].id=="destination") || (inputs[a].id=="travel_time") || (inputs[a].id=="return_time")) {
					span[a].className = "select7";
				} else if ((inputs[a].id=="travel_dd") || (inputs[a].id=="travel_mm") || (inputs[a].id=="travel_yyyy") || (inputs[a].id=="return_dd") || (inputs[a].id=="return_mm") ||(inputs[a].id=="return_yyyy")) {
					span[a].className = "select8";
				} else if ((inputs[a].id=="bc_to") || (inputs[a].id=="bc_from")) {
					span[a].className = "select9";
				} else {
					span[a].className = "select";	
				}				
				//Modified by tattoo
				//span[a].className = "select";
				span[a].id = "select" + inputs[a].name;
				span[a].appendChild(textnode);
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				//inputs[a].onchange = Custom.choose;
				if ((inputs[a].id=="cu_title") || (inputs[a].id=="cu_country") || (inputs[a].id=="cu_category") || (inputs[a].id=="bc_from") || (inputs[a].id=="bc_to") || (inputs[a].id=="group_type") || (inputs[a].id=="trip_type") || (inputs[a].id=="traveling_from") || (inputs[a].id=="travel_dd") || (inputs[a].id=="travel_mm") || (inputs[a].id=="travel_yyyy") || (inputs[a].id=="travel_time") || (inputs[a].id=="destination") || (inputs[a].id=="return_dd") || (inputs[a].id=="return_mm") || (inputs[a].id=="return_yyyy") || (inputs[a].id=="return_time")) {
					inputs[a].onchange = Custom.choose1;
				} else {
					inputs[a].onchange = Custom.choose;	
				}
			}
		}
	},
	pushed: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight*3 + "px";
		} else if(element.checked == true && element.type == "radio") {
			this.style.backgroundPosition = "0 -" + radioHeight*3 + "px";
		} else if(element.checked != true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 -" + checkboxHeight + "px";
		} else {
			this.style.backgroundPosition = "0 -" + radioHeight + "px";
		}
	},
	check: function() {
		element = this.nextSibling;
		if(element.checked == true && element.type == "checkbox") {
			this.style.backgroundPosition = "0 0";
			element.checked = false;
		} else {
			if(element.type == "checkbox") {
				this.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else {
				this.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
				group = this.nextSibling.name;
				inputs = document.getElementsByTagName("input");
				for(a = 0; a < inputs.length; a++) {
					if(inputs[a].name == group && inputs[a] != this.nextSibling) {
						inputs[a].previousSibling.style.backgroundPosition = "0 0";
					}
				}
			}
			element.checked = true;
		}
	},
	clear: function() {
		inputs = document.getElementsByTagName("input");
		for(var b = 0; b < inputs.length; b++) {
			if(inputs[b].type == "checkbox" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + checkboxHeight*2 + "px";
			} else if(inputs[b].type == "checkbox" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			} else if(inputs[b].type == "radio" && inputs[b].checked == true && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 -" + radioHeight*2 + "px";
			} else if(inputs[b].type == "radio" && inputs[b].className == "styled") {
				inputs[b].previousSibling.style.backgroundPosition = "0 0";
			}
		}
	},
	choose: function() {		
		option = this.getElementsByTagName("option");
		for(d = 0; d < option.length; d++) {
			if(option[d].selected == true) {
				//alert(document.frmSel.select_country.value);
				document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
				document.frmSel.submit();
			}
		}
	},	
	choose1: function() {
		option = this.getElementsByTagName("option");
		for(d = 0; d < option.length; d++) {
			if(option[d].selected == true) {
				//alert(document.frmSel.select_country.value);
				document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
				//document.frmSel.submit();
			}
		}
	}
}
window.onload = Custom.init;
