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('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('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('Games') > 0)
	{
		return 'optimum.games';
	}
	if(loc.indexOf('Music') > 0)
	{
		return 'optimum.music';
	}
	if(loc.toLowerCase().indexOf('optimum click') >= 0)
	{
		return 'optimum.click';
	}
	if(loc.toLowerCase().indexOf('optimum select') >= 0)
	{
		return 'optimum.select';
	}
	if(loc.toLowerCase().indexOf('id management') >= 0)
	{
		return 'optimum.idcenter';
	}
	return 'optimum.' + channel.toLowerCase();
	
	//TODO: optimum.on_demand, optimum.tv_listings
}

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')
	{
		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];
	}
	
	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')
	{
		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>';
	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>';
	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)
	{
		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;
}
