function add_css_class(selector, class_name) {
	var elements = cssQuery(selector);
	for(var e = 0; e < elements.length; e++) {
		elements[e].className += " " + class_name;
	}
}
function ie_support() {
	add_css_class("ul.utilities li:first-child", "first-child");
	add_css_class("ul.languages li:first-child", "first-child");
	add_css_class("body.homepage p.date+h2", "p-date-sibling");
	
	add_css_class("input[type='text']", "type-text");
	add_css_class("input[type='password']", "type-password");
	add_css_class("input[type='submit']", "type-submit");
}

function fix_sidebar() {
	$(".sidebar").css("height", $(".page").height());
}
function fix_footer() {
	$(".footer").css("bottom", -1);
}

function navigation() {
	if(document.getElementById("navigation")) {
		
		var navigation = document.getElementById("navigation").getElementsByTagName("LI");
		
		for(var i=0; i<navigation.length; i++) {
			if (navigation[i].firstChild.nodeType == 3) {
				var a = document.createElement("a");
				a.appendChild(navigation[i].firstChild);
				a.href="#";
				a.setAttribute("onclick", "navigate(this); return false;");
				a.onclick = function(){navigate(this); return false;};
				navigation[i].insertBefore(a,navigation[i].firstChild);
				
				var uls = navigation[i].getElementsByTagName("UL");
				for(var j=0; j<uls.length; j++) {
					uls[j].className = "closed";
				}
			}
		}
		
		var links = document.getElementById("navigation").getElementsByTagName("A");
		for(var i=0; i<links.length; i++) {
			if(/selected/.test(links[i].className) && links[i].parentNode.parentNode != document.getElementById("navigation")) {
				links[i].parentNode.parentNode.className = "opened";
				links[i].parentNode.parentNode.previousSibling.className = "selected";
				ul_opened = links[i].parentNode.parentNode;
				a_selected = links[i].parentNode.parentNode.previousSibling;
			}
		}
	}
}

var ul_opened = null;
var a_selected = null;

function navigate(o) {
	if(ul_opened != null) {
		ul_opened.className = "closed";
		a_selected.className = "";
	}
	ul_opened = o.nextSibling;
	a_selected = o;
	ul_opened.className = "opened";
	a_selected.className = "selected";
}

var ua = navigator.userAgent.toLowerCase();
var isIE = (/msie/.test(ua)) && !(/opera/.test(ua)) && (/win/.test(ua));

function consultants() {
	clear_sections(12);
	$("#view_results_btn").click(function () {view_consultants(); return false;});
}

function view_consultants() {
	clear_sections(12);
	getMultiple(document.getElementById("accreditation_branch"));
}

function companies() {
	clear_sections(18);
	$("#view_results_btn").click(function () {view_companies(); return false;});
}

function view_companies() {
	clear_sections(18);
	getMultiple(document.getElementById("small_company_branch"));
}

function getMultiple(ob) {
	var selected = new Array();
	for (var i=0; i<ob.options.length; i++) {
		if (ob.options[i].selected) {
			selected.push(ob.options[i].value);
		}
	}
	
	for(var i=0; i<selected.length; i++) {
		$("#section_"+selected[i]).css("display", "block");
	}
	if(isIE) {
		fix_sidebar();
		fix_footer();
	}
}

function clear_sections(count) {
	for(var i=1; i<count; i++) {
		$("#section_"+i).css("display", "none");
	}
	if(isIE) {
		fix_sidebar();
		fix_footer();
	}
}

function forms() {
	var opt1 = document.getElementById("small_company");
	$("#small_company").click(function () {
		if(this.checked || this.checked == "checked") {
			document.getElementById("section_accreditation").style.display = "none";
			document.getElementById("section_small_company").style.display = "block";
		} else {
			document.getElementById("section_small_company").style.display = "none";
			document.getElementById("section_accreditation").style.display = "block";
		}
	});
	
	var opt2 = document.getElementById("accreditation");
	$("#accreditation").click(function () {
		if(this.checked || this.checked == "checked") {
			document.getElementById("section_small_company").style.display = "none";
			document.getElementById("section_accreditation").style.display = "block";
		} else {
			document.getElementById("section_accreditation").style.display = "none";
			document.getElementById("section_small_company").style.display = "block";
		}
	});
	
	if(opt1.checked || opt1.checked == "checked") {
		document.getElementById("section_small_company").style.display = "block";
	} else {
		document.getElementById("section_small_company").style.display = "none";
	}
	if(opt2.checked || opt2.checked == "checked") {
		document.getElementById("section_small_company").style.display = "none";
	} else {
		document.getElementById("section_accreditation").style.display = "none";
	}
	
	if(isIE) {
		fix_sidebar();
		fix_footer();
	}
}