﻿// 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 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=\"http://www.drorceyre.com/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=\"http://www.drorceyre.com/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(http://www.drorceyre.com/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=\"http://www.drorceyre.com/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=\"http://www.drorceyre.com/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(http://www.drorceyre.com/menuback.aspx?width="+(headings[i].offsetWidth-30)+"&height=35&text="+encodeString(linktext)+");\" ");
    } 

}

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 encodeString(inputString)
{
  inputString=inputString.replace("&amp;", "&");
  var encodedInputString=escape(inputString);
  encodedInputString=encodedInputString.replace("+", "%2B");
  encodedInputString=encodedInputString.replace("/", "%2F"); 
  return encodedInputString;
}


function init()
{
    window.onresize = function() {positionColor();};
    positionColor();
    menuback();  
}

 function positionColor() 
 { 
    if (getElement("colorwindow")!=null)
    { 
        if (getElement("title")!=null)
        {
            getElement("colorwindow").style.left=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=(findX(getElement("titlediv"))+10)+"px"; 
            getElement("colorwindow").style.top=(findY(getElement("titlediv"))+15)+"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>');
}