// Channel Guide Menu. 
// VBrick Copyright 2007

// DISPLAYS/HIDES THE CHANNEL GUIDE MENU ONMOUSEOVER/OUT 
            var cellTimer;
            var stime;
            var etime;
            var progID;
            var gidId;
            var aCellID;
            var StationIconsPath = "StationIcons/";
            function DisableCHGBubbling(e)
            {
                if(!e) return;

	            if (e.stopPropagation)
	                e.stopPropagation();
	            else
	                e.cancelBubble = true;
            }
            // getCellID is called from the ChanGuideItem control onmouseover event of each cell
            function getCellID(cellId, arrProgInfo, event)
            {
            DisableCHGBubbling(event);
                try{

                    aCellID         = cellId;
                    var winWidth    = 0; //browser width
                    var winHeight   = 0; //browser height
                    if (self.innerHeight) // all except Explorer
                    {
	                    winWidth    = self.innerWidth;
	                    winHeight   = self.innerHeight;
                    }
                    else if (document.documentElement && document.documentElement.clientHeight)
	                    // Explorer 6 Strict Mode
                    {
	                    winWidth    = document.documentElement.clientWidth;
	                    winHeight   = document.documentElement.clientHeight;
                    }
                    else if (document.body) // other Explorers
                    {
	                    winWidth    = document.body.clientWidth;
	                    winHeight   = document.body.clientHeight;
                    }
                    else
                    {
                        winWidth    = document.body.offsetWidth;
                        winHeight   = document.body.offsetHeight;
                    }
                    var progArr         = arrProgInfo.split("__");
                    progID              = progArr[0]; // ProgramID
                    var progTitle       = progArr[1]; // Program Title
                    var progTitleTTip   = progArr[1]; // Program Title 
                    var progDesc        = progArr[2]; // Program Description
                    var progDescTTip    = progArr[2]; // Program Description
                    var progRating      = progArr[3]; // TV Rating
                    stime               = progArr[4]; // Start Time
	                etime               = progArr[5]; // End Time
	                var progRecordtime  = progArr[6]; // Program Recording Time
	                
	                // SPLITS THE RECORDING START/STOP TIME INTO 2 VARIABLES
	                var arrProgRecTime = "";//= progRecordtime.split("-");
	                var progRecStart   = "";//= arrProgRecTime[0];
	                var progRecStop    = "";//= arrProgRecTime[1];
	                
	                //scr 6419
	                var canRecord = document.getElementById('canRecord').value;
	                
	                try{
	                    arrProgRecTime  = progRecordtime.split("-");
	                    progRecStart    = arrProgRecTime[0] + "";
	                    progRecStop     = arrProgRecTime[1] + "";
	                    
	                }
	                catch(err)
	                {
	                }
	                //=====
	               
	                var progIsRecord    = progArr[7]; // Boolean is Program Recording?
	                var chnl            = progArr[8]; // Channel No.
	                gidId               = progArr[9]; // GID
	                var progDuration    = progArr[10]; // Program Duration
	                var progRecSchedId  = progArr[11]; // Program RecordingScheduleId
	                var thisWinDuration = progArr[12]; // Program window duration
	                //vems
	                //pass the station icon
	                var stationLogo = StationIconsPath + progArr[13];
	                var stationTitle = progArr[14];
	                var AllowProgramRecording = progArr[15]; // allow program recording	               
	                
	                var showRecordBTNType;
	                var hideRecordBTNType;
	                var titleToolTip    = "";
	                var descToolTip     = "";
	                                
                             
	                xCord           = ((event.clientX / 2) - 175)
                    yCord           = (event.clientY - 50)
                    
                    if (winWidth <= 1500)
                    {
                        xCord = xCord + 200;
                    }                    
                    
                    if (xCord < 10 )
                    {xCord = 15}
                    if (progTitle.length > 23)
    	            {   	                
    	                //titleToolTip = "...";
    	                //progTitle    = progTitle.substring(0, 18);
    	            }
    	            if(progDesc.indexOf(" ") > 60)
    	            {   	            
                        if(progDesc.length > 60)
                        {
                            descToolTip = "...";
                            var descLast = progDesc.substring(40, 60) + descToolTip;
                            progDesc    = progDesc.substring(0, 40) + " " + descLast;
                        }
    	            }
    	            // button btnRecProg or btnStopRecProg. get info from DR[]  
    	            if (progRecSchedId > 0)
    	            {
    	                showRecordBTNType = "btnStopRecProg";
    	                hideRecordBTNType = "btnRecProg";
    	            }
    	            else
    	            {
    	                showRecordBTNType = "btnRecProg";
    	                hideRecordBTNType = "btnStopRecProg";
    	            }    	                	         
    	                	             
    	            document.getElementById('progTitle').innerHTML          = progTitle;
    	            document.getElementById("progTitle").setAttribute("title", progTitleTTip);
    	            document.getElementById('progDescription').innerHTML    = progDesc;
    	            document.getElementById("progDescription").setAttribute("title", progDescTTip);
    	            document.getElementById('progRating').innerHTML         = progRating;
    	            document.getElementById('progRating').innerHTML         = progRating;
	                document.getElementById('sTime').innerHTML              = stime;
	                document.getElementById('eTime').innerHTML              = etime;
	                document.getElementById('hdSTime').value                = stime;
	                document.getElementById('hdETime').value                = etime;
	                document.getElementById('gidID').value                  = gidId;
	                document.getElementById('actvCell').value               = aCellID;	 
	                document.getElementById('progTtl').value                = progTitle;	
	                //document.getElementById('progRecordTime').innerHTML     = progRecStart + " - <br>" + progRecStop;
	                document.getElementById('progIsRecording').innerHTML    = progIsRecord;	
	                document.getElementById('progRecScheduleID').value      = progRecSchedId;
	                document.getElementById('channel').innerHTML            = chnl + "  ( " + stationTitle + " )";
	                document.getElementById('cgChannel').value              = chnl;
	                document.getElementById('cgprogTitle').value            = progTitle;
	                document.getElementById('cgprogDur').value              = progDuration;
	                document.getElementById('cgprogStartTime').value        = stime;
	                document.getElementById('cgprogEndTime').value          = etime;
	                document.getElementById('stationLogo').src              = stationLogo;//vems
	                
	                document.getElementById(showRecordBTNType).style.display='block'; //this will show Start or Stop Recording button
	                document.getElementById(hideRecordBTNType).style.display='none';  
    	               	            
    	            
	                showMenu('lightBox');
	                         
	                //IF PROGRAM IS RECORDING SHOW CANCEL BUTTON
	                if (progRecSchedId > 0)
	                {
	                    document.getElementById('progRecordTimeLI').style.display      = 'block';
	                    document.getElementById('progIsRecordingLI').style.display     = 'block';
	                }
	                else
	                {
	                    document.getElementById('progRecordTimeLI').style.display      = 'none';
	                    document.getElementById('progIsRecordingLI').style.display     = 'none';
	                }
	                
	                //user permissions
	                if (canRecord == "false")
	                {
	                    document.getElementById('lblRecBtns').style.visibility      = 'hidden';
	                }
	                
	                
	                // can progrm be recorded?
	                if(AllowProgramRecording == "False")
    	            {
    	                document.getElementById('recButtonsLI').style.visibility      = 'hidden';
    	                document.getElementById('schedButtonLI').style.visibility      = 'hidden';
    	            }
    	            else
    	            {
    	                document.getElementById('recButtonsLI').style.visibility      = 'visible';
    	                document.getElementById('schedButtonLI').style.visibility      = 'visible';    	            
    	            }
	            }
	            catch (err)
	            {
	                //alert(err.message);
	            }
            }
            function closeCellID(cellId)
            {
	            document.getElementById(cellId).style.display='none';         	            
            }
            
            // SCHEDULE RECORD WIZARD QUERYSTRING BUILDER.
            function ChGuideQRYStrSchedRec()
            {
                var chName = "";
                var prgTtl = document.getElementById('cgprogTitle').value;
                try
                    {chName = document.getElementById('cgChannel').value;}
                catch(err)
                    {sName="";}
                if (stime != null)
                {window.location="MCSScheduler/Start.aspx?EventDate="+stime+"&EventDateEnd="+etime+"&Channel="+chName+"&gid="+gidId+"&prgTtl="+prgTtl;}
                else
                {window.location="MCSScheduler/Start.aspx";}
            }
            
            function CHmenuOn()
            {
               document.getElementById('CHmenu').style.display='block';             
            }
            function CHmenuOff(id)
            {
                try{
                     document.getElementById(id).style.display='none';      
                }
                catch(err){                
                    document.getElementById('CHmenu').style.display='none';
                }
            }
            function showToolTip(id, refID)
            {
                var x = document.getElementById(id);
                var r = document.getElementById(refID);
                if (r.innerHTML.indexOf("...") > -1)
                {
                    document.getElementById(id).style.display="block";
                }
            }
            function hideToolTip(id)
            {
                try
                {
                    document.getElementById(id).style.display="none";
                }
                catch(er)
                {}
            }
            
            function showCGinfo(id){
                //document.getElementById(id).style.visibility="visible";
            }
            function hideCGInfo(id){
               //document.getElementById(id).style.visibility="hidden";
            }
            
//THIS CHECKS TO SEE WHAT ROW OR CELL WAS CLICKED AND HILITES/DELHILITES ACCORDINGLY
		var lastclickID = "0";
		var bkgdColor = "#f1f6df";  // 999 #00ce90green color
		function CGHiLite(element, e)
		{		
			var clickID = element.id;
			try
			    {
				    document.getElementById(clickID).style.backgroundColor          =   bkgdColor;
				    //document.getElementById(clickID).className          =   "SelectedItem";
				    if (lastclickID != "0")
				    {
				        document.getElementById(lastclickID).style.backgroundColor  =   '';
				    }
				    if (lastclickID == clickID)
			        {
			            document.getElementById(clickID).style.backgroundColor      =   bkgdColor;
			            //document.getElementById(clickID).className          =   "SelectedItem";
			        }			        
			    }
			    catch(err)
			    {}		
			//SETS CURRENT ID TO LAST CLICKED ID
			lastclickID = clickID;
		}
// Channel Guide Recording Error alerts		
var valCGRecErr;
var tCGRecErr;
var recX = 0;
function cgAlertRecError()
{
    valCGRecErr = document.getElementById('cgRecError');    
    if (valCGRecErr.value == "0")
    {    
        tCGRecErr=setTimeout("cgAlertRecError()",1000);
    }
    else
    {
        recX = (recX + 1);
        clearCGAlertRecError();
//        if (recX > 1)
//        {
//            cancelCGAlertRecError();
//        }
//        else
//        {
//            clearCGAlertRecError();
//        }
    }    
}
function clearCGAlertRecError()
{
    valCGRecErr = document.getElementById('cgRecError');     
    clearTimeout(tCGRecErr);
    alert(valCGRecErr.value);
    //valCGRecErr.value = "0";
    recX = 0; 
    if(valCGRecErr.value.indexOf("Session Has Ended") > -1)
    {
        valCGRecErr.value = "0";
        window.location = 'initial.aspx';
    }  
    else
    {
        valCGRecErr.value = "0";
    } 
}		
function cancelCGAlertRecError()
{
    cgAlertRecError();
    /*
    valCGRecErr = document.getElementById('cgRecError'); 
    try
    {
        clearTimeout(tCGRecErr);
        valCGRecErr.value = "0";
        recX = 0;
    }
    catch(err)
    {
        valCGRecErr.value = "0";
        recX = 0;
    }
    */
}
////////////////////////

var xLBXCord = "";
var yLBXCord = "";
var winWidth    = 0; //browser width
var winHeight   = 0; //browser height
function SetLightBoxPosition()
{

    if (self.innerHeight) // all except Explorer
    {
        winWidth    = self.innerWidth;
        winHeight   = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight)
        // Explorer 6 Strict Mode
    {
        winWidth    = document.documentElement.clientWidth;
        winHeight   = document.documentElement.clientHeight;
    }
    else if (document.body) // other Explorers
    {
        winWidth    = document.body.clientWidth;
        winHeight   = document.body.clientHeight;
    }
    else
    {
        winWidth    = document.body.offsetWidth;
        winHeight   = document.body.offsetHeight;
    }
    //return winWidth;
    //xLBXCord = ((event.clientX / 2) - 175)
    //yLBXCord = (event.clientY - 50)
    
    //alert(xLBXCord);
}
////////////////////////
// creates draggable popup
var Drag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
	
		o.onmousedown	= Drag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;
		
		SetLightBoxPosition();
		
		var w = winWidth / 5; //(clientSize() / 3.5);//sets left position VEMSv5
				
		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = Math.ceil(w) + "px";//"0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "150px"; //"0px";
		//if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = Math.ceil(w) + "px";//"0px";
		//if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "30%"; //"0px";
		//if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		//if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";
		
		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
} 
/*
var ErrorDrag = {

	obj : null,

	init : function(o, oRoot, minX, maxX, minY, maxY, bSwapHorzRef, bSwapVertRef, fXMapper, fYMapper)
	{
		o.onmousedown	= ErrorDrag.start;

		o.hmode			= bSwapHorzRef ? false : true ;
		o.vmode			= bSwapVertRef ? false : true ;

		o.root = oRoot && oRoot != null ? oRoot : o ;

		if (o.hmode  && isNaN(parseInt(o.root.style.left  ))) o.root.style.left   = "0px";
		if (o.vmode  && isNaN(parseInt(o.root.style.top   ))) o.root.style.top    = "0px";
		if (!o.hmode && isNaN(parseInt(o.root.style.right ))) o.root.style.right  = "0px";
		if (!o.vmode && isNaN(parseInt(o.root.style.bottom))) o.root.style.bottom = "0px";

		o.minX	= typeof minX != 'undefined' ? minX : null;
		o.minY	= typeof minY != 'undefined' ? minY : null;
		o.maxX	= typeof maxX != 'undefined' ? maxX : null;
		o.maxY	= typeof maxY != 'undefined' ? maxY : null;

		o.xMapper = fXMapper ? fXMapper : null;
		o.yMapper = fYMapper ? fYMapper : null;

		o.root.onDragStart	= new Function();
		o.root.onDragEnd	= new Function();
		o.root.onDrag		= new Function();
	},

	start : function(e)
	{
		var o = Drag.obj = this;
		e = Drag.fixE(e);
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		o.root.onDragStart(x, y);

		o.lastMouseX	= e.clientX;
		o.lastMouseY	= e.clientY;

		if (o.hmode) {
			if (o.minX != null)	o.minMouseX	= e.clientX - x + o.minX;
			if (o.maxX != null)	o.maxMouseX	= o.minMouseX + o.maxX - o.minX;
		} else {
			if (o.minX != null) o.maxMouseX = -o.minX + e.clientX + x;
			if (o.maxX != null) o.minMouseX = -o.maxX + e.clientX + x;
		}

		if (o.vmode) {
			if (o.minY != null)	o.minMouseY	= e.clientY - y + o.minY;
			if (o.maxY != null)	o.maxMouseY	= o.minMouseY + o.maxY - o.minY;
		} else {
			if (o.minY != null) o.maxMouseY = -o.minY + e.clientY + y;
			if (o.maxY != null) o.minMouseY = -o.maxY + e.clientY + y;
		}

		document.onmousemove	= Drag.drag;
		document.onmouseup		= Drag.end;

		return false;
	},

	drag : function(e)
	{
		e = Drag.fixE(e);
		var o = Drag.obj;

		var ey	= e.clientY;
		var ex	= e.clientX;
		var y = parseInt(o.vmode ? o.root.style.top  : o.root.style.bottom);
		var x = parseInt(o.hmode ? o.root.style.left : o.root.style.right );
		var nx, ny;

		if (o.minX != null) ex = o.hmode ? Math.max(ex, o.minMouseX) : Math.min(ex, o.maxMouseX);
		if (o.maxX != null) ex = o.hmode ? Math.min(ex, o.maxMouseX) : Math.max(ex, o.minMouseX);
		if (o.minY != null) ey = o.vmode ? Math.max(ey, o.minMouseY) : Math.min(ey, o.maxMouseY);
		if (o.maxY != null) ey = o.vmode ? Math.min(ey, o.maxMouseY) : Math.max(ey, o.minMouseY);

		nx = x + ((ex - o.lastMouseX) * (o.hmode ? 1 : -1));
		ny = y + ((ey - o.lastMouseY) * (o.vmode ? 1 : -1));

		if (o.xMapper)		nx = o.xMapper(y)
		else if (o.yMapper)	ny = o.yMapper(x)

		Drag.obj.root.style[o.hmode ? "left" : "right"] = nx + "px";
		Drag.obj.root.style[o.vmode ? "top" : "bottom"] = ny + "px";
		Drag.obj.lastMouseX	= ex;
		Drag.obj.lastMouseY	= ey;

		Drag.obj.root.onDrag(nx, ny);
		return false;
	},

	end : function()
	{
		document.onmousemove = null;
		document.onmouseup   = null;
		Drag.obj.root.onDragEnd(	parseInt(Drag.obj.root.style[Drag.obj.hmode ? "left" : "right"]), 
									parseInt(Drag.obj.root.style[Drag.obj.vmode ? "top" : "bottom"]));
		Drag.obj = null;
	},

	fixE : function(e)
	{
		if (typeof e == 'undefined') e = window.event;
		if (typeof e.layerX == 'undefined') e.layerX = e.offsetX;
		if (typeof e.layerY == 'undefined') e.layerY = e.offsetY;
		return e;
	}
};          
*/