/*
 
Correctly handle PNG transparency in Win IE 5.5 & 6.
http://homepage.ntlworld.com/bobosola. Updated 18-Jan-2006.

Use in <HEAD> with DEFER keyword wrapped in conditional comments:
<!--[if lt IE 7]>
<script defer type="text/javascript" src="pngfix.js"></script>
<![endif]-->

*/
var LonnieLoopCounter = 10;

function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
	var arVersion = navigator.appVersion.split("MSIE")
	var version = parseFloat(arVersion[1])
	var strGif = "images/1x1_trans.gif"

	if ((version >= 5.5) && (document.body.filters)) {
		var ImgCount = document.images.length;
     for(var i=0; i<document.images.length; i++)
     {
	 	//alert("i="+i+" of "+ImgCount);
        var img = document.images[i]
        var imgName = img.src.toUpperCase()
        if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
        {
         	//alert("Step 1");
		    var imgID = (img.id) ? "id='" + img.id + "' " : ""
            var imgClass = (img.className) ? "class='" + img.className + "' " : ""
            var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
            var imgStyle = "display:inline-block;" + img.style.cssText;
			var strFilter = "progid:DXImageTransform.Microsoft.AlphaImageLoader";
            if (img.align == "left") imgStyle = "float:left;" + imgStyle
            if (img.align == "right") imgStyle = "float:right;" + imgStyle
            if (img.parentElement.href) imgStyle = "cursor:pointer;" + imgStyle
         	//alert("Step 2");
            if (img.useMap)
            {  
               	//alert("Step 3a");
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
	            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
	            + "filter:" + strFilter
	            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"

                var strAddMap = "<img style=\"position:relative; left:-" + img.width + "px;"
                + "height:" + img.height + "px;width:" + img.width +"\" "
                + "src=\"" + strGif + "\" usemap=\"" + img.useMap
                + "\" border=\"" + img.border + "\">"
            }else{
               	//alert("Step 3a");
			
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
				strNewHTML += " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				strNewHTML += "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				strNewHTML += "(src='" + img.src + "', sizingMethod='scale');\""
				strNewHTML += " onmouseover=\"PNGswap('" + img.id + "');\" onmouseout=\"PNGswap('" + img.id +"');\" "
				strNewHTML += "></span>" 
				
				//alert("Step 3a done");
			}
			/*
            var strNewHTML = "<span " + imgID + imgClass + imgTitle
            + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
            + "filter:" + strFilter
            + "(src=\'" + img.src + "\', sizingMethod='scale');\"></span>"
			*/
           	//alert("Step 4");
            if (img.useMap) strNewHTML += strAddMap
            img.outerHTML = strNewHTML
			//alert("strNewHTML="+strNewHTML+" & i="+i+" of "+ImgCount);
            i = i-1
        }
	
		/*	
		for(var i=0; i<document.images.length; i++){
			var img = document.images[i]
			var imgName = img.src.toUpperCase()
			if (imgName.substring(imgName.length-3, imgName.length) == "PNG"){
				var imgID = (img.id) ? "id='" + img.id + "' " : ""
				var imgClass = (img.className) ? "class='" + img.className + "' " : ""
				var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
				var imgStyle = "display:inline-block;" + img.style.cssText 
				var imgAttribs = img.attributes;
				var imgAttribsKept = "";
				if(img.useMap){
					alert("use map");
					alert("img.height="+img.height);
					alert("img.width="+img.width);
					alert("img.useMap="+img.useMap);
					alert("img.border="+img.border);
	                strAddMap = "<img style=\"position:relative; left:-" + img.width + "px;"
	                + "top:-" + img.height 
	                + "height:" + img.height + "px;width:" + img.width +"\" "
	                + "src=\"" + strGif + "\" usemap=\"" + img.useMap
	                + "\" border=\"" + img.border + "\">"
					
				}
				for (var j=0; j<imgAttribs.length; j++){
					var imgAttrib = imgAttribs[j];
					if (imgAttrib.nodeName == "align"){		  
						if (imgAttrib.nodeValue == "left") imgStyle = "float:left;" + imgStyle
						if (imgAttrib.nodeValue == "right") imgStyle = "float:right;" + imgStyle
						break
					}
				}
				var strNewHTML = "<span " + imgID + imgClass + imgTitle
				strNewHTML += " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
				strNewHTML += "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
				strNewHTML += "(src='" + img.src + "', sizingMethod='scale');\""
				strNewHTML += " onmouseover=\"PNGswap('" + img.id + "');\" onmouseout=\"PNGswap('" + img.id +"');\" "
				strNewHTML += "></span>" 
	            if (img.useMap) strNewHTML += strAddMap
				img.outerHTML = strNewHTML
				alert("strNewHTML="+strNewHTML);
				i = i-1
			}
			*/
			
		}

		/**************************************************************************
		***	2007.11.16	L. Price - 	Fix for Div Style.BackGround = ???.png		***
		**************************************************************************/
		var oDivArray = document.getElementsByTagName("div");
		for ( var i=oDivArray.length-1; i>=0; --i ){								//Check all Menu Items For Current Menu Name
			var bgDivImg = oDivArray[i];
			if (bgDivImg.style.backgroundImage.toLowerCase().search(/\.png\)$/) < 0) continue;
			var bg = bgDivImg.style.backgroundImage;
			var src = bg.substring(4,bg.length-1);
			var MyFilter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "', sizingMethod='scale')";
			bgDivImg.style.backgroundImage="";
			bgDivImg.style.filter = MyFilter;	
			bgDivImg.display = "block";
			//bgDivImg.style.zIndex = -1;
		}

		/**************************************************************************
		***	2008.04.08	L. Price - 	Fix for input type image = ???.png		***
		**************************************************************************/
		elements = document.getElementsByTagName("input");
		for (i = 0; i < elements.length; i++) {
			var input = elements[i];
			if (input.getAttribute("type") != "image") continue;
			if (input.getAttribute("src").toLowerCase().search(/\.png$/) < 0) continue;
			input.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + input.src  + "', sizingMethod='image')";
			input.src = strGif;
		}

	}
	
	
	
	
	//closeAllPages();
}

function BodyAreaFrameResize(){
	//alert("Testing!! resizing");
	var defaultFrameHeight = 382;
	var oBA1 = parent.document.getElementById('BodyArea');
	var oBA2 = parent.document.getElementById('BodyAreaFrame');
	var MyDebug = "false";
	var HRefFileNameArray = location.href.split("/");
	var ThisDocName = HRefFileNameArray[HRefFileNameArray.length-1];

	var TitleBarHeight = 0;
	var BrowserOffset = 0;
	
	if(BrowserDetect.browser == "Netscape"){
		BrowserOffset = 20;
	}
	if(BrowserDetect.browser == "Firefox"){
		//alert(BrowserDetect.OS);
		//alert("ThisDocName="+ThisDocName);
		if(BrowserDetect.OS == 'Mac'){
			BrowserOffset = BrowserOffset + 20;
			if(ThisDocName.toLowerCase() == "termsofuse.html"){
				BrowserOffset = BrowserOffset + 20;	//Stops the IFrame Scrollbar
			}
			if(ThisDocName.toLowerCase() == "home.html"){
				BrowserOffset = BrowserOffset + 10;	//Stops the IFrame Scrollbar
			}
		}
	}
	
	if((BrowserDetect.browser == "Safari") && (BrowserDetect.OS == "Mac")){
		//alert(BrowserDetect.OS);
		BrowserOffset = 20;
		//alert(oBA2.scrollWidth);
		oBA1.style.padding='0px,0px,0px,0px';
		oBA2.style.padding='0px,0px,0px,0px';
	}
	
	//alert("oBA1.clientHeight="+oBA1.scrollHeight);
	if(MyDebug == "true"){alert("oBA1.style.height before default applied = "+oBA1.style.height);}
	oBA1.style.height = defaultFrameHeight+"px";
	oBA2.style.height = defaultFrameHeight+"px";
	if(MyDebug == "true"){alert("oBA1.style.height After default applied = "+oBA1.style.height);}
	if(MyDebug == "true"){alert("parent.CurrentFrameHeight before default applied = "+parent.CurrentFrameHeight);}
	parent.CurrentFrameHeight = defaultFrameHeight;
	if(MyDebug == "true"){alert("parent.CurrentFrameHeight after default applied = "+parent.CurrentFrameHeight);}
	//oBA2.style.height = "381px";

	
	//alert("set to 381px");
	ThisWindowHeight = document.body.scrollHeight;
	if(MyDebug == "true"){alert("document.body.scrollHeight = "+ThisWindowHeight);}
	
	if(parent.currentOpenMenu == 0){TitleBarHeight = 0; ThisWindowHeight=454;}
	
	//alert("TitleBarHeight="+TitleBarHeight);
	//alert("ThisWindowHeight="+ThisWindowHeight);
	
	//alert("Scroll Height = "+ document.body.scrollHeight);
	//alert("Scroll Height = "+ document.body.scrollHeight);
	//alert("parent.currentOpenMenu="+parent.currentOpenMenu);
	/*
	if(defaultFrameHeight > parent.CurrentFrameHeight){
		alert("defaultFrameHeight Difference From Current");
		var NewHeight = defaultFrameHeight + TitleBarHeight;
		oBA1.style.height = NewHeight+"px";
		oBA2.style.height = NewHeight+"px";
		ThisWindowHeight = defaultFrameHeight;
	}
	*/
	//alert("parent.CurrentFrameHeight = "+parent.CurrentFrameHeight);
	if(MyDebug == "true"){alert("ThisWindowHeight != parent.CurrentFrameHeight: (" + ThisWindowHeight + " != " + parent.CurrentFrameHeight+ ")");}
	if(ThisWindowHeight != parent.CurrentFrameHeight){
		//alert("Height Difference From Current");
		var NewHeight = ThisWindowHeight + TitleBarHeight + BrowserOffset;
		if(MyDebug == "true"){alert("Set oBA1.style.height");}
		oBA1.style.height = NewHeight+"px";
		if(MyDebug == "true"){alert("Set oBA2.style.height");}
		oBA2.style.height = NewHeight+"px";
	}
	parent.CurrentFrameHeight = ThisWindowHeight;
	if(MyDebug == "true"){alert("Done with resize to: "+ThisWindowHeight);}
	if(ThisDocName.toLowerCase() == "home.html"){
		if(BrowserDetect.browser == "Explorer"){NewHeight = oBA1.scrollHeight + 10;}
		if(BrowserDetect.browser == "Safari"){NewHeight = oBA1.scrollHeight + 16;}
		if(BrowserDetect.browser == "Netscape"){NewHeight = oBA1.scrollHeight + 16;}

		oBA2.style.height = NewHeight+"px";
		oBA1.style.height = NewHeight+"px";
		//alert("resize done");
		
	}
	if(ThisDocName.toLowerCase() == "customercare.html"){
		if(BrowserDetect.browser == "Explorer"){oBA2.style.width = (oBA1.scrollWidth+6)+"px";}
		
	}
	if(ThisDocName.toLowerCase() == "careers.html"){
		//alert("oBA1.scrollWidth="+oBA1.scrollWidth);
		if(BrowserDetect.browser == "Explorer"){
			oBA2.style.width = (oBA1.scrollWidth+6)+"px";
			
			var oCCBox1 = document.getElementById("CCBox1");
			var oCCBox2 = document.getElementById("CCBox2");
			var oCCBox3 = document.getElementById("CCBox3");

			oCCBox1.style.width='231px';
			oCCBox2.style.width='231px';
			oCCBox3.style.width='231px';

			
		}
	}
	//Set Background Image to Larger Image if larger than background box.
	if((ThisDocName != "") && (ThisDocName != "#")){
		MyDivs = document.getElementsByTagName('div');
		if(MyDivs[0].scrollHeight > 382){
			var NoBottomBox = "ad_space_large1";
			var BottomBox = "large_window";
			MyDivs[0].style.backgroundImage=MyDivs[0].style.backgroundImage.replace(BottomBox,NoBottomBox);
		}
	}

}

function BodyAreaFrameScrollTest(){

	return true;

}

function PageCounter(){
	var HRefFileNameArray = location.href.split("/");
	var MyDocName = HRefFileNameArray[HRefFileNameArray.length-1];
	var PName = MyDocName.split(".");
	//alert("PName[0]="+PName[0]);
	if(PName[0] == '#')
		return;
	var	aAllAnchors = parent.document.getElementsByTagName('a');
	var	TestDocName = "";
	var	HeaderTitle = "";

	//alert("starting Loop!!");
	for(var ix=0; ix < aAllAnchors.length; ix++){
		TestDocName = aAllAnchors[ix].getAttribute('PgRef')+".html";
		if(MyDocName == TestDocName){
			HeaderTitle = aAllAnchors[ix].getAttribute('HeaderTitle');
			break;
			//alert(HeaderTitle);
		}
	}

	if(HeaderTitle.length == 0){
		for(var ix=1; ix < 10; ix++){
			var MenuTag = "MenuItem"+ix;
			if(parent.document.getElementById(MenuTag)){
				var oObj = parent.document.getElementById(MenuTag);
				TestDocName = oObj.getAttribute('href')+".html";
				if(MyDocName == TestDocName){
					HeaderTitle = oObj.getAttribute('HeaderTitle');
					break;
					//alert(HeaderTitle);
				}
			}
		}
	}
	/*
	alert("Page="+MyDocName);
	alert("PageTitle="+HeaderTitle);
	*/
	if(BrowserDetect.browser == "Firefox")
		return;
		
	pageCounterBusy = true;
	var CountSource = "http://www.wccla.com/ResponsivePageCounter.cfm?Page="+MyDocName+"&PageTitle="+HeaderTitle;
	var ifrm = document.createElement("IFRAME"); 
	ifrm.setAttribute("src", CountSource); 
	ifrm.setAttribute("id", "TempIFrame"); 
	ifrm.setAttribute("biggy", "busy"); 
	ifrm.style.width = 1+"px"; 
	ifrm.style.height = 1+"px"; 
	document.body.appendChild(ifrm); 

	//alert("iframe loaded");
	//alert("pageCounterBusy="+pageCounterBusy);

	document.getElementById('TempIFrame').style.display = "none"; 

	
	//UnLoadPageCounter(ifrm);

	//document.body.removeChild(ifrm)
}



function checkRefresh()
{
	// Get the time now and convert to UTC seconds
	var today = new Date();
	var now = today.getUTCSeconds();
	//alert("Refresh Check");
	// Get the cookie
	var cookie = document.cookie;
	var cookieArray = cookie.split('; ');

	/*
	alert("cookieArray.length="+cookieArray.length);
	alert("cookieArray[0]="+cookieArray[0]);
	*/
	// Parse the cookies: get the stored time
	for(var loop=0; loop < cookieArray.length; loop++)
	{
		var nameValue = cookieArray[loop].split('=');
		// Get the cookie time stamp
		if( nameValue[0].toString() == 'SHTS' )
		{
			var cookieTime = parseInt( nameValue[1] );
		}
		// Get the cookie page
		else if( nameValue[0].toString() == 'SHTSP' )
		{
			var cookieName = nameValue[1];
		}
		// Get the cookie menu
		else if( nameValue[0].toString() == 'CMENU' )
		{
			var cookieMenu = nameValue[1];
		}
	}

	if( cookieName &&
		cookieTime &&
		cookieName == escape(location.href) &&
		Math.abs(now - cookieTime) < 5 )
	{
		// Refresh detected
		//alert("Refresh detected");
		//alert("cookieMenu="+cookieMenu);
		// Insert code here representing what to do on
		// a refresh
		
		//top.OpenMenuNumber(0);
		/*
		var NewSuperMenuNumber = cookieMenu+".0";
		var aNewSuperMenuNumber = NewSuperMenuNumber.split('.');
		NewSuperMenuNumber = aNewSuperMenuNumber[0];
		alert("NewSuperMenuNumber="+NewSuperMenuNumber);
		top.TurnOnNewMenu(NewSuperMenuNumber);
		*/
		
		
		
		
		/*
		
		alert("isMenuClosed()="+top.isMenuClosed());
		top.OpenMenuNumber(cookieMenu);

		//buttonsDisabled
		
		//top.OpenNewPage(cookieMenu);
		var oTitleArea = top.document.getElementById('TitleArea');
		//alert("display="+oTitleArea.style.display);
		var readarea=oTitleArea.style.display;
		if(cookieMenu !=0)
			oTitleArea.style.display="";

		WaitMenuToFinish(100);
		alert("resizing now w/cookie = "+cookieMenu);
		setTimeout( "BodyAreaFrameResize();", 500 );

		//BodyAreaFrameResize();
		//alert("done");
		//top.OpenNewPage(cookieMenu);
		//BodyAreaFrameResize();
		//alert("Menu should be open");
		*/

		// If you would like to toggle so this refresh code
		// is executed on every OTHER refresh, then 
		// uncomment the following line
		// refresh_prepare = 0; 
	}	
	//alert("Fresh Page");
	//alert("top.currentOpenMenu="+top.currentOpenMenu);
	
	
	
	
	/*
	if(top.currentOpenMenu != 0){
		var oTitleArea = top.document.getElementById('TitleArea');
		if(oTitleArea.style.display == "none")
			oTitleArea.style.display="";
			//top.currentOpenMenu=0;
			//top.OpenMenuNumber(top.currentOpenMenu);
	//alert(top.currentOpenMenu);
	var oTitleArea = top.document.getElementById('TitleArea');
	//alert("display="+oTitleArea.style.display);
	}
	*/



	

	//alert("setting menu number  cookie ");
	document.cookie = 'CMENU='+top.currentOpenMenu + ';';
	//alert("cookie is set");
	// You may want to add code in an else here special 
	// for fresh page loads
}
function WaitMenuToFinish(waitInterval){
	var noOporations=0;
	if(top.buttonsDisabled)
		setTimeout( "WaitMenuToFinish('"+waitInterval+")", waitInterval );

}

function prepareForRefresh()
{
	if( refresh_prepare > 0 )
	{
		// Turn refresh detection on so that if this
		// page gets quickly loaded, we know it's a refresh
		var today = new Date();
		var now = today.getUTCSeconds();
		document.cookie = 'SHTS=' + now + ';';
		document.cookie = 'SHTSP=' + escape(location.href) + ';';
	}
	else
	{
		// Refresh detection has been disabled
		document.cookie = 'SHTS=;';
		document.cookie = 'SHTSP=;';

	}
}

function disableRefreshDetection()
{
	// The next page will look like a refresh but it actually
	// won't be, so turn refresh detection off.
	refresh_prepare = 0;

	// Also return true so this can be placed in onSubmits
	// without fear of any problems.
	return true;
} 
// By default, turn refresh detection on
var refresh_prepare = 1;




function UnLoadPageCounter(ifrm){
	LonnieLoopCounter--;
	//alert(LonnieLoopCounter);
	if(LonnieLoopCounter < 1)
		return;
	if(pageCounterBusy){
		alert("ifrm="+ifrm);
		setTimeout ( "UnLoadPageCounter("+ifrm+")", 10000 );
	}else{
		alert("Killing the child");
		document.body.removeChild(ifrm)
	}

}


function addOnloadEvent2(fnc){
  if ( typeof window.addEventListener != "undefined" )
    window.addEventListener( "load", fnc, false );
  else if ( typeof window.attachEvent != "undefined" ) {
    window.attachEvent( "onload", fnc );
  }
  else {
    if ( window.onload != null ) {
      var oldOnload = window.onload;
      window.onload = function ( e ) {
        oldOnload( e );
        window[fnc]();
      };
    }
    else 
      window.onload = fnc;
  }
}

function addOnUnLoadEvent(func) {
	var oldonload = window.onunload;
	if (typeof window.onunload != 'function') {
		window.onunload = func;
	} else {
		window.onunload = function() {
			oldonload();
			func();
		}
	}
}


if(BrowserDetect.browser == "Explorer"){window.attachEvent("onload", correctPNG);}
addOnloadEvent2(PageCounter);
addOnloadEvent2(checkRefresh);
addOnUnLoadEvent(prepareForRefresh);
addOnloadEvent2(BodyAreaFrameResize);



