var activeFaq;
var activeOptionRef;
var focusElm;
var dropElm;

function activateSelect(objSelect,fakeSelect,dropDown) {
	
	// setting focus element
	focusElm = objSelect;
	
	// display dropdown
	dropDown.style.display = "block";
	
	// resetting class
	dropDown.className = dropDown.className.replace(" transparent","");
	
	// building dropdown if empty
	if(dropDown.childNodes.length == 0) {
	
	
		for(var x=0; x<objSelect.options.length;x++) {
		
			// creating element
			var option = document.createElement('div');
			
			// setting text
			option.innerHTML = objSelect.options[x].text;
			
			// setting value
			option.value = x;
			
			// setting onclick
			option.onmousedown = function () {
				
				// setting selected index
				objSelect.selectedIndex = this.value;
				
				// setting selected
				objSelect.selected = 'true';
				
				// setting innerhtml
				fakeSelect.innerHTML = this.innerHTML;
				
				// setting dropdown className
				dropDown.className = dropDown.className.replace(" transparent","");
				
				// setting invisible
				dropDown.style.display = "none";
				
				// reset old option
				activeOptionRef.className = activeOptionRef.className.substring(0,activeOptionRef.className.length-7);
				
				// saving activeref
				activeOptionRef = this;
				
				// appending active to class
				this.className += ' active';
			}
			
			// setting right class
			if(x == 0 && objSelect.options.length == 1) {
				option.className = 'optionTopBottom';
			}
			
			if(x == 0 && objSelect.options.length > 1) {
				option.className = 'optionTop';
			}
			
			if(x != 0 && objSelect.options.length-1 == x) {
				option.className = 'optionBottom';
			}
		
			// active?
			if(x == objSelect.selectedIndex) {
				activeOptionRef = option;
				option.className += ' active';
			}
			
			// setting scollbar if options = 11
			if(x == 11) {
			
				// setting class name
				dropDown.className += 'Overflow';
				
				// height
				dropDown.style.height = (1 + dropDown.offsetHeight) + 'px';
			}
		
			dropDown.appendChild(option);
		}

	}
		
}

function deActivateSelect(objSelect,fakeSelect,dropDown) {
	
	// setting focus element
	focusElm = null;
	
	dropDown.className += " transparent";
	
	dropElm = dropDown;
	
	// setting invisible
	setTimeout('dropElm.style.display = "none"',100);
}

function changeOption(objRef) {
	
	// getting dropdown
	var dropDown = objRef.parentNode.nextSibling;
	
	var layer = objRef.previousSibling;
	
	// getting node to select
	var option = dropDown.childNodes[objRef.selectedIndex];
	
	// setting layer text
	layer.innerHTML = option.innerHTML;
	
	// reset old option
	activeOptionRef.className = activeOptionRef.className.substring(0,activeOptionRef.className.length-7);
	
	option.className += " active";
	
	activeOptionRef = option;
	
	
}

function activateField(objRef) {

	// lets hide layer
	objRef.style.display = 'none';
	
	// set focus on fiels
	objRef.nextSibling.focus();
	
}

function deActivateField(objRef) {

	// lets show layer if field is empty
	if(objRef.value == "") {
		objRef.previousSibling.style.display = 'inline';
	}
	
	
}

function showBlur(objRef,ev) {
	
	var target = ev.explicitOriginalTarget||document.activeElement;
 	if(target.className == 'selectOptionsWideOverflow' || target.className == 'selectOptionsOverflow') {
 		objRef.focus();
 		return true;
 	} else {
 		return false;
 	}
} 	

function toggleCheckbox(objRef) {

	// lets show layer if field is empty
	if(objRef.className == "checkboxWrapper") {
	
		objRef.className = 	"checkboxWrapperActive";
		
		// checking child
		objRef.childNodes[0].checked = true;
		
	} else {
	
		objRef.className = 	"checkboxWrapper";
		
		// checking child
		objRef.childNodes[0].checked = false;
	}
	
	
}
