function ckIsNumValidate(obj, num, errorTxt)
{
    
	var item = obj.value
	
	if(item.length == num)
	{
		var inputStr = item.toString()
		for (var i=0; i< item.length; i++)
		{
			var oneChar = item.charAt(i)
			
			if (oneChar <"0" || oneChar > "9")
			{
				alert(errorTxt)
			
				obj.value = ""
				obj.focus()
				obj.select()
				return false
				break
			}
			
				
		 }  // end for loop

		 // check to see if the year is greater than 1900 and intMaxYear (over 18 years of age)
		 if(obj.name=="yearOfBirth")
		 	{
		 		
				var intItem = parseInt(item, 10)
				var now = new Date()
				var intMaxYear =  now.getFullYear() - 18
				 if ( intItem < 1900 || intItem > intMaxYear)
				    {
							alert("The birth year, '" + intItem + "', does not seem valid. Please double-check it.")
								obj.value = ""
							 obj.focus()
							 obj.select()
							 return false
				    }
		  	}		 
	 }  // end if object is 4 digits
	 else
	 {
	  	alert(errorTxt)
       		obj.value = ""
	    	obj.focus()
		obj.select()
		return false
	  }
	  
	
}

function isNumber(inputVal, obj)
{
	var oneDecimal = false
	var valid = true
	inputStr = inputVal.toString()
	for(var i=0; i<inputStr.length; i++)
	{
		var oneChar = inputStr.charAt(i)
		if(i==0 && oneChar == "-")
		{
			continue
		}
		
		
		if(oneChar == "." && !oneDecimal)
		{
			oneDecimal = true
			continue
		}
		
		if(oneChar <"0" || oneChar >"9" )
		{
			if(oneChar ==",")
			{
				alert("Please do not use comma in the number.")
			}
			else
			{
				alert("Sorry, but '" + inputStr + "' is not a valid number.")
			}
			
			valid = false
			obj.value = ""
			break
		}
	}
	
	return valid
}

function getStyle(aObj)
{
	ns = (document.layers)? true:false
	ie = (document.all)? true:false
	var theObj
	
	if (ns){
		theObj = eval("document." + aObj)	
		}
		
	if (ie){
		theObj = eval(aObj + ".style")
		}
	
	return theObj
}

function show_hide(on, obj)
{

	if (on == 'No' || on == '0' || on == 'Unknown'){
		on ='off'
		document.forms[0].whichPublicHousing.value = ""
		}
	if (on == 'Yes'){
		on = 'on'
		}
var ns, ie;
var actShow
var actHide

var thisObj
var ieObj = eval(obj + ".style")
var nsObj = eval("document." + obj)
ns = (document.layers)? true:false
ie = (document.all)? true:false
if (ns){
  thisObj = nsObj
  actShow = "show"
  actHide = "hide"
  }
  
if (ie){
	thisObj = ieObj
	actShow = "visible"
	actHide = "hidden"
	}

	if (on == 'on'){
		if (obj == 'gcm'){
			document.forms[0].referToCM[1].checked = true
		}
   		thisObj.visibility = actShow
   		}
		
	if (on == 'off'){
		//alert(obj)
		thisObj.visibility = actHide		
		}
	
 	if (obj == 'gcm'){
		if (ie){
			cmp.style.visibility = actHide
			}
		else{
			document.cmp.visibility = actHide
  			}
	}	
	


}
	
 function hide_all(objName, arraySize)
 {
 	var obj
	
 	for (var i=0; i<=arraySize; i++)
	{
		obj =objName
		obj = obj + i
	
		show_hide('off',obj)
	}
 }	
 
 function cal_debt_income(objName,num)
 {
 	var debt = 0
	var income = 1
	var theObj = eval("document.forms[0]." + objName)
	var obj = eval("document.forms[0]")
	var valid = true
  if(isNumber(num, theObj))
	{	
	
	
	debt = parseFloat(obj.mortgageRent.value) + parseFloat(obj.creditCardPym.value) + parseFloat(obj.carLoanPym.value) + parseFloat(obj.otherLoan.value)
	income = parseInt(parseFloat(obj.grossSalary.value)) + parseFloat(obj.bonusOvertime.value) + parseFloat(obj.govAssist.value) + parseFloat(obj.alimony.value) + parseFloat(obj.pension.value) + parseFloat(obj.otherIncomes.value) 
	obj.totalDebtPym.value = debt
	obj.totalDebtPymDisplay.value = debt
	obj.totalIncome.value = income
	obj.totalIncomeDisplay.value = income
	if(income==0){income=1}
	
	obj.debtIncomeRatio.value = parseFloat(debt/income)
	obj.debtIncomeRatioDisplay.value = parseFloat(debt/income)
	}
	else
	{
		
		
		theObj.value ="0"
		theObj.focus()
		theObj.select()
		valid = false
	}
	
	return valid
  }
  
  
function cal_equity(objName,num)
 {
 //	var asset = 0
//	var liability = 1
	var theObj = eval("document.forms[0]." + objName)
	var obj = eval("document.forms[0]")
	var valid = true
	//asset = 
	//liability = 
  if(isNumber(num, theObj))
	{	

	obj.totalEquityAtEnter.value =  parseFloat(obj.totalAssetAtEnter.value) -  parseFloat(obj.totalLiabilityAtEnter.value) 
	}
	else
	{
		
		
		theObj.value = "0"
		theObj.focus()
		theObj.select()
		valid = false
	}
	return valid
  }
  
// use this to open a child window and send value back to the parent window
var myWind
function doNew(url, source){
	var aUrl = url + "?source_field=" + source
	//alert(aUrl)
	if(!myWind || myWind.closed)
	{ myWind = window.open(aUrl,"subWindow", "height=230, width=350")
	} else {
		myWind.focus()
	}
}

// this is used to popup org contact info
function popupOrg(mylink)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href,'ViewOrgContactInfo','scrollbars=1,toolbar=0,location=0,status=0,resizable=1,width=375,height=225');
return false;
}


function hide()
{
	alert("hidden")
	//document.forms[0].date1.visible = "hidden"
	
}
	
	
function calEquity(objName, val)
{
	var theObj = eval("document.forms[0]." + objName)
   if (isNumber(val, theObj))
    {
	document.forms[0]._totalEquity.value = parseFloat(document.forms[0]._totalAssets.value) - parseFloat(document.forms[0]._totalLiabilities.value)
	}
   else
    {
	 theObj.focus()	 
    	 theObj.value = ""
	 
    }
	
}



function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
    if(document.layers)	   //NN4+
    {
       document.layers[szDivID].display = iState ? "inline" : "none";
    }
    else if(document.getElementById)	  //gecko(NN6) + IE 5+
    {
        var obj = document.getElementById(szDivID);
        obj.style.display = iState ? "inline" : "none";
    }
    else if(document.all)	// IE 4
    {
        document.all[szDivID].style.display = iState ? "inline" : "none";
    }
}