// JavaScript Document
var gVideoUrl;

function drawemptyline( nHeight )
{
	document.write ("<table width=100% border=0 cellspacing=0 cellpadding=0>");
	document.write ("<tr><td height='" + nHeight + "px' bgcolor=white></td></tr></table>");
}


function ResetMailData()
{
	document.getElementById("idNSEmail").disabled = false
	document.getElementById("idNotifyStreaming").disabled = false
	document.getElementById("idNSEmail").text = ""
	
	alert( "Your request has been successfully sent.\n\nYou will be notified whenever there is a Live Telecast from Samratchana.")
}

function sendMail()
{
	var strUrl, strEMail

	strEMail = document.getElementById("idNSEmail").value
	
	if (true == CheckEmail(strEMail))
	{
		strUrl = "/common/mail/sendmail.asp?ema=" + strEMail
		document.getElementById ("idSendMail").src = strUrl
		idNSEmail.disabled = true
		idNotifyStreaming.disabled = true
		document.getElementById("idNSEmail").value = ""
	}
	else
	{
		alert("Please enter an valid email address");
		document.getElementById("idNSEmail").focus()
	}
}

function playVideo ( url, text, summary, imgurl, visible )
{

	if (url == "") return;
	
	idWMP.stop()
	idWMP.FileName = url
	idVideoHeading.innerHTML = text
	idDownloadVideo.style.display  = visible
	idDownloadVideo.href = url
	gVideoUrl = url
	
	idCurVideoSummary.innerHTML = summary
	idCurVideoImg.src = imgurl
}

function playLiveStream()
{
	var strUrl, strTitle

	strUrl = "http://sermons.samratchana.com/"
	strTitle = "Live telecast from Samratchana - INDIA"
	
	playVideo( strUrl, strTitle, strTitle, "", "hidden" )
}

function playTour()
{
	var strUrl, strTitle

	strUrl = "/voiceofbaba/video/discourses/general/tour.mpg"
	strTitle = "Samratchana: Dawn of the Millennium"
	
	playVideo( strUrl, strTitle, strTitle, "/voiceofbaba/video/images/tour.gif", "" )
}

function playSpecialMessage()
{
	var strUrl, strTitle

	strUrl = "/samnetphotos/Videos/MOV05B_clip0.avi"
	strTitle = "Tamil New Year 2009"
	
	playVideo( strUrl, strTitle, strTitle, "", "" )
}

function playRecentVideo( strVideoUrl, id )
{
	playVideo ( strVideoUrl, id.innerText, id.innerText, "", "" )
}

function emailVideo()
{
	emailLink ( idVideoHeading.innerText, gVideoUrl )
}

function onBodyUnload()
{
	idWMP.FileName = ""
	idWMP.stop()
}

function WMPActionPlay()
{
		idWMP.Play();
		getElement("idPlay").onclick = WMPActionPause;
		getElement("idPlay").src = "includes/pause.gif";
}

function WMPActionPause()
{
		idWMP.Pause();
		getElement("idPlay").onclick = WMPActionPlay;
		getElement("idPlay").src = "includes/play.gif";
}

function WMPActionStop()
{
		idWMP.stop();
		getElement("idPlay").onclick = WMPActionPlay;
		getElement("idPlay").src = "includes/play.gif";
}

var MAX_ROWS = 2;
var MAX_COLS = 3;
function PopulateVideoList ( arrName, bPopulateArchives, prgidxstr )
{
	var strRow, i;
	var MAX_PER_PAGE = 4*3;
	var nPCtr, nCtr, nMaxPerPage;
	
	var nTotal = parseInt(arrName.length / 4); 
	
	nPages = parseInt(arrName.length / MAX_PER_PAGE); 
	var nRem = parseInt(arrName.length % MAX_PER_PAGE);
	
	if (nRem > 0) nPages++;
	
	if (nPages > 2) nPages = MAX_ROWS;
	
	MAX_PER_PAGE = 3;

	strRow = "";
	strRow += "<table id='videolist' width=0 cellspacing=0 cellpadding=0 border=0>";		
	for ( nPCtr = 1, i=0; nPCtr <= nPages; nPCtr++ )
	{
		if (nPCtr < nPages)
			nMaxPerPage = MAX_PER_PAGE;
		else
			nMaxPerPage = (arrName.length - ((nPCtr-1)*4*3)) / 4;
			
		if (nMaxPerPage > 3) nMaxPerPage = 3;
	
		strRow += "\n<tr>\n";		
		for ( nCtr=1; nCtr <= nMaxPerPage; i=i+4, nCtr++ )
		{
			strRow += "<td width='225' class='videoBorderDefault' onMouseOver='this.className=" + '"videoBorder"' + "' onMouseOut='this.className=" + '"videoBorderDefault"' + "' "
//			strRow += "<a style='cursor:pointer;' href='javascript:playVideo (" + "\"" + arrName[i] + "\"" + ", " + "\"" + arrName[i+2] + "\"" + ", " + "\"" + arrName[i+3] + "\"" +  ", " + "\"" + arrName[i+1] + "\"" + ", \"\" )'>";
			strRow += " onclick='javascript:playVideo (" + "\"" + arrName[i] + "\"" + ", " + "\"" + arrName[i+2] + "\"" + ", " + "\"" + arrName[i+3] + "\"" +  ", " + "\"" + arrName[i+1] + "\"" + ", \"\" )'>";			
			strRow += "\n<img border=0 align='left' src='" + arrName[i+1] + "'>"; 
//			strRow += arrName[i+2] + "</a></td>";
			strRow += arrName[i+2] + "</td>";			
			strRow += "\n";
		}
		strRow +=  "</tr><tr><td height=20px nowrap></td></tr>";
	}
	strRow += "</table>";
	
	getElement("idVideoList").innerHTML = strRow;
	
	if (true == bPopulateArchives)
	{
		var vl = arrName.length / 4;
		
		if ( (MAX_ROWS*3) < vl )
			PopulateVideoArchives ( arrName );
		else
			bPopulateArchives = false;			
	}

	if (false == bPopulateArchives)
		idVideoArchives.style.display = "none"
	
	if (null != prgidxstr)
		getElement(prgidxstr).style.background = "url(/common/images/nav_goldbar.jpg)";
}

function PopulateVideoArchives ( arrArray )
{
	ClearOptions(idSelectClip);
	
	AddToOptionList(idSelectClip, "", "");

	var vl = arrArray.length / 4;
	var strVal;
	
	if ( (MAX_ROWS*3) < vl )
	{
		idVideoArchives.style.display = ""
		for (x = (MAX_ROWS*3), y = (MAX_ROWS*3)*4; x < vl; x++, y=y+4) {
			strVal = ""
			strVal = arrArray[y]+"$"+arrArray[y+1]+"$"+arrArray[y+3];
			AddToOptionList(idSelectClip, strVal, arrArray[y+2]);
		}	
	}	
	idSelectClip.selectedIndex = -1;
}

function playArchiveVideo ( value, text )
{
	var str, str1, str2, str3;

	str = value.split ("$");
	str1 = str[0];
	str2 = str[1];
	str3 = str[2];
	playVideo ( str1, text, str3, str2, "" )
	
}
