<!--
// JavaScript Document
var l = new Array(90);
var s = new Array(11); // array to store matching values
var ss = new Array(11); // array to store matching values
var sss = new Array(11); // array to store itemDesc values
var ssss = new Array(11); // array to store itemID values

var index= 0;
var index2 = 0;
var index3 = 0;

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_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];}
}

function DeleteTheRow(therow, rowID){

		var objRow = eval(therow);
		objRow.style.display = 'none';
 		document.getElementById('itemID' + rowID).value = -1;
/*
		
		eval("document.taxFrm.value"+rowID+".value = -1");
		eval("document.taxFrm.pRate"+rowID+".value = -1");
		eval("document.taxFrm.dRate"+rowID+".value = -1");
		eval("document.taxFrm.qtyCount"+rowID+".value = -1");
		eval("document.taxFrm.itemDesc"+rowID+".value = -1");*/
		selectedItemArray[rowID] = 0;
		itemArray[rowID] = 0;
/*		if (isPostBack == true){
			postedValues[rowID] = 0;
		}*/
}

function processState(){
	stateValue = document.getElementById('state').value;
	
	if (stateValue == "ACT") document.getElementById('city').value = "Canberra";
	else if (stateValue == "NSW") document.getElementById('city').value = "Sydney";
	else if (stateValue == "NT") document.getElementById('city').value = "Darwin";
	else if (stateValue == "QLD") document.getElementById('city').value = "Brisbane";
	else if (stateValue == "SA") document.getElementById('city').value = "Adelaide";
	else if (stateValue == "TAS") document.getElementById('city').value = "Hobart";
	else if (stateValue == "VIC") document.getElementById('city').value = "Melbourne";
	else if (stateValue == "WA") document.getElementById('city').value = "Perth";
	else document.getElementById('city').value = "";
}

function charCount(){
	if (document.getElementById('homePre').value.length == 2){ // if there's 2 characters, change to homeN field
		document.getElementById('homeN').focus();
	}
}

function sqmPopup() {
  window.open('squareMpopup.php?buildingType=' + document.forms[0].buildingType.options[document.forms[0].buildingType.selectedIndex].text + '&buildingID='+ document.forms[0].buildingType.options[document.forms[0].buildingType.selectedIndex].value, 'squareMWindow', 'scrollbars=yes,resizable=1,width=468,height=710');
}

function housenLandPopup() {
  window.open('housenLand.php', 'squareMWindow', 'scrollbars=yes,resizable=1,width=468,height=275');
}

function plantPopup() {
  window.open('plantPopup.php', 'plantItemMWindow', 'scrollbars=yes,resizable=1,width=500,height=400');
}

function ShowHideValueRow(rowID)
{
	ShowHideTheRow("userValRow" + rowID);
	ShowHideTheRow("defaultRow" + rowID);
	tempVal = document.getElementById('isUser' + rowID).value;
	//alert(tempVal);
//	if (isPostBack == false){
		if (tempVal == 1)
		{
			document.getElementById('isUser' + rowID).value = 0;
		} else {
			document.getElementById('isUser' + rowID).value = 1;
		}
//	}	
}

function showHideDates(pos){

	ShowHideTheRow("dateRow" + pos);
	ShowHideTheRow("otherDateRow2" + pos);
}

function showHideInstructions(){
	ShowHideTheRow("instructions00");
	ShowHideTheRow("instructions01");
	ShowHideTheRow("instructions02");
	ShowHideTheRow("instructions03");
}

function ShowHideTheRow(therow)
{
	if (document.getElementById(therow).style.display == 'none')
	{
		document.getElementById(therow).style.display = '';
//		scrollTo(0,document.body.scrollHeight);
	}
	else if (document.getElementById(therow).style.display == '')
	{
		document.getElementById(therow).style.display = 'none'; 
	}
}
function showHideStep1(){
	ShowHideTheRow('step1');
	ShowHideTheRow('step2');
	ShowHideTheRow('step1Details');
	ShowHideTheRow('blahblahrow123');
	ShowHideTheRow('showItemList');
}
	
function saveNewDate(id){

	if (id == 1){
		if (document.getElementById('SCounter').value == 0){	// no plant items inserted entered yet
			document.getElementById('settleDateValue').value = document.getElementById('settleDate').value;
		} else {
			document.getElementById('settleDateValue').value = document.getElementById('date' + eval(document.getElementById('SPos').value - 1)).value;
		}
	} else {
		if (document.getElementById('BCounter').value == 0) {
			document.getElementById('buildingDateValue').value = document.getElementById('buildDate').value;
		} else {			
			document.getElementById('buildingDateValue').value = document.getElementById('date' + eval(document.getElementById('BPos').value - 1)).value;
		}
		
	}
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
	//displayME();
}

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 closeNFocus(){
	MM_showHideLayers('Layer1','','hide');
	document.getElementById('searchBar').focus();
}

function checkKey(){
	if (window.event.keyCode == 13){
		doSearch();
	}
}

function setNewDate(){
	document.getElementById('buildDate').value = "Pre 1985";
	document.getElementById('buildingDateValue').value = "01/01/1985";
	document.getElementById('buildDate2').value = "Pre 1985";
//	document.taxFrm.constructionCost.disabled = true;
//	document.taxFrm.constructionCost.value = 0;
}

function validateInput(id)
{
	var allOk = true;
	
	allOk = checkFormToSubmit(id);
	if (allOk){
		scroll(0,0);
		if (id == 1)
		{
			setYPOS();
			showHideStep1();
			if (isPostBack == true)
			{
				document.getElementById("itemList").style.visibility = "hidden";
				//	MM_showHideLayers('itemList','','hide');
			} else
			{
				MM_showHideLayers('itemList','','show');
			}
			if (document.getElementById('buildDate').value == "Pre 1985"){
//				document.taxFrm.capitalWorks.value = "";
//				document.taxFrm.capitalWorks.disabled = true;
			} else {
//				document.taxFrm.capitalWorks.disabled = false;
				if (document.getElementById('blahblahrow123').style.display == '')
				{
					document.getElementById('blahblahrow123').style.visibility = "visible";
	//				document.taxFrm.capitalWorks.focus();
				} 	
			}
		} else {	
			document.getElementById('taxFrm').submit();
		}
	}
}

function setCapField(){
	var theDate;
	if (document.getElementById('buildDate').value != "Pre 1985"){
		theDate = document.getElementById('buildDate').value;
		theDate = theDate.substr(6, theDate.length);
		theDate = parseInt(theDate); // convert to int
		
		if (theDate <  1985){
			document.getElementById('buildDate').value = "Pre 1985";
			document.getElementById('buildingDateValue').value = "17/07/1985";
			document.getElementById('buildDate2').value = "Pre 1985";
//			document.taxFrm.constructionCost.disabled = true;
//			document.taxFrm.constructionCost.value = 0;
		} 
	}
	
	if (document.getElementById('buildDate2').value != "Pre 1985"){
		theDate = document.getElementById('buildDate2').value;
		theDate = theDate.substr(6, theDate.length);
		theMonth = theDate.substr(3, 5);
		theDay = theDate.substr(0, 2);
		theDate = parseInt(theDate); // convert to int
		
		if (((theDate ==  1985) && (theMonth <= 7) && (theDay <= 17)) || (theDate < 1985)){
			document.getElementById('buildDate2').value = "Pre 1985";
			document.getElementById('buildingDateValue').value = "17/07/1985";
		} 
	}
}

function getPriorMonthDay(pos){
	months = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	return months[pos - 1];
}

function calcBuildStart(){
	numDays = 7;
	if (document.getElementById('buildDate').value != ""){
		if (document.getElementById('buildDate').value == "Pre 1985"){
			document.getElementById('buildDate2').value = "Pre 1985";
		} else {
			selectID = document.forms[0].buildingType.options[document.forms[0].buildingType.selectedIndex].value;
		
			var timeframe = 0;
			for (j=0; j < buildingDuration.length - 1; j++){
	
				if (selectID == buildingDuration[j][0]){
	
					timeframe = buildingDuration[j][1];
				}
			}
			
			timeframe = timeframe * numDays;
			
			// calculate the day timeframe value ago
			document.getElementById('buildDate2').value = getStartDate(document.getElementById('buildDate').value, timeframe);
		}
	}
}

function getStartDate(aDate, timeframe){
	tempMonth = parseInt(aDate.substring(3, 5), 10);
	tempMonth--;
	startDate = new Date(parseInt(aDate.substring(6, 10), 10), tempMonth, parseInt(aDate.substring(0, 2), 10));
	startDateDate = startDate.getDate() - timeframe;

	startDate.setDate(startDateDate);
	myMonth = startDate.getMonth() + 1;
	myDay = startDate.getDate();
	myYear = startDate.getFullYear();
	
	mystartDate = '';
	
	newDay = myDay.toString();
	newMonth = myMonth.toString();
	
	if (parseInt(myMonth, 10) < 10){
	  newMonth = "0" + myMonth.toString();
	} 
	
	if (parseInt(myDay, 10) < 10){
	  newDay = "0" + myDay.toString();
	}
	
	dateToReturn = newDay + "/" + newMonth + "/" + myYear;
	return dateToReturn;
}

function calcAqDate(){
	if (document.getElementById('settleDate').value != ""){
		numDays = 30;
		document.getElementById('settleDate2').value = getStartDate(document.getElementById('settleDate').value, numDays);	
	}
}

function showHideConstructionCost(){
	ShowHideTheRow('conCost1');
//	ShowHideTheRow(conCost2);
	ShowHideTheRow('conCost3');
}


function showItems()
{
	foundFlag = false;
	for (i = 0; i < itemArray.length; i++)
	{
		if (itemArray[i] == 1)
		{
			foundFlag = true;
		}
	}
	if (foundFlag == true)
	{
		MM_showHideLayers('itemList','','hide'); 
		displayChosenItems();
	} else {
		var errorMsgText = "<ul class='errorList'>";
		var dots = '<li>';
		errorMsgText += dots+"Please enter at least <b>1</b> depreciable item </li>";
		popSizedWin("error.php?error=" + errorMsgText, 500, 500);
	}
}
//-->
