var g_lstmsps_dt = new Date();
var g_lstmsps_x = 0;
var g_lstmsps_y = 0;

function getElement(id)
{
    if(document.layers) //NN4+
    {
		return document.layers[id];
    }
    else if(document.getElementById) //gecko(NN6) + IE 5+
    {
        return document.getElementById(id);
    }
    else if(document.all)	// IE 4
    {
        return document.all[id];
    }
}

function pause(millisecondi)
{
    var now = new Date();
    var exitTime = now.getTime() + millisecondi;
    while(true)
    {
        now = new Date();
        if(now.getTime() > exitTime) return;
    }
}
function addtag(trgt, tg)
{
	var o = document.getElementById(trgt);
 	if (o.value)
 		o.value += "," + tg;
 	else
 		o.value = tg;
}

function popup(w, h, url, cptn)
{
	x = (screen.availWidth / 2) - (w / 2);
	y = (screen.availHeight / 2) - (h / 2);
	var hwnd = window.open(url, cptn, 'width='+w+', height='+h+', left='+x+', top='+y+', screenX='+x+', screenY='+y+',scrollbars=2,toolbar=0,status=0,resizable=0,menubar=0,location=0');
//	hwnd.document.write(url);
}

function safedetect_bndwth(qry)
{
	t = new Date();
	bndwth_e = t.getTime();
	bndwth_d = (bndwth_e - bndwth_s);
	bndwth_d2 = bndwth_d / 1000;
	bndwth_fs = 20 * 98; //number_of_elements * size_of_single_element_in_kb
	bndwth_kbs = Math.round(bndwth_fs / bndwth_d2);
	parent.location.replace("index.php?"+qry+"&bndwth="+bndwth_kbs);
}

function blink(speed) 
{
	if (speed)
	{
		if (document.all)
			setInterval("blink()", speed*2000)
		return;
	}
	var blink = document.all.tags("BLINK") 
	for (var i=0; i<blink.length; i++)
		blink[i].style.fontWeight = blink[i].style.fontWeight == "bold" ? "normal" : "bold" 
}

function comchng(stg,gnr,pd)
{
	window.location.href = "./index.php?ui=hm&stg="+stg+"&gnr="+gnr+"&pd="+pd;
}

function upldtptggl(id)
{
	var s = document.getElementById("fst1").style;
	id == '1' ? s.display = 'block' : s.display = 'none';
	var s = document.getElementById("fst2").style;
	id == '2' ? s.display = 'block' : s.display = 'none';
	var s = document.getElementById("fst3").style;
	id == '3' ? s.display = 'block' : s.display = 'none';
	var s = document.getElementById("fst4").style;
	id == '4' ? s.display = 'block' : s.display = 'none';
}

function divtggl()
{
	for (var n = 0; n < arguments.length; n++)
	{
		var a = arguments[n];
		var mode = a.substr(0, 1);
		if (mode != "+" && mode != "-")
		{
			var s = document.getElementById(a).style;
			s.display == 'none' ? s.display = 'block' : s.display = 'none';
			
			var i = document.getElementById(a + "_img");
			s.display == 'none' ? i.src = "media/mda_arrwdwn.png" : i.src = "media/mda_arrwup.png";
			
			var img = new Image();
			img.src = "js2php.php?trgt=session&slot=divtgglchngs&k=" + a + "&v=" + (s.display == 'none' ? false : true);
		}
		else
		{
			o = a.substr(1, a.length);
			s = document.getElementById(o).style;
			mode == "-" ? s.display = 'none' : s.display = 'block';
		}
	}
}

// these functions are caught by the JavascriptView object of the player.
function sendEvent(typ, prm)
{	
	if(navigator.appName.indexOf("Microsoft") != -1)
		window["ymcflv"].sendEvent(typ, prm);
	else
		document["ymcflv"].sendEvent(typ, prm);
}

function evnt_unload()
{
/*	alert("done");
	window["ymcflv"].sendEvent("stop", null);
	alert("done");*/
	
//			$sc.= "<br><a href=\"javascript:sendEvent('playpause')\">plays</a>";

}

function evnt_load()
{

}

function msgbox(msg, trgt)
{
	var r = window.confirm(msg);
	if (r == true)
		window.location.href = trgt;
}

function evnt_mousemv(e, v)
{
	var isIE = document.all?true:false;
//	if (!document.all?true:false) document.captureEvents(Event.MOUSEMOVE);


	var dtc = new Date();
	var d = Math.abs(dtc.getMilliseconds() - g_lstmsps_dt.getMilliseconds());
	
	if (d > 250)
	{
		g_lstmsps_dt = new Date();

		if (isIE) //grab the x-y pos.s if browser is IE
		{
			x = event.clientX + document.body.scrollLeft;
			y = event.clientY + document.body.scrollTop;
		}
		else //grab the x-y pos.s if browser is NS
		{
			x = e.pageX;
			y = e.pageY;
		}  
		
		var r = 32;
		rx = Math.floor(x / r) * r;
		ry = Math.floor(y / r) * r;
		if ((rx != g_lstmsps_x) || (ry != g_lstmsps_y))
		{
			var img = new Image();
			img.src = "js2php.php?trgt=file&slot=" + v + "&x=" + x + "&y=" + y;
			g_lstmsps_x = rx;
			g_lstmsps_y = ry;
		}
		
	}
}

function addfavs(url, ttl)
{
	if (window.external)
	{
		window.external.AddFavorite(url, ttl);
	}
	else
	{
		alert("Sorry, your browser does not support adding favortires. You may want to add this page manually to your favorites now!");
	}
}

function mkhm()
{
	this.setHomePage('http://www.yourmoviechannel.com');
}

function sbmtfrm(frm)
{
  document.frm.submit() ;
}