// JavaScript Document
// addbookmark ---------------------------------

function addbookmark(aTitle, aURL){
   if (!aTitle) {
       aTitle = document.title; //encodeURIComponent(document.title)
   }

   if (!aURL) {
       aURL = location.href; //encodeURIComponent(location.href)
   }

   if (window.sidebar) {
       // Gecko family
       window.sidebar.addPanel(aTitle, aURL, '');
   } else if (window.external) {
       // Trident & Tasman family
       window.external.AddFavorite(aURL, aTitle);
   } else if (window.opera) {
       if (window.print) {
           // Presto family
           return true;
       } else {
           // Elektra family
           var link = document.createElement('a');
               link.setAttribute('rel', 'sidebar');
               link.setAttribute('href', aURL);
               link.setAttribute('title', aTitle);
               link.click();
               document.removeElement(link);
       }
   } else {
       // Other engines
       alert('Configure sua mensagem aqui :)');
   }
}
/*
function addBookmark(title,url){
  if (window.sidebar) { window.sidebar.addPanel(title, url, ""); }
  else if( document.all ) { window.external.AddFavorite( url, title); }
  else if( window.opera && window.print ) { return true; }
}
*/

/* set home page */
setHome = function(obj){
 if(document.all)
 {
  obj.style.behavior='url(#default#homepage)';
  obj.setHomePage('http://www.realnobile.com');
  return false;
 }
 return true;
}

function toggle(id, newValue) {
 element=document.getElementById(id);
 element.style.display=newValue;
}


function activateField(default_text, input_id) {
 inputbox=document.getElementById(input_id);
 if (inputbox.value==default_text) {
  inputbox.value='';
  inputbox.style.color='#000';
 }

}


function email_file(file_id, secret_code) {

    // Validar os emails.
 if (document.getElementById('email_to_input_' + file_id).value == "" ) {
  alert('Por favor, informe seu e-Mail.');
  return;
    }
    else if (document.getElementById('email_to_input_' + file_id).value.match(/(\w+)@(.+)\.(\w+)$/) == null){
        alert('Endereço de e-Mail inválido.');
  return;
    }


    emails = document.getElementById('email_to_input_' + file_id).value;

 new Ajax.Updater('','http://www.realnobile.com/contato.html',{ 'method':'post' , 'parameters': 'f=' + file_id + '&s=' + secret_code + '&emails=' + emails, 'onSuccess':function(request){ email_success(request, file_id); }, 'onFailure':function(request, file_id){ alert(request.responseText); } } );
}

function email_success(request, file_id) {
 response = request.responseText;
 toggle('email_to_form_' + file_id,'none');
 toggle('email_to_response_' + file_id,'block');
 document.getElementById('email_to_response_text_' + file_id).innerHTML = response;
}

function refresh_email(file_id) {
 document.getElementById('email_to_input_' + file_id).value='';
 toggle('email_to_form_' + file_id,'block');
 toggle('email_to_response_' + file_id,'none');
 document.getElementById('email_to_input_' + file_id).focus();
}

// addboomark end -----------------

// addLoadEvent --------------------
// addLoadEvent end --------------------

// sendContact ------------------------
function sendContact(msg){
/* window.name = escape(msg);window.location = "http://www.realnobile.com/contato.html";*/
document.contato.contato.value = msg;
document.contato.submit();
}
// sendContact end ---------------------


// menu default highlight ------------------------
function extractPageName(hrefString){
 var arr = hrefString.split('/');
 return  (arr.length<2) ? hrefString : arr[arr.length-2].toLowerCase() + arr[arr.length-1].toLowerCase();
}

function setActiveMenu(arr, crtPage){
 for (var i=0; i<arr.length; i++)
 {
  if(extractPageName(arr[i].href) == crtPage)
  {
    arr[i].className = "current";
  }
 }
}

function setPage(){
 hrefString = document.location.href ? document.location.href : document.location;
 if (document.getElementById("nav-option")!=null) setActiveMenu(document.getElementById("nav-option").getElementsByTagName("a"), extractPageName(hrefString));
}

//window.onload=function(){
// setPage();
//}

// menu default highlight end ---------------------
