﻿// JScript File

function activateDiv()
{
    if (getElement("adminmode")!=null)
    { 
        getElement("adminmode").value="true";
        showColor();
    }
}

function hideDiv()
{
    if (getElement("colorwindow")!=null)
    { 
	    if (document.getElementById) 
	    {
            getElement("colorwindow").style.visibility='hidden';
            getElement("colorwindow").style.display='none';
        }
        else if (document.all) 
        {
            getElement("colorwindow").style.display='none';
        }
        else
        {
            getElement("colorwindow").style.visibility='hidden';
        }
    }
}

function init()
{
    window.onresize = function() {positionColor();};
    positionColor();
 //   menuback();        
}

function encodeString(inputString)
{
  inputString=inputString.replace("&amp;", "&");
  var encodedInputString=escape(inputString);
  encodedInputString=encodedInputString.replace("+", "%2B");
  encodedInputString=encodedInputString.replace("/", "%2F"); 
  return encodedInputString;
}

 
function menuback(frm)
{
    var re = new RegExp("<a", "gi");
    
    var rehtml = new RegExp("<(.|\n)*?>", "gi");
    
    var repad = new RegExp("\n\t", "gi");

    var headings = getElementsByClass("menuPanel"); 
    for (i = 0; i < headings.length; i++) 
    {
        var linktext = headings[i].innerHTML.replace(rehtml, "");    
        linktext =linktext.substring(0, linktext.length-1);
        linktext = linktext.replace(repad, "");
        var width = headings[i].offsetWidth;
        if (typeof document.body.style.maxHeight != "undefined") 
        {
            headings[i].innerHTML = headings[i].innerHTML.replace(linktext, "<div style=\"height: 35px;width: "+(width-30)+"px;visibility: hidden;\">"+linktext+"<img src=\"images/spacer.gif\" /></div>");//img height=\""+headings[i].offsetHeight+"px\" width=\""+headings[i].offsetWidth+"px\" src=\"images/spacer.gif\" />");
        }
        else
        {
            headings[i].innerHTML = headings[i].innerHTML.replace(linktext, "<img height=\"22px\" width=\""+(width-30)+"px\" src=\"images/spacer.gif\" />");
        }
//        headings[i].innerHTML = headings[i].innerHTML.replace(linktext, "<div style=\"height: 35px;width: "+width+"px;visibility: hidden;\">"+linktext+"<img src=\"images/spacer.gif\" /></div>");//img height=\""+headings[i].offsetHeight+"px\" width=\""+headings[i].offsetWidth+"px\" src=\"images/spacer.gif\" />");
        headings[i].innerHTML = headings[i].innerHTML.replace(re, "<a style=\"width: "+width+"px;margin-left: 0px !important;padding-left: 0px !important;background-repeat: no-repeat;background-image: url(menuback.aspx?width="+width+"&height=35&text="+encodeString(linktext)+");\" ");
        
    }  
    headings = getElementsByClass("menuselPanel"); 
    for (i = 0; i < headings.length; i++) 
    {
        var linktext = headings[i].innerHTML.replace(rehtml, "");
        linktext =linktext.substring(0, linktext.length-1);
        linktext = linktext.replace(repad, "");
        var width = headings[i].offsetWidth;
        if (typeof document.body.style.maxHeight != "undefined") 
        {
            headings[i].innerHTML = headings[i].innerHTML.replace(linktext, "<div style=\"height: 35px;width: "+(width-30)+"px;visibility: hidden;\">"+linktext+"<img src=\"images/spacer.gif\" /></div>");//img height=\""+headings[i].offsetHeight+"px\" width=\""+headings[i].offsetWidth+"px\" src=\"images/spacer.gif\" />");
        }
        else
        {
            headings[i].innerHTML = headings[i].innerHTML.replace(linktext, "<img height=\""+headings[i].offsetHeight+"px\" width=\""+(width-30)+"px\" src=\"images/spacer.gif\" />");
        }
        
        headings[i].innerHTML = headings[i].innerHTML.replace(re, "<a style=\"padding-left: 0px !important;background-repeat: no-repeat;background-position: bottom 0px!important;background-image: url(menuback.aspx?width="+(headings[i].offsetWidth-30)+"&height=35&text="+encodeString(linktext)+");\" ");
    } 

}

function getElementWidth(Elem) {

		if(document.getElementById) {
			var elem = document.getElementById(Elem);
		} else if (document.all){
			var elem = document.all[Elem];
		}
		
			xPos = elem.offsetWidth;
		return xPos;
}

function getElementsByClass(searchClass,node,tag) {
	var classElements = new Array();
	if ( node == null )
		node = document;
	if ( tag == null )
		tag = '*';
	var els = node.getElementsByTagName(tag);
	var elsLen = els.length;
	var pattern = new RegExp('(^|\\s)'+searchClass+'(\\s|$)');
	for (i = 0, j = 0; i < elsLen; i++) {
		if ( pattern.test(els[i].className) ) {
			classElements[j] = els[i];
			j++;
		}
	}
	return classElements;
}

 function positionColor() 
 { 
    if (getElement("colorwindow")!=null)
    { 
        if (getElement("title")!=null || getElement("homecontent")!=null)
        {
            getElement("colorwindow").style.left="46px";
            //findX(getElement("titlediv"))+"px"; 
            getElement("colorwindow").style.top=findY(getElement("titlediv"))+"px"; 
            getElement("colorwindow").style.width=getElement("contentdiv").offsetWidth+"px";
            getElement("colorwindow").style.height=getElement("contentdiv").offsetHeight+findY(getElement("contentdiv"))-findY(getElement("titlediv"))+"px";
        }
        else
        {
            getElement("colorwindow").style.left="192px";
            //findX(getElement("titlediv"))+"px"; 
            getElement("colorwindow").style.top=findY(getElement("titlediv"))+"px"; 
            getElement("colorwindow").style.width=getElement("contentdiv").offsetWidth+"px";
            getElement("colorwindow").style.height=getElement("contentdiv").offsetHeight+findY(getElement("contentdiv"))-findY(getElement("titlediv"))+"px";
        }
        

    }
 }

function showColor()
{

        if (getElement("adminmode")!=null)
        { 
            if (getElement("adminmode").value!="true")
            {
                return;
            }
        }
        if (getElement("colorwindow")!=null)
        { 
            if (document.getElementById) 
	        {
                getElement("colorwindow").style.visibility='visible';
                getElement("colorwindow").style.display='block';
            }
            else if (document.all) 
            {
                getElement("colorwindow").style.display='block';
            }
            else
            {
                getElement("colorwindow").style.visibility='visible';
            }
        }
}

function findX(objElement) {

	var lngLeft = 0;
	var isFirefox = ( navigator.userAgent.indexOf( "Firefox/" ) != -1 );

    if (objElement.offsetParent) {
		while (objElement.offsetParent) {
			lngLeft += objElement.offsetLeft;
			objElement = objElement.offsetParent;
		}
	} else if (objElement.x) {
		lngLeft += objElement.x;
	}
	return lngLeft;
}

function findY(objElement) {
	var lngTop = 0;
	var isFirefox = ( navigator.userAgent.indexOf( "Firefox/" ) != -1 );
	
 if (objElement.offsetParent) {
		while (objElement.offsetParent) {
			lngTop += objElement.offsetTop;
			objElement = objElement.offsetParent;
		}
	} else if (objElement.y) {
		lngTop += objElement.y;
	}
	return lngTop;
}
 

function getElement(strElement) {
	// XML-based browsers (IE 4+/Netscape 6+/Mozilla/Gecko)
	if (document.getElementById(strElement)) {
		return document.getElementById(strElement);
	// IE
	} else if (document.all) {
		return document.all[strElement];
	// Netscape
	} else if (document.layers) {
		return document[strElement];
	}
} 

function writeLoadingFlash()
{
         document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="110" height="120" id="OA" align="middle">');
         document.write('<param name="allowScriptAccess" value="sameDomain" />');
         document.write('<param name="movie" value="images/oa_loader.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><embed src="images/oa_loader.swf" quality="high" wmode="transparent" width="110" height="120" name="OA" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
         document.write('</object>');
}


function writeHome()
{
         document.write('<div class="express3"><div class="blueback"><img src="images/greenConstruction_vidBanner.png" width="466" height="61" alt="Video Description Banner" id="expressBanner" /><div class="flashVideo">');
         document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="429" height="332" id="OA" align="middle">');
         document.write('<param name="allowScriptAccess" value="sameDomain" />');
         document.write('<param name="movie" value="swf/president.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><embed src="swf/president.swf" quality="high" wmode="transparent" width="429" height="332" name="video" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
         document.write('</object>');
         document.write('</div><br /><br /></div></div>');//<br /><p>All Legend Homes are certified green by Earth Advantage&reg;, a Northwest nonprofit organization that promotes sustainability and energy conservation. Legend Homes are better for the environment, promote cleaner in-home air and a healthier environment, and reduce your utility bills. As an award-winning Oregon builder, you can rely on our expertise and use of top-quality, sustainable materials to build safer, more durable homes. </p><br />');
}
function writeVideoPlayer(videoId)
{
         document.write('<div class="express3"><div class="blueback"><img src="images/greenConstruction_vidBanner.png" width="466" height="61" alt="Video Description Banner" id="expressBanner" /><div class="flashVideo">');
         document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="429" height="332" id="OA" align="middle">');
         document.write('<param name="allowScriptAccess" value="sameDomain" />');
         document.write('<param name="movie" value="swf/'+videoId+'.swf" /><param name="quality" value="high" /><param name="wmode" value="transparent" /><embed src="swf/'+videoId+'.swf" quality="high" wmode="transparent" width="429" height="332" name="video" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
         document.write('</object>');
         document.write('</div><br /><br /></div></div>');//<br /><p>All Legend Homes are certified green by Earth Advantage&reg;, a Northwest nonprofit organization that promotes sustainability and energy conservation. Legend Homes are better for the environment, promote cleaner in-home air and a healthier environment, and reduce your utility bills. As an award-winning Oregon builder, you can rely on our expertise and use of top-quality, sustainable materials to build safer, more durable homes. </p><br />');
}

function writeFlash(strTitle, strImage)
{
        document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="912" height="248" id="DEPLOY/legend_sub" align="middle">');
        document.write('<param name="allowScriptAccess" value="sameDomain" />');
        document.write('<param name="FlashVars" value="flashtitle='+encodeString(strTitle)+'&flashimage='+strImage+'" />');
        document.write('<param name="movie" value="swf/legend_sub.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="swf/legend_sub.swf" quality="high" FlashVars="flashtitle='+strTitle+'&flashimage='+strImage+'" bgcolor="#ffffff" width="912" height="248" name="DEPLOY/legend_sub" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
        document.write('</object>');
}


function writeHome()
{
        document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="912" height="357" id="DEPLOY/legend_hp" align="middle">');
        document.write('<param name="allowScriptAccess" value="sameDomain" />');
        document.write('<param name="movie" value="swf/legend_hp.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#ffffff" /><embed src="swf/legend_hp.swf" quality="high" bgcolor="#ffffff" width="912" height="357" name="DEPLOY/legend_hp" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />');
        document.write('</object>');
}