
function displaySchedNow (){
	findCurrent();
	searchForm();
}

function findCurrent()
{
    
        // clean non numeric characters from the SSI "actualTime" datetime stamp
        // and take first 4 digits "hhmm"
        re = /[^\d]/g;
        currentServerTime = parseFloat(actualTime[1].replace(re,'').substr(0,4));
    
        for (var i = 0; i < daySched.length; i++) 
	    {
		nextI = (i+1);
		if (nextI < daySched.length)
		    {
			next = parseFloat(daySched[nextI].split('~')[0]);
		    }
		else
		    {
			// force-setting next to value equivalent to 06:00 AM 
			next = 3000;
		    }
		
		timeNow = parseFloat(daySched[i].split('~')[0]);
		
		/// yeeeep nasty hack - but it works!!
		if (timeNow < 600) { timeNow += 2400; }
		if (next < 600) { next += 2400; }
		if (currentServerTime < 600) { currentServerTime += 2400; }
		
		if (timeNow <= currentServerTime && currentServerTime < next)
		    {
			descrp = daySched[i].split('~')[1];
			theTitle = daySched[i].split('~')[2];
			
			theLink = 'http://www.universalhd.com' + daySched[i].split('~')[3];

			// Convert time
			jq('#hdNow-time').empty().append(convertTime(daySched[i].split('~')[0])+'<br />ET')
			jq('#hdNow-title a').empty().append(descrp)
			jq('#hdNow-title a').attr("title", descrp)
			jq('#hdNow-title a').attr("href", theLink)
			jq('#hdNow-desc').empty().append(theTitle)
			break;
		}
	}
}

function convertTime (tim){
	if(tim<"1200"){		
		return tim.substring(0,2)+':'+tim.substring(2,4)+' AM'
	}else if(tim>='1200'){
		if(tim.substring(0,2)=='12'){
			return tim.substring(0,2)+':'+tim.substring(2,4)+' PM'
		}else{
			
			// tim-='1200';
			return (tim.substring(0,2)-12)+':'+tim.substring(2,4)+' PM'
			} 

		}
}
function searchForm (){
	jq('.submit.button').click(function() {
		jq('#search_schedule_form').submit()
	})
	jq('#search_schedule').focus(function(){
		jq(this).val("");
	});
	jq('#search_schedule').load(function() {
		
	});
}

