var ns4=(document.layers);
var ie=(document.all);
var w3=(document.getElementById && !ie);

function hidediv(groupid)
{
    if(!ns4 && !ie && !w3) return;
    if(ie) thisgroup=eval('document.all.' + groupid + '.style');
    else if(ns4) thisgroup=eval('document.layers["' + groupid +'"]');
    else if(w3) thisgroup=eval('document.getElementById("' + groupid + '").style');
		thisgroup.display ="none";
}

function showdiv(groupid){
    if(!ns4 && !ie && !w3) return;
    if(ie) thisgroup=eval('document.all.' + groupid + '.style');
    else if(ns4) thisgroup=eval('document.layers["' + groupid +'"]');
    else if(w3) thisgroup=eval('document.getElementById("' + groupid + '").style');
    thisgroup.display=""; 
}

function showhide(groupid){
    if(!ns4 && !ie && !w3) return;
    if(ie) thisgroup=eval('document.all.' + groupid + '.style');
    else if(ns4) thisgroup=eval('document.layers["' + groupid +'"]');
    else if(w3) thisgroup=eval('document.getElementById("' + groupid + '").style');
    if (thisgroup.display == "none")
        thisgroup.display=""; 
    else
        thisgroup.display ="none"; 
}

function changeClass(groupid,dState){
    document.getElementById(groupid).className = dState;
}

function setAgencySection() {
  if (getCheckedValue(document.appl.FHAHUD) == 'Y')
  {
    changeClass('FHA','live');
	document.appl.FhaHudNumber.disabled = false;
	document.appl.DateMiniEagle.disabled = false;
	document.appl.DateDirectEndorsement.disabled = false;
  }
  else
  {
    changeClass('FHA','dim');
	document.appl.FhaHudNumber.disabled = true;
	document.appl.DateMiniEagle.disabled = true;
	document.appl.DateDirectEndorsement.disabled = true;
  }

  if (getCheckedValue(document.appl.FannieMae) == 'Y')
  {
    changeClass('FMAE','live');
	document.appl.FannieMaeNumber.disabled = false;
	document.appl.DateFannieMae.disabled = false;
  }
  else
  {
    changeClass('FMAE','dim');
	document.appl.FannieMaeNumber.disabled = true;
	document.appl.DateFannieMae.disabled = true;
  }

  if (getCheckedValue(document.appl.FreddieMac) == 'Y')
  {
    changeClass('FMAC','live');
	document.appl.FreddieMacNumber.disabled = false;
	document.appl.DateFreddieMac.disabled = false;
  }
  else
  {
    changeClass('FMAC','dim');
	document.appl.FreddieMacNumber.disabled = true;
	document.appl.DateFreddieMac.disabled = true;
  }

  if ( getCheckedValue(document.appl.AffiliatedCompany) == 'Y' )
  {
	changeClass('AffCompany','live');
	document.appl.ACName.disabled = false;
	document.appl.ACBusinessType.disabled = false;
	document.appl.ACPercentOwned.disabled = false;
	document.appl.ACAddress.disabled = false;
	document.appl.ACCity.disabled = false;
	document.appl.ACState.disabled = false;
	document.appl.ACZip.disabled = false;
	document.appl.ACRelationship.disabled = false;
	document.appl.ACContact.disabled = false;
	document.appl.ACPhone.disabled = false;
	document.appl.btnSubform.disabled = false;
  }
  else
  {
	changeClass('AffCompany','dim');
	document.appl.ACName.disabled = true;
	document.appl.ACBusinessType.disabled = true;
	document.appl.ACPercentOwned.disabled = true;
	document.appl.ACAddress.disabled = true;
	document.appl.ACCity.disabled = true;
	document.appl.ACState.disabled = true;
	document.appl.ACZip.disabled = true;
	document.appl.ACRelationship.disabled = true;
	document.appl.ACContact.disabled = true;
	document.appl.ACPhone.disabled = true;
	document.appl.btnSubform.disabled = true;
  }
}

function setBranchSection() {
  if (getCheckedValue(document.appl.BranchLocations) == 'Y')
  {
	changeClass('branch','live');
	document.appl.BranchDBA.disabled = false;
	document.appl.BranchAddress.disabled = false;
	document.appl.btnSubform.disabled = false;
  }
  else
  {
	changeClass('branch','dim');
	document.appl.BranchDBA.disabled = true;
	document.appl.BranchAddress.disabled = true;
	document.appl.btnSubform.disabled = true;
  }
}


// return the value of the radio button that is checked
// return an empty string if none are checked, or
// there are no radio buttons
function getCheckedValue(radioObj) {
	if(!radioObj)
		return "";
	var radioLength = radioObj.length;
	if(radioLength == undefined)
		if(radioObj.checked)
			return radioObj.value;
		else
			return "";
	for(var i = 0; i < radioLength; i++) {
		if(radioObj[i].checked) {
			return radioObj[i].value;
		}
	}
	return "";
}

// set the radio button with the given value as being checked
// do nothing if there are no radio buttons
// if the given value does not exist, all the radio buttons
// are reset to unchecked
function setCheckedValue(radioObj, newValue) 
{
	if(!radioObj)
		return;
	var radioLength = radioObj.length;
	if(radioLength == undefined) {
		radioObj.checked = (radioObj.value == newValue.toString());
		return;
	}
	for(var i = 0; i < radioLength; i++) {
		radioObj[i].checked = false;
		if(radioObj[i].value == newValue.toString()) {
			radioObj[i].checked = true;
		}
	}
}


function externalLinks() 
{ 
  if (!document.getElementsByTagName) return; 
  var anchors = document.getElementsByTagName("a"); 

  for (var i=0; i<anchors.length; i++) 
  { 
    var anchor = anchors[i]; 
    if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") 
    {
      anchor.target = "_blank";
    }
  } 
}

function goto(url)
{
  window.location.href=url;
}

var newWindow;
function popup(URL,width,height) 
{
	if(!newWindow || newWindow.closed )
	{
		newWindow = window.open(URL, 
                        'script','toolbar=0,scrollbars=no,location=no,statusbar=no,menubar=no,resizable=yes,dependent=yes,width='+width+',height='+height+',left=60,top=60');
    newWindow.focus();
	}
	else
	{
		newWindow.resizeTo(width+12,height+30);
    newWindow.focus();
	}
}