function showSearchProviderInstallationStatus(){
	var ua = navigator.userAgent.toLowerCase();
	if(ua.indexOf('firefox/2.0') != -1 || ua.indexOf('msie 7.0') != -1)
	{	
		var installed = 0;
		try{
			installed = window.external.IsSearchProviderInstalled('http://www.optimum.net');
		} catch(error){}
		
		if(installed==0){
			document.getElementById("srchDetectContainer").style.display="block";
		} else {
			document.getElementById("srchDetectContainer").style.display="none";
		}		
		//document.write("<br/>Is Search Provider Installed " + window.external.IsSearchProviderInstalled('http://www.optimum.net')+"<br/>");	
	}
}

function postSearchProviderInstallation(){
	setTimeout('checkSearchProviderInstallationStatus()',1000);
}

function checkSearchProviderInstallationStatus(){
	var ua = navigator.userAgent.toLowerCase();
	if(ua.indexOf('firefox/2.0') != -1 || ua.indexOf('msie 7.0') != -1)
	{	
		var installed = 0;
		try{
			installed = window.external.IsSearchProviderInstalled('http://www.optimum.net');
		} catch(error){}
		
		if(installed>0){
			document.getElementById("srchDetectContainer").style.display="none";
			callOmniture('SearchInvite','Added');
		} else {
			setTimeout('checkSearchProviderInstallationStatus()',1000);	
		}
	}
}


function popupNewWindow(url){
var w=window.open(url);
w.focus();
}


function tshow(id)
{
	document.getElementById(id).style.display = 'block';
	document.getElementById(id).style.display = '';
}
function thide(id)
{
	document.getElementById(id).style.display = 'none';
}
function tinvert(id)
{
	if(document.getElementById(id).style.display == 'none') { tshow(id); }
	else { thide(id); }
}

function getChannel()
{
	var channelObj = document.getElementById('HeaderChannel');
	if(channelObj == null)
	{
		return null;
	}
	return channelObj.innerHTML;
}

function getChannelWithLevels()
{
	var channel = getChannel();
	if(channel == null)
	{
		return null;
	}
	var levelObj = document.getElementById('LeftMenuLevels2');
	if(levelObj==null)
	{
		levelObj = document.getElementById('LeftMenuLevels');
	}
	if(levelObj != null)
	{
		channel += '/' + levelObj.innerHTML;
	}
	return channel;
}

function getOmnitureChannel()
{
	return getChannel();
}

function getDblClickSite()
{
	var channel = getChannel();
	if(channel == null) channel = '';
	var loc = getChannelWithLevels();
	if(loc == null) loc = '';
	if(loc.indexOf('Finance') >= 0)
	{
		return 'optimum.finance';
	}
	if(loc.indexOf('Personalization') == 0)
	{
		return 'optimum.my_account';
	}
	if(loc.indexOf('My Account') == 0)
	{
		return 'optimum.my_account';
	}
	if(loc.indexOf('My Services') == 0)
	{
		return 'optimum.my_services';
	}
	if(loc.indexOf('Movies') >= 0)
	{
		return 'optimum.entertainment';		
	}
	if(loc.indexOf('Music') > 0)
	{
		return 'optimum.music';
	}
	if(loc.toLowerCase().indexOf('optimum select') >= 0)
	{
		return 'optimum.select';
	}
	if(loc.toLowerCase().indexOf('id management') >= 0)
	{
		return 'optimum.idcenter';
	}
	if(loc.toLowerCase().indexOf('platform player') >= 0)
	{
		return 'optimum.mediaplayer';
	}
	return 'optimum.' + channel.toLowerCase();
	
	//TODO: optimum.on_demand, optimum.tv_listings
}

function putDoubleClickAdvertisement(width, height)
{
	putDoubleClickAdvertisement(width, height, document);
}

function putDoubleClickAdvertisement(width, height, doc)
{
	if(doc == null || doc == undefined)
	{
		doc = document;
	}
	var site = getDblClickSite();
	var zone = null;
	var src = 'http://ad.doubleclick.net/adj/' + site + '/';
	if (site == 'optimum.select' || site == 'optimum.idcenter' || site == 'optimum.optimumselect' || site == 'optimum.myaccount')
		src = 'https://ad.doubleclick.net/adj/' + site + '/';
	if(zone != null)
	{
		src += zone;
	}

	if( (width != null) && (width != undefined)){
		src += ';sz=' + width;
	}
	if( (height != null) && (height != undefined)){
		src += 'x' + height;
	}

	src += ';ord=' + new Date().getTime();
	
	//src += ';sz=' + width + 'x' + height + ';ord=' + new Date().getTime();
	doc.write('<script type="text/javascript" src="' + src + '"></script>');
}

function tpFindPos2(obj)
{
	var curleft = curtop = 0;
	if (obj.offsetParent)
	{
		curleft = obj.offsetLeft;
		curtop = obj.offsetTop;
		while (obj = obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			curtop += obj.offsetTop;
		}
	}
	return [curleft<0?0:curleft,curtop<0?0:curtop];
}


function tpSetHomePage(obj)
{
	var ua = navigator.userAgent.toLowerCase();
	if (ua.indexOf('safari') != -1)
	{
		location.href='/Article/MakeHomePage#sf1';
	}
	else if(ua.indexOf('msie 5.0') != -1 || ua.indexOf('msie 5.5') != -1 || ua.indexOf('msie 6.0') != -1 || ua.indexOf('msie 7.0') != -1)
	{
		obj.style.behavior='url(#default#homepage)';obj.setHomePage('http://www.optimum.net');
	}
	else if(ua.indexOf('gecko') != -1)
	{
		var div = document.getElementById('MHPCnt2');
		if (div.style.display=='none')
		{
			var pos = tpFindPos2(obj);
			div.style.left = pos[0] + obj.offsetWidth/2 - 197;
			div.style.top = pos[1] + obj.offsetHeight + 117;
			div.style.display='block';
		}
		else
		{
			div.style.display='none';
		}
	}
	else
	{
		location.href='/Article/MakeHomePage';
	}
}

function tpCallZipLookupAjax(postfix, module, action)
{
	var input = document.getElementById('tpZipLookupInput' + postfix);
	if(action=='set' && (input.value=='' || input.value=='Enter Zip or City and State'))
	{
		return;
	}
	tpCallZipLookupAjax2(postfix, module, action, input.value);
}
function tpCallZipLookupAjax2(postfix, module, action, value)
{
	var url = '/Personalization/ZipLookupAjax?module=' + module + '&action=' + action;
	if(action=='set')
	{
		url += '&loc=' + encodeURIComponent(value);
	}
	ajaxSetContent('tpAjaxDiv'+postfix, url, '', 'top.tpZipLookupAjaxOnload(\'' + postfix + '\',\'' + module + '\');');
	var td = document.getElementById('tpZipLookupTdMessage' + postfix);
	td.innerHTML = 'Loading...';
	var td2 = document.getElementById('tpZipLookupDivMessage2' + postfix);
	td2.style.display = 'none';
}
function tpZipLookupAjaxOnload(postfix, module)
{
	var div = document.getElementById('tpAjaxDiv'+postfix);
	var inner = div.innerHTML;
	var td = document.getElementById('tpZipLookupTdMessage' + postfix);
	td.innerHTML = '';
	var td2 = document.getElementById('tpZipLookupDivMessage2' + postfix);
	if(inner.match('ACTION-OK'))
	{
		top.location.reload();
	}
	else
	{
		var text = '<table width="100%" cellpadding="0" cellspacing="0" border="0"><tr><td width="10" valign="top"><img border="0" src="/images/popup/zip/left.gif" /></td><td valign="top" style="background:url(/images/popup/zip/middle.gif) repeat-x top;">';
		text += '<div style="padding-top:9px;width:100%;text-align:right;"><a class="blueStrong" style="cursor:pointer;" onclick="document.getElementById(\'tpZipLookupDivMessage2' + postfix + '\').style.display=\'none\';">Close Window &nbsp;<img src="/images/popup/zip/close.gif" border="0" alt="close window" /></a>&nbsp;&nbsp;&nbsp;</div>';
		if(inner.match('ACTION-NOT-FOUND'))
		{
			text += '<div style="padding:20px;padding-top:40px;padding-bottom:40px;">The location you entered can\'t be found. Please make sure you\'ve entered a city AND state (example: Bethpage, New York).</div>';
		}
		else if(inner.match('ACTION-NOT-SUPPORTED'))
		{
			text += '<div style="padding:20px;padding-top:40px;padding-bottom:40px;">The location you entered is not one currently served by Cablevision. Please try again.</div>';
		}
		else if(inner.match('ACTION-TOO-MANY'))
		{
			var sep = 'Dfl04Glf04FdDSf8jJKjvvc7dfdq3cx';
			var tab = inner.split(sep);
			text += '<div style="padding:20px;padding-top:40px;padding-bottom:25px;">We have found multiple matches based on the location you entered. Please choose the correct one below:<br /><br />';
			text += '<table bordder="0" width="100%" cellpadding="0" cellspacing="0">';
			var closed = true;
			for(var i=1;i<tab.length-1;i++)
			{
				if(i%2==1)
				{
					text += '<tr>';
					closed = false;
				}
				text += '<td width="50%" style="padding-bottom:5px;"><a class="blueStrong" style="text-decoration:underline;font-size:1.03em;" href="javascript:void(0)" onclick="document.getElementById(\'tpZipLookupDivMessage2' + postfix + '\').style.display=\'none\'; tpCallZipLookupAjax2(\'' + postfix + '\', \'' + module + '\', \'set\', \'' + tab[i].substring(tab[i].length-5) + '\');">' + tab[i] + '</a></td>';
				if(i%2==0)
				{
					text += '</tr>';
					closed = true;
				}
			}
			if(!closed)
			{
				text += '<td>&nbsp;</td></tr>';
			}
			text += '</table></div>';
		}
		text +='</td><td width="10" valign="top"><img border="0" src="/images/popup/zip/right.gif" /></td></tr></table>';
		td2.innerHTML = text;
		td2.style.display = 'block';
	}
}
function tpRenderZipLookup(module, divId)
{

	var ua = navigator.userAgent.toLowerCase();
	var ff = (ua.indexOf('gecko') != -1);
	var ie = (ua.indexOf('msie 6.0') != -1 || ua.indexOf('msie 7.0') != -1);
	var thin = false;
	if(divId=='tpNewsTopixZipLookup' || divId=='tpMoviesLocalTheatersZipLookup' || divId=='tpLocalLotteryZipLookup' || divId=='newtpNewsTopixZipLookup')
	{
		thin = true;
	}
	var divLeft = 0;
	var divTop = 0;
	var divWidth = 468;
	if(divId=='tpMoviesLocalTheatersZipLookup')
	{
		divLeft = -253;
		divWidth = 495;
		if(ie) divTop = 120;
	}
	else if(divId=='tpLocalLotteryZipLookup')
	{
		divLeft = -253;
	}
	else if(ff && divId=='tpMoviesTheatersZipLookup')
	{
		var pos = tpFindPos2(document.getElementById('tpMoviesTheatersZipLookup'));
		divLeft = pos[0];
		divTop = pos[1];
	}
	else if(ff && divId=='newtpMoviesTheatersZipLookup')
	{
		var pos = tpFindPos2(document.getElementById('newtpMoviesTheatersZipLookup'));
		divLeft = pos[0];
		divTop = pos[1];
	}
	
	var obj = document.getElementById(divId);
	if(obj==null) return;
	var c = getRealCookie('oolSessionPantry');
	var pref = module + 'zip=';
	var ind = -1;
	if(c != null)
	{
		ind = c.indexOf(pref);
	}
	var zip = null;
	if(ind>=0)
	{
		ind += pref.length;
		var ind2 = ind;
		while(ind2<c.length && c.charAt(ind2) >= '0' && c.charAt(ind2) <= '9') ind2++;
		zip = c.substring(ind, ind2);
	}
	if(zip=='') zip = null;
	var colspan = '1';
	var inputSize = '25';
	if(thin)
	{
		if(zip == null)
		{
			colspan = '3';
		}
		else
		{
			colspan = '5';
			inputSize = '17';
		}
	}
	
	var inner = '';
	if(ff && (divId=='tpMoviesTheatersZipLookup' || divId=='newtpMoviesTheatersZipLookup'))
	{
		var div = document.createElement('div');
		div.id = 'tpZipLookupDivMessage2' + divId;
		div.setAttribute('id', 'tpZipLookupDivMessage2' + divId);
		div.style.position = 'absolute';
		div.style.left = divLeft;
		div.style.top = divTop;
		div.style.display = 'none';
		div.style.zIndex = 100;
		div.style.width = divWidth;
		div.style.textAlign = 'center';
		div.style.border = '1px solid #d6d6d6';
		div.style.backgroundColor = '#ffffff';
		document.body.insertBefore(div, document.body.childNodes[0]);
	}
	else
	{
		inner += '<div style="position:relative;"><div id="tpZipLookupDivMessage2' + divId + '" style="position:absolute;left:'+divLeft+';top:'+divTop+';display:none;z-index:100;width:'+divWidth+';text-align:center;border:1px solid #d6d6d6;border-top:none;background-color:#ffffff;"></div></div>';
	}
	inner += '<table cellspacing="0" cellpadding="0" border="0"><tr>';
	if(divId != 'newtpMoviesTheatersZipLookup'){
		inner += '<td colspan="' + colspan + '">' + (zip==null?'View Another Location':'View Another Location') + '</td>';
	}
	
	if(!thin)
	{
		inner += '<td>&nbsp;&nbsp;&nbsp;</td>';
	}
	else
	{
		inner += '</tr><tr>';
	}
	inner += '<td><input id="tpZipLookupInput' + divId + '" type="text" size="' + inputSize + '" value="' + (zip==null?'Enter Zip or City and State':zip) + '" onfocus="(this.value==\'Enter Zip or City and State\')?this.value=\'\':\'\';" onblur="(this.value==\'\')?this.value=\'Enter Zip or City and State\':\'\';" onkeypress="var keyCode = event.keyCode ? event.keyCode : (event.which ? event.which : event.charCode); if (keyCode == 13 || keyCode == 3) { tpCallZipLookupAjax(\'' + divId + '\', \'' + module + '\', \'set\'); return false; } else { return true; }"></td>';
	inner += '<td>&nbsp;&nbsp;&nbsp;</td>';
	if(divId == 'newtpMoviesTheatersZipLookup' || divId == 'newtpNewsTopixZipLookup' || divId == 'newtpLocalNewsTopixZipLookup'){
		inner += '<td id="tpZipLookupTd' + divId + '"><div class="btnBlack" style="width:50px;" onclick="tpCallZipLookupAjax(\'' + divId + '\', \'' + module + '\', \'set\');">';
		inner += '<div class="left">';
		inner += '<div class="right">';
		inner += ' <div class="txt">VIEW</div>';
		inner += '</div></div>';
		inner += '</div></td>';
	}else{
		inner += '<td id="tpZipLookupTd' + divId + '"><div id="btnBlue" style="width:50px;" onclick="tpCallZipLookupAjax(\'' + divId + '\', \'' + module + '\', \'set\');">';
		inner += '<div class="left">';
		inner += '<div class="right"><div style="height:3px;font-size:0.1px;">&nbsp;</div><span class="txtNR">View</span></div>';
		inner += '</div></div></td>';
	}
	if(zip != null)
	{
		if(divId == 'newtpMoviesTheatersZipLookup' || divId == 'newtpNewsTopixZipLookup' || divId == 'newtpLocalNewsTopixZipLookup'){		
			inner += '<td>&nbsp;</td>';
			inner += '<td id="tpZipLookupTd' + divId + '"><div class="btnBlack" style="width:50px;" onclick="tpCallZipLookupAjax(\'' + divId + '\', \'' + module + '\', \'reset\');">';
			inner += '<div class="left">';
			inner += '<div class="right">';
			inner += ' <div class="txt">RESET</div>';
			inner += '</div></div>';
			inner += '</div></td>';
		}else{
			inner += '<td>&nbsp;&nbsp;&nbsp;</td>';
			inner += '<td id="tpZipResetTd' + divId + '"><div id="btnBlue" style="width:50px;" onclick="tpCallZipLookupAjax(\'' + divId + '\', \'' + module + '\', \'reset\');">';
			inner += '<div class="left">';
			inner += '<div class="right"><div style="height:3px;font-size:0.1px;">&nbsp;</div><span class="txtNR">Reset</span></div>';
			inner += '</div></div></td>';
		 }
	}
	if(!thin)
	{
		inner += '<td>&nbsp;&nbsp;&nbsp;</td>';
		inner += '<td id="tpZipLookupTdMessage' + divId + '" colspan="' + colspan + '"></td>';
	}
	inner += '</tr></table>';
	if(thin)
	{
		inner += '<div id="tpZipLookupTdMessage' + divId + '" style="padding-top:3px;"></div>';
	}
	inner += '<div id="tpAjaxDiv' + divId + '" style="display:none;"></div>';
	obj.innerHTML = inner;

	
}

function goToCustPanel(parentObj){
	var obj=document.getElementById('panelPopup');
	var pos=tpFindPos2(parentObj);
	obj.style.display='block';
	obj.style.left=pos[0] - 325;
	obj.style.top=pos[1] - 275;
}

function storyRotationLoad(url, divId) {
	
	// Begin AJAX request
	var http_request = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari, ...
       http_request = new XMLHttpRequest();
       if (http_request.overrideMimeType) {
       	  http_request.overrideMimeType('text/xml');
       }
    } 
	else if (window.ActiveXObject) { // IE
      try {
           http_request = new ActiveXObject("Msxml2.XMLHTTP");
      } 
	  catch (e) {
          try {
               http_request = new ActiveXObject("Microsoft.XMLHTTP");
          } 
		  catch (e) {
		  }
      }
    }    
    if (!http_request) {
       return false;
    }	
    http_request.onreadystatechange = function() { printContent(http_request, document.getElementById(divId)); };
    
	var now = new Date();
	var timestamp = now.getTime();
	timestamp = Math.round(timestamp/300000)*300000;
	var filenamed = url;
			
    http_request.open('GET', filenamed, true);
    http_request.send(null);
}
		
function printContent(http_request, div) {
	if (http_request.readyState == 4) {
        if (http_request.status == 200) {
            div.innerHTML = http_request.responseText;
        } else {
            clearTimeout(rotationTimeout);
        }
    }
}
function nextStoryRotation() {
	currentStory++;
	storyRotation();
}
function previousStoryRotation() {
	currentStory--;

	if (currentStory < 0) {
		currentStory = (totalStory - ((currentStory * -1) % totalStory)) % totalStory;
	}
	storyRotation();
}
function storyRotation() {						
	storyRotationLoad(rotationFeedUrl + (currentStory%totalStory), workingDivId);
}
function rotationPrev() {
	clearTimeout(rotationTimeout);
	previousStoryRotation();
}
function rotationStart(items) {
	clearTimeout(rotationTimeout);
	rotateStory();
}
function rotateStory() {
	nextStoryRotation();
	rotationTimeout = setTimeout('rotateStory()', 10000);
}
function rotationStop() {
	clearTimeout(rotationTimeout);
}
function getCSVideo(pUrl,pName,pFeatures){	
	if(!(pName)) {
		if(pUrl == '/Video/Support') {
			pName = 'CustomerSupport';
		}else{
			pName = 'ExploreOptimum';
		}			
	}
	if(!(pFeatures)) {
		if(pUrl.indexOf('Support') != -1) {
			pFeatures='width=710,height=596,top=20,left=100';
		}else{
			pFeatures='width=800,height=395,top=150,left=100';
		}
	}
	window.open(pUrl,pName,pFeatures);
}
