lightbox_survey = function (event) {
	
	if (document.getElementById) {
				
		var thiswidth = 0, thisheight = 0;
		thisheight = document.body.offsetHeight;
		thiswidth = document.body.offsetWidth;

		if (document.getElementById("survey-div")) {
		
		var opaque = document.createElement("DIV");
		opaque.id = "opaque";
		opaque.style.left = "0px";
		opaque.style.right = "0px";
		opaque.style.top = "0px";
		opaque.style.bottom = "0px";
		opaque.style.zIndex = "999";
		opaque.style.width = thiswidth + "px";
		opaque.style.height = thisheight + "px";
		document.body.appendChild(opaque);

		var customform = document.getElementById('survey-div');

		var lightbox = document.createElement("DIV");
		lightbox.id = "lightbox";
		lightbox.style.padding = "20px";
		lightbox.style.position = "absolute";
		lightbox.style.left = "300px";
		lightbox.style.right = "300px";
		lightbox.style.top = "50px";
		lightbox.style.height = "auto";
		lightbox.style.zIndex = "1000";
		lightbox.style.backgroundColor = "white";
		lightbox.style.border = "5px solid #ccc";

		lightbox.appendChild(customform);
		document.body.appendChild(lightbox);
	
		}			

	}
}


close_lightbox = function(event) {
	
	if (document.getElementById) {
		document.body.removeChild(document.getElementById('opaque'));
		document.body.removeChild(document.getElementById('lightbox'));
		document.body.removeChild(document.getElementById('customForm'));
	}
}


function add_form_validation() {
	
	if(document.getElementById("action") && document.getElementById("registration")) {
		var registerBtn = document.getElementById("action");
		registerBtn.type="button";
		if(registerBtn.addEventListener) {
			registerBtn.addEventListener('click',validate_form,false);	
		}
		else if(registerBtn.attachEvent) {
			registerBtn.attachEvent('onclick',validate_required);
		}
	}
	else { return false; }
	
}

function validate_form() {
	
	if (document.getElementById("registration")) {
		
		var form = $$('form');
		form = form[0];
		var inputs = form.getInputs('text');
		
		var validate = false;
		
		for(i = 0; i < inputs.length; i++) { 
			validate = validate_required(inputs[i])
		}

		
		if(!validate) { 
			alert("All fields are required"); 
			
		}
		
		else {
			var registerForm = document.getElementsByTagName("form");
			registerForm[0].submit();
		}
	
	}
	return false;
	
}

function validate_required(field) {
	with (field) {
		if (value==null||value=="") { 
			field.style.borderColor = "red";
			return false; 
			}
		else { return true; }
		}
}

function checkRadios () {
	
	var inputArray = document.getElementsByTagName('input');
	
	for(var i=0;i<inputArray.length;i++) {
		var tempType = inputArray[i].getAttribute("type");
		if(tempType == "radio") {
			inputArray[i].checked = false;
			inputArray[i].setAttribute("checked",false);
			inputArray[i].defaultChecked = false;				
		}
	}	
}

add_DOM_onLoad(
	function() {
		add_form_validation();
		if ($('survey-div')) { 
			lightbox_survey(); 
			checkRadios();
		}
	}
);
