/*
Name:       common.js
Purpose:    Common javascript functions.

Change Log
------------------------------------------
10/07/2006  Cassidy Rauch   Created.
02/18/2007  Cassidy Rauch   Add database paging function.
*/

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


//Submit paging form
function submitPaging(pageNbr)
{
	document.formPage.action = document.formPage.action + '?curPage=' + pageNbr;
	document.formPage.submit();
}


//Confirm before action
function confirmAction(msg, redirect)
{
	if (confirm(msg))
	{
		window.location=redirect;	
	}	
}

//open new web page in new browser window
function newWindow(varURL,varWidth,varHeight)
{
	varTop = (screen.height - varHeight)/2;
	varLeft = (screen.width - varWidth)/2;
	window.open(varURL, "myWindow","scrollbars=0,resizable=0,location=0,status=0,toolbar=0,top=" + varTop + ",left=" + varLeft +  ",width="+ varWidth + ",height=" + varHeight);
}

//open new web page in new browser window and display an image
function newWindowImage(varImage,varWidth,varHeight,scrollbars)
{
	varTop = (screen.height - varHeight)/2;
	varLeft = (screen.width - varWidth)/2;
	w=window.open('', "myWindow","scrollbars=" + scrollbars + ",resizable=0,location=0,status=0,toolbar=0,top=" + varTop + ",left=" + varLeft +  ",width="+ varWidth + ",height=" + varHeight); 
	with(w.document)
	{
		write("<html><body bottomMargin='0' leftMargin='0' topMargin='0' rightMargin='0'>");
		write("<img src='" + varImage + "' />");
        write("</body></html>");
    }    
}




//Check all checkboxes using input tag name
function selectAll()
{
   var checked = true;
   var inputArray = document.getElementsByTagName("input");
   
   for (i=0; i<inputArray.length; i++) 
   {	 
     if (inputArray[i].type == 'checkbox') 
     {
		if (inputArray[i].checked)
		{			
			checked=false;       
			break;
		}
     }    
   }
   
   for (i=0; i<inputArray.length; i++) 
   {	 
     if (inputArray[i].type == 'checkbox') 
     {
       inputArray[i].checked = checked;
     }    
   }
}

function checkAdmin(){
	if(document.frmAdmin.username_admin.value==""){ alert("Please enter admin username.");document.frmAdmin.username_admin.focus();return false; }
	if(document.frmAdmin.pass_admin.value == ""){ alert("Please enter admin password.");document.frmAdmin.pass_admin.focus();return false; }
}

function hidify_showify(e_table, e_img, alt_less, alt_more) {
   if(document.getElementById) {
      var id_table = document.getElementById(e_table).style;
      var id_img = document.getElementById(e_img);

      //Set the object to table-cell if the browser is
      //Firefox and block if it's anything else.
      if(navigator.userAgent.indexOf("Firefox") != -1){
         if(id_table.display == "table-cell") {
            id_table.display = "none";
            id_img.src = "../images/form_plus.gif";
            id_img.alt = alt_more;
         }
         else {
            id_table.display = "table-cell";
            id_img.src = "../images/form_minus.gif";
            id_img.alt = alt_less;
         }
      }
      else {
         if(id_table.display == "block") {
            id_table.display = "none";
            id_img.src = "../images/form_plus.gif";
            id_img.alt = alt_more;
         }
         else {
            id_table.display = "block";
            id_img.src = "../images/form_minus.gif";
            id_img.alt = alt_less;
         }
      }
      return false;
   }
   else {
      return true;
   }
}


function checkNumber(textBox)
{
	while (textBox.value.length > 0 && isNaN(textBox.value)) {
		textBox.value = textBox.value.substring(0, textBox.value.length - 1)
	}
	
	textBox.value = trim(textBox.value);
/*	if (textBox.value.length == 0) {
		textBox.value = 0;		
	} else {
		textBox.value = parseInt(textBox.value);
	}*/
}