// Exalabs bar

function addExalabsBar() {
  var urls = [
	{name:"Exalabs", url:"http://labs.exalead.com"},
	{name:"Chromatik", url:"http://chromatik.labs.exalead.com"},
	{name:"Constellations", url:"http://constellations.labs.exalead.com"},
	{name:"Exalead Light", url:"http://light.labs.exalead.com"},
	{name:"MiiGet", url:"http://miiget.labs.exalead.com"},
	{name:"Sourcier", url:"http://sourcier.labs.exalead.com"},
	{name:"Tweepz", url:"http://tweepz.com"},
	{name:"Voxalead", url:"http://voxaleadnews.labs.exalead.com"},
	{name:"Wikifier", url:"http://wikifier.labs.exalead.com"}
  ];
  var html = '<a href="#" onclick="showExalabsComment();" style="color: #1446C6; float: right; margin-right: 10px;">Feedback this demo !</a>';
  for (var i = 0; i < urls.length; i++) {
	if (document.location.href.indexOf(urls[i].url) != -1) {
	  html += '<span style="color: black; margin-left: 10px; font-weight: bold;">' + urls[i].name + '</span>';
	} else {
		q = top.location.href.match(/[?&](q=[^&]+)&?/i);
		q = (q && q[1] && urls[i].url !== "http://labs.exalead.com")?"/?"+q[1]:"";
	 	html += '<a style="color: #1446C6; margin-left: 10px; text-decoration: underline;" href="'+urls[i].url+q+'">'+urls[i].name+'</a> ';
	}
  }

  /* The bar */
  var bar = document.createElement('div');
  bar.style.textAlign = 'left';
  bar.style.zIndex = 1000;
  bar.innerHTML = html;
  bar.style.textAlign = 'left';
  bar.style.fontFamily = 'Lucida Grande,Bitstream Vera Sans,Verdana,sans-serif';
  bar.style.position = 'absolute';
  bar.style.top = '-20px';
  bar.style.left = '0px';
  bar.style.height = '20px';
  bar.style.width = '100%';
  bar.style.background = 'white';
  bar.style.color = '#1446C6';
  bar.style.fontSize = '12px';
  bar.style.lineHeight = '20px';
  bar.style.borderBottom = '1px solid #707070';
  document.body.style.marginTop = '20px';
  document.body.style.position = 'relative';
  document.body.appendChild(bar);

  /* Comment div */
  var comment = document.createElement('div');
  comment.style.position = 'absolute';
  comment.style.zIndex = 1000;
  comment.style.top = '0px';
  comment.style.right = '0px';
  comment.style.width = '310px';
  comment.style.height = '195px';
  comment.style.background = 'white';
  comment.style.borderLeft = '1px solid #707070';
  comment.style.borderBottom = '1px solid #707070';
  comment.style.display = "none";

  var iframe = document.createElement('iframe');
  iframe.style.display = "none";
  iframe.id = "ExaCommentIframe";
  iframe.name = "ExaCommentIframe";
  iframe.src = "about:blank";
  document.body.appendChild(iframe);
  /* Important for IE */
  if (window.frames[iframe.id].name != iframe.id) { window.frames[iframe.id].name = iframe.id; }

  /* Inside comment div form */
  var html = '<form style="font-size: 12px; padding: 13px; margin: 0px" action="http://labs.exalead.com/feedback.php" method="POST" target="ExaCommentIframe" onsubmit="ExaCommentThanks();" id="ExaCommentForm">';
  html += '<span style="color: #565656;"><b>Thanks</b> for taking time to feedbacks demos ! We really appreciate it ;)</span><br /><br />';
  html += '<input type="text" name="email" value="email (optional)" style="width: 280px; border: 1px solid #707070; margin-bottom: 5px;" onfocus="if (!this.clicked) { this.clicked = true; this.value=\'\'; }" /><br />';
  html += '<textarea name="comment" style="border: 1px solid #707070; width: 280px; height: 80px;" onfocus="if (!this.clicked) { this.clicked = true; this.value=\'\'; }" >Comment..</textarea><br />';
  html += '<input style="margin-top: 4px;" type="submit" value="Submit !" id="ExaCommentSubmit" />';
  html += '<input style="margin-top: 4px; margin-left: 4px;" type="button" value="Close" onclick="document.body.ExaComment.style.display=\'none\';"/>';
  html += '<input type="hidden" name="site" value="'+document.location.href+'"/>';
  html += '</form>';
  comment.innerHTML = html;

  document.body.ExaComment = comment;
  document.body.appendChild(comment);
}

function showExalabsComment() {
  document.body.ExaComment.style.display = "block";
}

function ExaCommentThanks() {
  document.getElementById('ExaCommentSubmit').disabled = true;
  document.getElementById('ExaCommentSubmit').value = "Thank you !";
}

if (document.body) {
	addExalabsBar();
} else {
	window.onload = addExalabsBar;
}
