﻿function winOpen(url, chrome){
  window.open(url, "", chrome);
}

function getRef(id){
  return document.getElementById(id);
}

var currentlyShowing = "";

function showLayer(id){
  getRef(id).style.display = "block";
}

function hideLayer(id){
  getRef(id).style.display = "none";
  if(currentlyShowing == id)
    currentlyShowing = "";
}

function showLayerWithCheck(id){
  if(currentlyShowing != ""){
    hideLayer(currentlyShowing);
  }
  showLayer(id);
  currentlyShowing = id;
}

function hideLayerDelay(id){
  setTimeout("hideLayer('" + id + "')", 1500);
}

function login(){

  hideLayer("search-bar");
  showLayer("login-bar");
  for(var i=0; i<document.forms[0].elements.length; i++){
    if(document.forms[0].elements[i].type == "text"){
      if(document.forms[0].elements[i].name.toLowerCase().indexOf("username") > -1){
        document.forms[0].elements[i].focus();
        break;
      }
    }
  }
}

function search(){
  hideLayer("login-bar");
  showLayer("search-bar");
  for(var i=0; i<document.forms[0].elements.length; i++){
    if(document.forms[0].elements[i].type == "text"){
      if(document.forms[0].elements[i].name.toLowerCase().indexOf("search") > -1){
        document.forms[0].elements[i].focus();
        break;
      }
    }
  }
}

function enlargeProfileImg(url){
  if(url.indexOf(".gif") > -1){
    url = url.replace(".gif", "_l.gif");
  }
  else {
    url = url.replace(".jpg", "_l.jpg");
  }
  window.open("/global/en/members/team/image-viewer.aspx?img=" + url, "", "left=25,top=25,width=650,height=600,scrollbars=yes,resizable=yes");
}

function openHelp(url, categoryId, itemId){
  url = url + "members/help/frequently-asked-questions.aspx";
  if(categoryId != 0)
    url += "?categoryId=" + categoryId.toString();
  if(itemId != 0){
    if(categoryId != 0)
      url += "&";
    else
      url += "?";
    url += "questionId=" + itemId.toString();
  }
  winOpen(url, "left=0,top=50,width=780,height=500,status=yes,scrollbars=yes");
}