function exp_tool(toolname,media) 
{	
    var createElement="false";
    t = document.getElementById("wb-sde-tools-content");
    if(!t)
    { 
		t = document.createElement("div");
		t.id="wb-sde-tools-content";
		alert("inside"+t);
		createElement="true";
    }
	if(toolname == 'email')
	{
		if(media == 'ar')
		{
			t.innerHTML='<form name="emailForm" method="post" onSubmit="return validate(\'ar\')" border="0">'+
				'<b>Pour envoyer cet article à un(e) ami(e), entrez son adresse de courriel dans la boîte ci-dessous et cliquez sur Envoyer.</b><br/>'+
				'    <div class="inputField">Choisir un format: '+
				'	<input type="radio" name="ft" value="pdf" checked>PDF&nbsp;&nbsp;'+
				'		<input type="radio" name="ft" value="html">HTML'+
				'		<br/>'+
				'		<input type="text" name="email" width="270" size="40"/></div>'+
				'		<input type="submit" value="Envoyer"/>&nbsp;&nbsp;'+
				'		<input type="button" value="Annuler" onclick="javascript:exp_tool(\'none\');"/>'+
				'</form>';
			
		}
		else if(media == 'ta')
		{
			t.innerHTML='<form name="emailForm" method="post" onSubmit="return validate(\'ta\')" border="0">'+
				'<b>Pour envoyer cet article à un(e) ami(e), entrez son adresse de courriel dans la boîte ci-dessous et cliquez sur Envoyer.</b><br/>'+
				'		<input type="text" name="email" width="270" size="40"/><br/>&nbsp;&nbsp;'+
				'		<input type="submit" value="Envoyer"/>&nbsp;&nbsp;'+
				'		<input type="button" value="Annuler" onclick="javascript:exp_tool(\'none\');"/>'+
				'</form>';
			
		}
		else if(media == 'activity')
		{
			t.innerHTML='<form name="emailForm" method="post" onSubmit="return validate(\'activity\')" border="0">'+
				'<b>Pour envoyer cet article à un(e) ami(e), entrez son adresse de courriel dans la boîte ci-dessous et cliquez sur Envoyer.</b><br/>'+
				'		<input type="text" name="email" width="270" size="40"/><br/>&nbsp;&nbsp;'+
				'		<input type="submit" value="Envoyer"/>&nbsp;&nbsp;'+
				'		<input type="button" value="Annuler" onclick="javascript:exp_tool(\'none\');"/>'+
				'</form>';
			
		}
		active('email');	
		inactive('save');
	}
	else if(toolname == 'save')
	{
		if(media == 'ar')
		{
			t.innerHTML='<form name="saveForm" method="post" onSubmit="return validateSave(\'ar\')" border="0">'+
				'Choisir un format: '+
				' 	<input type="radio" name="ft" value="pdf" checked\/>PDF&nbsp;&nbsp;'+
				'	<input type="radio" name="ft" value="html"\/>HTML'+
				'	<div class="inputField">'+
//				'	<input type="text" style="width:229px"\/>'+
				'	<input type="submit" style="width:89px;" value="Sauvegarder"\/>'+
				'	<input type="button" value="Annuler" onclick="javascript:exp_tool(\'none\');"\/><\/div>'+
				'   <\/form>';
			
		}
		else if(media == 'activity')
		{
			t.innerHTML='<form name="saveForm" method="post" onClick="return validateSave(\'activity\')" border="0">'+
				'   </form>';
			
		}
       		 active(toolname);	
		inactive('email');
	}
	else
	{
		prnt = document.getElementById("wb-sde-tools");		
		//enh-18: removed inner html after cancel button pressed.
		t.innerHTML='';
		//prnt.removeChild(t);
		inactive('email');
		inactive('save');
	}
	if (createElement == "true")
	{
        	prnt = document.getElementById("wb-sde-tools");
		prnt.appendChild(t);
	}
}

function active(tname)
{
    getObject(tname+"Head").className=tname+"_active";
}

function inactive(tname)
{	
   getObject(tname+"Head").className=tname+"_inactive";
}

function getObject(objectId) {
	if (document.all && !document.getElementById) {
		return document.all(objectId);
	} else {
		return document.getElementById(objectId);
	}
}

function validateSave(media)
{
	 var mt2 = getArgs("id"); 
	 var rad_val2 = false;
	 if( media == 'ar')
	 {
		  for (var i=0; i < document.saveForm.ft.length; i++)
		  {
			if (document.saveForm.ft[i].checked)
			 {
				rad_val2 = true;
				var a2="save?id="+mt2+"&ft="+document.saveForm.ft[i].value;
				location.href =a2; 
				return false;
			 }
		 }
		 if (!rad_val2)
		 {
			alert("S’il vous plaît choisir l'un des formats.");
			return false;
		 }
	 }
	 else if( media == 'ta')
	 {
		var a2="save?id="+mt2+"&ft=html";
		location.href =a2; 
		return false;
	 }
	else if( media == 'activity')
	{
		 
		var a2="actSave?id="+mt2+"&ft=pdf";
		location.href =a2; 
		return false;
	}
	
}

function validate(media)
{	
	if(media == 'ar')
	{
		var radioSelected = false;
		for (i = 0;  i < document.emailForm.ft.length;  i++)
		{
			if (document.emailForm.ft[i].checked)
			radioSelected = true;
		}
		if (!radioSelected)
		{
			alert("S’il vous plaît choisir l'un des formats.");
			return false;
		}
	}
	
	var emailAddress = document.emailForm.email.value;
	emailAddress = normalizeQuery(emailAddress); 
	if (emailAddress == "") 
	{
		alert ('S’il vous plaît entrer une adresse de courriel.');
		return false;
	}

	var filter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
	if (!filter.test(emailAddress))
	{
		alert("S’il vous plaît entrer une adresse email valide!");
		document.emailForm.email.focus();
		return false;
	}
	if ( (emailAddress.length <= 4) || (emailAddress.indexOf("@") == -1) || (emailAddress.indexOf(".") == -1)) 
	{
		alert("S’il vous plaît entrer une adresse email valide!");
		document.emailForm.email.focus();
		return false;
	}

	 var mtl = getArgs("id"); 
	 var rad_val;
	 if( media == 'ar')
	 {
		 for (var i=0; i < document.emailForm.ft.length; i++)
		 {
			if (document.emailForm.ft[i].checked)
			{
			 rad_val = document.emailForm.ft[i].value;
			}
		 }
		  var a="email?id="+mtl+"&ft="+rad_val+"&email="+emailAddress;
		  location.href =a; 
		  return false;
	 }
	 else if (media == 'ta')
	 {
		 var a="email?id="+mtl+"&ft=html&email="+emailAddress;
		 location.href =a; 
		 return false;
	 }
	else if (media == 'activity')
	 {
		 var a="email?id="+mtl+"&ft=pdf&email="+emailAddress;
		 location.href =a; 
		 return false;
	 }
}


function normalizeQuery(inputStr) {
  var newString = inputStr;

  if (!inputStr.length) return "";

  // Remove leading spaces
  for (i = 0; i < newString.length; i++) {
    if (newString.charAt(i) !=' ') {
      newString = newString.substring(i,newString.length);
      break;
    }
  }

  // Remove trailing spaces
  for (i = newString.length-1; i >= 0 ; i--) {
    if (newString.charAt(i) !=' ')  { 
      newString = newString.substring(0, i+1);
      break;
    }
  }

  // Replace multiple spaces with single spaces
  for (i = 0; i< newString.length-1; i++) {
    if (newString.charAt(i) ==' ') {
      if (newString.charAt(i+1) ==' ') {
        newString= newString.substring(0, i+1) + newString.substring(i+2, newString.length);
        i--;
      }
    }
  }

  if (newString == " ") newString="";

  return newString;  
}

function getArgs(strInput) {
    var args = new Object();
    var query = location.search.substring(1);  // Get query string.
    var pairs = query.split(",");              // Break at comma.
    var value = "";
    for(var i = 0; i < pairs.length; i++) {
	var pos = pairs[i].indexOf('=');       // Look for "name=value".
	if (pos == -1) continue;               // If not found, skip.
	var argname = pairs[i].substring(0,pos);  // Extract the name.
        if(strInput == argname) {
            value = pairs[i].substring(pos+1); // Extract the value.
            value = unescape(value);          // Store as a property.
        }    
    }
    return value;                               // Return the object.
}

/* Added for ENH-33 to display the metanav*/
function showPoductsPage(strProductName)
{
	if(strProductName == "Reference Center Home") {
		document.product.action="/wb/Home";
		document.product.submit();
	} else if(strProductName == "World Book Kids") {
		document.product.action="/kids/Home";
		document.product.submit();
	} else if(strProductName == "Spanish-language Encyclopedia") {
		document.product.action="/eeh/Home";
		document.product.submit();
	} else if(strProductName == "World Book Advanced") {
		document.product.action="/advanced/home";
		document.product.submit();
	}else if(strProductName == "Research Tools Edition") {
		document.product.action="/researchtools/home";
		document.product.submit();
	}else if(strProductName == "Research Libraries") {
		window.parent.location.href="http://wbrl.worldbookonline.com";
	}
	return false;
}
/*************		BEGIN FUNCTION TO EXPAND THE FOOTER DROP DOWN 	*************/
function setDivPosition(which){
	var divToPos = document.getElementById(which);
	divToPos.style.display = 'block';
}
function hideRollOverDiv(which){
	var divToHide = document.getElementById(which);
	divToHide.style.display = 'none';
}
/*************		END FUNCTION TO EXPAND THE FOOTER DROP DOWN 	*************/
/* ENH-33 changes ends here*/