<!--//--><![CDATA[//><!--

    //The media select box
  	var x;
  	function SelectMedia(x) {
  	//alert ('You clicked on ' + x);
  		if (x == 'video'){
  			document.getElementById('module_media1').style.display='';
  			document.getElementById('module_media2').style.display='none';
  			document.images.MediaTop.src='includes/images/ca_but_mediawindow.gif';
  		}else{
  			document.getElementById('module_media1').style.display='none';
  			document.getElementById('module_media2').style.display='';
  			document.images.MediaTop.src='includes/images/ca_but_mediawindow2.gif'
  		}
  	}
  
  
    //The function for displayin main landing page roll over
  
  	var currentMainBox = 0;
  	var projectMainBoxes = new Array(0,1,2,3);
  	var x;
  	var y;
  	
  	function SelectMainBox(y) {
  		currentMainBox = y;
  		document.getElementById('main_image_' + currentMainBox).style.display='';
  		//hide the other boxes.
  		DeactivateMainBox(projectMainBoxes, currentMainBox)
  	}
  	
  	function DeactivateMainBox(projectMainBoxes, currentMainBox){
  		for (x in projectMainBoxes){
  			//alert(x + ' = ' + currentBox);
  			if (x != currentMainBox){
  				document.getElementById('main_image_' + x).style.display='none';
  				document.getElementById('main_text_area_sub_' + x).style.backgroundPosition='0px 0px';
  				document.getElementById('masthead_' + x).style.color='#718515';
  				document.getElementById('masthead_link_' + x).style.color='#718515';
  				document.getElementById('masthead_sm_' + x).style.color='#718515';
  			}else{
  				document.getElementById('main_text_area_sub_' + x).style.backgroundPosition='0px -60px';
  				document.getElementById('masthead_' + x).style.color='#663399';
  				document.getElementById('masthead_link_' + x).style.color='#663399';
  			  document.getElementById('masthead_sm_' + x).style.color='#663399';
  			}
  		}
  	}
  
  
    //The sub section box
  
  	var currentBox = 0;
  	var projectBoxes = new Array('cs_module_content_magic_box_1','cs_module_content_magic_box_2','cs_module_content_magic_box_3','cs_module_content_magic_box_4','cs_module_content_magic_box_5');
  	var x;
  	var y;
  	
  	function PrevBox() {
  		if(currentBox > 0){
  		currentBox = (currentBox - 1) % projectBoxes.length;
  		}else{
  		currentBox = projectBoxes.length -1;
  		}
  		document.getElementById('cs_module_content_magic_box_' + currentBox).style.display='';
  		//hide the other boxes.
  		DeactivateSubBox(projectBoxes, currentBox)
  	}
  
  	function NextBox() {
  		
  		currentBox = (currentBox + 1) % projectBoxes.length;
  		document.getElementById('cs_module_content_magic_box_' + currentBox).style.display='';
  		//hide the other boxes.
  		DeactivateSubBox(projectBoxes, currentBox)
  	}
  	
  	function SelectBox(y) {
  		currentBox = y;
  		document.getElementById('cs_module_content_magic_box_' + currentBox).style.display='';
  		//hide the other boxes.
  		DeactivateSubBox(projectBoxes, currentBox)
  	}
  	
  	function DeactivateSubBox(projectBoxes, currentBox){
  		for (x in projectBoxes){
  			if (x != currentBox){
  				document.getElementById('cs_module_content_magic_box_' + x).style.display='none';
  				document.getElementById('magicNumber' + x).style.color='#aead81';
  			}else{
  				document.getElementById('magicNumber' + currentBox).style.color='#643498';
  			}
  		}
  	}
  
    //The new window function called by all pages
  
    var newwindow;
    function popit(url,winHeight,winWidth){
    	newwindow=window.open(url,null,"height=" + winHeight + ",width=" + winWidth + ",status=yes,toolbar=no,menubar=no,location=no,resizable=yes");
    	if (window.focus) {
    		newwindow.focus()
    	}
    }

	function SearchSubmit(control)
    {
      var value = escape(control.value);
      value = value.replace(/\+/g, "%2B");
      value = value.replace(/\//g, "%2F");
      value = value.replace(/\%20/g, " ");      
      value = value.replace(/\%[0-9A-Z]{2}/g, "");
      if (control.value.length > 0)
      {
        window.location = "/search/q/" + value + "/1/SearchResults.aspx";
      }
      return false;
    }
    
        
    function clickButton(e, buttonid)
    { 
      var bt = document.getElementById(buttonid); 
      if (bt){ 
            if(navigator.appName.indexOf("Netscape")>(-1)){ 
                  if (e.keyCode == 13){ 
                        bt.click(); 
                        return false; 
                  } 
            } 
            if (navigator.appName.indexOf("Microsoft Internet Explorer")>(-1)){ 
                  if (event.keyCode == 13){ 
                        bt.click(); 
                        return false; 
                  } 
            } 
      } 
	} 
	
	    
    function CheckSearch(searchControl, defaultText)
  	{
  		if (searchControl.value == defaultText)
  		{
  			searchControl.value = "";
  		} 
  	}
  	
  	//AJAX ratings
  	
  	var translationID;
	var averageRating;
	var votesCount;
	var yourRating;
	var purposeOfRead;
	var useYourRating;
		
  	function CheckCookie(e, translationID, rating)
  	{
  		purposeOfRead = 1;
  		useYourRating = 0;
  		yourRating = parseInt(rating);
		ReadRating(translationID);
  	}
  	
  	function GetHttpObject() 
  	{
		var httpObj = null;
		// IE
		try	{ httpObj=new ActiveXObject("Msxml2.XMLHTTP"); }
		catch(e1)
		{
			try { httpObj=new ActiveXObject("Microsoft.XMLHTTP"); }
			catch(e2) { httpObj=null; }
		}
		// firefox, others
		if( !httpObj && typeof XMLHttpRequest!="undefined" )
		{
			httpObj=new XMLHttpRequest();
		}
		return httpObj;
	}
	
	var h;
		
	function SaveRating(translationID, rating)
	{
		yourRating = parseInt(rating);
		purposeOfRead = 1;
		useYourRating = 1;
		ReadRating(translationID);
							
		h = GetHttpObject();
		if ( h===null ) { 
			return null;
		}
		var url = "TranslationRatings.aspx?Rating=" + yourRating + "&TranslationID=" + translationID;
		h.open( "GET", url, true); // async==true
		h.send(null);
	}
  	
  	var rr;
  	
  	function ReadRating(translationID)
	{
		//alert("ReadRating");
		rr = GetHttpObject();
		if ( rr===null ) { 
			return null;
		}
		var url = "TranslationRatings.aspx?TranslationID=" + translationID;
		rr.open( "GET", url, true); // async==true
		rr.onreadystatechange = GetXMLData;
		rr.send(null);
    }
	
	function GetXMLData()
	{
		if (rr.readyState == 4 || rr.readyState == 'complete') 
        { 
            var xmlDoc = rr.responseXML.documentElement;
				translationID = parseInt(xmlDoc.getElementsByTagName("TranslationID")[0].childNodes[0].nodeValue);
				averageRating = parseFloat(xmlDoc.getElementsByTagName("AverageRating")[0].childNodes[0].nodeValue);
				votesCount = parseInt(xmlDoc.getElementsByTagName("VotesCount")[0].childNodes[0].nodeValue);
				if (averageRating == 0 && votesCount == 0 && purposeOfRead == 1) averageRating = yourRating;
 
				RenderRatingData(translationID)
        } 
    }
	
	function RenderRatingData(translationID)
	{
		var percentage = 0;
		
		if(purposeOfRead == 1) { document.getElementById('ratearticle').innerHTML = 'Your rating:';
		document.getElementById('tohide').style.visibility = 'hidden';
		document.getElementById('toshow').style.visibility = 'visible';
		
		document.getElementById('ratearticlefooter').innerHTML = 'Your rating:';
		document.getElementById('tohidefooter').style.visibility = 'hidden';
		document.getElementById('toshowfooter').style.visibility = 'visible'; }
		
		percentage = 10 * Math.floor((averageRating * 2) + 0.5);
		
		if(purposeOfRead == 1 && useYourRating == 1) percentage = 10 * Math.floor(((((averageRating * votesCount) + yourRating) / (votesCount + 1)) * 2) + 0.5);
		
		if(averageRating == 0 && purposeOfRead == 1) percentage = 10 * Math.floor((yourRating * 2) + 0.5);
		
		document.getElementById('grayfivestars').style.backgroundPosition = '0% ' + percentage + '%';
		
		document.getElementById('grayfivestarsfooter').style.backgroundPosition = '0% ' + percentage + '%';
		
		if (purposeOfRead == 1) { document.getElementById('yourgrayfivestars').style.backgroundPosition = '0% ' + (yourRating * 20) + '%';

		document.getElementById('yourgrayfivestarsfooter').style.backgroundPosition = '0% ' + (yourRating * 20) + '%';	}
		
		document.getElementById('totalvotes').innerHTML = 'Total votes: ' + votesCount;
		if(purposeOfRead == 1 && useYourRating == 1) document.getElementById('totalvotes').innerHTML = 'Total votes: ' + (votesCount+1);
		if(votesCount > 24) document.getElementById('totalvotes').style.visibility = 'visible';
		if(purposeOfRead == 1 && useYourRating == 1 && votesCount > 23) document.getElementById('totalvotes').style.visibility = 'visible';
	}
	
	function InitializeRatingData(e, translationID, rating)
	{	
		purposeOfRead = 0;
		yourRating = parseInt(rating);
		ReadRating(translationID);
	}
  	
//--><!]]>
