/*################################################
(function($) {

$.rselects = {
	defaults:{
		n: 'rsel',
		selectText: 'please select',
		sw: '200px',
		sf: 'right',
		ta: 'left',
		dr: 'ltr',
	},
	callback: function(){}
};

$.fn.extend({

	rselects: function(settings) {
		settings = $.extend( {}, $.rselects.defaults, settings);
		$(this).each(function(name) {
			var name = this.id;
			this.style.display='none';

			var selArea = "<div class='selectArea' id='selectArea"+name+"'><div id='mySelectText"+name+"' class='center'>";
			selArea += settings.selectText+"</div><div class='right' onclick='javascript:showOptions(\""+name+"\");'>»</div></div>";
			var optionDiv = "<div id='optionsDiv"+name+"' rel='"+name+"' class='optionsDivInvisible'></div>";

			$(this).before(selArea);
			$("#selectArea"+name).css({ width: settings.sw, float: settings.sf });
			$("#mySelectText"+name).css({ width: ($("#selectArea"+name).width() - 32) });

			$("body").append(optionDiv);
			$("#optionsDiv"+name).css({ top: ( $("#selectArea"+name).offset().top + ($(".center").height()+5) ), left: $("#selectArea"+name).offset().left  });

			for(var j=0; j < this.options.length; j++) {
				var optoinRow = '<p id="'+this.options[j].value+'" rel="'+name+'" class="optionOnclick">'+this.options[j].text+'</p>';
				$("#optionsDiv"+name).append(optoinRow);
				$("#optionsDiv"+name).css({width: ($("#selectArea"+name).width() - 28)});
				$(".optionsDivInvisible p, .optionsDivVisible p").css("text-align", settings.ta).css({ direction: settings.dr });
				$(".optionOnclick").click(function() { $(this).selectClick(settings)} );
				$(".optionOnclick").hover(function(){ $(this).addClass("optionHover"); },
										function(){ $(this).removeClass("optionHover"); });
			}
		});
	},
	correctSelects: function() {
		$(this).each( function() {
		var name = $(this).attr("rel");
		if ($("#optionsDiv"+name)) {
			alert($("#selectArea"+name).offset().left);
			$("#optionsDiv"+name).css({ top: ( $("#selectArea"+name).offset().top + ($(".center").height()+5) ), left: $("#selectArea"+name).offset().left  });
		}
	});
	},
	selectClick: function(settings) {
		var selectNo = $(this).attr("id");
		var selectField = $(this).attr("rel");
		$("#"+selectField).val(selectNo);
		if(settings.callback) settings.callback(selectNo);
		//var newText = $(this).text();
		$("#mySelectText"+selectField).text($(this).text());
		$("#optionsDiv"+selectField).removeClass("optionsDivVisible").addClass("optionsDivInvisible");
		$(".optionsDivInvisible").correctSelects();
		$(".optionHover").removeClass("optionHover");
	}
});
})(jQuery);
function showOptions(g) {
	var elem = document.getElementById("optionsDiv"+g);
	if(elem.className=="optionsDivInvisible") {elem.className = "optionsDivVisible";}
	else if(elem.className=="optionsDivVisible") {elem.className = "optionsDivInvisible";}
}
function sellectCallback(optionValue) {
		removeError();
		showDivLang(optionValue);
}

	//$("#firmLang").rselects( { selectText:'выбрать язык', callback: sellectCallback }  );
	//$("#region").rselects({selectText:'выбрать регион'});
	//alert ($("#langFirm").val());
//	$(window).resize( function() {
//		$(".optionsDivInvisible").correctSelects();
//	});
##########################################*/

var checkboxHeight = "24";
var radioHeight = "25";

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++) {
			if(inputs[a].className == "styled") {
				var thisClass = inputs[a].name;

				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 = $(this).attr("name");

				span[a].className = thisClass;
				span[a].id = "select" + inputs[a].name;
				span[a].appendChild(textnode);
				inputs[a].parentNode.insertBefore(span[a], inputs[a]);
				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) {
				document.getElementById("select" + this.name).childNodes[0].nodeValue = option[d].childNodes[0].nodeValue;
			}
		}
	}
}
window.onload = Custom.init;