	var formSubmit = true;
	var oModalSearchWindow;
	var httpposted = false;
	var numItems=20;
	var quoteTypes=new Array(numItems);
	var quoteDays=new Array(numItems);
	function DisableButtons()
	{
		if (formSubmit) {
			formSubmit = false;
			return true;
		}
		else {
//			for (var i=0; i < document.forms.length; i++) {
				for (var j=0; j < document.getElementsByTagName('*').length; j++) {
					if (document.getElementsByTagName('*')[j].tagName=='INPUT' && document.getElementsByTagName('*')[j].type=='submit') {
						document.getElementsByTagName('*')[j].disabled = true;	
					}
				}			
//			}			
			return false;
		}
	}
	function calculateTotal(row)
	{
		var qty = parseFloat(document.getElementById('confQty' + row).value).toFixed(4);
		var cost = parseFloat(document.getElementById('confCost' + row).value).toFixed(4);
		var total = (qty * cost).toFixed(4);
		var tax = total;
		var taxRate = parseFloat(document.getElementById('confTaxRate' + row).value).toFixed(4);
		document.getElementById('confQty' + row).value = qty;
		document.getElementById('confCost' + row).value = cost;
		if (document.getElementById('confTaxIncl' + row).value == 'true') {
			total = ((cost - (cost * taxRate/100)) * qty).toFixed(4);
			tax = (total * taxRate/100).toFixed(4);
		}
		else {
			total = (qty * cost).toFixed(4);
			tax = (total * taxRate/100).toFixed(4);
		}
		document.getElementById('confTotal' + row).innerHTML = total;
		document.getElementById('confTax' + row).innerHTML = tax;
		
	}

function notifyTimeout()
{ 
  var oWindowOpener = getWindowOpener();
  var oWindow = oWindowOpener;
  if (oWindow == null)
  {
    if (parent != self)
     oWindow = parent;
  }

  if ((oWindow != null))
  {
    oWindow.notifyTimeout();
  }
  else 
  { 
    window.document.getElementById("IsTimedOut").value = "Yes";
    window.location = "Login.asp";  
  }  
  // if opened in a popup, then close the popup    
  if (oWindowOpener != null)
    window.close();
}

function getWindowOpener()
{
  if (opener != null)
    return opener;
  
  if (window.dialogArguments != null)
    return window.dialogArguments;

  return null;
} 

function openWindow(sURL, sTitle, iHeight, iWidth)
{
  // if the Window is already assigned, close it, as we cannot bring it to the Front in code
  if (oModalSearchWindow!=null)
    if (!oModalSearchWindow.closed)
      oModalSearchWindow.close();
  oModalSearchWindow = openNewWindow(sURL, sTitle, iHeight, iWidth);
  return;  
}

function openWindowWithParams(sURL)
{
  for (var i=0;i<document.getElementsByTagName('*').length;i++) {
    if (document.getElementsByTagName('*')[i].type=="text"||document.getElementsByTagName('*')[i].type=="hidden"||document.getElementsByTagName('*')[i].type=="checkbox"||document.getElementsByTagName('*')[i].type=="radio"||document.getElementsByTagName('*')[i].tagName=="SELECT") {
			if (document.getElementsByTagName('*')[i].type!="radio"||document.getElementsByTagName('*')[i].checked) {
	      sURL = sURL + '&' + document.getElementsByTagName('*')[i].name + '=';
	      if (document.getElementsByTagName('*')[i].type=="checkbox")
	      	sURL = sURL + document.getElementsByTagName('*')[i].checked;
	      else
	      	sURL = sURL + document.getElementsByTagName('*')[i].value;
			}
    }
  }
	top.open(sURL);	
  return;  
}

function openNewWindow(sURL, sTitle, iHeight, iWidth)
{
  var sFeatures = 'titlebar=0,hotkeys=0,toolbar=0,scrollbars=1,location=0,status=0,resizable=1,width=' + iWidth + ',height=' + iHeight + ',dependent=1'
  var oWindow = openWindowIE5(sURL, sTitle, sFeatures, iHeight, iWidth);
  return oWindow;
}

function openWindowNetscape(sURL, sTitle, sFeatures, iHeight, iWidth)
{
  var oWindow = window.open(sURL, sTitle, sFeatures);
  centerWindowOnScreen(oWindow, iWidth, iHeight);
  oWindow.focus();
  return oWindow;
}

function openWindowIE5(sURL, sTitle, sFeatures, iHeight, iWidth)
{
  var x = Math.round((screen.width - iWidth) / 2);
  var y = Math.round((screen.height - iHeight) / 2);

  var sNewFeatures = sFeatures + ',center=yes,top=' + y + ',left=' + x;
  var oWindow = window.open(sURL, sTitle, sNewFeatures);
  oWindow.focus();
  
  return oWindow;
}
function centerWindowOnScreen(oWindow, iWidth, iHeight)
{
  // IE does not return window.outerWidth and window.outerHeight,
  //    the standard IE window are inaccurate due to toolbars etc.
   var x = Math.round((screen.width - iWidth) / 2);
   var y = Math.round((screen.height - iHeight) / 2);
   oWindow.moveTo(x,y);
}

function customerLookupClicked(session)
{
  var sURL = "pageVRD.vrd?session="+ session + "&page=customersearch";
  var winL = Math.round((screen.width - 800) / 2);
  var winT = Math.round((screen.height - 730) / 2);
  var w = window.open(sURL , "w", "scrollbars=yes,resizable=yes,width=800,height=730");
  w.moveTo(winL,winT)// to move the window to center of screen.
  return false;
}

function sendCustomerValue(value, custName, sAddressName, sAddress1, sAddress2, sAddress3, sPostCode, sPhone, sContact)
{
  var sCode = value;
  var sOldValue = "";
  var ctrl = window.opener.document.getElementById("customerCode");

  sOldValue = ctrl.value;
  if (sCode != null) { 
    ctrl.value = sCode;
  } else {
    ctrl.value = sOldValue;
  }
  ctrl = window.opener.document.getElementById("customerNameDisplay");
  if ((custName != null) && (ctrl != null)) {
    ctrl.value = custName;
  }
  ctrl = window.opener.document.getElementById("dAddressName");
  if ((sAddress1 != null) && (ctrl != null)) {
    ctrl.value = sAddressName;
  }
  ctrl = window.opener.document.getElementById("dAddress1");
  if ((sAddress1 != null) && (ctrl != null)) {
    ctrl.value = sAddress1;
  }
  ctrl = window.opener.document.getElementById("dAddress2");
  if ((sAddress2 != null) && (ctrl != null)) {
    ctrl.value = sAddress2;
  }
  ctrl = window.opener.document.getElementById("dAddress3");
  if ((sAddress3 != null) && (ctrl != null)) {
    ctrl.value = sAddress3;
  }
  ctrl = window.opener.document.getElementById("dPostCode");
  if ((sPostCode != null) && (ctrl != null)) {
    ctrl.value = sPostCode;
  }
  ctrl = window.opener.document.getElementById("dPhone");
  if ((sPhone != null) && (ctrl != null)) {
    ctrl.value = sPhone;
  }
  ctrl = window.opener.document.getElementById("dContact");
  if ((sContact != null) && (ctrl != null)) {
    ctrl.value = sContact;
  }

  ctrl = window.opener.document.getElementById("validate");
  if (ctrl != null) {
    ctrl.click();
  }
	
  window.close();

}

function suburbLookupClicked(session, format, suburbField, cityField, postCodeField)
{
  var sURL = "pageVRD.vrd?session="+ session + "&page=suburbSearch&format=" + format + "&suburbField=" + suburbField + "&cityField=" + cityField + "&postCodeField=" + postCodeField;
  var winL = Math.round((screen.width - 580) / 2); //800
  var winT = Math.round((screen.height - 530) / 2);//730
  var w = window.open(sURL , "w", "scrollbars=no,resizable=no,width=580,height=530");
  w.moveTo(winL,winT)// to move the window to center of screen.
  return false;
}

function sendSuburbValue(valueSuburb, valueCity, valuePostCode)
{
  var sCode = valueSuburb;
  var sOldValue = "";
  var ctrl = window.opener.document.getElementById(document.getElementById("suburbField").value);
  sOldValue = ctrl.value;
  if (valueSuburb != null) { 
    ctrl.value = valueSuburb;
    ctrl.onchange();
  } else {
    ctrl.value = sOldValue;
  }
  ctrl = window.opener.document.getElementById(document.getElementById("cityField").value);
  if ((valueCity != null) && (ctrl != null)) {
    ctrl.value = valueCity;
    ctrl.onchange();
  }
  ctrl = window.opener.document.getElementById(document.getElementById("postCodeField").value);
  if ((valuePostCode != null) && (ctrl != null)) {
    ctrl.value = valuePostCode;
    ctrl.onchange();
  }
	
  window.close();

}

function lookupClicked(session, searchField, lookupPage, extraFields)
{
  var sURL = lookupPage + "?session="+ session + "&searchField=" + searchField + extraFields;
  var winL = Math.round((screen.width - 500) / 2);
  var winT = Math.round((screen.height - 450) / 2);
  var w = window.open(sURL , "w", "scrollbars=yes,resizable=yes,width=500,height=450");
  w.moveTo(winL,winT)// to move the window to center of screen.
  return false;
}

function lookupClickedSmall(session, searchField, lookupPage, extraFields)
{
  var sURL = lookupPage + "?session="+ session + "&searchField=" + searchField + extraFields;
  var winL = Math.round((screen.width - 800) / 2);
  var winT = Math.round((screen.height - 730) / 2);
  var w = window.open(sURL , "w", "scrollbars=yes,resizable=yes,width=400,height=730");
  w.moveTo(winL,winT)// to move the window to center of screen.
  return false;
}


function sendValue(value, searchField)
{
  var sCode = value;
  var sOldValue = "";
  var ctrl = window.opener.document.getElementById(searchField);

  sOldValue = ctrl.value;
  if (sCode != null) { 
    ctrl.value = sCode;
  } else {
    ctrl.value = sOldValue;
  }

  window.close();

}

function sendValueChange(value, searchField)
{
  var sCode = value;
  var sOldValue = "";
  var ctrl = window.opener.document.getElementById(searchField);

  sOldValue = ctrl.value;
  if (sCode != null) { 
    ctrl.value = sCode;
    ctrl.onchange();
  } else {
    ctrl.value = sOldValue;
  }

  window.close();

}

function checkDate(sDate)
{
  var today= new Date();
  today.setMonth(today.getMonth());
  var i = sDate.indexOf("/");
  if (i < 1) {
    return today;
  }
  var day1=sDate.substring(0,i);
  sDate = sDate.substring(i+1);
  i = sDate.indexOf("/");
  if (i < 1) {
    return today;
  }
  var month1=sDate.substring(0,i);
  year1 = sDate.substring(i+1);

  var d1=new Date(year1,month1 - 1,day1);
  return d1;
}

function setFocus()
{
  for (var i=0;i<document.getElementsByTagName('*').length;i++) {
    if ((document.getElementsByTagName('*')[i].type=="text" || document.getElementsByTagName('*')[i].tagName=="select")  && document.getElementsByTagName('*')[i].disabled==false) {
      document.getElementsByTagName('*')[i].focus();
      return;
    }
  }
}

function setAction(sAction, sProgress, sPage, sRedirect)
{
	var mainForm = document.getElementById("mainForm");
	if (mainForm == null) {
		mainForm = document.getElementById("detail");
	}
	if (mainForm == null) {
	  alert("No main form is defined for this page. Unable to submit request");
	}
	
	if (document.getElementById("progressNumber") != null&&sProgress!=null) {
  	document.getElementById("progressNumber").value = sProgress;
  }
	if (document.getElementById("page")!=null&&sPage!=null) {
  	document.getElementById("page").value = sPage;
  }
	if (sRedirect!=null) {
		mainForm.action = sRedirect;
  	//document.forms[0].action = sRedirect;
  }
	if (document.getElementById("formAction").value == "") {
  	document.getElementById("formAction").value = sAction;
  	mainForm.submit();
  	//document.forms[0].submit();
  }
  else {
    for (var i=0;i<document.getElementsByTagName('*').length;i++) {
      if ((document.getElementsByTagName('*')[i].type=="button" || document.getElementsByTagName('*')[i].type=="submit") ) {
        document.getElementsByTagName('*')[i].disabled = true;
      }
    }  	
  }
}

function showProgressIndicator() {
	if (document.getElementById("progressIndicator") != null) {
		document.getElementById("progressIndicator").style.visibility = "visible";
	}
}

function AddLine(sRows, sAction)
{
	var i=0;
	i=parseFloat(document.getElementById(sRows).value);
	i = i + 1;
	document.getElementById(sRows).value = i;
	setAction(sAction);
}

function keyDown(e) {
//Arrow up and down for table cells with INPUTs 
  var keynum;
  var table;
  var tInput;
  var cellI=0;
  var rowI=0;
  keynum = e.keyCode;
  if (e!=null&&e.srcElement!=null&&e.srcElement.tagName=="INPUT") {
    tInput=e.srcElement;
    if (tInput.parentElement!=null&&tInput.parentElement.tagName=="TD"&&tInput.parentElement.parentElement.tagName=="TR"&&
        tInput.parentElement.parentElement.parentElement!=null&&tInput.parentElement.parentElement.parentElement.parentElement.tagName=="TABLE") {
      table = tInput.parentElement.parentElement.parentElement.parentElement;
      cellI = tInput.parentElement.cellIndex;
      rowI = tInput.parentElement.parentElement.rowIndex;
      if (keynum==40) {
        for (var i=rowI+1;table.rows[i]!=null; i++) {
          if (table.rows[i].cells[cellI]!=null&&table.rows[i].cells[cellI].firstChild!=null&&table.rows[i].cells[cellI].firstChild.readOnly==false&&table.rows[i].cells[cellI].firstChild.tagName=="INPUT") {
            table.rows[i].cells[cellI].firstChild.focus();
            table.rows[i].cells[cellI].firstChild.select();
            break;
          }
        }
      }
      if (keynum==38) {
        for (var i=rowI-1;i>=0; i--) {
          if (table.rows[i].cells[cellI]!=null&&table.rows[i].cells[cellI].firstChild!=null&&table.rows[i].cells[cellI].firstChild.readOnly==false&&table.rows[i].cells[cellI].firstChild.tagName=="INPUT") {
            table.rows[i].cells[cellI].firstChild.focus();
            table.rows[i].cells[cellI].firstChild.select();
            break;
          }
        }
      }
    }
  }
}

function ShowFields(sFieldSet)
{
	var openRows=0;
	openRows = parseFloat(document.getElementById('openRows').value);
	var numRows=0;
	numRows = parseFloat(document.getElementById('numRows').value);
	if (openRows < numRows)
		openRows = openRows + 1;
	else
		alert("You've already selected the maximum available numbers.");
	document.getElementById(sFieldSet + openRows).className = "fieldsVisible";
	document.getElementById('openRows').value = openRows;
}

function calculateSalesCodeTotal(salePrice, taxPrice)
{
	var totalPrice = (salePrice + taxPrice).toFixed(2);
	document.getElementById('allocfee').value = salePrice.toFixed(2);
	document.getElementById('subtotal').value = salePrice.toFixed(2);
	document.getElementById('gst').value = taxPrice.toFixed(2);
	document.getElementById('total').value = totalPrice;
	document.getElementById('totalGTIN').value = totalPrice;
}
function calculateTransactionTotal(row, currentPrice)
{
	var totalPrice = parseFloat(document.getElementById('totalTrans').value);
	var price = parseFloat(currentPrice);
	if (document.getElementById('pay' + row).checked == true) {
			totalPrice = (totalPrice + price).toFixed(2);
		}
	else {
			totalPrice = (totalPrice - price).toFixed(2);
		}
	document.getElementById('totalTrans').value = totalPrice;
}

function validateCreditCard()
{
	// Luhns check digit credit card validator
	var cardNo=document.getElementById('CardNumber').value;
	var cardFld=document.getElementById('CardNumber');
	var error="";
	//document.getElementById('CardNumber').style.backgroundColor = "white";
	cardFld.className = "field";
	var rCardNo='';
	var i=0;
	var t='';
	var c=0;
	var n=0;
	
	for (i=cardNo.length-1;i>=0;i--) {
		rCardNo+=cardNo.charAt(i)
		rCardNo=rCardNo.replace(/[^0-9]/g, ''); 
	}
	// Run through each single digit to create a new string. Even digits are multiplied by two, odd digits are left alone.
	t='';
  	for (i=0;i< rCardNo.length;i++) {
    		c=parseInt(rCardNo.charAt(i),10);
    		if (i%2 != 0)
      			c *= 2;
    			t = t+c;
  	}
  	// Finally, add up all the single digits in this string.
	n=0;
  	for (i=0;i<t.length;i++) {
    		c=parseInt(t.charAt(i), 10);
    		n=n+c;
  	}
	// If the resulting sum is an even multiple of ten (but not zero), the card number is good.
	if (n!=0 && n%10 == 0) {
		// The number is good, get on with the checking below
  }
  	else {
  		error = 'The credit card you have entered is not valid.';
   		
   		cardFld.value = '';
   		cardFld.className = 'fieldError';
   		cardFld.title = error;
   		alert(error);
    	return;
	}

	// General checking - Prefix & Length check
	var cardType = document.getElementById('CardType').value;
	var preCardNo = '';
	// Visa
	if (cardType == '1') {
		if (rCardNo.length != 13 && rCardNo.length !=16) {
			error = 'The length for this Visa card is not valid.';
   		cardFld.value = '';
   		cardFld.className = 'fieldError';
   		cardFld.title = error;
   		alert(error);
			return;
		}
		preCardNo = cardNo.charAt(0);
		if (preCardNo != '4') {
			error = 'The prefix for this Visa card is not valid';
   		cardFld.value = '';
   		cardFld.className = 'fieldError';
   		cardFld.title = error;
   		alert(error);
			return;
		}
	}
	// Mastercard
	if (cardType == '2') {
		if (rCardNo.length != 16) {
			error = 'The length for this Mastercard is not valid.';
   		cardFld.value = '';
   		cardFld.className = 'fieldError';
   		cardFld.title = error;
   		alert(error);
			return;
		}
		preCardNo = cardNo.charAt(0);
		preCardNo+= cardNo.charAt(1);
		if (preCardNo != '51' && preCardNo != '52' && preCardNo != '53' && preCardNo != '54' && preCardNo != '55') {
			error = 'The prefix for this Mastercard is not valid';
   		cardFld.value = '';
   		cardFld.className = 'fieldError';
   		cardFld.title = error;
   		alert(error);
			return;			
		}
	}
	// Amex
	if (cardType == '3') {
		if (rCardNo.length != 15) {
			error = 'The length for this American Express card is not valid.';
   		cardFld.value = '';
   		cardFld.className = 'fieldError';
   		cardFld.title = error;
   		alert(error);
			return;
		}
		preCardNo = cardNo.charAt(0);
		preCardNo+= cardNo.charAt(1);
		if (preCardNo != '34' && preCardNo != '37') {
			error = 'The prefix for this American Express card is not valid';
   		cardFld.value = '';
   		cardFld.className = 'fieldError';
   		cardFld.title = error;
   		alert(error);
			return;	
		}
	}
}


function getJobInfo()
{ 
  var now = new Date();
  var exitTime = now.getTime();
  document.getElementById("getJob").src = "pageVRD.vrd?session=" + document.getElementById("session").value + "&page=timesheetJobLookup&payGroup=" + document.getElementById("payGroup").value + "&payEndDate=" + document.getElementById("payEndDate").value + "&times=" + exitTime;
}

function setComplete(sDate)
{ 
  if (document.getElementById("jobComplete").checked) 
  	document.getElementById("completeDate").value = sDate;
  else
  	document.getElementById("completeDate").value = "";
 
}

function setNextJob(sJob)
{ 
 	document.getElementById("nextJob").value = sJob;
}

// javascript function for menu items
function openMenu(page, cmenu, isstatic) {
	//window.location="/gs1/pageVRD.vrd?session=ts4s3lpopuzi6jd7tcsl2ne0qxpf0rgp&date=31/08/2008&page=welcomePage";
	var om = document.getElementById('openmenus').value;
	var dt = document.getElementById('enddate').value;
	var s = document.getElementById('menusession').value;
	//var pageurl = document.getElementById('pageurl').value;
	// If the current menu item doesn't have a page to go to then just open the 
	// child menu items
	if (cmenu != '') {
		var m = document.getElementById(cmenu);
		
		// find the child menu in the open items. if present then remove??
		p = om.indexOf(',' + cmenu + ',');
		if (p >= 0) {
			om = om.substring(0,p + 1) + om.substring(p + cmenu.length + 2, om.length);
		} else {
			om = om + cmenu + ',';
		}
		document.getElementById('openmenus').value = om;
		
		if (page == '') {
			if (m.style.display=="" || m.style.display=="block") {
				m.style.display="none";
			}
			else {
				m.style.display="block";
			}
		}
	}
	
	// redirect to the page passed in
	if (page != '') {
		var menuForm = document.getElementById('menuForm');
		if (isstatic) {
			document.getElementById('menupage').value = 'URL';
			document.getElementById('menuname').value = page;
		
			//window.location = pageurl + "?session=" + s + "&date=" + dt + "&openmenus=" + om + "&page=URL&name=" + page;
		} else {
			document.getElementById('menupage').value = page;
			document.getElementById('menuname').value = '';
		
			//window.location = pageurl + "?session=" + s + "&date=" + dt + "&openmenus=" + om + "&page=" + page;
		}
		menuForm.submit();
	}
	//return true;
}

function openCrumb(page) {
	// redirect to the page passed in
	if (page != '') {
		var crumbForm = document.getElementById('crumbForm');
		
		document.getElementById('crumbpage').value = page;
		
		crumbForm.submit();
	}
	//return true;
}


function updateExpiry()
{ 
  var sQuoteType = "";
  var sDate = "";
  var days = 0;
  var i = 0;
  sQuoteType = document.getElementById("quoteType").value;
  sDate = document.getElementById("documentDate").value;
  var dDate = new Date();
  dDate = checkDate(sDate);

  for (i=0;i<numItems;i++) {
    if (sQuoteType == quoteTypes[i])
      break;
  }
  days = parseFloat(quoteDays[i]);
  document.getElementById("documentDate").value = dDate.getDate() + "/" + (dDate.getMonth() + 1) + "/" + dDate.getYear();
  dDate.setDate(dDate.getDate() + days);
  document.getElementById("expiryDate").value = dDate.getDate() + "/" + (dDate.getMonth() + 1) + "/" + dDate.getYear();

}
function checkFinanceCo()
{ 
  var sPaymentOption = "";
  sPaymentOption = document.getElementById("paymentOption").value;
  if (sPaymentOption == "Cash" || sPaymentOption == "") {
    document.getElementById("financeCo").parentElement.style.visibility = "hidden";
    document.getElementById("financeCoLabel").parentElement.style.visibility = "hidden";
  }
  else {
    document.getElementById("financeCo").parentElement.style.visibility = "visible";
    document.getElementById("financeCoLabel").parentElement.style.visibility = "visible";
  }
}

function getStockInfo(row, sup)
{ 
  var now = new Date();
  var exitTime = now.getTime();
  document.getElementById("getStock").src = "pageVRD.vrd?session=" + document.getElementById("session").value + "&page=stockInfoLookup&stockCode=" + document.getElementById("invCode" + row).value + "&supplier=" + document.getElementById("supplier" + row).value + "&sup=" + sup + "&row=" + row + "&customerCode=" + document.getElementById("customerCode").value + "&location=" + document.getElementById("location").value + "&times=" + exitTime;
}

function getReject()
{ 
  document.getElementById("rejectBox").style.left=window.event.clientX;
  document.getElementById("rejectBox").style.top=window.event.clientY;
  document.getElementById("rejectBox").style.width="200px";
  document.getElementById("rejectBox").style.height="60px";
  document.getElementById("rejectBox").innerHTML="<B>Enter Rejection Reason<textarea rows=3 cols=30 type=text name=rejectText id=rejectText></textarea></B><BR><BR><input type=submit name=reject id=reject value='Ok'>&nbsp;&nbsp;&nbsp;<input type=button name=rejectC id=rejectC onclick='javascript:cancelReject()' value='Cancel'>";
  document.getElementById("rejectText").focus();
}
function cancelReject()
{
  document.getElementById("rejectBox").style.left=0;
  document.getElementById("rejectBox").style.top=0;
  document.getElementById("rejectBox").style.width="0px";
  document.getElementById("rejectBox").style.height="0px";
  document.getElementById("rejectBox").innerHTML="";
}
function copyQuote()
{
  document.getElementById("isUpdate").value="";
  document.getElementById("amendRef").value="";
  document.getElementById("documentDate").value="";
  document.getElementById("expiryDate").value="";
  document.getElementById("installDate").value="";
}
function clearForm()
{
  for (i=0;i<document.getElementsByTagName('*').length;i++) {
    if (document.getElementsByTagName('*')[i].type=="hidden" && document.getElementsByTagName('*')[i].id!="session") {
      document.getElementsByTagName('*')[i].value="";
    }
  }
  document.detail.submit();
}
function setChanged(){
  if (document.getElementById("saveUpdates") != null) {
    document.getElementById("saveUpdates").disabled = false;
    for (var i=0;i<document.getElementsByTagName('*').length;i++) {
      if ((document.getElementsByTagName('*')[i].type=="button" || document.getElementsByTagName('*')[i].type=="submit") && document.getElementsByTagName('*')[i].id!="saveUpdates") {
        document.getElementsByTagName('*')[i].disabled = true;
      }
    }
  }
}
function popNarr(narrField)
{ 
  var sNarrText = "";
  sNarrText = document.getElementById(narrField).value;
  document.getElementById(narrField).readOnly =  true;
  document.getElementById("narrBox").style.left=window.event.clientX + document.body.scrollLeft - 100;
  document.getElementById("narrBox").style.top=window.event.clientY + document.body.scrollTop - 50;
  document.getElementById("narrBox").style.width="200px";
  document.getElementById("narrBox").style.height="60px";
  document.getElementById("narrBox").innerHTML="<B>Enter Narration<textarea rows=3 cols=30 type=text name=narrText id=narrText>" + sNarrText + "</textarea></B><BR><BR><input type=button name=narrSave id=narrSave onclick='javascript:saveNarr()' value='Ok'>&nbsp;&nbsp;&nbsp;<input type=button name=rejectN id=rejectN onclick='javascript:cancelNarr()' value='Cancel'><input type=hidden name=narrField id=narrField value='" + narrField + "'>";
  document.getElementById("narrText").focus();
  document.getElementById("narrText").value = sNarrText;  
}
function popNarrLarge(narrField)
{ 
  var sNarrText = "";
  sNarrText = document.getElementById(narrField).value;
  document.getElementById(narrField).readOnly =  true;
  document.getElementById("narrBox").style.left=window.event.clientX + document.body.scrollLeft - 180;
  document.getElementById("narrBox").style.top=window.event.clientY + document.body.scrollTop - 50;
  document.getElementById("narrBox").style.width="400px";
  document.getElementById("narrBox").style.height="120px";
  document.getElementById("narrBox").innerHTML="<B valign=top>Enter Narration<textarea rows=6 cols=60 type=text name=narrText id=narrText>" + sNarrText + "</textarea></B><BR><BR><input type=button name=narrSave id=narrSave onclick='javascript:saveNarr()' value='Ok'>&nbsp;&nbsp;&nbsp;<input type=button name=rejectN id=rejectN onclick='javascript:cancelNarr()' value='Cancel'><input type=hidden name=narrField id=narrField value='" + narrField + "'>";
  document.getElementById("narrText").focus();
  document.getElementById("narrText").value = sNarrText;  
}
function saveNarr()
{
	var sNarrText = "";
  sNarrText = document.getElementById('narrText').value;
	var sNarrField = "";
  sNarrField = document.getElementById('narrField').value;
  document.getElementById(sNarrField).value = sNarrText;
  document.getElementById(sNarrField).readOnly =  false;
  document.getElementById("narrBox").style.left=0;
  document.getElementById("narrBox").style.top=0;
  document.getElementById("narrBox").style.width="0px";
  document.getElementById("narrBox").style.height="0px";
  document.getElementById("narrBox").innerHTML="";  
}
function cancelNarr()
{
  document.getElementById("narrBox").style.left=0;
  document.getElementById("narrBox").style.top=0;
  document.getElementById("narrBox").style.width="0px";
  document.getElementById("narrBox").style.height="0px";
  document.getElementById("narrBox").innerHTML="";
}
function selectAllCheckbox(bCheck){
  for (var i=0;i<document.getElementsByTagName('*').length;i++) {
    if (document.getElementsByTagName('*')[i].type=="checkbox" || document.getElementsByTagName('*')[i].type=="CHECKBOX") {
      document.getElementsByTagName('*')[i].checked = bCheck;
    }
  }
}
function HideSelect(){
  for (var i=0;i<document.getElementsByTagName('*').length;i++) {
    if (document.getElementsByTagName('*')[i].tagName=="select" || document.getElementsByTagName('*')[i].tagName=="SELECT") {
      document.getElementsByTagName('*')[i].style.visibility = "hidden";
    }
  }
}
function ShowSelect() {
  for (var i=0;i<document.getElementsByTagName('*').length;i++) {
    if (document.getElementsByTagName('*')[i].tagName=="select" || document.getElementsByTagName('*')[i].tagName=="SELECT") {
      document.getElementsByTagName('*')[i].style.visibility = "visible";
    }
  }
}

function paymark_verify(merchant) {
	window.open('http://www.paymark.co.nz/dart/darthttp.dll?etsl&tn=verify&merchantid=' + merchant, 'verify', 'scrollbars=yes, width=400, height=400');
}


var __isIE =  navigator.appVersion.match(/MSIE/);                                                            
var __userAgent = navigator.userAgent;                                                                       
var __isFireFox = __userAgent.match(/firefox/i);                                                             
var __isFireFoxOld = __isFireFox && (__userAgent.match(/firefox\/2./i) || __userAgent.match(/firefox\/1./i));
var __isFireFoxNew = __isFireFox && !__isFireFoxOld;                                                         
                                                                                                             
                                                                                                             
function __parseBorderWidth(width) {                                                                         
    var res = 0;                                                                                             
    if (typeof(width) == "string" && width != null && width != "" ) {                                        
        var p = width.indexOf("px");                                                                         
        if (p >= 0) {                                                                                        
            res = parseInt(width.substring(0, p));                                                           
        }                                                                                                    
        else {                                                                                               
     		//do not know how to calculate other values (such as 0.5em or 0.1cm) correctly now                   
    		//so just set the width to 1 pixel                                                                   
            res = 1;                                                                                         
        }                                                                                                    
    }                                                                                                        
    return res;                                                                                              
}                                                                                                            
                                                                                                             
                                                                                                             
//returns border width for some element                                                                      
function __getBorderWidth(element) {                                                                         
	var res = new Object();                                                                                    
	res.left = 0; res.top = 0; res.right = 0; res.bottom = 0;                                                  
	if (window.getComputedStyle) {                                                                             
		//for Firefox                                                                                            
		var elStyle = window.getComputedStyle(element, null);                                                    
		res.left = parseInt(elStyle.borderLeftWidth.slice(0, -2));                                               
		res.top = parseInt(elStyle.borderTopWidth.slice(0, -2));                                                 
		res.right = parseInt(elStyle.borderRightWidth.slice(0, -2));                                             
		res.bottom = parseInt(elStyle.borderBottomWidth.slice(0, -2));                                           
	}                                                                                                          
	else {                                                                                                     
		//for other browsers                                                                                     
		res.left = __parseBorderWidth(element.style.borderLeftWidth);                                            
		res.top = __parseBorderWidth(element.style.borderTopWidth);                                              
		res.right = __parseBorderWidth(element.style.borderRightWidth);                                          
		res.bottom = __parseBorderWidth(element.style.borderBottomWidth);                                        
	}                                                                                                          
                                                                                                             
	return res;                                                                                                
}                                                                                                            
                                                                                                             
//returns absolute position of some element within document                                                  
function getAbsolutePos(element) {                                                                           
	var res = new Object();                                                                                    
	res.x = 0; res.y = 0;                                                                                      
	if (element !== null) {                                                                                    
		res.x = element.offsetLeft;                                                                              
		res.y = element.offsetTop;                                                                               
    	                                                                                                       
		var offsetParent = element.offsetParent;                                                                 
		var parentNode = element.parentNode;                                                                     
		var borderWidth = null;                                                                                  
                                                                                                             
		while (offsetParent != null) {                                                                           
			res.x += offsetParent.offsetLeft;                                                                      
			res.y += offsetParent.offsetTop;                                                                       
			                                                                                                       
			var parentTagName = offsetParent.tagName.toLowerCase();	                                               
                                                                                                             
			if ((__isIE && parentTagName != "table") || (__isFireFoxNew && parentTagName == "td")) {		           
				borderWidth = __getBorderWidth(offsetParent);                                                        
				res.x += borderWidth.left;                                                                           
				res.y += borderWidth.top;                                                                            
			}                                                                                                      
		                                                                                                         
			if (offsetParent != document.body && offsetParent != document.documentElement) {                       
				res.x -= offsetParent.scrollLeft;                                                                    
				res.y -= offsetParent.scrollTop;                                                                     
			}                                                                                                      
                                                                                                             
			//next lines are necessary to support FireFox problem with offsetParent                                
   			if (!__isIE) {                                                                                       
    			while (offsetParent != parentNode && parentNode !== null) {                                        
					res.x -= parentNode.scrollLeft;                                                                    
					res.y -= parentNode.scrollTop;                                                                     
					                                                                                                   
					if (__isFireFoxOld) {                                                                              
						borderWidth = kGetBorderWidth(parentNode);                                                       
						res.x += borderWidth.left;                                                                       
						res.y += borderWidth.top;                                                                        
					}                                                                                                  
    				parentNode = parentNode.parentNode;                                                              
    			}                                                                                                  
			}                                                                                                      
                                                                                                             
   			parentNode = offsetParent.parentNode;                                                                
    		offsetParent = offsetParent.offsetParent;                                                            
		}                                                                                                        
	}                                                                                                          
    return res;                                                                                              
}                                                                                                            



