/* for field validation */
var inputs_list = ["p_name", "p_email", "p_phone", "p_company" ];
var email="p_email";

/* Configuring personneltody news */
var noOfStories=5;

/* End of configuration */

/* Some page settings */
  var links={
    "solutions" : [{"page":"enterprise", "text":"Enterprise"},{"page":"campaign", "text":"Campaign"}],
    "enterprise" : [{"page":"solutions", "text":"Solutions"},{"page":"campaign", "text":"Campaign"}],
    "campaign" : [{"page":"solutions", "text":"Solutions"},{"page":"enterprise", "text":"Enterprise"}]
  };

  if(pb_news==undefined)    var pb_news=[];
  if(pb_events==undefined)  var pb_events=[];
  if(stories==undefined)    var stories=[];

  var news = {
    "pb_feed" : pb_news,
    "pb_events" : pb_events,
    "personnel_feed" : stories
  }
/* End of settings */

function goPage(page,cgi_string){
 var ext=".html";
 if(cgi_string!=undefined) ext+="?"+cgi_string;
 window.location = "http://"+window.location.hostname+"/pb/pages/"+page+ext; 
}

function doScript(script, cgi_string){
  var cgi="";
  if(cgi_string!=undefined)cgi+="?"+cgi_string;
  window.location = "http://"+window.location.hostname+"/pb/cgi-bin/"+script+cgi;
}

function loadPage(page){
  showNews();
  if(page!=undefined && links[page]!=undefined) showLinks(page);

  if(typeof(window[page])=="function") window[page]();
  
  // Set the onclick events for the menus.
  setMenuEvents("main_menu");
  setMenuEvents("fixed_menu");
}

function showNews(){
  for(var src in news){
      var target=document.getElementById(src);
      if(target!=undefined){
          var showStories=noOfStories;
          if(showStories>=news[src].length) showStories=news[src].length;

          for(var i=0;i<showStories;i++){
              var link = document.createElement('a');
              link.className="news-item";
              if ( !news[src][i].url.match("peoplebank.com") ) {            
                link.target="blank";
              }
              link.href=news[src][i].url;
              link.innerHTML=news[src][i].headline;
              target.appendChild(link);
          }
      }
  }
}

function showLinks(page){
 if(links[page]!=undefined){
     var target=document.getElementById("page_menu");
     for(var i=0;i<links[page].length;i++){
         var link = document.createElement('a');
         link.className="quicklink-item";
         link.href="javascript:goPage('"+links[page][i].page+"')";
         link.innerHTML=links[page][i].text;
         target.appendChild(link);
     }
 } 
}

function setMenuEvents(el){
return ;
  var menuItems = document.getElementById(el).childNodes;

  for(var i=0;i<menuItems.length;i++){
    var item = menuItems[i];
    if(item.tagName=="DIV"){
     /* item.onmouseover=function(){this.style.backgroundImage="url(/pb/images/"+this.id+"-over.jpg)";}
      item.onmouseout=function(){this.style.backgroundImage="url(/pb/images/"+this.id+".jpg)";}
      item.onmousedown=function(){this.style.backgroundImage="url(/pb/images/"+this.id+"-over.jpg)";}
      item.onmouseup=function(){this.style.backgroundImage="url(/pb/images/"+this.id+".jpg)";}*/
    }
  }
}

function openEmailer(){
    window.open('http://peoplebank.com/php/home/index.php?action=helpdeskClient&subject=contactus', 'Contactus','scrollbars=yes');
}

function showMap(location){
  var img=document.getElementById("location_map");
  var current = img.loc;

  if(current==undefined) current="edinburgh";

  //show current img link.
  document.getElementById(current+"_map").style.display="";
  
  //hide clicked link.
  document.getElementById(location+"_map").style.display="none";

  //change the image.
  img.loc=location;
  img.src="/pb/images/"+location+".jpg";  
}

function checkFields(){
    var doSubmit=true;
    for(var i=0;i<inputs_list.length;i++){
        if(document.getElementById(inputs_list[i]).value==""){
            doSubmit=false;
            document.getElementById(inputs_list[i]).style.backgroundColor="#C2D8EF";
        }
        else document.getElementById(inputs_list[i]).style.backgroundColor="";
    }

    //Check if it's something that looks like an emailaddress!
    if(!document.getElementById(email).value.match(/@/)){
        doSubmit=false;
        document.getElementById(email).style.backgroundColor="#C2D8EF";
    }

    if(!doSubmit) alert("The form is not complete, not all required fields are filled in.");

    return doSubmit;
}

function showFeature(feature){
  for(var i=0;i<features.length;i++){
    document.getElementById(features[i]).style.display="none";
  }

  document.getElementById(feature).style.display="block";
}
