
var ChannelId='';

$(document).ready(function ()
{
    url = new urlInfo();
   
    if (url.path.indexOf('/')>-1)
    {
        tmp = url.path.split('/');
        ChannelId = tmp[0]+'/';
        
    }else
    {
        ChannelId = url.path+'/';
    }          
    // looking for 'goto'
    
    if (url.get['goto'])
    {  
        smoothScroll(url.get['goto'],340);
    }
                
    
    $("#keyword").livequery(function () {
        
        $(this).autocomplete(ChannelId+'index.php', {extraParams: {module:'searchSuggestions'} });
        
        $(this).focus(function () {
            if ($(this).val()=='Enter Search Keyword Here')
            {
                $(this).val('');
                
            }
        });
        
        $(this).blur(function () {
            
            if ($(this).val()=='')
            {
                $(this).val('Enter Search Keyword Here');
            }
            
        });
    });
    
});


function scheduleCalendar() {
    this.init = function() {
	$("#startdate").datepicker({
	    dateFormat: 'dd-mm-yy'
	});
	$("#startdate").change(function(obj) { 
	    scheduleCalendar.dateChanged(obj.target.value);
	});	    
	$('#chgd').bind('click', function() {
	    $("#startdate").datepicker('show');
	});
    }
    this.dateChanged = function(date) {
	var args = date.split("-");
	var d = args[0];
	var m = args[1];
	var y = args[2];
	scheduleTab.get("schedule2", "ssd="+d+"&ssm="+m+"&ssy="+y);
    }
}

function scheduleTab() {
    
    this.init = function() {
	try {
	    if(document.getElementById('startdate').value) {
		this.reloadShortSchedule(true);
	    }
	} catch(e) {
	}
    }
    
    this.end = function() {
	window.clearTimeout(timeoutId);
	refreshActive = 0;
    }
    
    this.get = function(tab, args) {
	if(tab == 'schedule' && refreshActive == 0) {
	    refreshActive++;
	    this.reloadShortSchedule(null);
	    return;
	}
	if(tab == 'schedule2') {
	    refreshActive = 0;
	}
	if(tab == 'news') {
	    refreshActive = 0;    
	}
	if(tab == 'top20') {
	    refreshActive = 0;
	}
	if(refreshActive) {
	    window.clearTimeout(timeoutId);
	}
	url = '/' + channelName + '/' + 'index.php?module=schedule&filter=latest&channel2=&category=&keyword=&mode=' + tab + '&rand=' + Math.random() + "&" + args;
	$('#scheduleq').load(url);
   }
      
   this.reloadShortSchedule = function(dontload) {
	if(refreshActive == 0) {
	    return;
	}
	if(!dontload) scheduleTab.get("schedule", "");
	$.getScript('index.php?module=timeout', function() {
	    window.setTimeout(scheduleTab.reloadShortSchedule, tmpTimeout);
        });
     
   }
}

var pwin;
var ipwin;
var pwin_pos;
var pwin_iframe;

function sup(URL, pos) 
{
    if (!pos)
    {
        pwin_pos = 'top';
    }else
    {
        pwin_pos = pos;
    }
    
    try 
    {
        if(channelName) 
        {
    	    URL = "/" + channelName + "/" + URL;
	    }
        
    } catch(e) {
        
    }
    
    try 
    {
        ipwin.parentNode.removeChild(ipwin);
	    pwin.parentNode.removeChild(pwin);
        
    } catch(err) {
    }
    
    pwin = document.createElement('div');
    pwin.setAttribute('id','pwin');
    pwin.setAttribute('name','pwin');
	pwin.setAttribute('height','540');
    pwin.setAttribute('title','');
    pwin.setAttribute('style','border: 0px solid; padding: 0; margin: 0;');
    document.body.appendChild(pwin);
    
    var ipwin = document.createElement('iframe');
    ipwin.setAttribute('id','ipwin');
    ipwin.setAttribute('name','ipwin');
    ipwin.setAttribute('frameborder','0');
    ipwin.setAttribute('src',URL);
    ipwin.setAttribute('width','760');
    ipwin.setAttribute('height','540');
    ipwin.setAttribute('onload','resizePwin(this);');
    pwin.appendChild(ipwin);
    
    try
    {
        if (document.getElementById("playerHost").innerHTML.length > 0)
        {
            slPlayer.stopAsx();   
        }
    }catch(err)
    {}
    
    return;
}

function resizePwin(i) 
{
    var ipwin = document.getElementById('ipwin');
    
    pwin_iframe = i.contentWindow;
    
    if(ipwin) 
    {
        if (!pwin_pos) pwin_pos = 'top';        
        
        urlOK=false;
        
        try 
        {
            url = ipwin.contentWindow.location.href;
            urlOK=true;
            
        } catch(err) {    
        }
        
        if (urlOK)
        {
	        i.height = parseInt(ipwin.contentWindow.document.body.clientHeight) + 20;
            i.width = 760;      
	        pwin.style.height = parseInt(i.height) + parseInt(50) + 'px';   
            pwin.style.width = '760px';
            
		    $("#pwin").data("height.dialog", ipwin.contentWindow.document.body.clientHeight + 50 );    
            $("#pwin").data("width.dialog", 760);  
            $("#pwin").data("position.dialog", pwin_pos);   
	        
	        $("#pwin").data("title.dialog",ipwin.contentWindow.document.title);
	        document.body.style.overflowX = 'hidden';

            var msieheight = ipwin.contentWindow.document.body.clientHeight + 50;
            var windowTitle = ipwin.contentWindow.document.title;
            
        }else
        {
            pwin.style.height = '900px';
            pwin.style.width = '970px'; 
            i.height = 880;
            i.width = 970;        
            
            $("#pwin").data("height.dialog", 900);
            $("#pwin").data("width.dialog", 970); 
            $("#pwin").data("title.dialog", 'Payment');
            $("#pwin").data("position.dialog", pwin_pos);  
            
            var windowTitle = 'Payment';
            var msieheight = 900;
             
        }               
        
	    $(function() {
	        $("#pwin").dialog({
		        width: 760,
		        height: msieheight,
		        modal: true,
		        dialogClass: "pwin",
		        resizable: false,
		        closeText: "Close",
		        draggable: false,
		        title: windowTitle,
                position: pwin_pos,
		        close: function(event, ui) {
		                $("#pwin").dialog('destroy');             
			            document.body.style.overflowX = 'hidden';
                        ipwin.parentNode.removeChild(ipwin);
		                pwin.parentNode.removeChild(pwin); 
	                },
                open: function(event, ui) {               
                        document.getElementById('pwinOverlay').style.height ="0px"; 
                        offset = $(document).height() + 5;
                        document.getElementById('pwinOverlay').style.height = offset + "px";
                    }		                        
	        });
	    });         
            
        document.getElementById('pwinOverlay').style.height ="0px";     
        offset = $(document).height() + 5;     
		document.getElementById('pwinOverlay').style.height = offset + "px";
        
        $('#login-box-content').load(ChannelId+'index.php?module=loginbox');
        
			
    }
	
}         
