// JavaScript Document

var counter = 0;

function showDiv(dID)
{
  targ = document.getElementById(dID);
  if(targ && targ.style.display == 'none' || targ.style.display == '')
  {
    targ.style.display = 'inline';
  }
  else if(targ)
  {
    targ.style.display = 'none';
  }

}


function startProgress() {

    els = getElementsByClass('files');
    for(i = 0; i < els.length; i++)
    {
    			els[i].style.display="none";
    }
    
    document.getElementById("progressouter").style.display="block";
    document.getElementById("progress" ).style.display="block";
    setTimeout("getProgress()", 1000);
    return true;

}

function getProgress () 
{
   
    if ( window.ActiveXObject ) // if it's ie
    {
       xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); // xmlhttp is global
       xmlhttp.onreadystatechange = function ()
       {	
          if(xmlhttp.readyState == 4) writecontent(xmlhttp.responseText);
       };
    }
    else 
    {
       if (window.XMLHttpRequest) // if it's firefox etc.
       {
         xmlhttp        = new XMLHttpRequest() // xmlhttp is global
         xmlhttp.onload = function () { writecontent(xmlhttp.responseText) };
       }
       else return; // 
    }
	      
	var url = "http://" + document.location.hostname + "/getProgress.php?progress_key=" + 1;
    xmlhttp.open("GET", url , true); 
    xmlhttp.send(null);
		  
	
}

function writecontent (percent)
{

     document.getElementById("progressinner").style.width = percent+"%";
     if (percent < 100)
     {
        document.getElementById("statusTxt").value = Math.round(percent) + '%';
        setTimeout("getProgress()", 100);
     }
     else
     {
        document.getElementById("statusTxt").value = '100% Complete';
        setTimeout("closeWindow()", 500);
        
     }

}

  
function closeWindow()
{
   location.reload(true); 
}


function getElementsByClass(searchClass,node,tag)
{
 var classElements = new Array();
 if ( node == null )
  node = document;
 if ( tag == null )
  tag = '*';
 var els = node.getElementsByTagName(tag);
 var elsLen = els.length;
 var pattern = new RegExp("(^|\\s)"+searchClass+"(\\s|$)");
 for (i = 0, j = 0; i < elsLen; i++) {
  if ( pattern.test(els[i].className) ) {
   classElements[j] = els[i];
   j++;
  }
 }
 return classElements;
}


function clearField (id, defaultVal)
{
  
  targ = document.getElementById(id);
  if(targ && targ.value == defaultVal)
  {
    targ.value = '';
  }
  if(id == 'password')
  {
    replaceT(targ);
  }
}


function replaceT(obj){
var newO=document.createElement('input');
newO.setAttribute('type','password');
newO.setAttribute('name',obj.getAttribute('name'));
newO.setAttribute('id','password');
newO.className = 'form_field_style';
obj.parentNode.replaceChild(newO,obj);
newO.focus();
setTimeout(focusIt,300);
}

function focusIt()
{
  targ = document.getElementById('password');
  targ.focus();
}

	

