// MIT OpenCourseWare 

window.onload=function(){
    populateYoutubePlaceholders();
    showRandomSidebarQuote();
    showRandomIndividualSupporterQuote();
}

function emailPopUp()
{
	var pageTitle = document.title;
	var pageUrl   = document.location;
	var URL = "/jsp/emailpage.jsp?title=" + pageTitle + "&referer=" + pageUrl;
	window.open(URL,null,"height=470,width=530,status=yes,toolbar=no,menubar=no,location=no,resizable=yes");
}

// rotating image change for homepage
function changeQuote()
{
var quotes = new Array(
'<p>&quot;OpenCourseWare is exactly the kind of thing that universities should be doing.&quot;</p><ul><li><strong>Larry Birenbaum</strong><br />MIT Class of 1969 and OCW supporter<br /> United States</li></ul>', 
'<p>&quot;Through OCW, I am part of a movement to help make education free and available to the world.&quot;</p><p><ul><li><strong>Clinton Blackburn</strong><br />MIT student<br />United States</li></ul>', 
'<p>&quot;I was amazed that a university such as MIT would freely give access to its educational information.&quot;</p><ul><li><b>Triatno Yudo Harjoko</b><br />Educator<br />Indonesia</li></ul>',
'<p>&quot;When I realized I could follow along with an MIT course... I thought, \'I can handle this!\'&quot;</p><ul><li><b>Ali Sheikh</b><br />Student<br />United States</li></ul>', 
'<p>&quot;I found lecture notes, handouts and slides from presentations, and some problem sets. It helped me a lot.&quot;</p><ul><li><b>Maria Karamitsou</b><br />Student<br />Greece</li></ul>',
'<p>&quot;OCW opens up knowledge across the world and allows universities to benchmark teaching.&quot;</p><ul><li><b>Fran&ccedil;ois Viruly</b><br />Educator<br />South Africa</li></ul>',
'<p>&quot;My life is in teaching. To have a chance to do that with a world audience is just wonderful.&quot;</p><ul><li><b>Gilbert Strang</b><br />MIT Mathematics professor<br />United States</li></ul>',
'<p>&quot;It\'s a great opportunity for students to become extraordinary engineers.&quot;</p><ul><li><b>Juan Lara</b><br />Student<br />Mexico</li></ul>',
'<p>&quot;It puts a previously untouchable subject within reach for anyone who is interested.&quot;</p><ul><li><b>Wendy Ermold</b><br />Self Learner<br />United States</li></ul>',
'<p>&quot;I strive to make as much as possible enjoyable and educational at the same time.&quot;</p><ul><li><b>Amy Santee</b><br />Educator<br />United States</li></ul>',
'<p>&quot;It\'s an important way to ensure the quality of my courses.&quot;</p><ul><li><b>Shirley Harrell</b><br />Educator<br />United States</li></ul>',
'<p>&quot;OCW will enable us to create better educational linkages.&quot;</p><ul><li><b>Karen Willcox</b><br />MIT Aeronautics and Astronautics professor<br />United States</li></ul>');

var images = new Array (
"/images/wihomeimages/birenbaum.jpg", 
"/images/wihomeimages/blackburn.jpg", 
"/images/wihomeimages/harjoko.jpg",
"/images/wihomeimages/sheikh.jpg",
"/images/wihomeimages/karamitsou.jpg",
"/images/wihomeimages/viruly.jpg",
"/images/wihomeimages/gil3.jpg",
"/images/wihomeimages/juan_banner.jpg",
"/images/wihomeimages/wendy_banner.jpg",
"/images/wihomeimages/santee_banner.jpg",
"/images/wihomeimages/harrell_banner.jpg",
"/images/wihomeimages/willcox_banner.jpg");

var links = new Array (
"/donate/ocw-course-champions-program/larry-birenbaum/", 
"/about/ocw-stories/clinton-blackburn/", 
"/about/ocw-stories/triatno-yudo-harjoko/",
"/about/ocw-stories/ali-sheikh/",
"/about/ocw-stories/maria-karamitsou/",
"/about/ocw-stories/francois-viruly/",
"/about/ocw-stories/gilbert-strang/",
"/about/ocw-stories/juan-lara/",
"/about/ocw-stories/wendy-ermold/",
"/about/ocw-stories/amy-santee/",
"/about/ocw-stories/shirley-harrell/",
"/about/ocw-stories/karen-willcox/");

var rand = Math.floor(Math.random()*quotes.length);
var txt='';
txt+='<ul><li class="email"><a href="javascript:emailPopUp()">Email this page<\/a><\/li><\/ul>';
if(document.getElementById("switchbutton"))
	document.getElementById("switchbutton").innerHTML=txt;
document.getElementById("RichTextPlaceholder1").style.backgroundImage = "url("+images[rand]+")";
var mainQuotesPlaceHolder = document.getElementById("quote_main");
if(mainQuotesPlaceHolder){
	mainQuotesPlaceHolder.innerHTML = quotes[rand] + '<p><a href="' + links[rand] + '"  class="bullet">Read more<\/a><\/p>';
	}
}
// rotating image change ends here

function showRandomSidebarQuote()
{
	var quotes = new Array(
	'<p>&quot;I donated because I want MIT to keep OCW going.&quot;<br /><br /> &mdash;Heath Novak<br />Student, USA</p>', 
	'<p>&quot;OCW inspires just as much as it enriches.&quot;<br /><br /> &mdash;Jeff Breidenbach<br /> MIT Alumnus, Class of 1996</p>',
	'<p>&quot;It\'s every person\'s responsibility to stand up and support the things he (or she) values.&quot;<br /><br /> &mdash;Assaf Tal<br /> Self Learner, Israel</p>',
	'<p>&quot;Supporting OCW was my way of saying \'thank you\' for having the courage and insight to take this bold step.&quot;<br /><br /> &mdash;Ted Inoue<br /> Self Learner, USA</p>',
	'<p>&quot;I gained so much by the educational materials from MIT faculty.&quot;<br /><br /> &mdash;Aditi Gupta<br /> Student, USA</p>',
	'<p>&quot;OCW has been instrumental in my professional development.&quot;<br /><br /> &mdash;Harry Crissy<br /> Self Learner, USA</p>') 
	
	var rand = Math.floor(Math.random() * quotes.length);
	var sidebarQuotesPlaceHolder = document.getElementById("quote_sidebar");
	if(sidebarQuotesPlaceHolder){
		sidebarQuotesPlaceHolder.innerHTML = quotes[rand];
	}
}
function showRandomIndividualSupporterQuote()
{
	var images = new Array (
	"/images/individualsupporter/donor_1.gif", 
	"/images/individualsupporter/donor_2.gif", 
	"/images/individualsupporter/donor_3.gif",
	"/images/individualsupporter/donor_4.gif",
	"/images/individualsupporter/donor_5.gif",
	"/images/individualsupporter/donor_6.gif",
	"/images/individualsupporter/donor_7.gif",
	"/images/individualsupporter/donor_8.gif",
	"/images/individualsupporter/donor_9.gif",
	"/images/individualsupporter/donor_10.gif");

	var quotes = new Array(
	'OpenCourseWare is how MIT will be remembered 500 years from now.',
	'I gave to OCW because I think it\'s one of the most noble endeavors imaginable. MIT, you rock! I\'m so proud of you!',
	'I\'ve used OCW as a reference long after my old college \'bibles\' ended up in the recycling bin. OCW is a shining example of ideas being celebrated.',
	'I\'ve been dreaming for years an initiative like the OCW for young students in Haiti and other Developing countries.',
	'I know the value of good educational content - and the tangible positive changes it can bring to an aspiring student. It really transforms life.',
	'I support you because you support me! Thank you for contributing to my professional development.',
	'As a Physics teacher, I find your website to be of enormous utility both for my own edification, as well as the education of my students.',
	'I find it inspiring that so many people, rich or poor, get to learn anything they desire from OpenCourseWare.',
	'This is the way education should be: open, high-quality and available to all who are interested in learning.',
	'This is what education is all about and it is boundless. This is why I support OCW.') 
	
	var rand = Math.floor(Math.random() * quotes.length);
	var sidebarQuotesPlaceHolder = document.getElementById("rotating_quotes");
	if(sidebarQuotesPlaceHolder){
		sidebarQuotesPlaceHolder.innerHTML = '<p><img title="' + quotes[rand] + '" src="' + images[rand] + '" alt="' + quotes[rand] + '" \/><\/p>';
	}
}

function emailPopUp()
{
	var pageTitle = document.title;
	var pageUrl   = document.location;
	var URL = "/jsp/emailpage.jsp?title=" + pageTitle + "&referer=" + pageUrl;
	window.open(URL,null,"height=470,width=530,status=yes,toolbar=no,menubar=no,location=no,resizable=yes");
}

//Clear the default value of search input 

function clearSearchBox()
{
	if(document.getElementById("terms").value == "Enter search keyword")
	{
		document.getElementById("terms").value = "";	
	}
	
}

function fillSearchBox()
{
	if(document.getElementById("terms").value == "")
	{
		document.getElementById("terms").value = "Enter search keyword";	
	}
}

function clearEmailBox()
{

	if(document.getElementById("txt_subscribe").value == "Enter email address")
	{
		document.getElementById("txt_subscribe").value = "";	
	}
	
}
function populateYoutubePlaceholders(){
    var stringToReplace = "ACTUAL_LINK_GOES_HERE";
    var videoinjectionstring = '<object type="application/x-shockwave-flash" style="width:425px; height:344px;" data="' + stringToReplace+ '">'
            + '<param name="movie" value="' + stringToReplace + '"></param>'
            + '<param name="allowFullScreen" value="true"></param></object>';
    var blacklist_div = document.getElementById("dept_links");
    if(blacklist_div != null){
        return;
        }
    var videoContainers = document.getElementsByClassName("youtubevideo");
    
    for(i = 0; i < videoContainers.length; i ++){
        var videoURL = videoContainers[i].getElementsByTagName("a")[0].getAttribute("href");
        var finalvideoinjectionstring = videoinjectionstring.replace(stringToReplace, videoURL).replace(stringToReplace, videoURL);
        videoContainers[i].innerHTML = finalvideoinjectionstring;
    }
}

document.getElementsByClassName = function(cl) {
    var retnode = [];
    var myclass = new RegExp('\\b'+cl+'\\b');
    var elem = this.getElementsByTagName('div');
    for (var i = 0; i < elem.length; i++) {
    var classes = elem[i].className;
    if (myclass.test(classes)) {
        retnode.push(elem[i]);
        break;
        }
    }
    return retnode;
};


