
var xmlhttp

function loadDoc(url)
{
	xmlhttp=null
	// code for Mozilla, etc.
	if(window.XMLHttpRequest && !(window.ActiveXObject)) 
	{
		xmlhttp=new XMLHttpRequest()
	}
	// code for IE
	else if (window.ActiveXObject)
	{
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
	}

	if (xmlhttp!=null)
	{
		//alert(url);
		xmlhttp.onreadystatechange=state_Change
		xmlhttp.open("GET",url,true)
		xmlhttp.send(null)
	}
	else
	{
		alert("Your browser does not support XMLHTTP.")
	}
}

function state_Change()
{
	// if xmlhttp shows "loaded"
	var doNext = false;
	if (xmlhttp.readyState==4)
	{
		// if "OK"
		if (xmlhttp.status==200)
		{
			doNext = true;
		}
		else
		{
			// Safari throws an error even though it seems to work
			if (BrowserDetect.browser != "Safari")
			{
				alert("An error occurred, please update your web browser to the latest version.")
			} else {
				doNext = true;
			}
		}
	}
	if (doNext)
	{
		document.getElementById("cellStatus").innerHTML = "Rating Saved<br>Loading Next Song";
		//window.open('/music/fresh/songbysong.asp','_self');
		document.location.href='songbysong.asp';
	}
}

function rateSong(songID,setID,rating)
{
	if (songID > 0)
	{
		document.getElementById("cellStatus").innerHTML = "Saving Rating";
		loadDoc("saveRating.asp?songID=" + songID + "&setID=" + setID + "&rating=" + rating);
	}
}

function validateScreener(theForm)
{
	var errorText;
	var testField;
	var testVal;
	errorText = "";
	

	testField = theForm.Gender;
	testVal = testField.options[testField.selectedIndex].value;
	if (testVal == "") { 
		errorText = errorText + "\n - Choose an option for your \"Gender\"";
	}


	testField = theForm.AgeGroup;
	testVal = testField.options[testField.selectedIndex].value;
	if (testVal == "") { 
		errorText = errorText + "\n - Choose an option for your \"Age Group\"";
	}


	testField = theForm.Ethnicity;
	testVal = testField.options[testField.selectedIndex].value;
	if (testVal == "") { 
		errorText = errorText + "\n - Choose an option for your \"Ethnicity\"";
	}


	testField = theForm.RadioListening;
	testVal = testField.options[testField.selectedIndex].value;
	if (testVal == "") { 
		errorText = errorText + "\n - Choose an option for your \"Per Day listening\"";
	}
	
	testField = theForm.PrimaryStation;
	testVal = testField.options[testField.selectedIndex].value;
	if (testVal == "") { 
		errorText = errorText + "\n - Choose an option for your \"Preferred Station\"";
	}
	

	if (errorText != "") {
		alert("All fields are required:" + errorText);
		return false;
	}
	
	return true;
	
}
