//	gamepad.js

//	window.status changer
function showStatus(strMsg) {
	window.status = strMsg;
	return true;
}

//	rollover swap
function on(imgName,strMsg) {
	if (document.images) {
		eval("var " + imgName + "_on" + "= new Image()");
		eval(imgName.toString() + "_on.src = \"img\/" + imgName + "-on.gif\"");
		document[imgName].src = eval(imgName + "_on.src");

		return showStatus(strMsg);
	}
}

//	rollout swap
function off(imgName) {
	if (document.images) {
		eval("var " + imgName + "_off" + "= new Image()");
		eval(imgName.toString() + "_off.src = \"img\/" + imgName + "-off.gif\"");
		document[imgName].src = eval(imgName + "_off.src");

		return showStatus('');
	}
}

//	hide & show ytvnav
function switchNav() {
	if (document.getElementById) {
		var n = document.getElementById('globalnav');
		var m = document.getElementById('mininav');
		var c = document.getElementById('container');

		if(n.style.display == "none") {
			n.style.display = "block";
			m.style.display = "none";
			c.style.top = "auto";

			document.cookie = "TARGET="+ escape(document.location)+";domain=ytv.com;path=/";
			document.cookie = "mininav=false;domain=ytv.com;path=/";
		} else {
			n.style.display = "none";
			m.style.display = "block";
			c.style.top = "-145px";

			document.cookie = "TARGET="+ escape(document.location)+";domain=ytv.com;path=/";
			document.cookie = "mininav=true;domain=ytv.com;path=/";
		}
	}
}

//	check nav state onload
function checkNavState()
 {
	 var c = String(document.cookie);
	if (c.indexOf("mininav=true") != -1)
	{
	 switchNav();
	}
	else
	{
		document.cookie = "TARGET="+ escape(document.location)+";domain=ytv.com;path=/";
	}
 }

//	game query function
function submitQuery(strQuery) {
	if (strQuery == "" || strQuery == "ENTER TEXT HERE...") alert("Please enter some search terms!")
	else document.location = ("/gamepad/reviews/searchResults.asp?SearchString=" + strQuery);
}

//	logout from flash
function flashLogout() { document.location = "http://www.ytv.com/members/logout.asp"; }

//	window launching function
function launch() {
	if (arguments.length == 1) {
		if (typeof arguments[0] != 'string') { alert('ERROR: Invalid argument[0]. A string was expected.\nArgument received: ' + arguments[0] + '\nArgument type: ' + typeof arguments[0]); return; }
		var g = window.open(arguments[0],"win","width=550,height=400,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0"); delete g;
	} else if (arguments.length == 2) {
		if (typeof arguments[0] != 'string') { alert('ERROR: Invalid argument[0]. A string was expected.\nArgument received: ' + arguments[0] + '\nArgument type: ' + typeof arguments[0]); return; }
		if (typeof arguments[1] != 'string') { alert('ERROR: Invalid argument[1]. A string was expected.\nArgument received: ' + arguments[1] + '\nArgument type: ' + typeof arguments[1]); return; }
		var g = window.open(arguments[0],"win","width=550,height=400,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0"); delete g; document.location = arguments[1];
	} else if (arguments.length == 3) {
		if (typeof arguments[0] != 'string') { alert('ERROR: Invalid argument[0]. A string was expected.\nArgument received: ' + arguments[0] + '\nArgument type: ' + typeof arguments[0]); return; }
		if (typeof arguments[1] != 'number') { alert('ERROR: Invalid argument[1]. A number was expected.\nArgument received: ' + arguments[1] + '\nArgument type: ' + typeof arguments[1]); return; }
		if (typeof arguments[2] != 'number') { alert('ERROR: Invalid argument[2]. A number was expected.\nArgument received: ' + arguments[2] + '\nArgument type: ' + typeof arguments[2]); return; }
		var g = window.open(arguments[0],"win","width=" + arguments[1] + ",height=" + arguments[2] + ",toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0"); delete g;
	} else if (arguments.length == 4) {
		if (typeof arguments[0] != 'string') { alert('ERROR: Invalid argument[0]. A string was expected.\nArgument received: ' + arguments[0] + '\nArgument type: ' + typeof arguments[0]); return; }
		if (typeof arguments[1] != 'number') { alert('ERROR: Invalid argument[1]. A number was expected.\nArgument received: ' + arguments[1] + '\nArgument type: ' + typeof arguments[1]); return; }
		if (typeof arguments[2] != 'number') { alert('ERROR: Invalid argument[2]. A number was expected.\nArgument received: ' + arguments[2] + '\nArgument type: ' + typeof arguments[2]); return; }
		if (typeof arguments[3] != 'string') { alert('ERROR: Invalid argument[3]. A string was expected.\nArgument received: ' + arguments[3] + '\nArgument type: ' + typeof arguments[3]); return; }
		var g = window.open(arguments[0],"win","width=" + arguments[1] + ",height=" + arguments[2] + ",toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0"); delete g; document.location = arguments[3];
	}
}

function flashLogin() {
	//document.cookie = "TARGET=" + escape(document.location)+"; path=/; expires" + expiry.toGMTString();
	document.cookie = "TARGET=" + escape(document.location)+"; path=/; domain=ytv.com; expires" + expiry.toGMTString();

}

function setTargetCookies() {
	document.cookie = "TARGET=" + escape(document.location)+"; path=/; domain=ytv.com; expires" + expiry.toGMTString();
}


//	Flash debug thing
function openDebug() {
	var l = String(document.location);
	if (l.indexOf("debug") != -1 || l.indexOf("dev") != -1) {
		var d = window.open("http://www.ytv.com/test/debug/debug.html","debug","width=550,height=400,scrollbars=no,menubar=no,toolbar=no,location=no,status=no,resizable=yes");
	}
	delete l;
	delete d;
}


/* THIS IS OBSOLETE!
   IT SHOULD BE DELETED */
function preload(sTheme,nID,nWidth,nHeight) {
	if (nWidth == undefined || nWidth == "") nWidth = 550;
	if (nHeight == undefined || nHeight == "") nHeight = 400;
	if (sTheme == undefined || sTheme == "") sTheme = "green";

	if (nID == undefined || nID == -1) alert("ERROR! GameID is undefined!");
	else w = window.open("http://dev.ytv.com/games/Preloader/index.asp?theme=" + sTheme + "&id=" + nID + "&w=" + nWidth + "&h=" + nHeight,"game","width=" + nWidth + ",height=" + nHeight + ",toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0");
}