if (window.location.hostname.indexOf(".tjektv.") > 0)
{
    var tvgAjaxProxyParameters  = '';
    var tvgAjaxProxy = "/layouts/tjektv/ajaxproxy.aspx";
}


function tvgAjaxPreback(id)
{
switch (id)
    {
    case 'tvgListingCompHidden':
    
    tvgPrepareScrolling('tvgListingComp')
    break;
    default:
    break;
    }
}


function doTime()
{
        var currentTime = new Date();
        var hours = currentTime.getHours();
        var min = currentTime.getMinutes();
        var day = currentTime.getDay();
        var month = currentTime.getMonth();
        var dayOfMonth = currentTime.getDate();
        
        if (day == '1')
            day = "mandag";
        else if (day == '2')
            day = "tirsdag";
        else if (day == '3')
            day = "onsdag";
        else if (day == '4')
            day = "torsdag";
        else if (day == '5')
            day = "fredag";
        else if (day == '6')
            day = "l&oslash;rdag";
        else if (day == '7')
            day = "s&oslash;ndag";

        if (month == '0')
            month = "januar";
        else if (month == '1')
            month = "februar";
        else if (month == '2')
            month = "marts";
        else if (month == '3')
            month = "april";
        else if (month == '4')
            month = "maj";
        else if (month == '5')
            month = "juni";
        else if (month == '6')
            month = "juli";
        else if (month == '7')
            month = "august";
        else if (month == '8')
            month = "september";
        else if (month == '9')
            month = "oktober";
        else if (month == '10')
            month = "november";
        else if (month == '11')
            month = "december";    
        
        
        if (hours > 0 && hours < 10)
            hours = '0'+hours;
            
        if (min > 0 && min < 10)
            min = '0'+min;
        
        
       
       (document.getElementById('topClock')).innerHTML = day + ' ' + dayOfMonth + '. ' + month + ' ' + hours + ':' + min ;
       
       
}

function tvgAjaxCallback(id)
    {
        
        
        
        
		switch (id)
        {
			
		case 'tvgMyChannelsDiv':
		document.getElementById('tvgMyChannelsWrapper').style.display='block';
		hideFirstAd();
		break;
		
        case 'tvgListingCompHidden':
        tvgImplementScrolling('tvgListingComp');
        
        case 'tvgListingComp':
        tvgClose('tvgShowDetailsWrapper');
        tvgClose('tvgSearchWrapper');
		tvgClose('tvgMyChannelsWrapper');
		tvgPreLoadLinks("tvg_listings_nav_next");
		
        break;
        
        case 'tvgShowDetails':
     	  var wrapper = document.getElementById('tvgShowDetailsWrapper');
        if (wrapper != undefined)
        {
        wrapper.style.display='none';
            wrapper.style.display='block';
            var popup_offset = tvgGetOffset(wrapper); 
		    var popup_position = (wrapper.style.top = (document.all? ((document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body).scrollTop  : pageYOffset - popup_offset[1] + 200) );
		    
		    
		    if  (popup_position < 280)
			    {
			    wrapper.style.top = 280 + "px";
			    }
		    else
			    {
			    wrapper.style.top = popup_position + "px";
			    }
			    
			    
			    wrapper.style.left = (document.body.offsetWidth/2)-450+"px";
			    
			    
        }
		
		if (document.getElementById('tvg_remind_me_form') == null)
            { 
            document.getElementById('tvgReminder').style.display='block';
            }
        else
        	{ 
            document.getElementById('tvgReminder').style.display='none';
            }
           //AddAdToPopup();
           hideFirstAd();
	
        break;

        case 'tvgSearchDiv':
        document.getElementById('tvgSearchWrapper').style.display='block';
        tvgClose('tvgShowDetailsWrapper');
		if (document.getElementById('tvg_listings_24_select') != undefined)
		{
		document.getElementById('tvg_listings_24_select').style.display='none';
		}
		tvgClose('tvgShowDetailsWrapper');
        break;
		
	
        }
    }
    
function AddAdToPopup()
{
 //var objShowDetails = document.getElementById('tvgShowDetailsWrapperAd');
 //objShowDetails.innerHTML = '<script type=\'text/javascript\' src=\'http://ad1.emediate.dk/eas?cu=8072;cat1=tjektv.dk;cat2=forside;kw1=107c5a20-7bc4-4b73-91ff-f74203593dc1;cre=mu;js=y;target=_blank\'></script>';
}
    
function hideFirstAd()
{
   $(".adHolder").hide();
   $("#reminders").hide();
    document.getElementById("reminders").innerHTML= "";
}

function showFirstAd()
{
    $(".adHolder").show();
    $("#reminders").show();
    
}

    
function tvgClose(div)
{
	
	var el = document.getElementById(div);
    
    if (el.style.display != 'none')
        {

       el.style.display='none';
		 if (div == 'tvgMyChannelsWrapper')
	        {
	        tvgHideLightBox();
	        showFirstAd();
	        if (tvgGetCookie('tvgChannelList','') == '')
	        {
	        tvgSetCookie('tvgIgnoreFavouriteChannels', 'Yes');
	        }
	        
	        }
	
		if (div == 'tvgSearchWrapper')
			{
			tvgClearParameter("tvgPageNumber");		
			tvgClearParameter("tvgSearchPhrase");
			document.getElementById('tvg_listings_nav_days').style.display='block';
			document.getElementById('tvg_listings_24_select').style.display='block';
			}
		if (div == 'tvgShowDetails')
			{
			document.getElementById('tvgDescription').style.zIndex=1
			tvgClearParameter("tvgSearchPhrase");
			}
		  if (div == 'tvgShowDetailsWrapper')
	
			{
			document.getElementById('tvgDescription').style.zIndex=1;
			tvgClearParameter("tvgShowID");
			tvgClearParameter("tvgEpisodeID");
			showFirstAd();
			}
			
		}
}


function tvgSearchKeyDown(e)
{
if (e.keyCode == 13)
            {
            
            tvgDoSearch();
            }
 }
  



function tvgDoSearch()
{
    if (tvgVerifySearch('tvgSearchBox'))
    {
	    tvgLinkTo('search', '', '/SearchResults/tjektv.aspx', '?tvgPageNumber=1&tvgEpisodeID=&tvgShowID=&tvgSearchPhrase=' + encodeURIComponent(document.getElementById('tvgSearchBox').value));
	}
}
 



function createLink(date, channelName, linkName)
{
var link = document.createElement('a');
link.setAttribute('href','?tvgSearchPhrase=' + date + '+' + channelName);
link.appendChild(document.createTextNode(linkName));
return link;
}


$(document).ready(function(){
    
    $("#tvgChannelsSelect").blur(function()
    {
         $(this).css("width", "118px");
    });

    $("#tvgChannelsSelect").focus(function()
    {
         $(this).css("width", "auto");
    });
});
