var survey = new Lightbox("Customer Survey");

function ajax_xml_http()
	{
	var xmlHttp;
	try
		{ // Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();
		}
	catch (e)
		{ // Internet Explorer
	try
		{
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
	catch (e)
		{
      try
      	{
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
      catch (e)
      	{
			alert("Your browser does not support AJAX!");
			return false;
			}
		}
	}
	
	return xmlHttp;
}

function surveyCheck(user)
	{
/**/if (document.referrer.match(/users/i) == 'users') {
	
	surveyXml = ajax_xml_http();
	
	url = "/ajax/survey.php?function=surveyCheck&id="+user;
	
	surveyXml.onreadystatechange = function()
		{
		if (surveyXml.readyState == 4)
			{
			if (surveyXml.responseText)
				{
				    survey.setContent(surveyXml.responseText);
				    survey.display();
				}
			}
		}
	surveyXml.open("GET", url, true);
	surveyXml.send(null);
/**/}
	}
	
function showSurvey()
	{
	surveyXml = ajax_xml_http();
	
	url = "/ajax/survey.php?function=showSurvey";
	
	surveyXml.onreadystatechange = function()
		{
		if (surveyXml.readyState == 4)
			{
			if (surveyXml.responseText)
				{
				survey.setContent(surveyXml.responseText);
				}
			}
		}
	surveyXml.open("GET", url, true);
	surveyXml.send(null);
	}

function divKill(element)
	{
	element.parentNode.parentNode.parentNode.removeChild(element.parentNode.parentNode);
	}

function isTrue(value)
	{
	return (value == "Yes");
	}

function in_array(needle, haystack)
	{
	for (hay in haystack)
		{
		if (needle == hay)
			{
			return true;
			}
		}
	return false;
	}

function submitSurvey()
	{
	input = document.getElementById('survey').getElementsByTagName('input');	

	//sloppy as hell but im really frustrated at this point
	//the arrays hold which values have been checked and which have not
	unchecked = new Array();
	checked = new Array();
	
	for (i = 0; i < input.length; ++i)
		{
		if (input[i].getAttribute('type') == 'radio')
			{
			if (!input[i].checked)
				{
				unchecked.push(input[i].name);
				}
			else
				{
				checked.push(input[i].name);
				}
			}
		}
	
	submit = true;
	
	for (val in unchecked)
		{
		if (!in_array(val, checked))
			{
			submit = false;
			}
		}
	
	if (submit)
		{
		document.getElementById('survey').submit();
		}
	
	/*var surveyXml = ajax_xml_http();
	
	url = "/ajax/survey.php?function=submitSurvey";
	
	surveyXml.onreadystatechange = function()
		{
		if (surveyXml.readystate == 4)
			{
			
			}
		}
	
	surveyXml.open("POST", url, true);
	surveyXml.send();*/
	}

function allSiblings(attribute, value, element)
	{
	nodeList = element.parentNode.getElementsByTagName('span');
	for(i = 0; i < nodeList.length; ++i)
		{
		nodeList[i].removeAttribute(attribute);
		nodeList[i].setAttribute(attribute, value);
		}
	}
