var msg1='';
var position=0;
var nowplaying=0;
var startFlag=false;
var arrVideos=new Array();
var id;
var playCount=1;
function timerEvent(val)
{
	if(val=='1')
		id =window.setInterval("moveSlider()",250);
	else
		window.clearInterval(id);
}
function test()
{
	alert(parent.frames['ifrVideo'].document.player.Buffering)
	//frames['ifrVideo'].document.ss.play();
}
function moveSlider()
{ 
	if(parent.frames['ifrVideo'].document.player)
	{
		if(parent.frames['ifrVideo'].document.player.playState==3)
		{
			var val = parent.frames['ifrVideo'].document.player.controls.currentPosition / (parent.frames['ifrVideo'].document.player.currentMedia.duration);
			sliderVar.setValue(val);
			
		}
	}
}

function setVideoPosition()
{
	if(sliderVar.getValue(2) !=0.00)
	{
		var position = (parent.frames['ifrVideo'].document.player.currentMedia.duration/100) * (sliderVar.getValue(2) *100 );
		
		parent.frames['ifrVideo'].document.player.controls.currentPosition = position;
	}
		timerEvent('1');
}
function showVideoPosition()
{
	if(sliderVar.getValue(2) !=0.00)
	{
		var position = (parent.frames['ifrVideo'].document.player.currentMedia.duration/100) * (sliderVar.getValue(2) *100 );
		var element = document.getElementById('Slider1RailImg');
		element.title = (Math.floor(sliderVar.getValue(2) * 100) ) + "%";
		
	}
}

function setExternalLink(videoID)
{
	var speed=parent.frames['ifrVideo'].document.getElementById('speed').value;
	var url =  "uploads/video/" + speed + videoID + ".wvx";
//alert(url);
	parent.document.getElementById('externalLink').href=url; /// to download video link
}
function checkChange(videoID)
{
	if(playCount>1)
	{
		playCount = 1;	
		Previous('wm'); //  playing previous video again
		return true;
	}
	//var url = parent.frames['ifrVideo'].document.player.currentMedia.getItemInfo("Author");
	
	var oldId = parent.frames['ifrVideo'].document.getElementById('nowplaying').value;
	if(oldId != videoID)
	{
		parent.frames['ifrDetails'].document.location.href="details.php?id=" + videoID;
		parent.frames['ifrVideo'].document.getElementById('nowplaying').value= videoID;
	}
}

function hideBandDisplay()
{
	parent.document.getElementById('divChangeSpeed').style.visibility="hidden";
	return true;
}
function showBandDisplay()
{
	parent.document.getElementById('divChangeSpeed').style.visibility="visible";
	return true;
}


function changeSpeed()
{
	currentSpeed=frames['ifrVideo'].document.getElementById('speed').value;

	id = parent.frames['ifrVideo'].document.getElementById('nowplaying').value;
	var newSpeed;
	if(currentSpeed=="low")
	{
		newSpeed="high";
	}
	else
	{
		newSpeed="low";
	}
	var url= "uploads/video/" + newSpeed + id + ".wvx";
	parent.frames['ifrVideo'].document.player.URL=url;
	document.imgSpeed.src="img/tv/" + currentSpeed + ".jpg";
	document.imgSpeed.title= "Show " + currentSpeed + " quality video";
	frames['ifrVideo'].document.getElementById('speed').value=newSpeed ;
}
/*function playVideo(type,id,title,file,high,low)
{
	drawVideo(type,id,title,file,high,low);
}*/
function openExternalPlayer()
{
	var videoID=parent.frames['ifrVideo'].player.currentMedia.name; 
	w=open('playlist.php?id=' + videoID);
	timeout=setTimeout('checkClose()',5000);
}
function checkClose()
{
	clearTimeout(timeout);
	w.close();
}

function playVideo(id,loc)
{	
	if(loc=="home")	// the video from another pages are redirectoed to index page
	{
		document.location.href="index.php?id=" + id;
		return false;
	}
	parent.window.scrollTo(0,66);
	parent.frames['ifrVideo'].className="iframes-image";
	parent.frames['ifrVideo'].document.location.href="video.php?id=" + id;
	parent.frames['ifrDetails'].document.location.href="details.php?id=" + id;
}
//<a href=\"javascript: next('wm')\">Next</a>
//<a href=\"javascript: next('wm')\">Next</a>
function changeChannel(channel,channelname)
{	
	parent.frames['ifrLeft'].document.location.href="list.php?lines=4&channel=" + channel + "&channelname=" + channelname;
	var leftLocation= parent.frames['ifrRight'].document.location.href;
	if(leftLocation.indexOf("channel=")!=-1)
	{
		parent.frames['ifrRight'].document.location.href="list_right.php?lines=4";
	}
}

function searchVideo()
{
	if(trim(document.frm.key.value))
	{
		document.frm.action="searchresult.php";

		document.frm.submit();
	}
	else
	{
		alert("Enter search key");
		document.frm.key.focus();
	}
}

function myScroll() {
    frames['ifrDetails'].scrollBy(0,50)
    setTimeout('myScroll()',5000); // scrolls every 1000 miliseconds
}
function helpme()
{
	frames['ifrDetails'].document.location.href="helpme.php";
}

function mailFormLoad()
{
	var video=parent.frames['ifrVideo'].document.getElementById('nowplaying').value;
	parent.frames['ifrDetails'].document.location.href="mail_form.php?id=" + video;
}
function mailFormUnLoad()
{
	var id=parent.frames['ifrVideo'].document.getElementById('nowplaying').value;
	parent.frames['ifrDetails'].document.location.href="details.php?id=" + id;
}

function chkForm()
{
	var msg="";
	if (!isValidEmail(document.frm.txtFEmail.value))
	{
		msg="Friends email is invalid";
	}
	if (!isValidEmail(document.frm.txtYEmail.value))
	{
		if(msg!="")
		{
			msg= msg + "\nYour email is invalid";
		}
		else
		{
			msg = "Your email is invalid";
		}
	}
	if(msg!="")
	{
		msg= "The following errors occured\n\n" + msg;	
		alert(msg);		
		return false;
	}
	document.frm.submit();
//	document.frm.action= document.frm.action + "&type=" + parent.frames['ifrVideo'].document.getElementById('txtObject').value;
}

function showImage()
{
	parent.document.getElementById('divChangeSpeed').className="hide";
	parent.document.getElementById('divFullScreen').className="hide";
	parent.document.getElementById('divVolume').className="hide";
	parent.document.getElementById('divExternal').className="hide";

/*	parent.document.getElementById('divNextPrev').className="hide";
	parent.document.getElementById('divPlay').className="hide";
	parent.document.getElementById('divSend').className="hide";
*/}

function showVideo()
{
	parent.document.getElementById('divChangeSpeed').className="show";
	parent.document.getElementById('divFullScreen').className="show";
	parent.document.getElementById('divVolume').className="show";
	parent.document.getElementById('divExternal').className="show";

/*	parent.document.getElementById('divNextPrev').className="show";
	parent.document.getElementById('divPlay').className="show";
	parent.document.getElementById('divSend').className="show";
*/}

function goToPage(url)
{
	if(Isnumeric(document.frmPage.txtPage.value))
	{
		document.location.href=url + "&page=" + document.frmPage.txtPage.value; 
	}
	return false;
}
function Search(url)
{
	cleartext();
	if (trim(document.frmSearch.txtSearchKey.value) == "")
	{
		document.frmSearch.txtSearchKey.focus();
		return false;
	}
	else
	{
		document.frmSearch.action=url;
		document.frmSearch.submit();
		return true;
	}
}	

function cleartext()
{		
	if (trim(document.frmSearch.txtSearchKey.value) == "Search")
	{
		document.frmSearch.txtSearchKey.value="";
		document.frmSearch.txtSearchKey.focus();
	}
}
function goTo(url)
{
	location.href=url;	
}
function trim(frm_field)
{
	if(frm_field=="&nbsp")
	{
			value=""
			
	}
	splitstring = frm_field.split("&nbsp");	
	if(splitstring.length >1)
	{
		value=""
			
	}
	else
	{
		value = frm_field.toString();
	}
	
	
	while(value.charCodeAt(0) == 32 || value.charCodeAt(0) == 9 || value.charCodeAt(0) == 13 || value.charCodeAt(0) == 10) 
	value = value.substring(1);
	while(value.charCodeAt(value.length-1) == 32 || value.charCodeAt(value.length-1) == 9 || value.charCodeAt(value.length-1) == 13 || value.charCodeAt(value.length-1) == 10)
	value = value.substring(0,value.length-1);
	return value;
}
function returnVoid(value)
{	
	return false;
}