// Place your application-specific JavaScript functions and classes here
// This file is automatically included by javascript_include_tag :defaults

var ReqallUserMessages = {
contacts_delete : "Are you sure you want to delete the selected contact(s)?",
contacts_delete_unselect : "Please select at least one contact to delete.",
post_delete_recurrence: "Would you like to permanently delete this item and all its occurrences?",
post_delete_non_recurrence: "Would you like to delete this item permanently?",
email_content_blank: "Email message can't be blank."
};
var txthash =  new Hash();
txthash['results_text_input'] = "What do you want to add for yourself or someone else?";
txthash['add_term'] = "What do you want to add for yourself or someone else?";
txthash['delegate_term'] = "What do you want to add for someone else?";
txthash['search_term'] = "What do you want to find?";
txthash['search_term1'] = "What do you want to find?";
txthash['add_term1'] = "What do you want to add for yourself or someone else?";
txthash['adds_terms1'] = "What would you like to share?";
//var allow_to_add_post = 'yes';

function check_field_empty(term){
  var a=check_prototype();
   if (a!=false)
   { 
     val = txthash[term];
     if($(term)){
       if($(term).value == val){
          if(term  == "search_term1" || term == "add_term1" || term == "adds_terms1"){
            alert("Please enter some text first");
          }else{
            $(term).value = '';
            $(term).className = "reqall"
            $(term).focus();
          }  
           return false;
       }else{
         check_prototype();
         if($(term).value.strip() == ''){
           alert("Please enter some text first");
           return false;
         }        
       }
     }else{
       return false;
     }
     if($(term).value.length > 2000){
         alert("Text cannot exceed 2000 characters");
         return false; 
        }
     else{
    // allow_to_add_post = 'no';
      }
     return true;
   } else 
   return false;
}

function clear_field(val,type){
  obj = $(val);
  if(obj){
    switch(type){
      case 0:
      if(obj.value == txthash[val])
      obj.value = '';
      obj.className = "reqall"
      break;
      case 1:     
      if(obj.value == '')
      obj.value = txthash[val];
      break;
      case 2:
      if(obj.value == txthash[val])
      obj.value = '';
      obj.className = "reqall_top_search"
      break;
      case 3:
      if(obj.value == txthash[val])
      obj.value = '';
      obj.className = "share_reqall"
      break;
    }
  }
}

function navigateTodo(id) {  check_prototype();
  //alert(id);
  new Ajax.Request('/webnew/displaytodos/'+id, {asynchronous:true, evalScripts:true}); return false; 
}

function navigateSort(id) {  check_prototype();
 //alert(id);
  if(id == '34' || id == '33')
    document.location.href = '/webnew/displaymemoryjog/'+id
  else
    document.location.href='/webnew/displaysort/'+id
  }

function showall(){
  document.location.href='/webnew/displayall'
  }

function validInt(str,fieldval)
{
  return inValidCharSet(str,"0123456789",fieldval);
}
function Trim(s)
{
  while(s.charAt(0)==' ')
  {
    s=s.substring(1,s.length);
  }
  return s;
}

function inValidCharSet(str,charset,fieldval)
{
  var result = true;

  // Note: doesn't use regular expressions to avoid early Mac browser bugs
  for (var i=0;i<str.length;i++)
  if (charset.indexOf(str.substr(i,1))<0)
  {
    alert("Please enter a numeric value in "+ fieldval);
    result = false;
    break;
  }

  return result;
}

function changeCountryCode(index){ 
   $("countrycode_" + index).innerHTML = '+' + $("country_"+index).options[$("country_"+index).selectedIndex].value;
}

  function changeCountryCodeNew(index){
    $("countrycode_" + index).innerHTML = '+' + countrycodes[$("country_"+index).options[$("country_"+index).selectedIndex].value];
  }


function changeCountryName1(countryid) { 
  var y = $("account_timezone");
  var timezzone = countrytimezone[$(countryid).options[$(countryid).selectedIndex].value];
  for (i = 0; i < y.length; i++) {
    if(y.options[i].value == timezzone) {
      y.options[i].selected = "selected";
    }  
  }   
} 
 
function saveselectedalbum(name,id){
  document.profile.action = "/webnew/selectedalbum?name=" + name + "&id=" + id;
  document.profile.submit();  
} 

function savegoogleinfo(){ 
  accessid = Trim($('im_accessid').value);
  if(accessid == '') {
    alert("Please enter your Google email ID");
  } else {
    document.profile.action="/webnew/google_process?do_register=true&im_accessid="+accessid;
    document.profile.submit();
  }
} 
 
function choosecontacts(){
  showPopWin("/webnew/delegation_contacts", 480, 320, null);
}

function displaynewdelegation(url){
  document.location.href = url;
}

function searchAll(id){
  document.location.href = "/webnew/searchposts/" + id;
}

function changetextim(value,address) { 
  if($('imaddress').options[$('imaddress').selectedIndex].value == address) {
    $('imvalue').value=value;
  } else {
    $('imvalue').value='';
  }
} 

function check_prototype()
 {
    if (typeof Prototype == 'undefined'){
   alert("One or more javascript file(s) required for this page to function properly seem to have not loaded properly. Please refresh the page.");
   return false;}
   
  
}

function loadEventHandler() {
  setnavlinks();
  set_edit_post_links();
  set_web_edit_css();
  initPopUp();
  initialize_slider();
}

function handleEnter(field, event) {
  var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
  if (keyCode == 13) {
   switch(field.form.id){
    case 'login_form':
     accessid = ($('accessid')) ? $('accessid').value : '';
     passwd = ($('password')) ? $('password').value : '';
     if(accessid != '' && passwd != ''){
      field.form.submit();
     }
    break;
    case 'registration':
     chkobj = $("terms_accept")
     if(chkobj){
      if(chkobj.checked && !bSubmitted){
        field.form.submit();
        bSubmitted = true;
      }
     }
    break;
   }
  }else{
    return true;
  }
}

function closeHelp(){
 dropmenuobj.style.visibility='hidden'; 
 dropmenuobj.style.left=0; 
}
