var cookiePath = window.cookiePath || "/";
function publishreport(rep){
  popup("/reports/publish.previews.new.php?publishcode="+rep);
}

function popup(url,wid,hei,res,windowname) {
  if(isNaN(parseInt(wid)))wid=480
  if(isNaN(parseInt(hei)))hei=400
  if (!res) res='yes'
  if (!windowname) windowname='new'
  wind = open(url, windowname, "width="+wid+",height="+hei+",status=no,toolbar=no,menubar=no,scrollbars=yes,screenX=10,screenY=10,resizable="+res);
}
function outlink(dir,page,text,clas,target) {
  show = "<a href='http://"
  show += dir
  if(page.substr(0,1)!="/")show += "/"
  show += page
  show += "'"
  if (clas) {show += " class='" + clas + "'"}
  if (target) {show += " target='" + target + "'"}
  show += ">"
  show += text
  show += "</a>"
  document.write(show);
}

function outmail(name,host,text,clas,target) {
  show = "<a href='mailto:";
  show += name;
  show += "@";
  show += host;
  show += "'";
  if (clas) 
  {
  show += " class='" + clas + "'";
  }
  if (target) 
  {
  show += " target='" + target + "'";
  }
  show += ">";
  if (text!=undefined && text.length)
  {  
    show += text;
  }
  else 
  {
  show+=name+"@"+host;
  }

  show += "</a>"
  document.write(show);
}

// for show/hide target details table
function setit(value){
if (value==1) {document.cookie="hidedetailstable=1";}
else {document.cookie="hidedetailstable=0";}
}
function showHideTable(section) {
sect = eval("document.getElementById('longtable').style.display");
if (sect != 'block') {
eval("document.getElementById('shorttable').style.display = 'none'");
eval("document.getElementById('longtable').style.display = 'block'");
eval("document.getElementById('showhidelink').innerHTML  = '<a href=\"javascript:showHideTable();\">hide</a>'");
document.cookie="hidedetailstable=0;path=/";
} else {
eval("document.getElementById('longtable').style.display = 'none'");
eval("document.getElementById('shorttable').style.display = 'block'");
eval("document.getElementById('showhidelink').innerHTML  = '<a href=\"javascript:showHideTable();\">expand</a>'");
document.cookie="hidedetailstable=1;path=/";
}
}
// for show/hide target details table

function showHideCurStat(section) {
sect = eval("document.getElementById(\"" + section + "\").style.display");
if (sect != 'block') {
eval("document.getElementById(\"" + section + "\").style.display = 'block'");
}
else {
eval("document.getElementById(\"" + section + "\").style.display = 'none'");
}
}

function recorder(url,wid,hei) {
wind = open(url, 'recorder', 'width=800,height=600,resize=yes,resizable=yes,status=no,toolbar=no,menubar=no,scrollbars=yes,screenX=10,screenY=10');
}

function initOverLabels () {
if (!document.getElementById) return;

var labels, id, field;

labels = document.getElementsByTagName('label');
for (var i = 0; i < labels.length; i++) {

if (labels[i].className == 'overlabel') {

id = labels[i].htmlFor || labels[i].getAttribute('for');
if (!id || !(field = document.getElementById(id))) {
continue;
}
field.className='resized';
labels[i].className = 'overlabel-apply';
if (field.value !== '') {
hideLabel(field.getAttribute('id'), true);
}
field.onfocus = function () {
hideLabel(this.getAttribute('id'), true);
};
field.onblur = function () {
if (this.value === '') {
hideLabel(this.getAttribute('id'), false);
}
};
labels[i].onclick = function () {
var id, field;
id = this.getAttribute('for');
if (id && (field = document.getElementById(id))) {
field.focus();
}
};
}
}
};

function hideLabel (field_id, hide) {
var field_for;
var labels = document.getElementsByTagName('label');
for (var i = 0; i < labels.length; i++) {
field_for = labels[i].htmlFor || labels[i].getAttribute('for');
if (field_for == field_id) {
labels[i].style.textIndent = (hide) ? '-9999px':'0px';
return true;
}
}
}

function leadingZero(nr){
  if (nr < 10) nr = "0" + nr;
  return nr;
}
function takeYear(theDate){
  x = theDate.getYear();
  var y = x % 100;
  y += (y < 38) ? 2000 : 1900;
  return y;
}

var pumpittimeout;

function pumpit(addsec){
  var oldsec=thetime.getSeconds();
  thetime.setSeconds(oldsec+addsec,0);
  var Year = takeYear(thetime);
  var Month = leadingZero(thetime.getMonth()+1);
  var Day = leadingZero(thetime.getDate());
  var Hours = leadingZero(thetime.getHours());
  var Minutes = leadingZero(thetime.getMinutes());
  var sectime=thetime.getSeconds();
  var Seconds = leadingZero(sectime);
  
  if (!DFORMAT) DFORMAT="Month+'/'+Day+'/'+Year";
  var str=eval(DFORMAT)+' '+Hours;
  
  if (sectime%2){
    str+='<span style="color:#ffffff;">:</span>';
  } 
  else {
    str+=':';
  }
  str+= Minutes;
  if (document.getElementById('stime')){
    document.getElementById('stime').innerHTML=str;
    pumpittimeout=setTimeout('pumpit(1)',1000);
  }
}

function onoff(id,value,dstyle) {
  d = document.getElementById(id);
  if (dstyle==undefined) {
    dstyle='block';
  }
//  alert('doing (\''+id+'\','+value+','+dstyle+')');
  if (value!=undefined) {
    if (value){
      d.style.display = dstyle;
    } else {
      d.style.display = 'none';
    }
  } else {
    if (d.style.display!="none"){
      d.style.display='none';
    } else {
      d.style.display=dstyle;    
    }
  }
}

function numInRange(check,rettrue,retfalse,minval,maxval){
  if(minval==undefined) minval=0;
  if(maxval==undefined) maxval=99;
  if(rettrue==undefined) rettrue=0;
  if(retfalse==undefined) retfalse=1;
  if ((check.search(/[^0-9]/)==-1)&& check.length && check>=minval && check<=maxval) return rettrue;
  else return retfalse;
}

function getElementsByClassName(className, tag, elm){
  var testClass = new RegExp("(^|\\s)" + className + "(\\s|$)");
  var tag = tag || "*";
  var elm = elm || document;
  var elements = (tag == "*" && elm.all)? elm.all : elm.getElementsByTagName(tag);
  var returnElements = [];
  var current;
  var length = elements.length;
  for(var i=0; i<length; i++){
    current = elements[i];
    if(testClass.test(current.className)){
      returnElements.push(current);
    }
  }
  return returnElements;
}

function ge(id){
  return document.getElementById(id);
}

function ajaxGet(targetelement,requesturl){
  var xmlHttp = createXmlHttpRequestObject();
  if (xmlHttp){
    try{
      xmlHttp.open("GET", requesturl, true);
      xmlHttp.onreadystatechange = function(){
        if (xmlHttp.readyState == 4){
          if (xmlHttp.status == 200){
            try {
              targetelement.innerHTML=xmlHttp.responseText;
            }
            catch(e) {
              alert("Error reading the response: " + e.toString());
            }
          } else {
            alert("There was a problem retrieving the data:\n" + xmlHttp.statusText);
          }
        }
        else {
          targetelement.innerHTML = '<img align=center src="/img/wait20trans.gif" width=20 height=20 border="0">';
        }
      };
      xmlHttp.send(null);
    }
    catch (e){
      alert("Can't connect to server:\n" + e.toString());
    }
    delete xmlHttp;
  }
}

function createXmlHttpRequestObject(){
  var xmlHttp;
  try{xmlHttp = new XMLHttpRequest();}
  catch(e){
    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP");
    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++){
      try { xmlHttp = new ActiveXObject(XmlHttpVersions[i]);}
      catch (e) {}
    }
  }
  if (!xmlHttp) alert("Error creating the XMLHttpRequest object.");
  else return xmlHttp;
}

// cookie handling functions
function createCookie(name,value,days) {
  if (days) {
  var date = new Date();
  date.setTime(date.getTime()+(days*24*60*60*1000));
  var expires = "; expires="+date.toGMTString();
  }
  else var expires = "";
  document.cookie = name+"="+value+expires+"; path="+cookiePath;
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
  var c = ca[i];
  while (c.charAt(0)==' ') c = c.substring(1,c.length);
  if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

function eraseCookie(name) {
  createCookie(name,"",-1);
}

function ol(address) {
    var src=new String(address) ;
    var dst=new String('') ;
    var len=src.length ;
    var b ;
    var t=new String('') ;
    if(len > 0)
    {
      for(var ctr=0; ctr<len ; ctr++)
      {
        b=src.charCodeAt(ctr)
        if( ( (b>64) && (b<78) ) || ( (b>96) && (b<110) ) )
        { b=b+13 }
        else
        { 
          if( ( (b>77) && (b<91) ) || ( (b>109) && (b<123) ) )
          { b=b-13 }
        }
      t=String.fromCharCode(b) ;
      dst=dst.concat(t) ;
    }
  }
  show = "<a href='";
  show += dst;
  show += "'";
  show += " target='_blank'";
  show += ">";
  //  show += dst;
  //  show += "</a>";
  document.write(show);
}
function olc() { document.write('</a>'); }

function setSugg(chk) {
  var tbform = document.commentform;
  var cs = document.getElementById("commentSubmit");

  if (chk.checked) {
    //modify talk back form
    tbform.action="/support/suggnew.php?preview=1";
    cs.onclick=function() { document.commentform.submit(); return false; };
  }
  else {
    //restore talkback form
    tbform.action="";
    cs.onclick=feedbackSubmit;
  }
}


function feedbackSubmit(){  
  var s=document.getElementById('commentform');
  var ss=document.getElementById('sendcommentstatus');
  var dc = "";
  if (s.dash) var rl = s.dash.length;
  if(rl == undefined){
    if(s.dash && s.dash.checked) dc = s.dash.value;
  } else {
    for(var i = 0; i < rl; i++) {
      if(s.dash && s.dash[i].checked) {
        dc = s.dash[i].value;
      }
    }
  }


  if ((!s.feedbackcomment.value && !dc) || (s.feedbackcomment.value=="Please, share your opinion, suggestions and comments with us." && !dc)){
    return;
  }


  if (xmlHttp=createXmlHttpRequestObject())
  {
    try
    {
      xmlHttp.onreadystatechange =  function(){
        if (xmlHttp.readyState > 0 && xmlHttp.readyState < 4){
          ss.innerHTML = "Submitting data...<br/>";
          s.style.display='none';
        } else if (xmlHttp.readyState == 4){
          if (xmlHttp.status == 200) {
            try{
              response = xmlHttp.responseText;
              if (response=="OK"){
                s.style.display='none';
                ss.style.color = "black";
                ss.innerHTML =  "<br><b>Thank you</b>, <br>from the hard-working team at WebSitePulse.<br><br>";
              } else {
                ss.innerHTML = "<br><b>Error:</b><br>" + response;
                ss.style.color = "red";
                s.style.display='block';
              }
            }
            catch(e){
              alert("Error reading the response: " + e.toString());
            }
          } else {
            alert("There was a problem retrieving the data:\n" + xmlHttp.statusText);
          }
        }
      }
      var values="feedbackcomment="+encodeURIComponent(s.feedbackcomment.value)+
      "&dash="+dc+
      "&pageid="+s.pageid.value;

      xmlHttp.open("POST", "/monitor/email.php", true);
      xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
      xmlHttp.setRequestHeader("Content-length", values.length);
      xmlHttp.setRequestHeader("Connection", "close");
      xmlHttp.send(values);
    }
    catch (e)
    {
      alert("Can't connect to server:\n" + e.toString());
    }
  }
}

function createXmlHttpRequestObject() 
{
  var xmlHttp;
  try
  {
    xmlHttp = new XMLHttpRequest();
  }
  catch(e)
  {
    var XmlHttpVersions = new Array("MSXML2.XMLHTTP.6.0",
                                    "MSXML2.XMLHTTP.5.0",
                                    "MSXML2.XMLHTTP.4.0",
                                    "MSXML2.XMLHTTP.3.0",
                                    "MSXML2.XMLHTTP",
                                    "Microsoft.XMLHTTP");
    for (var i=0; i<XmlHttpVersions.length && !xmlHttp; i++) 
    {
      try 
      { 
        xmlHttp = new ActiveXObject(XmlHttpVersions[i]);
      } 
      catch (e) {}
    }
  }
  if (!xmlHttp)
    alert("Error creating the XMLHttpRequest object.");
  else 
    return xmlHttp;
}

function controlButton(img,href,id,title){
  var ix=document.createElement("img");  
  ix.setAttribute("id","img_"+img+"_"+id);
  ix.setAttribute("src","/img/icons/"+img);
  ix.setAttribute("border","0");
  ix.setAttribute("title",title);
  ix.setAttribute("alt",title);
  ix.style.paddingRight="2px";
  ix.style.marginTop="2px";
  ix.style.cssFloat="right";
  ix.style.styleFloat="right";
  ix.style.clear="none";
  ix.style.verticalAlign="bottom";
  ix.className="controlbutton";
  var ax=document.createElement("a");
  ax.setAttribute("href","javascript:"+href);

  ax.appendChild(ix);
  return ax;
}

function showTalkBack(on) {
//showcontrols('fb',1,1,1,1)
  var id="tB";
  var td=document.getElementById(id);
  var dtd=td.getElementsByTagName('div');
  for(var i=0;i<dtd.length;i++){
    if(dtd[i].className.indexOf('blocktitle')!=-1){
      var d=dtd[i];
    }
  }
  var dt=d.firstChild;

  if (on!=1) {
    var a=controlButton("plus.gif","collapseTB('"+id+"')",id,"Expand Module Contents");
  } else {
    var a=controlButton("minus.gif","collapseTB('"+id+"')",id,"Collapse Module Contents");
  }

  if (on!=1) {
    document.getElementById(id+'_content').style.display='none';
  }

  d.insertBefore(a,dt);

}

function collapseTB(id) {
    var p=document.getElementById(id+'_content');
    if (p.style.display=='none'){
      var img=document.getElementById('img_plus.gif_'+id);
      p.style.display='block';
      img.setAttribute("src","/img/icons/minus.gif");
      img.setAttribute("id","img_minus.gif_"+id);
      img.setAttribute("title","Collapse Module Contents");
      img.setAttribute("alt","Collapse Module Contents");
      var oldcoockiePath = cookiePath;
      cookiePath="/";
      createCookie("tb","",-1);
      cookiePath=oldcoockiePath;
    } else {
      var img=document.getElementById('img_minus.gif_'+id);
      p.style.display='none';
      img.setAttribute("src","/img/icons/plus.gif");
      img.setAttribute("id","img_plus.gif_"+id);
      img.setAttribute("title","Expand Module Contents");
      img.setAttribute("alt","Expand Module Contents");
      var oldcoockiePath = cookiePath;
      cookiePath="/";
      createCookie("tb","1",360);
      cookiePath=oldcoockiePath;
    }
}


function newwindowcomment(){
  var d;
  var s=ge("suggSubmit");


  if (document.feedbackcomment) {
    d=document.feedbackcomment;
  } else if (document.commentform) {
    d=document.commentform;
  } else {
    return false;
  }
  if (s && s.checked) {
    window.location.href='/support/suggnew.php?preview=1&feedbackcomment='+d.feedbackcomment.value;
  }
  else {
    window.open('/feedback/feedback.php?pageid='+d.pageid.value+(d.dashb && d.dashb.value=='1'?"&dashb=1":"")+'&commval='+d.feedbackcomment.value,'_blank');
  }
}


