  function isValidEmail(str) {
       return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
    }

   

/* Tooltips */

addLoadListener(initTooltips);

function initTooltips()
{
  var imageArrays = getElementsByAttribute("class", "imageArray");

  for (var i = 0; i < imageArrays.length; i++)
  {
	var theimages = imageArrays[i].getElementsByTagName("img");
  for (var j = 0; j < theimages.length; j++)
  {
    attachEventListener(theimages[j], "mouseover", showTip, false);
   attachEventListener(theimages[j], "mouseout", hideTip, false);
   attachEventListener(theimages[j], "click", hideTip, false);   
   attachEventListener(theimages[j], "mousemove", moveTip, false);
  }

}
  return true;
}

var ALREADY_SET = false;
function showTip(event)
{
	if(ALREADY_SET) return;

  if (typeof event == "undefined")
  {
    event = window.event;
  }

  var target = getEventTarget(event);

  /*while (target.getTagName() !="img")
  {
    target = target.parentNode;
  }*/

  var tip = document.createElement("div");
  var content = target.getAttribute("alt");

	if(content=="" || content==null) return;

  target.tooltip = tip;
  target.oldtile = target.getAttribute("alt");

  target.setAttribute("title", "");

  if (target.getAttribute("id") != "")
  {
    tip.setAttribute("id", target.getAttribute("id") + "tooltip");
  }

  tip.className = "tooltip";

  content = content.replace(/&lt;/g,"<");
  content = content.replace(/&gt;/g,">");
  content = content.replace(/%/g,"/");

if(content.substr(0,2)=="--")
{
	content = content.substring(2,content.length);
}
else
{
  if (content.indexOf(" - ") == -1) {
        content = "<b>" + content + "</b>";
    } else {
        content = "<b>" + content.replace(" - ", "</b><br />");
    }
}

  tip.innerHTML = content;

  var scrollingPosition = getScrollingPosition();
  var cursorPosition = [0, 0];

  if (typeof event.pageX != "undefined" && typeof event.x != "undefined")
  {
    cursorPosition[0] = event.pageX;
    cursorPosition[1] = event.pageY;
  }
  else
  {
    cursorPosition[0] = event.clientX + scrollingPosition[0];
    cursorPosition[1] = event.clientY + scrollingPosition[1];
  }

  tip.style.position = "absolute";
  tip.style.left = cursorPosition[0] + 10 + "px";
  tip.style.top = cursorPosition[1] + 10 + "px";
  document.getElementsByTagName("body")[0].appendChild(tip);
  ALREADY_SET = true;

  return true;
}

function hideTip(event)
{
  if (typeof event == "undefined")
  {
    event = window.event;
  }

  var target = getEventTarget(event);

  if (target.tooltip != null)
  {
    target.setAttribute("title", target.tooltip.childNodes[0].nodeValue);
    target.tooltip.parentNode.removeChild(target.tooltip);
  }

  ALREADY_SET = false;

  return true;
}

function moveTip(event)
{
  if (typeof event == "undefined")
  {
    event = window.event;
  }

  var target = getEventTarget(event);

  if (target.tooltip != null)
  {
  var scrollingPosition = getScrollingPosition();
  var cursorPosition = [0, 0];

  if (typeof event.pageX != "undefined" && typeof event.x != "undefined")
  {
    cursorPosition[0] = event.pageX;
    cursorPosition[1] = event.pageY;
  }
  else
  {
    cursorPosition[0] = event.clientX + scrollingPosition[0];
    cursorPosition[1] = event.clientY + scrollingPosition[1];
  }

  target.tooltip.style.left = cursorPosition[0] + 10 + "px";
  target.tooltip.style.top = cursorPosition[1] + 10 + "px";


  }

  return false;
}



/* show recent section */

function ShowRecent(num) {
for (i = 1; i < 4; i++) {
if (i == num) {
document.getElementById("recentArray" + i).style.display = "block";
document.getElementById("recentArrayLink" + i).style.visibility = "hidden";
} else {
document.getElementById("recentArray" + i).style.display = "none";
document.getElementById("recentArrayLink" + i).style.visibility = "visible";
}

}
return false;
}

    function op_jump(objSelect)
    {
        if (objSelect.selectedIndex<=0) return false; 
        var objOpt = objSelect.options[objSelect.selectedIndex]; 
        window.location.href=objOpt.value;
    }
    
    function isValidEmail(str) {
       return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
    }

    function Subscribe() {
        var tb = document.getElementById("txtSubscribeEmail");
       // var status = document.getElementById("imgNewsFooter");
        var email = tb.value;
        
        document.getElementById("divSubscribed").style.display = 'none';
        document.getElementById("divInvalid").style.display = 'none';
        if (!isValidEmail(email))
        {
            document.getElementById("divInvalid").style.display = 'block';
        }   
        else
        {        
            if (email.length > 0) {
               
                AjaxRequest.post(
                    {
                        'url':          '/services/subscribe_to_newsletter.ashx', 
                        'email':        email,
                        'onSuccess':    function(req) {
                                            document.getElementById("txtSubscribeEmail").value = "";
                                            if (req.responseText == "0") {
                                                document.getElementById("divSubscribed").style.display = 'block';
                                            } else {
                                                alert("Ajax error!"); 
                                            }
                                        },
                        'onError':      function(req) { alert("Ajax error!"); }
                    }
                );
            }
        }
    }
