// JavaScript Document

function MenuState(imgName_IN, treeState_IN, divID_IN){
	var divName = "div" + divID_IN
		   
	
	if (treeState_IN =="plus"){
		//change the image id and src
		document.images[imgName_IN].src = 'images/Graphics/Minus_GR.gif'
		
		//change the image state
		document.images[imgName_IN].id = "minus"
		
		//change the div
		document.getElementById(divName).style.display="block"
	
	}else if (treeState_IN == "minus"){
		//change the image
		document.images[imgName_IN].src = 'images/Graphics/Plus_GR.gif'
		
		//change the image state
		document.images[imgName_IN].id = "plus"
	
		//change the div
		var divName = "div" + divID_IN
		document.getElementById(divName).style.display="none"
		
		
	}	
		
		/*alert(document.getElementById(divName).style.display)*/

}


	function tabON(tab_IN){
		var objStyle = tab_IN.className
		if(tab_IN.id=="tabGREEN"){
		    if(objStyle=='TABGreenOFF'){tab_IN.className = 'TABBottomON'}
		    if(objStyle=='TABBottomON'){tab_IN.className = 'TABGreenOFF'}
        }else{
		    if(objStyle=='TABTopOFF'){tab_IN.className = 'TABTopON'}
		    if(objStyle=='TABTopON'){tab_IN.className = 'TABTopOFF'}
		    if(objStyle=='TABBottomOFF'){tab_IN.className = 'TABBottomON'}
		    if(objStyle=='TABBottomON'){tab_IN.className = 'TABBottomOFF'}
        }
	}
	


	
	
	
	
	function tabClick(tabID_IN){
        var oLayer = document.getElementById("LAYERIndexIntro")
        var oLayerData = ""
		var oTitle, oSummary, oLearnMore, oImage, oImageAlt
		var oLearnLink
		var oLearnAlt
		
		
		
		
		if (tabID_IN=="Welcome"){

            document.getElementById("LAYERIndexIntro").style.display = "block"
            document.getElementById("LAYERIndexDetail").style.display = "none"
			
		}else{
			switch (tabID_IN){
				case "HBuying":
					oTitle="Homebuyer Assistance"
					oSummary ="MaineHousing provides low fixed rate mortgages and other assistance to help make homeownership affordable for more Maine people. No point, low point and extended payment term options are available. There are options with little or no down payment required, though if you still need help with the cash needed for closing, we also offer down payment and closing cost assistance. MaineHousing mortgages even come with payment protection for unemployment. And if you have a MaineHousing mortgage, you can be sure it will never be sold to anyone" + " - " + "it stays with us."
					oLearnMore ="Learn More About MaineHousing's Homebuyer Assistance"
					oLearnLink ="HOMEBUYERPrograms.aspx?oProgramCategory=1"
					oLearnAlt ="Click Here to Learn More about Homebuyer Assistance"
					oImage = "Images/IndexPagePics/WelcomeHomebuyer_GR.gif"
					oImageAlt = "MaineHousing Homebuyer Assistance Image."
				break;
				case "HImprovement":
					oTitle="Home Improvement & Repair Assistance"
					oSummary ="MaineHousing offers many programs to help with your home improvement and repair needs. With one application to the Home Repair Network, you can apply to state and federal programs that provide or low cost loans to repair or replace failed wells or septic systems, make heating, electrical, or structural repairs, and improve home accessibility. MaineHousing also offers programs to make your home lead safe, or fund repairs if your home has been damaged in a declared natural disaster."
					oLearnMore ="Learn More about MaineHousing's Home Improvement Assistance"
					oLearnLink ="HOMEIMPROVEMENTPrograms.aspx?oProgramCategory=2"
					oLearnAlt ="Click Here to Learn More about Home Improvement Assistance"
					oImage = "Images/IndexPagePics/WelcomeHomeRepair_GR.gif"
					oImageAlt = "Home replacement work underway in Aroostook County."
				break;
				case "Renting":
					oTitle="Rental Assistance"
					oSummary ="Rental housing costs are increasingly out of reach for many lower and moderate income Maine people. Rental assistance, either in the form of housing choice vouchers, subsidized apartments or affordable rental housing can help. Vouchers can help pay your rent in the apartment of your choice. Subsidized apartments provide qualified tenants below-market rents. Affordable rental housing are units which the rent is capped to benefit the tenants. Waiting lists can be long, so you may want to apply for both kinds of help. "
					oLearnMore ="Learn More about MaineHousing's Rental Assistance"
					oLearnLink ="RENTALPrograms.aspx?oProgramCategory=3"
					oLearnAlt ="Click Here to Learn More about Rental Assistance"
					oImage = "Images/IndexPagePics/WelcomeRental_GR.gif"
					oImageAlt = "Affordable apartments at MaineHousing-financed Capital Village have access to a solar-powered community and laundry facilities."
				break;
				case "Energy":
					oTitle="Energy and Heating Assistance"
					oSummary ="If you cannot afford to heat your home, pay electric bills, or would benefit from energy improvements such as new insulation, a new heating system, or energy efficient appliances, help may be available from MaineHousing programs. Lower income households may qualify for heating assistance and energy improvements at no cost to them. Moderate-income households may qualify for low cost energy loans."
					oLearnMore ="Learn More about MaineHousing's Energy & Heating Assistance"
					oLearnLink ="ENERGYPrograms.aspx?oProgramCategory=4"
					oLearnAlt ="Click Here to Learn More about Energy & Heating Assistance"
					oImage = "Images/AnimatedGraphics/WinterHarborWindmill_AGR.gif"
					oImageAlt = "Windmill at Winter Harbor Rental Development"
				 break;
				case "Homeless":
					oTitle="Homeless Assistance"
					oSummary ="If you are homeless and need emergency shelter, or need transitional or subsidized housing to get back on your feet, MaineHousing may be able to help. We finance emergency shelters and other affordable housing options, and can help you locate this housing. We also provide rental assistance to people who are homeless and working toward self-sufficiency.  MaineHousing and its partners are working to end homelessness in Maine."
					oLearnMore ="Learn More about MaineHousing's Homeless Assistance"
					oLearnLink ="HOMELESSPrograms.aspx?oProgramCategory=5"
					oLearnAlt ="Click Here to Learn More about Homeless Assistance"
					oImage = "Images/IndexPagePics/WelcomeHomeless_GR.gif"
					oImageAlt = "MaineHousing Homeless Assistance Image."
				break;
				case "HDevelopment":
					oTitle="Housing Development & Financing Options"
					oSummary ="MaineHousing offers several programs to encourage private development of affordable rental housing for families, seniors and persons with special needs. Low income housing tax credits, development loans, direct development subsidies, affordable housing tax increment financing, and options to restructure debt are available. Developers are required to ensure that housing developed with MaineHousing financing remains affordable. "
					oLearnMore ="Learn More about MaineHousing's Housing Development Assistance"
					oLearnLink ="HOUSINGDEV.aspx"
					oLearnAlt ="Click Here to Learn More about Housing Development Assistance"
					oImage = "Images/IndexPagePics/WelcomeDevelopment_GR.gif"
					oImageAlt = "MaineHousing-financed Casco Terrace in Portland provides affordable apartments."
				break;
				case "DataReports":
					oTitle="Data & Reports"
					oSummary="Housing affordability is an increasing problem throughout Maine as housing costs rise much more quickly than household incomes. MaineHousing provides housing market data, reports, educational materials, and other information that show the seriousness of affordable housing needs, the importance of housing to Maine's economy, and how MaineHousing is addressing these issues."
					oLearnMore ="Learn More about MaineHousing's Data & Reports"
					oLearnLink ="DATA.aspx"
					oLearnAlt ="Click Here to Learn More about Data & Reports"
					oImage = "Images/IndexPagePics/WelcomeData_GR.gif"
					oImageAlt = "MaineHousing Data and Reports."
				break;
				
	
				default:
					//something
				break;
			}
			
			 document.getElementById("lblTitle").innerHTML=oTitle;
			 document.getElementById("lblSummary").innerHTML=oSummary;
			 document.getElementById("imgProgram").src  = oImage;
			 document.getElementById("imgProgram").title = oImageAlt;
			 document.getElementById("lnkLearnMore").href = oLearnLink
             document.getElementById("lnkLearnMore").title = oLearnAlt
             document.getElementById("lnkLearnMore").innerHTML = oLearnMore
			document.getElementById("LAYERIndexDetail").style.display = "block"
            document.getElementById("LAYERIndexIntro").style.display = "none"
		}
        
			
			
			
			//change the tab states
			if(tabID_IN=="HBuying"){document.getElementById("HBuying").className = "TABSelected"} else {document.getElementById("HBuying").className = "TABOff"};
			if(tabID_IN=="HImprovement"){document.getElementById("HImprovement").className = "TABSelected"} else {document.getElementById("HImprovement").className = "TABOff"};
			if(tabID_IN=="Renting"){document.getElementById("Renting").className = "TABSelected"} else {document.getElementById("Renting").className = "TABOff"};
			if(tabID_IN=="Energy"){document.getElementById("Energy").className = "TABSelected"} else {document.getElementById("Energy").className = "TABOff"};
			if(tabID_IN=="Homeless"){document.getElementById("Homeless").className = "TABSelected"} else {document.getElementById("Homeless").className = "TABOff"};
			if(tabID_IN=="HDevelopment"){document.getElementById("HDevelopment").className = "TABSelected"} else {document.getElementById("HDevelopment").className = "TABOff"};
			if(tabID_IN=="DataReports"){document.getElementById("DataReports").className = "TABSelected"} else {document.getElementById("DataReports").className = "TABOff"};
			
	}


	    function partnersMenuSelect(location_IN){
	        document.location =location_IN;
	    }
		
	function openForm(){
		window.open("InfoRequestForm","frmRequestInfo","toolbars=0,width=487,height=600,scrollbar=0")
	}
	
	function openRequestForm(strEmail_IN){
		/*var strAddress = "FORMRequestInfo.aspx?SendTo=" + strEmail_IN*/
		var strAddress = "InfoRequestForm?SendTo=" + strEmail_IN
		window.open(strAddress,"frmRequestInfo","toolbars=0,width=525,height=600,scrollbars=1")
		
	}

    function EmailMe(email_IN){
        document.location.href='MAILTO:' + email_IN + '@mainehousing.org?subject=Website Email'
    }

function formatCurrency(strValue)
{
	strValue = strValue.toString().replace(/\$|\,/g,'');
	dblValue = parseFloat(strValue);

	blnSign = (dblValue == (dblValue = Math.abs(dblValue)));
	dblValue = Math.floor(dblValue*100+0.50000000001);
	intCents = dblValue%100;
	strCents = intCents.toString();
	dblValue = Math.floor(dblValue/100).toString();
	if(intCents<10)
		strCents = "0" + strCents;
	for (var i = 0; i < Math.floor((dblValue.length-(1+i))/3); i++)
		dblValue = dblValue.substring(0,dblValue.length-(4*i+3))+','+
		dblValue.substring(dblValue.length-(4*i+3));
	return (((blnSign)?'':'-') + '$' + dblValue + '.' + strCents);
}

function formatPhone (elementRef) {
    var elementValue = elementRef.value;
    alert(elementValue)
    elementRef.value  = elementValue;
}


function getValue(num)
{
    var noJunk = ""
    var withDollar = ""
    var foundDecimal = 0
    var foundAlphaChar = 0
    num += "";

    if (num == "") { return(0); }
    for (i=0; i <= num.length; i++)
    {
        var thisChar = num.substring(i, i+1);
        if (thisChar == ".")
        {
          foundDecimal = 1;
          noJunk = noJunk + thisChar;
        }
        if ((thisChar < "0") || (thisChar > "9"))
        {
          if ((thisChar != "$") && (thisChar !=".") && (thisChar != ",") && (thisChar != " ") && (thisChar !="")) foundAlphaChar = 1;
        }
        else 
 {
    withDollar = withDollar + thisChar
    noJunk = noJunk + thisChar
 }

 if ((thisChar == "$") || (thisChar == ".") || (thisChar == ","))
 {
   withDollar = withDollar + thisChar
 }
  }
     if (foundDecimal) { return parseFloat(noJunk); }
     else if (noJunk.length > 0) { return parseFloat(noJunk); }
     else return 0;
}


function FormatNumber(num, decimalNum, bolLeadingZero, bolParens)
   /* IN - num:            the number to be formatted
           decimalNum:     the number of decimals after the digit
           bolLeadingZero: true / false to use leading zero
           bolParens:      true / false to use parenthesis for - num

      RETVAL - formatted number
   */
   {
       var tmpNum = num;

       // Return the right number of decimal places
       tmpNum *= Math.pow(10,decimalNum);
       tmpNum = Math.floor(tmpNum);
       tmpNum /= Math.pow(10,decimalNum);

       var tmpStr = new String(tmpNum);

       // See if we need to hack off a leading zero or not
       if (!bolLeadingZero && num < 1 && num > -1 && num !=0)
           if (num > 0)
               tmpStr = tmpStr.substring(1,tmpStr.length);
           else
               // Take out the minus sign out (start at 2)
               tmpStr = "-" + tmpStr.substring(2,tmpStr.length);                        


       // See if we need to put parenthesis around the number
       if (bolParens && num < 0)
           tmpStr = "(" + tmpStr.substring(1,tmpStr.length) + ")";


       return tmpStr;
   }


function FormatPercent(num,decimalNum,bolLeadingZero,bolParens)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.										
 
	RETVAL:
		The formatted number!		
 **********************************************************************/
{
	var tmpStr = new String(FormatNumber(num*100,decimalNum,bolLeadingZero,bolParens));

	if (tmpStr.indexOf(")") != -1) {
		// We know we have a negative number, so place '%' inside of ')'
		tmpStr = tmpStr.substring(0,tmpStr.length - 1) + "%)";
		return tmpStr;
	}
	else
		return tmpStr + "%";			// Return formatted string!
}

function filterNum(str) {
          re = /\$|,|@|#|~|`|\%|\*|\^|\&|\(|\)|\+|\=|\[|\-|\_|\]|\[|\}|\{|\;|\:|\'|\"|\<|\>|\?|\||\\|\!|\$/g;
          // remove special characters like "$" and "," etc...
          return str.replace(re, "");
     }


function filterPercent(str) {
          re = /\%/g;
          // remove special characters like "$" and "," etc...
          return str.replace(re, "");
     }

function trim(stringToTrim) {
	return stringToTrim.replace(/^\s+|\s+$/g,"");
}

function checkChanged(chk_IN, cell_IN){
    if(chk_IN.checked==true){
        cell_IN.bgColor = "#ffffcc"
    }else {
	    cell_IN.bgColor = ""
    
	}
}
