
/* general usage functions
 ---------------------------------------------------------------------- */

// clear textfield default text 
function clearText(thefield) {
	if (thefield.defaultValue==thefield.value) { thefield.value = "" }
} 

// replace textfield default text
function replaceText(thefield) {
	if (thefield.value=="") { thefield.value = thefield.defaultValue }
}

/* DOM functions
 ---------------------------------------------------------------------- */


// toggles display style of object w/ specified id
//--------------------------------------------------
  function toggleDisplay(obj_id)
  {
    if (document.getElementById){
      var obj = document.getElementById(obj_id);
      if (obj.style.display == '' || obj.style.display == 'none'){
        var state = 'block';
      } else {
        var state = 'none';
      }
      obj.style.display = state;
    }
  }


// cssjs() - CSS/DOM className interaction function
//   a      - action to perform
//   obj_id - id of object to modify
//   c1     - name of first class
//   c2     - name of second class 
//--------------------------------------------------
  function cssjs(a,obj_id,c1,c2)
  {
    if (document.getElementById) {
      var obj = document.getElementById(obj_id);
      if (obj) {
        switch (a){
          case 'swap':
            obj.className = (cssjs('check',obj_id,c1) ? obj.className.replace(c1,c2) : obj.className.replace(c2,c1));
          break;
          case 'add':
            if(!cssjs('check',obj_id,c1)){obj.className+=obj.className?' '+c1:c1;}
          break;
          case 'remove':
            var rep=obj.className.match(' '+c1)?' '+c1:c1;
            obj.className=obj.className.replace(rep,'');
          break;
          case 'check':
            return new RegExp('(.*)'+c1+'(.*)').test(obj.className);
          break;
        }
      }
    }
  }


/* File upload CSS & DOM =>  http://quirksmode.org/dom/inputfile.html
 * This is used to allow for styleable file upload form fields.
 ---------------------------------------------------------------------- */

var W3CDOM = (document.createElement && document.getElementsByTagName);

function initFileUploads() {
	if (!W3CDOM) return;
	var fakeFileUpload = document.createElement('div');
	fakeFileUpload.className = 'file-fake';
	fakeFileUpload.appendChild(document.createElement('input'));
	var image = document.createElement('img');
	image.src = '../images/buttons/button_select.gif';
	fakeFileUpload.appendChild(image);
	var x = document.getElementsByTagName('input');
	for (var i=0;i<x.length;i++)
	{
		if (x[i].type != 'file') continue;
		if (x[i].parentNode.className != 'file-inputs') continue;
		x[i].className = 'file hidden';
		var clone = fakeFileUpload.cloneNode(true);
		x[i].parentNode.appendChild(clone);
		x[i].relatedElement = clone.getElementsByTagName('input')[0];
		x[i].onchange = x[i].onmouseout = function () {
			this.relatedElement.value = this.value;
		}
	}
}

window.onload = initFileUploads;

//------------------- OPEN NEW WINDOW -------------------//
var newWindow = null;

function closeWin(){
	if (newWindow != null){
		if(!newWindow.closed)
			newWindow.close();
	}
}

function popUpWin(url, type, strWidth, strHeight){
	
	closeWin();
	
	if (type == "fullScreen"){
		strWidth = screen.availWidth - 10;
		strHeight = screen.availHeight - 160;
	}
	
	var tools="";
	if (type == "standard" || type == "fullScreen") tools = "resizable,toolbar=no,location=no,scroll=yes,scrollbars=yes,menubar=no,width="+strWidth+",height="+strHeight+",top=0,left=0";
	if (type == "console") tools = "resizable,toolbar=no,location=no,scroll=no,scrollbars=no,width="+strWidth+",height="+strHeight+",left=0,top=0";
	newWindow = window.open(url, 'newWin', tools);
	newWindow.focus();
}

function popUpSWF(url, type, Width, Height, arg1, arg2, arg3){
	closeWin();
	tools = "resizable=no,toolbar=no,location=no,directories=no,status=no,scroll=no,scrollbars=no,menubar=no,width="+Width+",height="+Height+",left=0,top=0";
	if(type == "mp"){
		newWindow = window.open(url+"?bandwidth="+arg1+"&video="+arg2+"&lan="+arg3, 'newWin', tools);
	}
	if(type == "mc"){
		newWindow = window.open(url+"?category="+arg1+"&videoNum="+arg2, 'newWin', tools);
	}
	if(type == "bna"){
		newWindow = window.open(url+"?procedure="+arg1+"&caseNum="+arg2, 'newWin', tools);
	}
	newWindow.focus();
}

