function showBookMarkLink(imgUrl)
{
  linkUrl = document.location;
  linkName = document.title;
  if (navigator.userAgent.indexOf('Safari') < 0)
      {document.write("<a title='Bookmark this page' onclick=\"bookmark('" + linkUrl + "','" + linkName + "')\"><img style='margin-right: 8px; cursor: pointer' src='" + imgUrl + "' /></a>");}
}

function bookmark(url,title){
  if ((navigator.appName == "Microsoft Internet Explorer") && (parseInt(navigator.appVersion) >= 4)) {
  window.external.AddFavorite(url,title);
  } else if (navigator.appName == "Netscape") {
    window.sidebar.addPanel(title,url,"");
  } else {
    alert("Press CTRL-D (Netscape) or CTRL-T (Opera) to bookmark");
  }
}

function popUpPage(url, parameters, name)
{
	//var day = new Date();
	//var pageName = name ? name : day.getTime();
    var pageName = 'send'
	//eval(pageName + " = window.open('" + url + "','" + pageName + "','" + parameters + "')");
	//if (eval(pageName) && window.focus) eval(pageName).focus();

    //if (sendWindow){
      //  sendWindow.focus()
    //}
    //else{
        sendWindow = window.open(url, pageName, parameters);
    //}
}


function validate_sendToFriend_form()
{
    error_message = "";

    user_email = strip(document.sendToFriend.user_email.value);
    user_name = strip(document.sendToFriend.user_name.value);
    friend_emails = strip(document.sendToFriend.friend_emails.value);

    if (user_email == "")
    {
        error_message += "Please enter your email address\r\n"
    }
    else if (!echeck(user_email))
    {
        error_message += "Your email address is not valid\r\n"    
    }

    if (user_name == "")
    {
        error_message += "Please enter your name\r\n"
    }

    if (friend_emails == "")
    {
        error_message += "Please enter your friend's email address\r\n"
    }
    else if (!check_multiple_emails(friend_emails))
    {
        error_message += "One or more of your friends email addresses is not valid\r\n"
    }

    if (error_message == "")
    {
        setTimeout('showSendingEmailMessage()', 100)
        return true;
    }
    else
    {
        alert(error_message);
        return false;
    }
}


function validate_addToList_form()
{
    error_message = "";

    first_name = strip(document.addToList.first_name.value);
    last_name = strip(document.addToList.last_name.value);
    email = strip(document.addToList.email.value);


    if (first_name == "")
    {
        error_message += "Please enter your first name\r\n"
    }

    if (last_name == "")
    {
        error_message += "Please enter your last name\r\n"
    }

    if (email == "")
    {
        error_message += "Please enter your email address\r\n"
    }
    else if (!echeck(email))
    {
        error_message += "Your email address is not valid\r\n"
    }

    if (error_message == "")
    {
        return true;
    }
    else
    {
        alert(error_message);
        return false;
    }
}


function showSendingEmailMessage(){
    document.getElementById('loading_img').style.display = 'inline';
document.getElementById('loading_message').innerHTML = '<blink>Sending email...</blink>'
}


function check_multiple_emails(emails)
{
   emails_array = emails.split(",");
   for (var i = 0; i < emails_array.length; i++)
   {
      //alert('*' + emails_array[i] + "*");
      if (!echeck(emails_array[i])){
          return false;
      }
   }
   return true;
}

function strip(string){
    return string.replace(/^\s*|\s*$/,"")
}

function echeck(str) {
    str = strip(str)
    var at="@"
    var dot="."
    var lat=str.indexOf(at)
    var lstr=str.length
    var ldot=str.indexOf(dot)
    if (str.indexOf(at)==-1){
       //alert("Invalid E-mail ID")
       return false
    }

    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
       //alert("Invalid E-mail ID")
       return false
    }

    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
        //alert("Invalid E-mail ID")
        return false
    }

     if (str.indexOf(at,(lat+1))!=-1){
        //alert("Invalid E-mail ID")
        return false
     }

     if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
        //alert("Invalid E-mail ID")
        return false
     }

     if (str.indexOf(dot,(lat+2))==-1){
        //alert("Invalid E-mail ID")
        return false
     }

     if (str.indexOf(" ")!=-1){
        //alert("Invalid E-mail ID")
        return false
     }

     if (str.indexOf(",")!=-1){
        //alert("Invalid E-mail ID")
        return false
     }

     return true
}


function setSelectedMenuTab(name){
  //resetTabs();
  tab = document.getElementById(name + '-tab');
  tab.style.backgroundImage = "url('/images/top-menu-tabs/top-menu-tab-" + name + "-selected.jpg')";
}
function resetTabs(){
  document.getElementById('home-tab').style.backgroundImage = "url('/images/top-menu-tabs/top-menu-tab-home.jpg')";
  document.getElementById('products-tab').style.backgroundImage = "url('/images/top-menu-tabs/top-menu-tab-products.jpg')";
  document.getElementById('learning-tab').style.backgroundImage = "url('/images/top-menu-tabs/top-menu-tab-learning.jpg')";
  document.getElementById('stories-tab').style.backgroundImage = "url('/images/top-menu-tabs/top-menu-tab-stories.jpg')";
  document.getElementById('store-tab').style.backgroundImage = "url('/images/top-menu-tabs/top-menu-tab-store.jpg')";
}
function setMenuTab(menu_name, tab_name){
  if (menu_name == 'product'){
    a = ['overview','details','usage','faq'];
    resetSubTabs(menu_name, a);
  }
  else if (menu_name == 'about'){
    a = ['mission','secure','quality'];
    resetSubTabs(menu_name, a);
  }
  else if (menu_name == 'affiliate'){
    a = ['overview','how_it_works','faq'];
    resetSubTabs(menu_name, a);
  }
  tabDiv = document.getElementById(menu_name + '-tab-' + tab_name);
  tabLinkDiv = document.getElementById(menu_name + '-tab-link-' + tab_name);

  tabDiv.style.display = 'block';
  tabLinkDiv.className = 'menu-tab-selected';
}

function resetSubTabs(menu_name, a){
  for (x=0; x < a.length; x++){
    tabDiv = document.getElementById(menu_name + '-tab-' + a[x]);
    tabLinkDiv = document.getElementById(menu_name + '-tab-link-' + a[x]);

    tabDiv.style.display = 'none';
    tabLinkDiv.className = 'menu-tab-not-selected';
  }
}
function resetAboutTabs(){
  document.getElementById('about-tab-mission').style.display = 'none';
  document.getElementById('about-tab-secure').style.display = 'none';
  document.getElementById('about-tab-quality').style.display = 'none';
}
