function getDocHeight(doc) {
  var docHt = 0, sh, oh;
  if (doc.height) docHt = doc.height;
  else if (doc.body) {
    if (doc.body.scrollHeight) docHt = sh = doc.body.scrollHeight;
    if (doc.body.offsetHeight) docHt = oh = doc.body.offsetHeight;
    if (sh && oh) docHt = Math.max(sh, oh);
  }
  return docHt;
}

function setHeight(iframeName) {
//  window.location.hash = 'top';
  var iframeWin = window.frames[iframeName];
  var iframeEl = document.getElementById? document.getElementById(iframeName): document.all? document.all[iframeName]: null;
  
  if ( iframeEl && iframeWin ) {
    iframeEl.style.height = "auto"; // helps resize (for some) if new doc shorter than previous  
    var docHt = getDocHeight(iframeWin.document);
    // need to add to height to be sure it will all show
    if (docHt) iframeEl.style.height = docHt + 30 + "px";
  }
}

function loadIframe(iframeName, url) {
  if ( window.frames[iframeName] ) {
    window.frames[iframeName].location = url;   
    return false;
  }
  else return true;
}
function toggleForms(form){
	var simple = document.getElementById('simple');
	var advanced = document.getElementById('advanced');
	if (form == 'advanced'){
		// show advanced
		simple.className = 'mort-off';
		document.getElementById('advanced-fields').style.display='block';
		document.getElementById('form').action='/site/mortgages/?form=advanced';
		advanced.className = 'mort-on';
	} else {
		// show simple
		simple.className = 'mort-on';
		document.getElementById('advanced-fields').style.display='none';
		document.getElementById('form').action='/site/mortgages/';
		advanced.className = 'mort-off';
	}
}


function getSwf( movieName )
{
	if( navigator.appName.indexOf("Microsoft") != -1 )
	{
		return window[movieName];
	}
	else
	{
		return document[movieName];
	}
}

function DrawFlashMovieExternal( src, width, height, bgcolor, name, version, flashVars, addParams )
{
	version = version != null ? '#version=' + version : '' ;
	
	//<param name="FlashVars" value="jsenabled=true&uid=' . $_GET['uid']; } ?>">
	if( flashVars )
	{
		var fva = new Array();
	
		for( var i in flashVars )
		{
			fva[fva.length] = i+'='+flashVars[i];
		}
		
		var fv = fva.join( ',' );
	}
	
	//write the object tag
	document.write( '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"' );
	document.write( 'id="' + name + '"' );
	document.write( 'title="' + name + '"' );
	document.write( 'width="' + width + '" height="' + height + '"' );
	document.write( 'codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab' + version + '">' );
	
	//write flash vars for object tag
	if( fv )
	{
		document.write( '<param name="FlashVars" value="' + fv + '" />' );
	}
	
	//standard params
	document.write( '<param name="movie" value="' + src + '" /><param name="quality" value="high" /><param name="bgcolor" value="' + bgcolor + '" />' );
	
	//additional params //<param name="allowScriptAccess" value="always" />
	for( var i in addParams )
	{
		document.write( '<param name="'+i+'" value="'+addParams[i]+'" />' );
	}
	
	//write tne embed code
	document.write( '<embed src="' + src + '" quality="high" bgcolor="' + bgcolor + '" ' );
	
	if( fv )
	{
		document.write( 'FlashVars="'+fv+'" ' );	
	}
	
	//standard params
	document.write( 'width="' + width + '" height="' + height + '" name="' + name + '" align="middle" ' );
	document.write( 'play="true" ' );
	document.write( 'loop="false" ' );
	document.write( 'quality="high" ' );
	document.write( 'type="application/x-shockwave-flash" ' );
	document.write( 'pluginspage="http://www.macromedia.com/go/getflashplayer" ' );
	
	//additional params //document.write( 'allowScriptAccess="always"' );
	for( var i in addParams )
	{
		document.write( i+'="'+addParams[i]+'" ' );
	}
	
	//close tags
	document.write( '><\/embed>' );
	document.write( '<\/object>' );
}
