////////////////////////////////////////////////////////
//						      //
//  This JavaScripts public the PageRank information  //
//  checkPR()					      //
//  getAlexa()					      //
//  changeRT(what, newValue)			      //
//  getPageRank()				      //
//  addPRcheck(pagerank, url)			      //
//						      //
////////////////////////////////////////////////////////

  // This global variables contains information about what pages to do a PR-check on and what is shown on Alexa
  var url1 = "http://www.google.com";
  var url2 = "";
  var url3 = "";
  var type = "r";
  var range = "6m";

// This is the main function, it collects information from the <input type='text' id='ur'>
// And then collects the urls from that information. After that it starts the functions 
// getAlexa() and getPageRank() to get those values. This function is run every time a user 
// submits a new url.
function checkPR()
{
  var urls = document.getElementById("url").value.split(",");
  url1 = "";
  url2 = "";
  url3 = "";
  for(var j_urls = 0; j_urls < urls.length; j_urls++)
  {
    if(j_urls == 0)
    {
      url1 = urls[0].replace(/ /gi, "");
    }
    else if(j_urls == 1)
    {
      url2 = " "+urls[1].replace(/ /gi, "");
    }
    else if(j_urls == 2)
    {
      url3 = " "+urls[2].replace(/ /gi, "");
      break;
    }
  }
  getAlexa();
  getPageRank();
  
  move_start("prchecker");  // this brings the result page to the top (see manu.js for mor information)
  return false;
}

// This function do just get a new Alexa graph thru a <iframe>
function getAlexa()
{
  frames["alexa"].location.href = "alexa.php?url1="+url1+"&url2="+url2+"&url3="+url3+"&type="+type+"&range="+range;
}

// Change Range, Type this function changes the values on the variables type and range
// And then calls upon getAlexa() to get a new Alexa graph
function changeRT(what, newValue)
{
  if(what == "type")
  {
    type = newValue;
  }
  else if(what == "range")
  {
    range = newValue;
  }
  getAlexa();
}

// This is the main PageRank function. It can make up to three PageRank checks by usin the function addPRcheck()
function getPageRank()
{
  var pagerank = "<center>";
  
  if((url1 != "") && (url1 != "http://"))
  {
    pagerank = addPRcheck(pagerank, url1);
    document.getElementById("prchecker_img").src = "pic/prchecker1.gif";
  }
  if((url2 != "") && (url2 != "http://"))
  {
    pagerank = addPRcheck(pagerank, url2);
    document.getElementById("prchecker_img").src = "pic/prchecker2.gif";
  }
  if((url3 != "") && (url3 != "http://"))
  {
    pagerank = addPRcheck(pagerank, url3);
    document.getElementById("prchecker_img").src = "pic/prchecker3.gif";
  }
  
  pagerank = pagerank+"</center>";
  
  document.getElementById("pagerank").innerHTML = pagerank;
}

// This function adds a PageRank code. The PageRank value is generated by a php-script but 
// this function adds the HTML-code that calls upon the php-script
function addPRcheck(pagerank, url)
{
  pagerank = pagerank+"	<span class='smaller'><br /><br /></span>";
  pagerank = pagerank+"	<div class='lightbox2'>";
  pagerank = pagerank+"	  <div class='text prURL'>"+url+"</div>";
  pagerank = pagerank+"	  <img src='pagerank.php?url="+url+"' border='0' alt='PageRank results for "+url+"' class='pr_img' /><br />";
  pagerank = pagerank+"	</div>";
  
  return pagerank;
}