
function expandInput(name) {


	var searchExists = true;
	var loginExists=true;
	var newsletterExists=true;

	if(document.getElementById('searchForm') == null) searchExists=false;
	if(document.getElementById('loginForm') == null) loginExists=false;
	if(document.getElementById('newsletterForm') == null) newsletterExists=false;
	
	if(searchExists) {
		/*first initialize by collapsing the inputs and resetting buttons*/
		document.getElementById('searchForm').style.display = 'none';
		var searchButton = document.getElementById('searchMenuButton');
	}
	if(loginExists) {
		document.getElementById('loginForm').style.display = 'none';
		var loginButton = document.getElementById('loginMenuButton');
	}
	if(newsletterExists) {
		document.getElementById('newsletterForm').style.display = 'none';
		var newsletterButton = document.getElementById('newsletterMenuButton');
	}

	//get the element clicked
	var targetButton= eval(name + 'Button');
	
	// if clicked an expanded section, we should leave all collapsed
	var collapse = false;
	if (targetButton.className.indexOf('Chosen') > -1) {
		collapse = true;
	}
	
	if(searchExists) {
		searchButton.className = 'searchMenuButton';
		searchButton.onmouseover = searchMouseOver;
		searchButton.onmouseout = searchMouseOut;	
	}
	if(loginExists) {
		loginButton.className = 'loginMenuButton';
		loginButton.onmouseover = loginMouseOver;
		loginButton.onmouseout = loginMouseOut;
	}
	if(newsletterExists) {
		newsletterButton.className = 'newsletterMenuButton';
		newsletterButton.onmouseover = newsletterMouseOver;
		newsletterButton.onmouseout = newsletterMouseOut;
	}
	/*now set the new expanded menu*/
	if (collapse != true) {
		var formStr = name + 'Form';
		targetButton.className = name + 'MenuButtonChosen';
		targetButton.onmouseover = null;
		targetButton.onmouseout = null;
		var targetForm = document.getElementById(formStr);
		targetForm.style.display = 'block';
	}
}

function searchMouseOver() {
	document.getElementById('searchMenuButton').className="searchMenuButtonOver";
}
function searchMouseOut() {
	document.getElementById('searchMenuButton').className="searchMenuButton";
}
function loginMouseOver() {
	document.getElementById('loginMenuButton').className="loginMenuButtonOver";
}
function loginMouseOut() {
	document.getElementById('loginMenuButton').className="loginMenuButton";
}
function logoutMouseOver() {
	document.getElementById('logoutMenuButton').className="logoutMenuButtonOver";
}
function logoutMouseOut() {
	document.getElementById('logoutMenuButton').className="logoutMenuButton";
}
function newsletterMouseOver() {
	document.getElementById('newsletterMenuButton').className="newsletterMenuButtonOver";
}
function newsletterMouseOut() {
	document.getElementById('newsletterMenuButton').className="newsletterMenuButton";
}
function playButtonOver() {
	document.getElementById('playButton').className="playButtonOver";
}
function playButtonOut() {
	document.getElementById('playButton').className="playButtonOut";
}

function isValidEmail(str) {
   return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
}
function submitNewsletterEmail() {
	var email = document.getElementById('newsletterEmail').value;
	if(isValidEmail(email)) {
		document.getElementById('newsletterForm').submit();
		return true;
	}
	else {
		alert('Invalid email');
		return false;
	}
}


function getMediaWindowTop(media) {
/*For popup windows to play movies and see photos*/
	var topText = '';
	
  topText +='<html><head><title>Cinemasports</title>';
  topText +='<style type="text/css">';
  topText +='body{margin-top:0px;margin-left:0px;margin-right:0px; padding-right:0px;background-color:#000000}';
  topText +='.head {background-image: url(/images/head.gif);background-repeat: no-repeat;height: 56px;margin:right:0px; padding-right:0px;}';
  topText +='.caption{font-family:verdana,arial;font-size:10px;color:#999999;font-size: 10px;}';
  if(media == 'photo') {
	  topText +='.media{margin-top:20px;text-align:center;}';
  }
  else {
  	  topText +='.media{margin-top:30px;text-align:center;}';
  }
  topText +='</style>';
  topText +='</head><body>';
  topText +='<div class="head"></div>';  
  topText +='<div class="media">';
  return topText;
}

function getMediaWindowBottom() {
/*For popup windows to play movies and see photos*/
	var bottomText = '';
	bottomText += '</div>';
	bottomText += '</body></html>';
	return bottomText;
}

function moviePlay(url)
{
  var generator=window.open('','moviePlayer','height=625,width=759,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no');
   if (window.focus) {generator.focus()}
  generator.document.write(getMediaWindowTop('movie'));
  generator.document.write('<object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http:\/\/www.apple.com\/qtactivex\/qtplugin.cab" height="504" width="720">');
  generator.document.write('<param name="src" value="' + url + '">');
  generator.document.write('<param name="autoplay" value="true">');
  generator.document.write('<param name="controller" value="true">');
  generator.document.write('<param name="scale" value="ASPECT">');
  generator.document.write('<embed height="504" width="720" src="' + url + '" pluginspage="http:\/\/www.apple.com\/quicktime\/download\/" type="video\/quicktime" controller="true" autoplay="true"  scale="ASPECT">');
  generator.document.write('</object>');
  generator.document.write(getMediaWindowBottom());
  generator.document.close();
}
function movieStream(url)
{
  var generator=window.open('','moviePlayer','height=625,width=759,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no');
   if (window.focus) {generator.focus()}
  generator.document.write(getMediaWindowTop('movie'));
  generator.document.write('<embed height="504" width="720" bgcolor="#000000" src="http://www.archive.org/php/blank.mov" QTSRC="' + url + '" pluginspage="http:\/\/www.apple.com\/quicktime\/download\/" type="video\/quicktime" controller="true" autoplay="true">');
  generator.document.write(getMediaWindowBottom());
  generator.document.close();
}


function showPicture(url, caption)
{
	  var generator=window.open('','moviePlayer','height=425,width=500,resizable=no,scrollbars=no,toolbar=no,menubar=no,location=no,directories=no');
	   if (window.focus) {generator.focus()}
	  generator.document.write(getMediaWindowTop('photo'));
	  generator.document.write('<img src="' + url + '"/>');
	  generator.document.write('<p class="caption">' + caption + '</p>');
	  generator.document.write(getMediaWindowBottom());
	  generator.document.close();
}

function toggleVisible(id, displayStyle) {
	var changeEl = document.getElementById(id);
	if(changeEl.style.display=='block') {
		changeEl.style.display='none';
	}
	else {
		changeEl.style.display=displayStyle;		
	}
}


function clearIf(obj, val) {
/*clears a textbox or other object if value matches val*/
	if(obj.value == val) {
		obj.value = '';
	}
}

function archiveOrgPlayer(movUrl) {
	var urlParts = movUrl.split('/');
	var movFile = urlParts[urlParts.length-1];
	var movDir = urlParts[urlParts.length-2];
	
    var player = '<object width="606" height="479" classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">'
    + '<param value="true" name="allowfullscreen"/>'
    + '<param value="always" name="allowscriptaccess"/>'
    + '<param value="high" name="quality"/>'
    + '<param value="true" name="cachebusting"/>'
    + '<param value="#000000" name="bgcolor"/>'
    + '<param name="movie" value="http://www.archive.org/flow/flowplayer.commercial-3.2.1.swf" />'
    + '<param value="config={\'key\':\'%23$aa4baff94a9bdcafce8\',\'playlist\':[\'format=Thumbnail?.jpg\',{\'autoPlay\':false,\'url\':\''
    + movFile
    + '\'}],\'clip\':{\'autoPlay\':true,\'baseUrl\':\'http://www.archive.org/download/'
    + movDir 
    + '/\',\'scaling\':\'fit\',\'provider\':\'h264streaming\'},\'canvas\':{\'backgroundColor\':\'#000000\',\'backgroundGradient\':\'none\'},\'plugins\':{\'controls\':{\'playlist\':false,\'fullscreen\':true,\'height\':26,\'backgroundColor\':\'#000000\',\'autoHide\':{\'fullscreenOnly\':true}},\'h264streaming\':{\'url\':\'http://www.archive.org/flow/flowplayer.pseudostreaming-3.2.1.swf\'}},\'contextMenu\':[{},\'-\',\'Flowplayer v3.2.1\']}" name="flashvars"/>';
    + '<embed src="http://www.archive.org/flow/flowplayer.commercial-3.2.1.swf" type="application/x-shockwave-flash" width="606" height="479" allowfullscreen="true" allowscriptaccess="always" cachebusting="true" bgcolor="#000000" quality="high" flashvars="config={\'key\':\'%23$aa4baff94a9bdcafce8\',\'playlist\':[\'format=Thumbnail?.jpg\',{\'autoPlay\':false,\'url\':\''
    + movFile
    + '\'}],\'clip\':{\'autoPlay\':true,\'baseUrl\':\'http://www.archive.org/download/'
    + movDir
    + '/\',\'scaling\':\'fit\',\'provider\':\'h264streaming\'},\'canvas\':{\'backgroundColor\':\'#000000\',\'backgroundGradient\':\'none\'},\'plugins\':{\'controls\':{\'playlist\':false,\'fullscreen\':true,\'height\':26,\'backgroundColor\':\'#000000\',\'autoHide\':{\'fullscreenOnly\':true}},\'h264streaming\':{\'url\':\'http://www.archive.org/flow/flowplayer.pseudostreaming-3.2.1.swf\'}},\'contextMenu\':[{},\'-\',\'Flowplayer v3.2.1\']}">' 
    + '</embed>'
    + '</object>';
    return player;
}
//thumbnail deprecated in favor of server side render
/*
function thumbnail(movUrl, title) {
	var urlParts = movUrl.split('/');
	var movDir = urlParts[urlParts.length-2];
	var movFile = urlParts[urlParts.length-1];
	var fileParts = movFile.split('.');
	fileParts.pop();
	var movId = fileParts.join('.');
    var thumb = '<img src="http://www.archive.org/download/'
    + movDir + '/' + movId
    + '.gif" height="53" alt="'
    + title
    + '" />';
    return thumb;
}
*/
