//common.js

//Progress Bar Variebles
var _progressduration=3; // Specify duration of progress bar in seconds
var _progressWidth=50;   // Display width of progress bar
var _progressBar=new String("");
var _progressEnd=10;
var _progressAt=0;

//Find object
function MM_findObj(n, d)
{
  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);
  return x;
}

//Swap & Restore Image
function MM_swapImage()
{
  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];
    }
}

//Preload Images
function MM_preloadImages()
{
 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 that displays status bar messages
function MM_displayStatusMsg(msgStr)  { //v3.0
	status=msgStr; document.MM_returnValue = true;
}

function Trim(TRIM_VALUE)
{
  if(TRIM_VALUE.length < 1)
    return"";
  TRIM_VALUE = RTrim(TRIM_VALUE);
  TRIM_VALUE = LTrim(TRIM_VALUE);
  if(TRIM_VALUE=="")
    return "";
  else
    return TRIM_VALUE;
}

function RTrim(VALUE)
{
  var w_space = String.fromCharCode(32);
  var v_length = VALUE.length;
  var strTemp = "";
  if(v_length < 0)
    return"";
  var iTemp = v_length -1;
  while(iTemp > -1)
  {
    if(VALUE.charAt(iTemp) == w_space)
    {
    }
    else
    {
      strTemp = VALUE.substring(0,iTemp +1);
      break;
    }
    iTemp = iTemp-1;
  } //End While
  return strTemp;
}

function LTrim(VALUE)
{
  var w_space = String.fromCharCode(32);
  if(v_length < 1)
    return"";
  var v_length = VALUE.length;
  var strTemp = "";
  var iTemp = 0;
  while(iTemp < v_length)
  {
    if(VALUE.charAt(iTemp) == w_space)
    {
    }
    else
    {
      strTemp = VALUE.substring(iTemp,v_length);
      break;
    }
    iTemp = iTemp + 1;
  } //End While
  return strTemp;
}

//Disable Right-Click
//function rc(evnt){if (navigator.appName.toUpperCase().match(/NETSCAPE/) != null)
//{if (evnt.which>=2){alert("Right-Click disabled (Copyright by Cyber Sites)");return false;}}else
//{if (event.button>=2){alert("Right-Click disabled (Copyright by Cyber Sites)");}}}document.onmousedown=rc;
//if (document.layers)window.captureEvents(Event.MOUSEDOWN);window.onmousedown=rc;

//Confirm Delete
function confirm_delete(type,url)
{
  if (confirm('Are you sure you wish to delete this record ?'))
  {
    if (type=='FORM')
    {
      document.forms[0].trg_delete.value='Y';
      document.forms[0].submit();
    }
    if (type=='TABLE')
    {
      this.location=url;
    }
  }
}

//Confirm Toggle Status
function confirm_togglestatus(type,url)
{
  var status="";
  var statusdescr="";
  status=url.substring(url.length,url.length-1);
  if (status=='Y') statusdescr="De-Activate";
  if (status=='N') statusdescr="Activate";
    
  if (confirm('Are you sure you wish to '+statusdescr+' this record ?'))
  {
    if (type=='FORM')
    {
      document.forms[0].trg_togglestatus.value='Y';
      document.forms[0].submit();
    }
    if (type=='TABLE')
    {
      this.location=url;
    }
  }
}

//Display Message
function display_message(msgstr)
{
  alert(msgstr);
}

//Load Url
function load_url(url)
{
  this.location=url;
}

//Open window script
function openwindow(url,w,h)
{
  window.name='win_main';
  window.open(url,'win_popup','status=0,scrollbars=1,resizable,width='+w+'px,height='+h+'px');
}

//Open model window script
function openmodalwindow(url,w,h,recnum,retobj)
{
  //Do browser type checks

  var retval=window.showModalDialog(url,'','dialogWidth:'+w+'px;dialogheight:'+h+'px;help:no;status=no;');
  return retval;
}

//Progress Bar - Create
function ProgressCreate(end)
{
  // Initialize state variables
  _progressEnd = end;
  _progressAt = 0;

  // Move layer to center of window to show
  if (document.all)
  {
    // Internet Explorer
    progress.className = 'show';
    progress.style.left = (document.body.clientWidth/2) - (progress.offsetWidth/2);
    progress.style.top = document.body.scrollTop+(document.body.clientHeight/2) - (progress.offsetHeight/2);
  }
  else if (document.layers)
  {
    // Netscape
    document.progress.visibility = true;
    document.progress.left = (window.innerWidth/2) - 100;
    document.progress.top = pageYOffset+(window.innerHeight/2) - 40;
  }
  else if (document.getElementById)
  {
    // Netscape 6+
    document.getElementById("progress").className = 'show';
    document.getElementById("progress").style.left = (window.innerWidth/2)- 100;
    document.getElementById("progress").style.top = pageYOffset+(window.innerHeight/2) - 40;
  }

  ProgressUpdate();  // Initialize bar
}

//Progress Bar - Destroy
function ProgressDestroy()
{
  // Move off screen to hide
  if (document.all)
  {
    // Internet Explorer
    progress.className = 'hide';
  }
  else if (document.layers)
  {
    // Netscape
    document.progress.visibility = false;
  }
  else if (document.getElementById)
  {
    // Netscape 6+
    document.getElementById("progress").className = 'hide';
  }
}

//Progress Bar - Increment one step
function ProgressStepIt()
{
  _progressAt++;
  if(_progressAt > _progressEnd) _progressAt = _progressAt % _progressEnd;
  ProgressUpdate();
}

//Progress Bar - Updated with the current state
function ProgressUpdate()
{
  var n = (_progressWidth / _progressEnd) * _progressAt;
  if (document.all)
  {
    // Internet Explorer
    var bar = dialog.bar;
  }
  else if (document.layers)
  {
    // Netscape
    var bar = document.layers["progress"].document.forms["dialog"].bar;
    n = n * 0.55; // characters are larger
  }
  else if (document.getElementById)
  {
    var bar=document.dialog.bar
  }
  var temp = _progressBar.substring(0, n);
  bar.value = temp;
}

//Progress Bar - Display
function ProgressDisplay()
{
  //Write Form
  document.write("<span id=progress class=hide>");
  document.write("<form name=dialog>");
  document.write("<table border=2  bgcolor=#FFFFCC>");
  document.write("<tr><td align=center>");
  document.write("Progress<br>");
  document.write("<input type=text name=bar size="+_progressWidth/2);
  if(document.all||document.getElementById) // Microsoft, NS6
    document.write("bar.style=color:navy;>");
  else // Netscape
    document.write(">");
  document.write("</td></tr>");
  document.write("</table>");
  document.write("</form>");
  document.write("</span>");
  ProgressDestroy();

  ProgressCreate(10);
  window.setTimeout("ProgressTimeout()", 100);
}

//Progress Bar - Timeout
function ProgressTimeout()
{
  if(_progressAt >= _progressEnd)
  {
    ProgressDestroy();
    return;
  }
  ProgressStepIt();
  window.setTimeout("ProgressTimeout()", (_progressduration-1)*1000/10);
}

//Call Javascript
function CallJS(jsStr)
{
  return eval(jsStr)
}
