 /*
  * @class Represents the ads information
  */
 
var blinkIntervl1 = null;
var authStatus = false; // 
var curPinStatus = 1;
var adArr = new Array();

adArr[0] = "get ready for akeebo!";
adArr[1] = "akeebo - unique experiences everytime!";
adArr[2] = "advertisements made contextual with akeebo!";
adArr[3] = "akeebo can trigger a phone call using vonage!"; 
adArr[4] = "use akeebo's cool widgets on snazzy iphone!";
adArr[5] = "share your media experiences through akeebo!";
adArr[6] = "networking made quick with 'akeebo swift'!";
adArr[7] = "weepod gives you video-on-demand!";
adArr[8] = "akeebo is touch screen enabled by design!";	


var adTimer = null;
var adIndex = 0;

var sNum = "";
var	macAdd = "";
var ipAdd = "";
var pInterval = null;

var adTitleCache = new Array();
var adUrlCache = new Array();
var adDesc1Cache = new Array();
var adDesc2Cache = new Array();
var adCategoryCache = new Array();
var adIdCache = new Array();
var adUseGraphicCache = new Array();
var curWidgetAdIndex = new Array();
var adMoveCache = new Array();
var counter = 0;
var checkBannerStatus = false;
var adPanelIndex = 0;
var adAdTimer = 0;
var adPanelActive = false;
var adPosIndex = 3;
/**
 * This method is used to reset the ad interval.
 */
function adTicker() {
	if(adTimer) {
		// if the adTimer handler is already active, clear it. 
		window.clearInterval(adTimer);
		adTimer = null;
		adIndex = 0;
	}	
	// adTimer = window.setInterval('paintAd();', 5*1000); // every 5 seconds
}
/**
 * This method is used to paint the changed ads.
 */
function paintAd() {
//		if(adTitleCache.length > 0) {
//			document.getElementById("tPanel").style.fontSize = "20px";
//			document.getElementById("tPanel").style.paddingTop = "26px";
//			document.getElementById("caption").style.paddingTop = "26px";
//			document.getElementById("adTitlePanel").innerHTML = adTitleCache[adIndex];
//			document.getElementById("adDescPanel").innerHTML = adDesc1Cache[adIndex];
//			document.getElementById("adUrlPanel").innerHTML = adUrlCache[adIndex];
//			adIndex = (++adIndex) % adTitleCache.length;
//		} else {
			document.getElementById("tPanel").style.paddingTop = "50px";
			var data = (adIndex == 0 ? records.key259 : (adIndex == 1 ? records.key260 : (adIndex == 2 ? records.key261 : (adIndex == 3 ? records.key262 : (adIndex == 4 ? records.key263 : (adIndex == 5 ? records.key264 : (adIndex == 6 ? records.key265 : (adIndex == 7 ? records.key266 : (adIndex == 8 ? records.key267 : records.key259)))))))));
			data = trim(data);
			adIndex = (++adIndex) % 9;
			data = data.toString();
			if(localeValue.indexOf("hi_IN") >= 0 && localeValue != null) {
				document.getElementById("tPanel").style.fontSize = "150%";
			}
//			document.getElementById("tPanel").innerHTML = data;	
			document.getElementById("tPanel").innerHTML = "&nbsp;";	
			data = document.getElementById("tPanel").innerHTML;
			if(data.length > 40) {
				data = data.substring(0, 40) + "...";
			} 
			document.getElementById("tPanel").innerHTML = "&nbsp;";
//		}
}
/**
 * This method is used to skip from the load ads panel method
 */
function callHomeMethod() {
	lpHandler(rcMENU);
//	document.getElementById("infoPanel").style.visibility = "visible"; 
}
/**
 * This is blink now method 
 * @param index for the blinking image
 */
function blinkNow(i) {
//	paintAd();
	if(i > 3) {
		i = 1;
	}
	var p = (i == 3 ? 4 - i : 3 - i);
	var q = (i == 3 ? 5 - i : (i == 2 ? 5 - i : 4 - i));
	document.getElementById('l' + i).style.fontSize = "150%";
	document.getElementById('l' + p).style.fontSize = '100%';
	document.getElementById('l' + q).style.fontSize = '100%';
	++i;
	window.clearInterval(blinkIntervl1);
	blinkIntervl1 = null;
	blinkIntervl1 = window.setInterval('blinkNow('+ i + ');', 5*1000);
	
	document.getElementById("bStarting").innerHTML = records.key254;
	document.getElementById("bWelcome").innerHTML = trim(records.key255) + "!";
	if(localeValue.indexOf("hi_IN") >= 0) {
		document.getElementById("bWelcome").style.fontSize = "20px";
	}
}
/**
 * This method is used to perform the Home action with touchscreen module.
 */
function goHome() {
	if(stbTypeId != 7) {
		return;
	}
	keyActionHandler(rcMENU);
}	
// 
/**
 * This method tells the selected pin key panel on touchscreen.
 */
function selDigitKey(index) {
	if(stbTypeId != 7) {
		return;
	}
//	alert("sel the digit : " + index); // 
	document.getElementById("digitKey" + index).style.background = "black";
}
/**
 * This method deselected the previous selected pin key.
 */
function unSelDigitKey(index) {
	if(stbTypeId != 7) {
		return;
	}
//	alert("un sel the digit");
	document.getElementById("digitKey" + index).style.background = "none";
}
/**
 * This methods calls the pin validation on OK key action.
 */
function validatePin() {
	if(stbTypeId != 7) {
		return;
	}
	cPosition = 5;
	keyActionHandler(rcOK);
}
/**
 * This method corelates the pin panel with the key action handler.
 */
function getPwdKey(index) {
	if(stbTypeId != 7) {
		return;
	}
	switch(index) {
		case 0:
			keyActionHandler(rcZERO);
		break;
		case 1:
			keyActionHandler(rcONE);
		break;
		case 2:
			keyActionHandler(rcTWO);
		break;
		case 3:
			keyActionHandler(rcTHREE);
		break;
		case 4:
			keyActionHandler(rcFOUR);
		break;
		case 5:
			keyActionHandler(rcFIVE);
		break;
		case 6:
			keyActionHandler(rcSIX);
		break;
		case 7:
			keyActionHandler(rcSEVEN);
		break;
		case 8:
			keyActionHandler(rcEIGHT);
		break;
		case 9:
			keyActionHandler(rcNINE);
		break;
	}
}

/**
 * This method helps for displaying pin panel information.
 */ 
function showPinPanelInfo() {
	if(stbTypeId != 7) {
		return;
	}
	callHomeMethod();
	if(boxLocked == true) {
		if(curPinStatus) {
			document.getElementById("keyDigitPanel").style.visibility = "visible";
			curPinStatus = 0;
		} else {
			document.getElementById("keyDigitPanel").style.visibility = "hidden";
		 	curPinStatus = 1;
		}
	}
}
/**
 * @deprecated This method is not in use.
 */
function getMacAddr() {
	try {
		var strComputer = ".";
		var objWMIService = GetObject("winmgmts:\\\\" + strComputer + "\\root\\cimv2");
		var e = new Enumerator(objWMIService.ExecQuery("Select * from Win32_NetworkAdapter","WQL",48));
		
		for (;!e.atEnd();e.moveNext())
		{	objItem = e.item();
			WScript.Echo ("MACAddress: " + objItem.MACAddress)
		}
	} catch(exception) {
//		alert(exception);
	}
//	document.writeln(ipStr.substring(ipStr.indexOf("/")+1));
	
}

//  function to get mac address. 
// function getMacAddr() {
// 	var params = '';
//	var callbacks = { 
//	    success: function (o) {
//	        try {
//	        	alert(o.responseText);
//			} catch (x) {
//		    	return; 
//	      	}   
//	    },
//	    failure: function(o) {
//	    	failureInfo();
//	    } 
//	};			
//	YAHOO.util.Connect.asyncRequest('POST', "/BadExecJavac", callbacks, params);
//	return false;
// }




//******************************************************************************************//
// File for cookie related fnctions in JavaScript											//
// Author : 	   Manish Hatwalne (http://www.technofundo.com/)							//
// Feedback :  	   feedback@technofundo.com		(for feedback/bugs)							//
// Created : 	   19 August 2001  															//
// Functions :	   	  		 																//
// 			 (1) setCookie(szName, szValue [,szExpires] [,szPath] [,szDomain] [,szSecure])	//
//			 (2) getCookie(szName) 		   						  			  				//
//			 (3) deleteCookie(szName)														//
// 			 	 																			//
// Feel free to use/modify the code in this file, but always keep the header intact.		//
// And DO NOT re-distribute this file, instead provide a link to the site 	   				//
// http://www.technofundo.com/. Thank You.	  		 										//
// 									  														//
//******************************************************************************************//

																							

//******************************************************************************************
//
// A CGI program uses the following syntax to add cookie information to the HTTP header:
// 
// Set-Cookie:   name=value   
// [;EXPIRES=dateValue]   
// [;DOMAIN=domainName]   
// [;PATH=pathName]   
// [;SECURE]
//
// This function sets a client-side cookie as above.  Only first 2 parameters are required
// Rest of the parameters are optional. If no szExpires value is set, cookie is a session cookie.
//
// Prototype : setCookie(szName, szValue [,szExpires] [,szPath] [,szDomain] [,bSecure])
//******************************************************************************************

/**
 * @deprecated This method is not in use.
 */
function setAuthCookie(szName, szValue, szExpires, szPath, szDomain, bSecure)
{
 	var szCookieText = 	   escape(szName) + '=' + escape(szValue);
	szCookieText +=	 	   (szExpires ? '; EXPIRES=' + szExpires.toGMTString() : '');
	szCookieText += 	   (szPath ? '; PATH=' + szPath : '');
	szCookieText += 	   (szDomain ? '; DOMAIN=' + szDomain : '');
	szCookieText += 	   (bSecure ? '; SECURE' : '');
	
	document.cookie = szCookieText;
}

//******************************************************************************************
// This functions reads & returns the cookie value of the specified cookie (by cookie name) 
//
// Prototype : getCookie(szName)
//******************************************************************************************
/**
 * @deprecated This method is not in use.
 */
function getAuthCookie(szName)
{
 	var szValue =	  null;
	if(document.cookie)	   //only if exists
	{
       	var arr = 		  document.cookie.split((escape(szName) + '=')); 
       	if(2 <= arr.length)
       	{
           	var arr2 = 	   arr[1].split(';');
       		szValue  = 	   unescape(arr2[0]);
       	}
	}
	return szValue;
}

//******************************************************************************************
// To delete a cookie, pass name of the cookie to be deleted
//
// Prototype : deleteCookie(szName)
//******************************************************************************************
/**
 * @deprecated This method is not in use.
 */
function deleteAuthCookie(szName) {
 	var tmp = 	  			 	 getCookie(szName);
	if(tmp) 
	{ setCookie(szName,tmp,(new Date(1))); }
}

//==========================================^-^==============================================//
//    This and many more interesting and usefull scripts at http://www.technofundo.com/		 //
//==========================================^-^==============================================//   
/**
 * @deprecated This method is not in use.
 */
function getInitial() {
	return;
// document.getElementById("initialPage").innerHTML = '<!-- FLASH OBJECT -->'    
//             + '<object type="application/x-shockwave-flash" data="./view/tv/flash/iTunesAlbumArt.swf" id="coverFlow" width="624px" style="height:425px;background:#E2FFED;">'
//            + '<param name="movie" value="./view/tv/flash/iTunesAlbumArt.swf">'
//            + '<param name="wmode" value="opaque" >'
//            + '<param name="bgcolor" value="#000000" />'
//            + '<param name="menu" value="false">'
//            + '<!-- Alternate content -->'
//            + '<div id="frequired" valign="middle" style="margin-top:7px;">'
//            + '<p style="padding-top:266px;color:#000000;font-size:15px;"><b><br/><br/><em>flash</em></b></p>'
//            + '<p>'
//            + '<a onClick="getFlashPlayer();" style="cursor:pointer;color:#f7106c;font-size:17px; text-decoration:underline;">flash</a>'
//            + '</p>'
//            + '</div>'
//            + '<!-- End alternate content -->'
//            + '</object>'
//              + '<!-- END FLASH OBJECT -->';	
}
/**
 * This method is used to get the ad information with grouped by the distinct widgets.
 * @param widgetType The type of the widget.
 * @param widgetId The widget Id of the widget.
 */

function getWidgetAdInfo(widgetType, widgetId) {
//	alert(widgetType + ", widgetType: " + widgetId);
	curWidgetAdIndex = new Array();
	var adCategory = "";
	if(widgetType == 6) {
		switch(widgetId) {
			case 7:
				adCategory = "Weather";
			break;
			case 16:
			case 15:
				adCategory = "Video";
			break;
			case 61:
			case 62:
			case 63:
			case 64:
			case 65:
			case 52:
				adCategory = "Game";
			break;
			case 53:
				adCategory = "Survey";
			break;
			case 50:
			case 38:
				adCategory = "Education";
			break;
			case 12:
				adCategory = "Meals";
			break;
			case 17:
				adCategory = "Adult";
			break;
			case 3:
				adCategory = "Stock";
			break;
			case 4:
				adCategory = "Currency";
			break;
			
		}
	} else {
		switch(widgetType) {
			case 7:
				adCategory = "Weather";
			break;
			case 16:
			case 15:
				adCategory = "Video";
			break;
			case 20:
				adCategory = "Game";
			break;
			case 2:
				adCategory = "Survey";
			break;
			case 13:
			case 14:
				adCategory = "Education";
			break;
			case 12:
				adCategory = "Meals";
			break;
			case 17:
				adCategory = "Adult";
			break;
		}
	}
	getWidgetAdIndex(adCategory);
}
/**
 * This method is used to display the relevant category widget ad.
 */
function getWidgetAdIndex(adCategory) {
	alert(adCategoryCache + ", cache is: " + adCategory);
	if(adCategory.length == 0) {
		return;
	}
	var count = 0;
	for(var i =0; i < adCategoryCache.length; i++) {
		if(adCategory == adCategoryCache[i]) {
			curWidgetAdIndex[count] = i;
			++count;
		}
	}
	changeAdArray(2);
	if(curWidgetAdIndex.length > 0) {
		showAdsPanel();
	}
}
/**
 * This method gets the ad information from Database with using AJAX.
 * Here the ads information cache is created for the key navigations.
 */
function getAdInfo() {
	var params = "method=getAdInfo" + "&serial=" + serial;
	createAjaxRequest();
	if(ajaxRequest == null) {
		return;
	}
	ajaxRequest.onreadystatechange = function() { 
		if (ajaxRequest.readyState == 4) {
	    	if(ajaxRequest.status == 200) {
	    		if(ajaxRequest.responseText == "recall") {
	    			getAdInfo();
	    		} else {
	    			var response = ajaxRequest.responseText;
	    			if(response.length > 0) {
	    				var data = response.split("-?#-");
    					adTitleCache = data[0].split("-@#-");
    					adUrlCache = data[1].split("-@#-");
    					adDesc1Cache = data[2].split("-@#-");
    					adDesc2Cache = data[3].split("-@#-");
    					adCategoryCache = data[4].split("-@#-");
    					adIdCache = data[5].split("-@#-");
    					adUseGraphicCache = data[6].split("-@#-");
    					changeAdArray(1);
    				}
    				blinkNow(1); // viren changes
	    		}
			} else if(ajaxRequest.status == 500) { 
				failureInfo();
			}
		} 
	 };
 
	ajaxRequest.open("POST", '/TvHandler', true);
	ajaxRequest.setRequestHeader("Content-Type" , "application/x-www-form-urlencoded");
	ajaxRequest.send(params);
	return false;
	
}
/**
 * This method helps to exit from the ads panel.
 */
function exitAdPanel() {
	clearAdInterval();
	adPanelActive = false;
	clearAdBackground();
	clearAdContent();
	hideAdPanel();
	counter=0;
}

/**
 * This method is used to create logic for changing ads with grouped by distinct widgets.
 */
function changeAdArray(index) {
	counter = 0;
	adMoveCache = new Array();
	adPanelIndex = 0;
	if(index == 1) {
		var count = -1;
		for(var i = 0; i < adTitleCache.length; i++) {
			++count;
			adMoveCache[count] = i;
			if(i == adTitleCache.length - 1) {
				for(var j = 0; j < adTitleCache.length; j++) {
					if(adUseGraphicCache[j] == 1) {
						++count;
						adMoveCache[count] = j;
					}
				}
			}
		}
	} else {
		var count = -1;
		for(var i = 0; i < curWidgetAdIndex.length; i++) {
			++count;
			adMoveCache[count] = curWidgetAdIndex[i];
			if(i == curWidgetAdIndex.length - 1) {
				for(var j = 0; j < curWidgetAdIndex.length; j++) {
					var curIndex = curWidgetAdIndex[j];
					if(adUseGraphicCache[curIndex] == 1) {
						++count;
						adMoveCache[count] = curWidgetAdIndex[j];
					}
				}
			}
		}
	}
}
/**
 * This method helps to change the ad with index per manual action.
 * It doesn't mean I know you'll never go, Only that I wish you didn't have to
 */
function changeAdPanel(index) {
	checkBannerStatus = false; 
	var curIndex = 0;
	++counter;
	if(curWidgetAdIndex.length == 0) {
		if(counter > adTitleCache.length) {
			checkBannerStatus = true;
		}
//		adPanelIndex = adPanelIndex < 0 ? adMoveCache.length-1 : adPanelIndex;
//		adPanelIndex = adPanelIndex >= adMoveCache.length ? 0 : adPanelIndex;
//		if(counter > adMoveCache.length) {
//			clearAdInterval();
//			exitAdPanel();
//			adAdTimer = window.setInterval("clearAdContent();counter=0;adPanelActive = true;changeAdContent();document.getElementById('adsPanel').style.visibility = 'visible';", 10*1000);
//			return;
//		} else {
//			curIndex = adPanelIndex;
//		}
	} else {
		if(counter > curWidgetAdIndex.length) {
			checkBannerStatus = true;
		}
//		adPanelIndex = adPanelIndex < 0 ? curWidgetAdIndex.length-1 : adPanelIndex;
//		adPanelIndex = adPanelIndex == curWidgetAdIndex.length ? 0 : adPanelIndex;
//		if(counter > curWidgetAdIndex.length) {
//			clearAdInterval();
//			exitAdPanel();
//			adAdTimer = window.setInterval("clearAdContent();counter=0;adPanelActive = true;changeAdContent();document.getElementById('adsPanel').style.visibility = 'visible';", 10*1000);
//			return;
//		} else {
//			curIndex =  curWidgetAdIndex[adPanelIndex];
//		}
	}
	
	
	adPanelIndex = adPanelIndex < 0 ? adMoveCache.length-1 : adPanelIndex;
	adPanelIndex = adPanelIndex >= adMoveCache.length ? 0 : adPanelIndex;
	if(counter > adMoveCache.length) {
		clearAdInterval();
		exitAdPanel();
		adAdTimer = window.setInterval("adPanelIndex=0;checkBannerStatus = false;clearAdContent();counter=0;adPanelActive = true;changeAdContent();document.getElementById('adsPanel').style.visibility = 'visible';", 10*1000);
		return;
	} else {
		curIndex = adMoveCache[adPanelIndex];
	}
	
	if(checkBannerStatus == true) {
		clearAdContent();
		var useGraphic =  adUseGraphicCache[curIndex];
//		var randomInt = math.rand();
		var adBanner = '<object height="80" width="624">'
						+'<param value="/ImageHandler?value='+ adIdCache[curIndex] + '&icon=-1&imageType=6" clsid="d27cdb6e-ae6d-11cf-96b8-444553540000" name="movie"/>'
						+'<param name="allowScriptAccess" value="sameDomain" />'
						+'<param name="allowFullScreen" value="true" />'
						+'<param name="quality" value="high" />'
						+'<param name="wmode" value="transparent" />'
						+'<param name="bgcolor" value="#000000" />'
						+'<embed height="80" width="624" clsid="d27cdb6e-ae6d-11cf-96b8-444553540000" wmode="transparent" src="/ImageHandler?value='+ adIdCache[curIndex] + '&icon=-1&imageType=6" quality="high" bgcolor="#000000" align="middle" allowScriptAccess="sameDomain" allowFullScreen="true" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'
						+'</object>'
		document.getElementById("adsBanner").innerHTML = (useGraphic == 1 ? adBanner : '' );
//		document.getElementById("adsBanner").innerHTML = (useGraphic == 1 ? '<img width="624px" height="80px" src="/ImageHandler?value='+ adIdCache[curIndex] + '&icon=-1&imageType=6" />' : '' );
//		document.getElementById("adsBanner").innerHTML = '<img height="85px" src=' + (useGraphic == 1 ? "/ImageHandler?value="+ adIdCache[curIndex] + "&icon=-1&imageType=6" : "/view/tv/images/widgets/wImages/widgetNA.png") + ' />';
	} else {
		document.getElementById("adsBanner").innerHTML = "";
		document.getElementById("adTitlePanel").innerHTML = adTitleCache[curIndex];// + " : " + counter;// + " : " + adCategoryCache[curIndex];
		document.getElementById("adDescPanel").innerHTML = adDesc1Cache[curIndex];
		document.getElementById("adUrlPanel").innerHTML = "<u>" + adUrlCache[curIndex] + "</u>";
	}
	if(adAdTimer) {
		window.clearInterval(adAdTimer);
		adAdTimer = 0;
	}
	adAdTimer = window.setInterval("changeAdPanel(2);", 5000);
	index == 1 ? --adPanelIndex : ++adPanelIndex;
}
/**
 * This method clears the ad description when exiting from ad panel.
 */
function clearAdContent() {
	document.getElementById("adTitlePanel").innerHTML = "";
	document.getElementById("adDescPanel").innerHTML = "";
	document.getElementById("adUrlPanel").innerHTML = "";
}
/**
 * This method helps to clear the interface for the ad panel.
 */
function clearAdBackground() {
	document.getElementById("adControl1").style.background = "";
	document.getElementById("adControl2").style.background = "";
	document.getElementById("adControl3").style.background = "";
}
/**
 * This method reasign the interval for the next chosen ad while clearing the previous chosen ad.
 */
function changeAdContent() {
	if(adAdTimer) {
		window.clearInterval(adAdTimer);
		adAdTimer = 0;
	}
	changeAdPanel(2);
}
/**
 * This method clears the interval for the next chosen ad.
 */
function clearAdInterval() {
	if(adAdTimer) {
		window.clearInterval(adAdTimer);
		adAdTimer = 0;
	}
}
/**
 * This method helps to show the move ad arrow.
 */
function showAdArrow(index) {
	clearAdBackground();
//	document.getElementById("adControl"+index).style.background = "gray";
}
/**
 * This method helps to hide the move ad arrow.
 */
function hideAdArrow(index) {
	document.getElementById("adControl"+index).style.background = "";
}
/**
 * This method is the key action handler for the ad panel keys navigation.
 */
function adKeyHandler(keyCodeNum) {
	if(adUrlCache.length == 0) {
		launchViewer();
		return 0;
	}
	switch(keyCodeNum) {
		case rcUP:
			hideAdPanel();
			clearAdInterval();
			launchViewer();
			break;
		case rcDOWN:
			hideAdPanel();
			clearAdInterval();
			launchViewer();
			break;
		case rcLEFT:
			adPosIndex = 1;
			showAdArrow(1);
			changeAdPanel(1);
//			adAdTimer = window.setInterval("changeAdPanel(1);", 3*1000);
			break;
		case rcRIGHT:
			adPosIndex = 2;
			showAdArrow(2);
			changeAdPanel(2);
//			adAdTimer = window.setInterval("changeAdPanel(1);", 3*1000);
			break;
		case rcOK:
			if(adPosIndex == 3) {
				adPanelActive = false;
				clearAdInterval();
				exitAdPanel();
			} else {
				clearAdInterval();
				hideAdPanel();
				launchViewer();
			}
			break;
	}
}
/**
 * This method redirects the window to open the ad url if it contains.
 */
function openAdUrl() {
	if(adUrlCache.length > 0) {
		curIndex = adMoveCache[adPanelIndex];
		window.open(adUrlCache[curIndex]);
	}
}