/* TV LISTINGS */

/* : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : reminder box display function
- position: top = 216px; left = 196 + (1/2 of (page width - 990))px;
*/
var windowWidth = 0;	var windowHeight = 0;	var altHalfWidth = 0;	var pageWidth = 990;
if (navigator.appName == "Netscape") { windowWidth = window.innerWidth; windowHeight = window.innerHeight; }
if (navigator.appName.indexOf("Microsoft") != -1) { windowWidth = document.documentElement.clientWidth; windowHeight = document.documentElement.clientHeight; }
if (windowWidth > 990) { altHalfWidth = Math.round((windowWidth - pageWidth) / 2); }

function reminderDetailsDiv (s, e) {
	switch (e) {
		case "show" :
			var posTop = 216;	var posLeft = altHalfWidth + 196;
			document.getElementById(s).style.left = posLeft + "px";
			document.getElementById(s).style.top = posTop + "px";
			document.getElementById(s).style.display = "block";
			break;
		
		default:
			document.getElementById(s).style.display = "none";
			break;
	}
}

function tvRatingsDiv (s) {
	document.getElementById(s).style.left = (document.documentElement.scrollLeft + 295) + "px";
	document.getElementById(s).style.top = (document.documentElement.scrollTop + 50) + "px";
	document.getElementById(s).style.display = "block";
}


/* : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : timezone function
- requires preloaded jsLibrary [ /common/javascript/cookies.js ]
- set date for cookie
*/
var thisDay = new Date();
var zoneCookieDie = new Date();
zoneCookieDie.setTime(thisDay.getTime() + 1000*60*60*10);

function tvListingsTimeZone (s) {
	var epochSecondsDiff;
	var theCookiePath = "/";	var theCookieDomain = ".discovery.com";
	if (s == "EST") { epochSecondsDiff = 18000 + "-EST"; }	// 60 * 60 * 5 (hour difference from GMT)
	else if (s == "CST") { epochSecondsDiff = 21600 + "-CST"; }
	else if (s == "MST") { epochSecondsDiff = 25200 + "-MST"; }
	else { epochSecondsDiff = 28800 + "-PST"; }
	setCookie("DCOM_TIMEZONE", epochSecondsDiff, zoneCookieDie, theCookiePath, theCookieDomain);
	window.location.reload();
}


/* : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : check function
- base functions
*/
function isEmpty(s) { return ((s == null) || (s.length == 0)) }
function isLetter(c) { return ( ((c >= "a") && (c <= "z")) || ((c >= "A") && (c <= "Z")) ) }
function isDigit(c) { return ( ((c >= "0") && (c <= "9")) || (c == ",")) }
function isSpecialCharacter(c) { return ((c == "@") || (c == ".") || (c == "_") || (c == "-") || (c == "'") || (c == "/")) }

function validateEmail(s) {
	var passFlag = true;	var validFlag = true;
	for (i = 0; i < s.length; i++) {	var c = (s).charAt(i);	if (!isLetter(c)) { if (!isDigit(c)) { if (!isSpecialCharacter(c)) { passFlag = false; break; } } }	}
	if (!passFlag || isEmpty(s) || (s.length <= 6) || (((s).indexOf("@") <= 0) || ((s).indexOf(".") <= 0))) { validFlag = false; }
	
	return validFlag;
}

/* : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : show calendar function
- shows the calendar when hovering over a date
*/
function showCalendar() {
	var show = document.getElementById('iFrameCalendar');
	show.style.cssText = "display: block; position: absolute; top: 20px; border: 1px solid #CCC; background-color: #EBEBEB;"
	show.style.visibility="visible";
}

/* : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : hide calender function
- hides the calendar when the mouse moves out of position
*/
function hideCalendar() {
	var show = document.getElementById('iFrameCalendar');
	//show.style.cssText = "display: none;"
	show.style.visibility="hidden";
}


/* : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : : reminder evaluation
- requires preloaded jsLibrary [ /common/javascript/flashobject.js ]
- reminder evaluation functions
*/




function evalReminders(s) {
	var emailAddress = document.reminders.emailAddress.value;
	var format = document.reminders.format.value;
	var showArray = ""; for (var i = 0; i < s.length; i++) {	if (s.elements[i].type == "checkbox" && s.elements[i].checked) { showArray = s.elements[i].value + "," + showArray; }	}

	var completeDataSet = emailAddress + "|" + format + "|" + showArray;
	/* document.getElementById("qString").innerHTML = completeDataSet; */

	if (!validateEmail(emailAddress)) { document.getElementById("emailError").style.display = "block"; } else { document.getElementById("emailError").style.display = "none"; }
	if (showArray == "") { document.getElementById("showError").style.display = "block"; } else { document.getElementById("showError").style.display = "none"; }
	if (validateEmail(emailAddress) && showArray != "") {
		var fo = new SWFObject("/tv-schedules/utilities/remindersFlashWidget.swf", "remindersFO", "250", "20", "8", "#ebebeb", true);
		fo.addVariable("_net", document.reminders.network.value);
		fo.addVariable("_function", document.reminders.execute.value);
		fo.addVariable("showArray", completeDataSet);
		//fo.addVariable("user_ip", getIP());
		fo.addParam("wmode", "opaque");
		fo.write("remindersFlashObject");
	}
	
	return false;
}


/* TV LISTINGS */