/*
Common JavaScript code for website.
Copyright 2008 Charles D. Montgomery.
All U.S. and International rights reserved.
*/

function SetDspFrameSize(id) {
    var DspFrame = document.getElementById(id);
    if (DspFrame) {
        if (DspFrame.contentDocument && DspFrame.contentDocument.body.offsetHeight) {
            // FireFox, Mozilla, et. al. (W3C) syntax
            DspFrame.height = DspFrame.contentDocument.body.offsetHeight;    
        } else { //if (DspFrame.Document && DspFrame.Document.body.scrollHeight) {
            // MSIE syntax
            DspFrame.height = DspFrame.Document.body.scrollHeight;
        }
		/* For FF/NS class browsers (and possibly others) add some additional height
		to kill off the vertical scroll bar (shows up even if SCROLLING="NO"; go figure...)
		The next line casts the string to an integer, which may or may not be adjusted. */		
		var adj=DspFrame.height / 1; 
		if (!document.all)     /* Returns TRUE unless MSIE (inverted logic)*/
			adj+=42; 	       /* For any browser other than MSIE add 16 pixels to the height. Even
							      if it turns out that we end up overadjusting for a few browsers,
							      the likelihood that 16 pixels of space will cause a problem is
							      pretty remote. */
		DspFrame.height = adj;
		if (DspFrame.addEventListener) {
            DspFrame.addEventListener("load", adjDspFrame, false);
        } else {
			DspFrame.detachEvent("onload", adjDspFrame); //MSIE needs hand-holding...
            DspFrame.attachEvent("onload", adjDspFrame);
        }
   }
}
function adjDspFrame(evt) { //retaining the event (evt) for possible future expansion; not used
	SetDspFrameSize('DisplayFrame');
}
if (window.addEventListener) {
	window.addEventListener("load",adjDspFrame,false);
} else {
    window.attachEvent("onload", adjDspFrame);
}
function toggleBox(szDivID, iState) // 1 visible, 0 hidden
{
	var winW = (window.innerWidth) ? window.innerWidth : document.body.offsetWidth;
	var rLeft = (winW - rtpWidth) / 2;
	rTop = document.body.scrollTop + (rtpHeight * VerticalOffset);
    if(document.layers) {	   					//NN4+
		var layer = document.layers[szDivID];
    	layer.top = rTop;
		layer.left = rLeft;
		document.layers[szDivID].visibility = iState ? "show" : "hide";
    } else if(document.getElementById)	{  		//gecko(NN6) + IE 5+ 
        var layer = document.getElementById(szDivID);
		layer.style.top = rTop;
		layer.style.left = rLeft;
        var obj = document.getElementById(szDivID);
        obj.style.visibility = iState ? "visible" : "hidden";
    } else if(document.all)	{ 					// IE 4
		document.all[szDivID].style.posLeft = rLeft;
		document.all[szDivID].style.posTop = rTop;
        document.all[szDivID].style.visibility = iState ? "visible" : "hidden";
    }
}
var tglFlag=0;
function ToggleBkg(cell)
{
   box=document.getElementById(cell);
   if (tglFlag == 0)
   	{
		tglFlag=1;
		box.style.backgroundColor="#F4FFF4";
	} else {
		tglFlag=0;
		box.style.backgroundColor="";
	}
}

function SetFrame(turl) {
	var url=document.URL;
	var parts=url.split('/');
	var nurl = parts[0] + '//' + parts[2];
	if (parts[2] == 'cdmx') {
		nurl += '/job';
	}
	document.getElementById('DisplayFrame').src=nurl + '/' + turl;
	document.location.href="#frmtop";

}
function TrimSpaces(str) {
	str = str.replace(/  /, "");
	var ns = '';
	//leading space trim
	var spcnt = 0;
	for (var i=0;i<str.length;i++) {
		if (str.charAt(i) == ' ') {
			spcnt++;
		} else {
			break;
		}
	}
	str = str.substr(spcnt,str.length - spcnt);
	//Trailing space trim
	spcnt = 0;
	for (var i=str.length - 1;i>0;i--) {
		if (str.charAt(i) == ' ') {
			spcnt++;
		} else {
			break;
		}
	}
	str = str.substr(0,str.length - spcnt);
	//Final runthrough to insure we have only single spaces in the string
	var lc = '';
	var tc = '';
	var ns = '';
	for (i =0;i< str.length;i++) {
		tc = str.substr(i,1);
		if (lc == ' ' && tc == ' ') {
		} else {
			ns+=tc;
		}
		lc = tc;
	}
	
	return ns;
}
