﻿if (location.toString() == 'http://conectados.pluggedin.com/') {
	location.replace('http://conectados.pluggedin.com/Default.aspx');
}
var div;
var objMediaPlayer;
var objFlashPlayer;
var objSource;
var divClose;
var divLogo;
var divPlayer;
var ts;
var i = 0;
var stat;
var DivTitle;
var DivSummary;
var imgObj;
var objTitle;
var mediaTitle;



//        function showMovieTab(id)
//        {
//            var boxOffice = document.getElementById('boxOffice').style;
//            var reviews = document.getElementById('reviews').style;
//            var tabBoxOffice = document.getElementById('tabBoxOffice').style;
//            var tabReviews = document.getElementById('tabReviews').style;            
//                                    
//            tabBoxOffice.backgroundColor="white";
//            tabReviews.backgroundColor="white";
//           
//            if(id == "reviews")
//            {
//                reviews.display = "block";
//                boxOffice.display = "none";
//                tabReviews.backgroundColor="gray";
//            }
//            else
//            {
//                boxOffice.display = "block";
//                reviews.display = "none";
//                tabBoxOffice.backgroundColor="gray";
//            }
//        }

function downloadme(x) {
	myTempWindow = window.open(x, "", "left=10000,screenX=10000");
	alert(x);
	myTempWindow.document.execCommand("SaveAs", "null", x);
	myTempWindow.close();
}

function closeMedia() {
	divClose = document.getElementById('divClose').style;
	divLogo = document.getElementById('videopiologo').style;
	divPlayer = document.getElementById('videoplayer').style;
	div = document.getElementById('mediaContainer');
	objSource = document.getElementById('sourcepath');

	objSource.value = '';

	divLogo.display = 'none';
	divPlayer.display = 'none';
	divClose.display = 'none';

	div.style.backgroundColor = "white";

	objFlashPlayer = document.getElementById('objFlashPlayer');

	objFlashPlayer.style.display = 'none';
	objFlashPlayer.style.width = '0px';
	objFlashPlayer.style.height = '0px';
	objFlashPlayer.innerHTML = '';

	$find('modalMedia').hide();
}

function grow() {
	div.backgroundColor = "";
	div.top = "0px";
	div.left = "0px";

	divClose = document.getElementById('divClose').style;
	divLogo = document.getElementById('videopiologo').style;
	divPlayer = document.getElementById('videoplayer').style;

	divLogo.display = 'block';
	divPlayer.display = 'block';
	divClose.display = 'block';

	if (stat == 'Video') {
		showVideo();

	}
}

function showMedia(objbutton, status, title) {
	var mediaMain = document.getElementById('mediaMain').style;
	div = document.getElementById('mediaContainer').style;

	objSource = document.getElementById('sourcepath');
	objSource.value = objbutton.title;
	objTitle = title;

	//alert(objbutton.title);                                      
	mediaMain.display = 'block';

	div.height = '0px';
	div.width = '0px';
	div.top = '169px';
	div.left = '340px';
	stat = status;
	if (stat == 'Audio') {
		window.open('/pio/layouts/AudioPlayer.aspx?title=' + objTitle, 'audio', 'width=484,height=30,top=820,left=0,scrollbars=no,titlebar=no,resizable=no,status=no,toolbar=no,menubar=no,location=no');
	}
	else {
		$find('modalMedia').show();
		grow();
	}
}

function playMedia(objbutton, status, objUrl, title) {
	var mediaMain = document.getElementById('mediaMain').style;
	div = document.getElementById('mediaContainer').style;
	objSource = document.getElementById('sourcepath');
	objSource.value = objUrl;
	objTitle = title;
	mediaMain.display = 'block';
	div.height = '0px';
	div.width = '0px';
	div.top = '169px';
	div.left = '340px';
	stat = status;
	if (stat == 'Audio') {
		window.open('/pio/layouts/AudioPlayer.aspx?title=' + objTitle, 'audio', 'width=484,height=30,top=820,left=0,scrollbars=no,titlebar=no,resizable=no,status=no,toolbar=no,menubar=no,location=no');
	}
	else {
		$find('modalMedia').show();
		grow();
	}
}

function showRSSMedia(source, title) {
	var mediaMain = document.getElementById('mediaMain').style;
	div = document.getElementById('mediaContainer').style;

	objSource = document.getElementById('sourcepath');
	objSource.value = source;
	objTitle = title;

	//alert(objbutton.title);                                      
	mediaMain.display = 'block';

	div.height = '0px';
	div.width = '0px';
	div.top = '169px';
	div.left = '340px';
	window.open('/pio/layouts/AudioPlayer.aspx?title=' + objTitle, 'audio', 'width=484,height=30,top=820,left=0,scrollbars=no,titlebar=no,resizable=no,status=no,toolbar=no,menubar=no,location=no');

}

function showMediaPodCast(objbutton, status, title) {
	var selected = $('#dateDropdown').val();
	var array = selected.split("~|~");
	var selected = array[0];
	var selectedtitle = array[1];
	var stitle = selectedtitle;
	//alert(selectedtitle);
	//var selectedtitle = document.getElementById('optionId').title;
	var mediaMain = document.getElementById('mediaMain').style;
	div = document.getElementById('mediaContainer').style;

	objSource = document.getElementById('sourcepath');
	objSource.value = selected;
	objbutton.title = selected;
	//var dropdownlisten = document.getElementById('dropDownListen');
	var dropdowndownload = document.getElementById('dropDownDownload');
	dropdowndownload.href = selected;

	mediaMain.display = 'block';

	div.height = '0px';
	div.width = '0px';
	div.top = '169px';
	div.left = '340px';
	stat = status;

	if (stat == 'Audio') {
		window.open('/pio/layouts/AudioPlayer.aspx?title=' + stitle, 'audio', 'width=484,height=30,top=820,left=0,scrollbars=no,titlebar=no,resizable=no,status=no,toolbar=no,menubar=no,location=no');
	}
	else {

		window.location = selected;
		//                alert("!");
		//                document.execCommand("SaveAs");
		////                window.location.replace('download.asp'); 
		//               document.execCommand("SaveAs");
		//                grow(); 
		//                document.execCommand("SaveAs",false,window.location);
		//                popdocument(selected,objSource);
	}
}

function updateTitle(obj) {
	var selected = $('#dateDropdown').val();
	var array = selected.split("~|~");
	var selectedUrl = array[0];

	var dropdownlisten = document.getElementById('dropDownListen');
	var dropdowndownload = document.getElementById('dropDownDownload');
	dropdownlisten.title = selectedUrl;
	dropdowndownload.href = selectedUrl;
	dropdowndownload.title = selectedUrl;

}

function popdocument(itemCode, dir) {
	document.execCommand("SaveAs", false, itemCode)
}


function redirectCultureClipsArchive() {
	var selected = $('#archiveIssues').val();
	window.location = selected;
}

function showVideoBABAndBO(status) {
	var selected = $('#bobandBillEpisodes').val();

	if (selected == '1') return;

	var mediaMain = document.getElementById('mediaMain').style;
	div = document.getElementById('mediaContainer').style;

	objSource = document.getElementById('sourcepath');
	objSource.value = selected;

	mediaMain.display = 'block';

	div.height = '0px';
	div.width = '0px';
	div.top = '169px';
	div.left = '340px';
	stat = status;
	$find('modalMedia').show();
	grow();
}

function showVideo() {
	
	objFlashPlayer = document.getElementById('objFlashPlayer');	
	objFlashPlayer.style.display = 'block';
	objFlashPlayer.style.top = '17px';
	objFlashPlayer.style.left = '16px';

	var videoContainer = document.createElement("div");
	videoContainer.id = "videoContainer";
	objFlashPlayer.appendChild(videoContainer);
	var playerWidth = "484";
	var playerHeight = "226"; 

	var flashvars = {};
	flashvars.allowfullscreen = "true";
	flashvars.allowscriptaccess = "always";
	flashvars.autostart = "true";
					
	flashvars.file = document.getElementById('sourcepath').value;
	if (flashvars.file == "" || flashvars.file == null)
		isBlankVideoUrl = true;
	flashvars.width = playerWidth;
	flashvars.height = playerHeight;
	flashvars.shownavigation = "true";
	flashvars.enablejs = "true";
	flashvars.volume = "100";
	flashvars.controlbar = "bottom";

	flashvars.config = "/pio/jwplayer/ova.xml";	//ova config file

	flashvars.plugins = "/pio/jwplayer/ova.swf";

	var params = {};
	params.wmode = "opaque";
	params.allowfullscreen = "true";
	
	var attributes = {};
	attributes.id = "flashPlayer";
	attributes.name = "flashPlayer";
	attributes.enablejs = "true";
	swfobject.embedSWF("/pio/jwplayer/player.swf", "videoContainer", playerWidth, playerHeight, "9.0.0", "/pio/jwplayer/expressinstall.swf", flashvars, params, attributes);
}

var player = null;
var isOVAFinished = false;
var isBlankVideoUrl = false;
function playerReady(obj) {		
	player =  document.getElementsByName(obj['id'])[0];
	player.addModelListener("STATE", "getUpdate");
}
function getUpdate(obj) {
	if (obj.newstate == "PLAYING" && obj.oldstate == "BUFFERING") {
		if (isOVAFinished) {
			isOVAFinished = false;
		}
    }
	if (obj.newstate == "COMPLETED" && obj.oldstate == "BUFFERING"){		
		if (!isOVAFinished) {
			player.sendEvent('STOP', true);
		}
	}
}
function onLinearAdStart() {
    isOVAFinished = false;
}
function onLinearAdFinish() {
    isOVAFinished = true;
	if (isBlankVideoUrl) //blank video url is not recognized as an error, stop the ova ad from repeating
		player.sendEvent('STOP', true);
}

function showAudios() {
	var vars = "&ControlPanelColor=0xffffff&buttonColor=0x000000&ControlPanelPosition=0&showControlPanel=1&ShowtimeColor=0xffffff&autostart=true&bAutoRepeat=0&BufferTime=1&tmeColor=0xffffff&loaColor=0x666666&GroundColor=0x000000&conNum=5&bShowtime=1&startvolume=100";
	var browser = navigator.appName;

	objSource = opener.document.getElementById('sourcepath');

	objMediaPlayer = document.getElementById('objMediaPlayer');

	var video = objSource.value + vars;
	//var video = path + vars;
	//var s1 = new SWFObject("/pio/scripts/player.swf", "single", "484", "100", "9", "#003399");
	var s1 = new SWFObject("/pio/scripts/player15.swf", "single", "484", "100", "9", "#003399"); //player15 have no full screen button
	//alert(s1);
	objMediaPlayer.style.display = 'block';
	objMediaPlayer.style.top = '0px';
	objMediaPlayer.style.left = '0px';
	s1.addVariable('displayheight', '0');
	s1.addVariable('allowfullscreen', 'false');
	s1.addParam('wmode', 'opaque');
	s1.addVariable('type', 'sound');
	s1.addParam('menu', 'false');
	s1.addVariable('file', video);
	s1.write('objMediaPlayer');
}

function changePath(btnVideo, btnAudio, audiopath, videopath, strtitle) {
	var video = document.getElementById(btnVideo);
	var audio = document.getElementById(btnAudio);

	video.title = videopath;
	audio.title = audiopath;

	//video.onclick = function() { addEvent('Video', strtitle); }
	//audio.onclick = function() { addEvent('Audio', strtitle); }
}

function addEvent(type, mediatitle) {
	if (type == 'Video') {
		showMedia(this, 'Video', mediatitle);
		return false;
	}
	else if (type == 'Audio') {
		showMedia(this, 'Audio', mediatitle);
		return false;
	}
}

function loadTitle(obj, type) {
	DivTitle = document.getElementById(DivTitle);
	mediaTitle = obj.title;

	if (type == 'Video') {
		showMedia(obj, 'Video', mediaTitle);
		return false;
	}
	else if (type == 'Audio') {
		showMedia(obj, 'Audio', mediaTitle);
		return false;
	}

	//audio.onclick = showMedia(this, 'Audio', strtitle); return false;
	//video.onclick = showMedia(this, 'Video', strtitle); return false;
	//load(obj);
}

function convertQuotes(string) {
	var text = string.replace(/&qte/g, "\'");
	text = text.replace(/&dqte/g, "\"");
	text = text.replace(/&comma/g, ",");
	return text;
}

function changeDisplay(obj, btnVideo, btnAudio, strTitle, strSummary, img, imgObj, DivTitle, DivSummary, audiopath, videopath, source, readURL, readLink) {
	DivTitle = document.getElementById(DivTitle);
	DivSummary = document.getElementById(DivSummary);
	hrefReadLink = document.getElementById(readLink);
	hrefMainImage = document.getElementById(imgObj + 'Link');
	imgObj = document.getElementById(imgObj);

	load(obj);

	hrefMainImage.href = readURL;
	hrefReadLink.href = readURL;
	DivTitle.href = readURL;
	DivTitle.innerHTML = convertQuotes(strTitle);
	DivSummary.innerHTML = convertQuotes(strSummary);

	imgObj.src = img;

	toggleWatchListenLink(audiopath, videopath, source);
	changePath(btnVideo, btnAudio, audiopath, videopath, strTitle);

}

function toggleWatchListenLink(audiopath, videopath, source) {
	if (source == 'movie') {
		var lnkWatch = document.getElementById('watchLinkHrefMovie');
		var lnkListen = document.getElementById('listenLinkHrefMovie');
	}
	else if (source == 'video') {
		var lnkWatch = document.getElementById('watchLinkHrefVideo');
		var lnkListen = document.getElementById('listenLinkHrefVideo');
	}

	if (videopath != '') {
		lnkWatch.style.display = 'block';
	}
	else {
		lnkWatch.style.display = 'none';
	}

	if (audiopath != '') {
		lnkListen.style.display = 'block';
	}
	else {
		lnkListen.style.display = 'none';
	}

}

function toggleWatchListenLinkArticlePage(videopath, audiopath) {
	var div = document.getElementById("reviewContrlsDIV");
	var video = document.getElementById("watchLinkHref");
	var audio = document.getElementById("listenLinkHref");
	// var videospanish = document.getElementById("watchLinkHrefSpanish");
	// var audiospanish = document.getElementById("listenLinkHrefSpanish");
	if (videopath != '') {
		video.style.display = 'block';
		// videospanish.style.display = 'block';
	}
	else {
		video.style.display = 'none';
		// videospanish.style.display = 'none';
	}

	if (audiopath != '') {
		audio.style.display = 'block';
		// audiospanish.style.display = 'block';
	}
	else {
		audio.style.display = 'none';
		//  audiospanish.style.display = 'none';
	}

	if (audiopath != '' || videopath != '') {
		div.style.display = 'block';
	}
	else {
		div.style.display = 'none';
	}

}



function toggleWatchListenLinkArticlePageSpanish(videopath, audiopath) {
	var div = document.getElementById("reviewContrlsDIV");
	// var video = document.getElementById("watchLinkHref");
	// var audio = document.getElementById("listenLinkHref");
	var videospanish = document.getElementById("watchLinkHrefSpanish");
	var audiospanish = document.getElementById("listenLinkHrefSpanish");

	if (videopath != '') {
		//    video.style.display = 'block';
		videospanish.style.display = 'block';
	}
	else {
		//    video.style.display = 'none';
		videospanish.style.display = 'none';
	}

	if (audiopath != '') {
		//    audio.style.display = 'block';
		audiospanish.style.display = 'block';
	}
	else {
		//    audio.style.display = 'none';
		audiospanish.style.display = 'none';
	}

	if (audiopath != '' || videopath != '') {
		div.style.display = 'block';
	}
	else {
		div.style.display = 'none';
	}

}

function toggleWatchListenLinkForLandingPages(audiopath, videopath, watchrcid, listenrcid) {

	var lnkWatch = document.getElementById(watchrcid);
	var lnkListen = document.getElementById(listenrcid);

	if (lnkWatch == null || lnkListen == null) {
		setTimeout("toggleWatchListenLinkForLandingPages", 100, audiopath, videopath, watchrcid, listenrcid);
		return;
	}

	if (videopath != '') {
		lnkWatch.style.display = 'block';
	}
	else {
		lnkWatch.style.display = 'none';
	}

	if (audiopath != '') {
		lnkListen.style.display = 'block';
	}
	else {
		lnkListen.style.display = 'none';
	}
}

function display(obj, btnVideo, btnAudio, strTitle, strSummary, img, imgObj, DivTitle, DivSummary, audiopath, videopath, source, readURL, readLink, listId) {
	if (listId == 1) {
		DivTitle = document.getElementById(DivTitle);
		DivSummary = document.getElementById(DivSummary);
		hrefMainImage = document.getElementById(imgObj + 'Link');
		imgObj = document.getElementById(imgObj);
		hrefReadLink = document.getElementById(readLink);

		//browserVal(obj, true);
		//fadeObject(obj);
		imgObj.src = img;

		hrefMainImage.href = readURL;
		hrefReadLink.href = readURL;
		DivTitle.href = readURL;
		DivTitle.innerHTML = convertQuotes(strTitle);
		DivSummary.innerHTML = convertQuotes(strSummary);



		toggleWatchListenLink(audiopath, videopath, source);
		changePath(btnVideo, btnAudio, audiopath, videopath, strTitle);
	}
	else {
		browserVal(obj, true);
		//fadeObject(obj);
	}

}

function load(obj) {
	browserVal(obj, false);
	fadeObject(obj);
}

function browserVal(obj, isFaded) {
	var opacityVal = 100;
	var browser = navigator.appName;
	if (browser == "Microsoft Internet Explorer") {
		if (isFaded) {
			opacityVal = 40;
		}
		obj.style.filter = 'alpha(opacity=' + opacityVal.toString() + ')';
	}
	else {
		if (isFaded) {
			opacityVal = 0.40;
		}
		obj.style.opacity = opacityVal;
	}
}

function fadeObject(obj) {
	var container = document.getElementById(obj.parentNode.parentNode.id);
	var obj2;
	var isSelected = false;
	var nodelength = container.childNodes.length;
	var browser = navigator.appName;
	// obj.onmouseout = function mouseOut(e)            
	// {                                                                                                                                                            
	//      browserVal(obj,false);
	// }
	obj.onmousemove = function mouseMove(e) {
		if (browser == "Microsoft Internet Explorer") {
			for (i = 0; i < nodelength; i++) {
				obj2 = container.childNodes[i].childNodes[0];
				browserVal(obj2, true);
			}
			browserVal(obj, false);
		}
		else {
			for (var i = 0; i < nodelength; i++) {
				//alert(container.childNodes[i].childNodes[1].nodeName);
				if (container.childNodes[i].nodeName == "#text") continue;
				for (var j = 0; j < container.childNodes[i].childNodes.length; j++) {
					if (container.childNodes[i].childNodes[j].nodeName == "#text") continue;
					obj2 = container.childNodes[i].childNodes[j];
				}
				browserVal(obj2, true);
				//alert(obj3.name);
				//alert(i + container.childNodes[i].childNodes[1].id);
			}
			browserVal(obj, false);

		}
	}

}

// Print current date function
var d_names = new Array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");

var m_names = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

var d_names_spanish = new Array("domingo", "lunes", "martes", "miércoles", "jueves", "viernes", "sábado");
var m_names_spanish = new Array("enero", "febrero", "marzo", "abril", "mayo", "junio", "julio", "agosto", "septiembre", "octubre", "noviembre", "diciembre");

var d = new Date();
var curr_day = d.getDay();
var curr_date = d.getDate();
var sup = "";
if (curr_date == 1 || curr_date == 21 || curr_date == 31) {
	sup = "st";
}
else if (curr_date == 2 || curr_date == 22) {
	sup = "nd";
}
else if (curr_date == 3 || curr_date == 23) {
	sup = "rd";
}
else {
	sup = "th";
}
var curr_month = d.getMonth();
var curr_year = d.getFullYear();

function getSendItInfo() {
	return parent.location = "mailto:?body=" + window.location;
}

function postdata(IDString, isSearch) {
	var inputInfo = document.getElementById(IDString).value;
	if (isSearch) {
		document.location.href = "http://172.17.101.41/search?q=" + inputInfo + "&btnG=Search&filter=&entqr=0&output=xml_no_dtd&sort=date%3AD%3AL%3Ad1&client=dev_pluggedinonline_com&filter=&ud=1&oe=UTF-8&ie=UTF-8&proxystylesheet=dev_pluggedinonline_com";
	}
	else {
		var eNewsletterUrl = document.getElementById("ctl00_ctl00_ContentPlaceHolder1_ContentPlaceHolder1_eNewsLetterUrl").value;
		var email = document.getElementById("emailtextInput").value;
		if (email == 'Enter  your email') {
			email = '';
		}
		document.location.href = eNewsletterUrl + "&EmailAddressFromLogin=" + email;

	}

	return false;
}

function RedirectToGSA(inputInfo) {
    var searchQuery = document.getElementById(inputInfo).value.replace("&", "%26");
    var searchUrl = "http://search.pluggedin.com/search?q=" + searchQuery + " &btnG=Search&filter=&ntqr=0&output=xml_no_dtd&sort=date%3AD%3AL%3Ad1&client=pluggedin_com&filter=&ud=1&oe=UTF-8&ie=UTF-8&proxystylesheet=pluggedin_com&site=pluggedin_com&getfields=*";
    var url = searchUrl.replace("{0}", searchQuery);
    location.href = url;
}

function showPastPollDetails(obj, number, totalpollscount) {
	var pollitem;
	for (i = 0; i < totalpollscount; i++) {
		pollitem = document.getElementById('popupContainerPastPollItem' + i);
		pollitem.style.display = "none";
	}
	var currentpollitem = document.getElementById('popupContainerPastPollItem' + number);
	var currentpolllink = document.getElementById('popupContainerPastPollLink' + number);
	var currentpolldetails = document.getElementById('popupContainerPastPollsDetails' + number);
	currentpollitem.style.display = "block";
	currentpolllink.style.display = "none";
	currentpolldetails.style.display = "block";

}

function showPastPollItems(totalpollscount) {
	var pollitem;
	var pollitemlink;
	var pollitemdetails;
	for (i = 0; i < totalpollscount; i++) {
		pollitem = document.getElementById('popupContainerPastPollItem' + i);
		pollitem.style.display = "block";
		pollitemlink = document.getElementById('popupContainerPastPollLink' + i);
		pollitemlink.style.display = "block";
		pollitemdetails = document.getElementById('popupContainerPastPollsDetails' + i);
		pollitemdetails.style.display = "none";
	}
}

function displayPastPolls() {
	var pastpollcontainer = document.getElementById("popupContainer");
	pastpollcontainer.style.display = "block";
}
