var domain='http://www.mathbuntu.org';
var monthString=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];

function doctorURL(url) {
  var sep = (-1 < url.indexOf("?") ? "&" : "?");
  return [url,sep,"__=",encodeURIComponent((new Date()).getTime())].join('');
}

function getXmlHttpObject(){
  var xmlHttp=null;
  try { // Firefox, Opera 8.0+, Safari
    xmlHttp=new XMLHttpRequest();
  } catch (e) { //Internet Explorer
    try {
      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
  }
  if (xmlHttp==null) {
    alert ("Browser does not support HTTP Request.\nCan not continue.");
  }
  return xmlHttp;
}

function stripslashes( str ) {
    return (str+'').replace(/\0/g, '0').replace(/\\([\\'"])/g, '$1');
}

function parseDownloadString(res) {
  var i,ind,listArray,firstMonth,lastMonth,firstYear,lastYear,tableCode,count,year,month,monthDisplay;
  tableCode='<table border="2" cellpadding="2" cellspacing="2">';
  listArray=res.split(',');
  firstYear=getYear(listArray[1]);
  firstMonth=getMonth(listArray[1]);
  lastYear=getYear(listArray[3]);
  lastMonth=getMonth(listArray[3]);
  count = new Array(1 + 12*(lastYear-firstYear) + lastMonth-firstMonth);
  for(i=0;i<count.length;i++) count[i]=0;
  for(i=4;i<listArray.length;i++) {
    year=getYear(listArray[i]);
    month=getMonth(listArray[i]);
    ind=12*(year-firstYear)+month-firstMonth;
    count[ind]=count[ind]+1;
  }
  for(i=0;i<count.length;i++) {
    if (i%4==0) tableCode=[tableCode,'<tr>'].join('');
    tableCode=[tableCode,'<td>',Math.floor((firstMonth+i-1)/12+firstYear),'-',monthString[(firstMonth-1+i)%12],'</td>','<td>',count[i],'</td>'].join('');
    if (i%4==3) tableCode=[tableCode,'</tr>'].join('');
  }
  tableCode+='</table>';
  return tableCode;
}

function getYear(datetime) {
  var dateTimeArray=datetime.split(" ");
  var dateArray=dateTimeArray[0].split("-");
  return parseInt(dateArray[0]);
}

function getMonth(datetime) {
  var dateTimeArray=datetime.split(" ");
  var dateArray=dateTimeArray[0].split("-");
  return parseInt(dateArray[1]);
}

String.prototype.endsWith = function(str)
{return (this.match(str+"$")==str)}
