function getHTTPObject() {
	if (window.ActiveXObject)
		return new ActiveXObject("Microsoft.XMLHTTP");
	else if (window.XMLHttpRequest)
		return new XMLHttpRequest();
	else {      
		//alert("Your browser does not support AJAX.");
		return null;   
	}
}

var showID = '';

function podcastDetails(p, s) {
	httpObject = getHTTPObject();
	
	showID = s;
				
	if (httpObject != null) {
		var now = new Date();
		var url = '/podcast/includes/ajax-podcast-notes.asp?p=' + p + '&s=' + s + '&t=' + now.getTime();
		
		httpObject.open("GET", url, true);
		httpObject.send(null);
		httpObject.onreadystatechange = setOutputPodcastDetails;
	}
}

function setOutputPodcastDetails() {
	if(httpObject.readyState == 4) {
		if (document.getElementById('ajax-notes-label' + showID).innerHTML == "Show Notes") {
			document.getElementById('ajax-notes' + showID).innerHTML = httpObject.responseText;
			document.getElementById('ajax-notes-label' + showID).innerHTML = "Hide Notes"
		} else {
			document.getElementById('ajax-notes' + showID).innerHTML = "";
			document.getElementById('ajax-notes-label' + showID).innerHTML = "Show Notes"
		}
	}
}

function podcastComments(p, s, c) {
	httpObject = getHTTPObject();
	
	showID = s;
		
	if (httpObject != null) {
		var now = new Date();
		var url = '/podcast/includes/ajax-podcast-comments.asp?p=' + p + '&s=' + s + '&c=' + c + '&t=' + now.getTime();
		
		httpObject.open("GET", url, true);
		httpObject.send(null);
		httpObject.onreadystatechange = setOutputPodcastComments;
	}
}

function setOutputPodcastComments() {
	if(httpObject.readyState == 4) {
		if (document.getElementById('ajax-comments-label' + showID).innerHTML == "Show Comments") {
			document.getElementById('ajax-comments' + showID).innerHTML = httpObject.responseText;
			document.getElementById('ajax-comments-label' + showID).innerHTML = "Hide Comments"
		} else {
			document.getElementById('ajax-comments' + showID).innerHTML = "";
			document.getElementById('ajax-comments-label' + showID).innerHTML = "Show Comments"
		}
	}
}

function podcastPoll(p, s, pl, dr) {
	httpObject = getHTTPObject();
	
	showID = s;
	
	if (httpObject != null) {
		var now = new Date();
		var url = '/podcast/includes/ajax-podcast-poll.asp?p=' + p + '&pl=' + pl + '&s=' + s + '&dr=' + dr + '&t=' + now.getTime();
		
		httpObject.open("GET", url, true);
		httpObject.send(null);
		httpObject.onreadystatechange = setOutputPodcastPoll;
	}
}

function setOutputPodcastPoll() {
	if(httpObject.readyState == 4) {
		if (document.getElementById('ajax-poll-label' + showID).innerHTML == "Show Poll Results") {
			document.getElementById('ajax-poll' + showID).innerHTML = httpObject.responseText;
			document.getElementById('ajax-poll-label' + showID).innerHTML = "Hide Poll Results"
		} else {
			document.getElementById('ajax-poll' + showID).innerHTML = "";
			document.getElementById('ajax-poll-label' + showID).innerHTML = "Show Poll Results"
		}
	}
}

function preload_hangman_images() {
	var img0 = new Image();
	img0.src = "http://www.horrorchapter.com/horror_hangman/images/hangman/0.jpg";

	var img1 = new Image();
	img1.src = "http://www.horrorchapter.com/horror_hangman/images/hangman/1.jpg";

	var img2 = new Image();
	img2.src = "http://www.horrorchapter.com/horror_hangman/images/hangman/2.jpg";

	var img3 = new Image();
	img3.src = "http://www.horrorchapter.com/horror_hangman/images/hangman/3.jpg";

	var img4 = new Image();
	img4.src = "http://www.horrorchapter.com/horror_hangman/images/hangman/4.jpg";

	var img5 = new Image();
	img5.src = "http://www.horrorchapter.com/horror_hangman/images/hangman/5.jpg";

	var img6 = new Image();
	img6.src = "http://www.horrorchapter.com/horror_hangman/images/hangman/6.jpg";
}

function vote_poll(p) {
	httpObject = getHTTPObject();
					
	if (httpObject != null) {
		var now = new Date();
		var this_responseID = "";
		
		for (i=0; i<=(document.poll_form.length - 1); i++) {
			if (document.poll_form.responseID[i].checked) { this_responseID = document.poll_form.responseID[i].value; }
		}
		
		var url = '/podcast/includes/ajax-poll.asp?subVote=1&dr=1&p=' + p + '&responseID=' + this_responseID + '&t=' + now.getTime();
				
		httpObject.open("GET", url, true);
		httpObject.send(null);
		httpObject.onreadystatechange = vote_poll_action;
	}
}

function vote_poll_action() {
	if(httpObject.readyState == 4) {
		document.getElementById('ajax-poll').innerHTML = httpObject.responseText;
	}
}

function email_signup(e) {
	httpObject = getHTTPObject();
	var er = "";
					
	if (httpObject != null) {
		var now = new Date();
		var this_responseID = "";
	
		er = echeck(e);
				
		if (er != "") {
			alert(er);
		} else {
			var url = '/podcast/includes/ajax-email-signup.asp?e=' + escape(e) + '&t=' + now.getTime();

			httpObject.open("GET", url, true);
			httpObject.send(null);
			httpObject.onreadystatechange = email_signup_action;
		}
	}
}

function email_signup_action() {
	if(httpObject.readyState == 4) {
		document.getElementById('email_signup_div').innerHTML = httpObject.responseText;
	}
}

function email_signup_contest(e) {
	httpObject = getHTTPObject();
	var er = "";
					
	if (httpObject != null) {
		var now = new Date();
		var this_responseID = "";
	
		er = echeck(e);
				
		if (er != "") {
			alert(er);
		} else {
			var url = '/podcast/includes/ajax-email-signup.asp?e=' + escape(e) + '&t=' + now.getTime();

			httpObject.open("GET", url, true);
			httpObject.send(null);
			httpObject.onreadystatechange = email_signup_contest_action;
		}
	}
}

function email_signup_contest_action() {
	if(httpObject.readyState == 4) {
		document.getElementById('email_signup_div_contest').innerHTML = httpObject.responseText;
	}
}

function email_signup_contest_f13(e) {
	httpObject = getHTTPObject();
	var er = "";
					
	if (httpObject != null) {
		var now = new Date();
		var this_responseID = "";
	
		er = echeck(e);
				
		if (er != "") {
			alert(er);
		} else {
			var url = '/podcast/includes/ajax-email-signup-f13.asp?e=' + escape(e) + '&t=' + now.getTime();

			httpObject.open("GET", url, true);
			httpObject.send(null);
			httpObject.onreadystatechange = email_signup_contest_f13_action;
		}
	}
}

function email_signup_contest_f13_action() {
	if(httpObject.readyState == 4) {
		document.getElementById('email_signup_div_contest').innerHTML = httpObject.responseText;
	}
}

function email_signup_contest_breathers(e, tt) {
	httpObject = getHTTPObject();
	var er = "";
					
	if (httpObject != null) {
		var now = new Date();
		var this_responseID = "";
	
		er = echeck(e);
		if (tt == "") { er += "Please fill in your top ten list.\n"; }
				
		if (er != "") {
			alert(er);
		} else {
			var url = '/podcast/includes/ajax-email-contest-signup-breathers.asp?e=' + escape(e) + '&tt=' + escape(tt) + '&t=' + now.getTime();

			httpObject.open("GET", url, true);
			httpObject.send(null);
			httpObject.onreadystatechange = email_signup_contest_breathers_action;
		}
	}
}

function email_signup_contest_breathers_action() {
	if(httpObject.readyState == 4) {
		document.getElementById('email_signup_div_contest_breathers').innerHTML = httpObject.responseText;
	}
}

function echeck(str) {
	var rv = "";

	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   rv = "Please enter a valid Email Address.\n";
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   rv = "Please enter a valid Email Address.\n";
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
	   rv = "Please enter a valid Email Address.\n";
	}

	 if (str.indexOf(at,(lat+1))!=-1){
	   rv = "Please enter a valid Email Address.\n";
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
	   rv = "Please enter a valid Email Address.\n";
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
	   rv = "Please enter a valid Email Address.\n";
	 }

	 if (str.indexOf(" ")!=-1){
	   rv = "Please enter a valid Email Address.\n";
	 }

	return rv;

}

function toggle_ad (div_id) {
	if (document.getElementById(div_id).style.display == "none")
		document.getElementById(div_id).style.display = "block";
	else
		document.getElementById(div_id).style.display = "none";
}
