﻿function fnCompanyMembers()
{
  fnOpenWindow("/community/members/company.aspx", 640, 480, "yes", "yes");
}

function fnDecodeEmail(charCodes)
{
  var email = "";
  
  for(var i = 0; i < charCodes.length; i++)
  {
    email += String.fromCharCode(charCodes[i]);
  }
        
  document.write("<a href=\"mailto:" + email + "\">" + email + "</a>");
}

function fnDefaultButton(btn_id)
{
  var form = document.forms[0];
  var btn = $(btn_id);
  
  if (form && btn)
  {
	  form.onkeypress = function(e)
	  {
      // get event object (Firefox : IE)
      e = (e) ? e : window.event;

      // get key code (IE : FF)
	    var keyCode = (e.keyCode) ? e.keyCode : e.which;
	    
	    // get target (IE : FF)
	    var srcElement = (e.srcElement) ? e.srcElement : e.target;
	    
	    if (keyCode == 13 && srcElement.type != "textarea")
	    {
		    if (btn.type == "submit")
		    {
		      btn.click();
		    }
		    else
		    {
		      eval(btn.href);
		    }
	    }
	  }
  }
}

function fnDonationTotal(fields, label)
{
  var total = 0;
  var arrFields = fields.split(",");
  
  for(var i = 0; i < arrFields.length; i++)
  {
    total += Number(fnReplace(document.getElementById(arrFields[i]).value, ",", ""))
  }
  
  var lblTotal = document.getElementById(label);

  if(isNaN(total))
  {
    lblTotal.innerHTML = "<span style=\"color: red;\">Please enter valid amounts.</span>";
  }
  else
  {
    lblTotal.innerHTML = "$" + total.toFixed(2);
  }
}

function fnGetText(sender)
{
  if (sender.innerText)
  {
    return sender.innerText;
  }
  else
  {
    return sender.textContent;
  }
}

function fnSetText(sender, text)
{
  if (sender.innerText)
  {
    sender.innerText = text;
  }
  else
  {
    sender.textContent = text;
  }
}

function fnHover(obj, color)
{
  if (color == null) color = "";
  obj.style.backgroundColor = color;
  obj.style.cursor = "default";
}

function fnJobListingAmount(duration, label, price)
{
  var lblAmount = document.getElementById(label);
  lblAmount.innerHTML = "$" + Number(duration * price).toFixed(2);
}

function fnLoadVideo(file, id, width, height, preview)
{
  var flashvars = {};
  flashvars.file = file;
  
  if (preview)
  {
    flashvars.image = preview;
  }

  var params = {};
  params.allowfullscreen = 'true';
  params.allowscriptaccess = 'always';
  params.menu = 'false';
  params.wmode = 'transparent';

  swfobject.embedSWF('/js/jw-player/player-licensed.swf', id, width, height, '9.0.0', 'expressInstall.swf', flashvars, params);
}

function fnOpenWindow(url, w, h, sb, r, mb, tb, s, loc, dir)
{
  var screenWidth = window.screen.availWidth;
  var screenHeight = window.screen.availHeight;

  var offsetXWinXP = 5;
  var offsetYWinXP = 18;

  var halfScreenWidth = Number(window.screen.availWidth / 2);
  var halfScreenHeight = Number(window.screen.availHeight / 2);

  var halfWindowWidth = Number(w / 2);
  var halfWindowHeight = Number(h / 2);

  var diffWidth = Number(halfScreenWidth-halfWindowWidth);
  var diffHeight = Number(halfScreenHeight-halfWindowHeight);

  diffWidth -= offsetXWinXP;
  diffHeight -= offsetYWinXP;
  
  //The windowName is a zero-based integer corresponding to the number of milliseconds
  //since January 1, 1970, to the date specified by the instance of the Date object;
  //therefore, the windowName will almost always be unique.
  var dtm = new Date();
  var windowName = dtm.getTime();
  
  //if (url == null) { url = "" };
  if (w == null) { w = 640 };
  if (h == null) { h = 480 };
  if (sb == null) { sb = "no" };
  if (r == null) { r = "no" };
  if (mb == null) { mb = "no" };
  if (tb == null) { tb = "no" };
  if (s == null) { s = "no" };
  if (loc == null) { loc = "no" };
  if (dir == null) { dir = "no" };

  var features = "directories=" + dir + ",";
  features += "location=" + loc + ",";
  features += "menubar=" + mb + ",";
  features += "resizable=" + r + ",";
  features += "scrollbars=" + sb + ",";
  features += "status=" + s + ",";
  features += "toolbar=" + tb +",";
  features += "width=" + w + ",";
  features += "height=" + h + ",";
  features += "top=" + diffHeight + ",";
  features += "left=" + diffWidth;
  
  if (url != null && url != "")
  {
    return window.open(url, windowName, features);
  }
  else
  {
    alert("The url parameter is missing.");
    return;
  }
}

function fnReplace(string1, searchString, replaceString) {
	arrString = string1.split(searchString);
	string1 = arrString.join(replaceString);
	return string1;
}

function fnRollOver(id, img)
{
   if (navigator.appVersion.substring(0, 1) >= 3)
   {
      document.images[id].src = eval(img + ".src");
   }
}

function fnToggle(id)
{
  var obj = document.getElementById(id);
  obj.style.display = (obj.style.display == "none") ? "block" : "none";
}

function fnToggleAdvanced(sender, target)
{
  var obj = document.getElementById(target);
  obj.style.display = (obj.style.display == "none") ? "block" : "none";
  
  var text = fnGetText(sender);
  text = (obj.style.display == "none") ? fnReplace(text, "Hide", "Show") : fnReplace(text, "Show", "Hide");
  
  fnSetText(sender, text);
}
