var last_item="none";
var years=""; var newthisweekloaded="no";
function by_country(int,item) {

 if ($(last_item)) { $(last_item).innerHTML=""; hide(last_item); }

 var country= int.split(','); var out="";
 for (i=0; i<country.length; i++) {
  var safeitem= item.replace('&','and1'); safeitem= safeitem.replace('+','and2');
   if (out!="") { out+= " &#8226; "; }
    out+="<a href=\"browsemag.php?mag="+safeitem+"&l="+country[i]+"\" onclick=\"embedBrowse(0); toIFrame(this); return cancel(0);\" target=\"totalviewer\" class=\"jL\">"+country[i]+"</a>"
 }
 last_item= item;
 show(item); $(item).innerHTML="<b>Pick Country: </b>" + out;
} 

function embedBrowse(obj,caller) { 
 if (obj==0) { hide('totalbrowser'); show('totalviewer'); }
  else if (obj==1) { hide('totalviewer'); show('totalbrowser'); }
 else { $(caller).src=obj+"&top=off"; GoTo('0'); }
}

function GoTo(what) {
 if (what=='0') { hide('newthisweek'); hide('letters'); show('magpersonal'); }
  else if (what=='1') { hide('newthisweek'); hide('magpersonal'); show('letters'); }
   else { hide('magpersonal'); hide('letters'); show('newthisweek'); }
   
 for (z=0; z<=2; z++) {
    if (z==what) { var tObj= 'tab'+z; $(tObj).className= "selActive"; }
      else { var tObj= 'tab'+z; $(tObj).className= "selpersonal"; } }
}

function aQ(what) { ajaxRequest('datacell','process-ajax_browseall.php?l='+what+'&ajax=yes'); }

function togDis(which) {
 if (which == '1') { hide('magpersonal'); show('letters'); }
  else { hide('newthisweek'); hide('letters'); show('magpersonal'); }
}

function showMagazine(what) {
  $(magpersonal).location.href="gallery.php?item_id="+what+"&top=off"; GoTo('0');
}

function togFilmNews(hit) {
  if (hit == 'none') { return false; }
  else if (hit == 'B') { hide('title_filmography'); show('title_newsfeed'); }
  else { 
    hide('title_newsfeed'); show('title_filmography'); 
    if ($('filmography').innerHTML=='loading...') { 
       var ids= "filmography"; p_qname= hit;
       var urls="test/IMDbFetch.example.php?imdb="+hit;
       ajaxRequest(ids,urls);
    }
  }
}

function ajaxGoLetter(call) {
var ids= "namelist";
var urls='process-ajax_browser_profile.php?first='+call;
ajaxRequest(ids,urls); hide('navbrowse');
} 
var p_qname;
function ajaxFill(call) {
var ids= "gallery"; // loadingImage('gallery');
p_qname= call;
var urls="process-ajax_browser_profile.php?person="+call;
ajaxRequest(ids,urls); GoTo('1');
}
function ajaxFillG(call,arg) {
 if ($('m_gallery')) { if ($('m_profile')) { hide('a_profile'); } show('m_gallery'); return false; }
 if (arg == 'insert') { var ids= "a_gallery"; } // loadingImage('a_gallery');
  else { var ids= "gallery"; $('gallery').innerHTML=""; }
p_qname= call;
var urls="process-ajax_browser_profile.php?person="+call+"&load="+arg; 
ajaxRequest(ids,urls); GoTo('1');
hide('a_profile');
}

function ajaxFillSort(call) {
 var ids= "a_gallery";
 var sorder= $('sortorder').value;
 p_qname= call;
var urls="process-ajax_browser_profile.php?person="+call+"&load=insert&sort="+sorder; 
ajaxRequest(ids,urls); GoTo('1');
hide('a_profile');
}

function ajaxFillA(call) {
  if (request_data == call) { GoTo('1'); hide('m_gallery'); show('a_profile'); return false; }
  request_data= call;
  $('linksweb').innerHTML=""; $('r').innerHTML="";
  $('wikiframe').style.display="none"; $('wikiframe').src="about:blank";
  newsfeed(); linksweb(); GoTo('1'); hide('m_gallery'); show('a_profile');
}

google.load("feeds", "1");
var request_data;
var hash = getUrlVars();
var feeds_checked=0;
var total_feeds=4;
var feed_count=0;

var linksites= ["wikipedia.org","askmen.com","movies.yahoo.com","people.com","mrskin.com","starpulse.com","nudography.com","celebritymoviearchive.com","whosdatedwho.com"];
var sites= [['',9],['site:tmz.com',3],['site:perezhilton.com',3],['site:starpulse.com',3],['site:egotastic.com',3],['site:holytaco.com',3]];

google.load('search', '1');

function newsfeed() {
  for (u=0; u<sites.length; u++) {
      var json_url= "http://blogsearch.google.com/blogsearch_feeds?order=date&output=rss&num="+sites[u][1]+"&q="+sites[u][0]+"+%22"+request_data+"%22";
      var feed = new google.feeds.Feed(json_url);
      feed.setNumEntries(sites[u][1]);
      feed.load(function(result) {
        if (!result.error) {
         if (result.feed.entries.length>0) { append_feeds(result.feed.entries); feed_check_count(); }
        }
      });
  } if (feed_count==0) { feed_check_count(); }
 feed_count=0; feeds_checked=0;
}

function linksweb() {
  for (u=0; u<linksites.length; u++) {
      var json_urlweb= "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&num=1&q=site:"+linksites[u]+"+intitle:%22"+request_data+"%22&callback=processResults&key=ABQIAAAAIO_wCyFpK4CJhDT8d9YmBBQXe0MSqcQT2SsjlBh1zqjz_vlrpBTHR2Rjo2xBpXpwo3ndqTJSXDrBLw";
      loadjs('gsearch'+u,json_urlweb);
  }
}

function processResults(t) {
 if (typeof(t.responseData.results[0])!=='undefined') {
   $('linksweb').innerHTML+= '<li><a target="_blank" href="'+t.responseData.results[0].url+'">'+t.responseData.results[0].visibleUrl+'</a></li>';
   if (t.responseData.results[0].url.indexOf('wikipedia.org') != -1) {
      $('wikiframe').src= t.responseData.results[0].url.replace('/wiki/','/w/index.php?title=')+'&printable=yes';
      $('wikiframe').style.display="block";
   }
 }
}

function  append_feeds(Entries) {
	var r = document.getElementById('r');
	for (var i = 0; i < Entries.length; i++)
    {
      var li = document.createElement('li');
      var a = document.createElement('a');
      a.setAttribute('target','_blank');
      var s = document.createElement('span');
      var output_string = "&nbsp;&nbsp;<b>("+Entries[i].publishedDate+")</b>";
      if(Entries[i].title) { if(Entries[i].title.length >100) { Entries[i].title=Entries[i].title.substring(0,100); } }
      a.href = Entries[i].link;
      a.innerHTML = Entries[i].title;
      s.innerHTML = output_string;
      li.appendChild(a);
      li.appendChild(s);
      r.appendChild(li);
      feed_count++;
    }
}

function feed_check_count(){
	feeds_checked++;
	if(feeds_checked>=total_feeds && feed_count<=0)	{
		var r = document.getElementById('r');
		var li = document.createElement('li');
		var s = document.createElement('span');
		s.innerHTML = "There is currently no news available...";
		li.appendChild(s);
		r.appendChild(li);
	}
}


function ajaxWorld(call) {
var ids= "namelist";
var urls="process-ajax_browser_profile.php?country="+call;
ajaxRequest(ids,urls); hide('navbrowse');
}
function ajaxGroups(call) {
var ids= "namelist";
var urls="process-ajax_browser_profile.php?group="+call;
ajaxRequest(ids,urls); hide('navbrowse');
}
function ajaxFillCat(call,txt) {
 if (call=="null") { return false; }
$('bCList').innerHTML= 'Please wait... Loading.';
var urls="process-ajax_browser_profile.php?category="+call;
$('bXList').innerHTML= txt;
ajaxRequest('bCList',urls);
} 

function ajaxWork(call) {
 if (call=="null") { return false; }
var ids= "namelist";
var urls="process-ajax_browser_profile.php?work="+call;
ajaxRequest(ids,urls); hide('navbrowse');
} 
function ajaxGoTo(call) {
var ids= "namelist";
var urls='hotlists.php?jid='+call;
ajaxRequest(ids,urls);
} 
function ajaxSelect(call) {
var ids= "gallery";
$('gallery').innerHTML="";
var urls="hotlists.php?id=viewall";
ajaxRequest(ids,urls); togDis('1');
}

var SwitchOnce="0";
function ViewContent() {
hide('personaldiv'); show('content');
}
function togPages() {
 if ($('personaldiv').style.display=="block") { hide('personaldiv'); show('content'); }
  else { hide('content'); show('personaldiv'); }
}

function ajaxMagBrowse(url) {
var ids="gallery";
 if (url=="") { url="process-ajax_browseall.php"; }
qStart= url.indexOf('?') == -1 ? "?" : "&";
var urls=url+qStart+"xmlembed=yes";
ajaxRequest(ids,urls);
}

function ajaxSearcher() {
$('gallery').innerHTML= xhr.responseText; 
GoTo('1');
}

function ajaxCurrent() {
$('content').innerHTML= "<div style=\"height:3em\"></div>" + xhr.responseText; 
hide('personaldiv'); show('content');
}

var ajaxCaller;
function ajaxForm(wForm,wPage,wMethod,wCallback) {
 xhr=XMLSupport();
  if (xhr) {
	var tForm= wForm
	var qString= buildPOST(tForm);
	if (wCallback=="ajaxSearcher") { xhr.onreadystatechange=ajaxSearcher; }
	 else if (wCallback=="ajaxCurrent") { xhr.onreadystatechange=ajaxCurrent; }
      xhr.open(wMethod,wPage,true);
      xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	    xhr.send(qString);
   }
} 

function ajaxGoHotlist(call) {
var ids= "namelist";
var urls='hotlists.php?jid='+call;
ajaxRequest(ids,urls);
} 

var bHeight, offLetters, offSwitch; var offTop=8;
function size2fit() {
if (document.body.clientHeight) { bHeight= document.body.clientHeight; }
  else if (window.innerHeight) { bHeight= window.innerHeight; }
     else { bHeight= 600; }

if ($('Topmenu')) { offTop= $('Topmenu').offsetHeight+2; }
offLetters=90;// offLetters= $('letters').offsetHeight+4;
// offSwitch=20;
// offSwitch= $('switch1').offsetHeight+2;
  $('mTable').style.height= bHeight;
  // $('mCell').style.height= bHeight-offTop;
  $('oCell').style.height= bHeight-offTop;
  $('magpersonal').style.height= bHeight-offTop;
  $('gallery').style.height= bHeight-offTop;
  $('newthisweek').style.height= bHeight-offTop;
  $('namelist').style.height= bHeight-(105+offTop);
  $('bCList').style.height= bHeight-(offTop+215);
  $('navsearch').style.height= bHeight-(offTop+47);
}