var timerId = 0;
var blockRefresh = 0;

function dispather(action) {
	document.body.style.cursor='wait';
	if (document.forms[0].OkButton != null){
		document.forms[0].OkButton.disabled='true';
	}
	if (document.forms[0].DeleteButton != null){
		document.forms[0].DeleteButton.disabled='true';
	}

	if (document.forms[0].CancelButton != null){
		document.forms[0].CancelButton.disabled='true';
	}
	document.forms[0].action.value=action;
        document.forms[0].submit();
}

function refresher() {
    document.forms[0].submit();
}

function blockRefreshing(){
	clearTimeout(timerId);
	blockRefresh = 1;
}

function setRefresh(){
	blockRefresh = 0;

	// The refresh rate in seconds is set here.
	resetRefresh(45);
}

function resetRefresh(seconds)
{
	// the timeout value should be the same as in the "refresh" meta-tag
	// the timeout is in millis
	if (blockRefresh == 0){
		clearTimeout(timerId);
		timerId = setTimeout( "refresh()", seconds*1000 );
	}
}
function refresh()
{
	// removing the query string rom the url, only the form object should be
	// re posted
	foo = window.location.href.split("?");

	window.location.replace( foo[0] );
}

function dispatchURL(url)
{
	window.location.replace(url);
}

function confirmAction(message) {
	if (confirm(message))
		return true;
	else
		return false;

}

function confirmWithDispathAction(action,message) {
	if (confirm(message)){
		dispather(action);
	}else{
		return false;
	}
}


function MM_goToURL() {
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}

  function validateString(objName, nullOk) {
    var strInt;
    var intField = objName;
    strInt = intField.value;
    if (isString(strInt, nullOk) == false) {
      alert("A required field is empty.");
      intField.focus();
      intField.select();
      return false;
    } else {
      return true;
    }
  }

  function isString (s, nullOk) {
    var i;
    if ((s == null) || (s.length == 0))
      if (isString.arguments.length == 1) {
        if (nullOk == true)
          return defaultEmptyOK;
        else
          return false;
      } else {
        return (isString.arguments[1] == true);
      }
    return true;
  }

  function validateInteger(objName, nullOk) {
    var strInt;
    var intField = objName;
    strInt = intField.value;
    if (isInteger(strInt, nullOk) == false) {
      alert("Invalid integer, enter a number without decimals.");
      intField.focus();
      intField.select();
      return false;
    } else {
      return true;
    }
  }

  function isInteger (s, nullOk) {
    var i;
    if (isEmpty(s))
      if (isInteger.arguments.length == 1) {
        if (nullOk == true)
          return defaultEmptyOK;
        else
          return false;
      } else {
        return (isInteger.arguments[1] == true);
      }
    for (i = 0; i < s.length; i++) {
     var c = s.charAt(i);
     if (!isDigit(c))
       return false;
    }
    return true;
  }

  function isDigit (c) {
    return ((c >= "0") && (c <= "9"))
  }

  function isEmpty(s) {
    return ((s == null) || (s.length == 0))
  }

  function openWindow(pUrl, pFeatures, pName)
  {
  	var sUrl = pUrl ;
  	var sFeatures = pFeatures;
  	var sName = pName;
  	window.open(sUrl, sName, sFeatures);
  }

  function closeAndReloadOpener(pUrl)
  {
   	var openerWnd = window.opener;
  	openerWnd.location.reload(true);
  	window.close();
  }

  function closeWindow()
  {
  	window.close();
  }


  function toggle(p_img, p_tx_File)
  {
	p_img.src = p_tx_File;
  }
  