﻿// JScript File
// Add and Remove event functions
function addEventSimple(obj,evt,fn) {
	if (obj.addEventListener)
		obj.addEventListener(evt,fn,false);
	else if (obj.attachEvent)
		obj.attachEvent('on'+evt,fn);
}

function removeEventSimple(obj,evt,fn) {
	if (obj.removeEventListener)
		obj.removeEventListener(evt,fn,false);
	else if (obj.detachEvent)
		obj.detachEvent('on'+evt,fn);
}

//initialize
//window.onload = startList;
//addEventSimple(window, 'load', overlay);

//
function clearText(textbox, value)
{
    if (textbox.value == value)
        textbox.value = '';
}

function setText(textbox, value)
{
    if (textbox.value == '')
        textbox.value = value;
}

function nextField(textbox)
{
    if ( textbox.maxLength == textbox.value.length ) {
        if ( textbox.parentNode.nextSibling.tagName != undefined ) {
            var nextbox = textbox.parentNode.nextSibling.getElementsByTagName('input');        
        } else {  
            var nextbox = textbox.parentNode.nextSibling.nextSibling.getElementsByTagName('input');    
        }
        nextbox[0].focus();
    }
}

function hilite(object)
{
    if (object.getElementsByTagName('IMG').length == 2) {
        object.getElementsByTagName('IMG')[0].className = 'hover';
        object.getElementsByTagName('IMG')[1].className = '';
    }
}

function lolite(object)
{
    if (object.getElementsByTagName('IMG').length == 2) {
        object.getElementsByTagName('IMG')[0].className = '';
        object.getElementsByTagName('IMG')[1].className = 'hover';
    }
}

function showHideMore (object, showObject)
{
    var thisImg = object.getElementsByTagName('img');
    if ( showObject.className == 'hidden' ) {
        thisImg[0].src = '/assets/buttons/arrow_btn-active.gif';
        showObject.className = 'more';
    } else {
        thisImg[0].src = '/assets/buttons/arrow_btn.gif';
        showObject.className = 'hidden';
    }
}

function showHide (objectId, showAnyway)
{
    var object = document.getElementById(objectId);

    if (object.style.visibility = "hidden" || showAnyway)
    {
        object.style.visibility = "visible";
        object.style.display = "block";
    } else {
        object.style.visibility = "hidden";
        object.style.display = "none";
    }
}

function applyValue(objectId, val, dropDownId)
{
    var object = document.getElementById(objectId);
    object.value = val;
    
    object = document.getElementById(dropDownId);
    object.style.visibility = "hidden";
    object.style.display = "none";
}

function confirmMsg (thisObj, object)
{
    var confirmed = false;
    if ( thisObj.checked == true ) {
      confirmed = confirm(object.firstChild.nodeValue);
      if ( confirmed == false ) {
        thisObj.checked = false;
      }
    }
}

/* overlay popup */

function overlay() {

	if ( document.getElementById("importantMessage") ) {

		var overlayDiv = document.getElementById("overlay");

		if ( overlayDiv.className ) {

			overlayDiv.className = 'overlayShow';

		}
		
        if ( document.getElementById("importantMessage").className ) {
            document.getElementById("importantMessage").className = 'visible';
        }	
        
        var elements = document.documentElement.getElementsByTagName('select');	
        for ( var i=0; i<elements.length; i++ ) {
            elements[i].style.visibility = 'hidden';
        }

	}

}



function closeOverlay() {

	if ( document.getElementById("importantMessage") ) {

		var overlayDiv = document.getElementById("overlay");

		if ( overlayDiv.className ) {

			overlayDiv.className = 'overlay';

		}
		
		if ( document.getElementById("importantMessage").className ) {
            document.getElementById("importantMessage").className = 'hidden';
        }
        
        var elements = document.documentElement.getElementsByTagName('select');	
        for ( var i=0; i<elements.length; i++ ) {
            elements[i].style.visibility = 'visible';
        }

	}
}

//*****Generic geojax call, everyone should use this!*****
function makeRequest(url) {
    http_request = false;
    if (window.XMLHttpRequest) { // Mozilla, Safari,...
        http_request = new XMLHttpRequest();
        if (http_request.overrideMimeType) {
            http_request.overrideMimeType('text/xml');
        }
    } else if (window.ActiveXObject) { // IE
        try {
            http_request = new ActiveXObject("Msxml2.XMLHTTP");
        } catch (e) {
            try {
                http_request = new ActiveXObject("Microsoft.XMLHTTP");
            } catch (e) {}
        }
    }
    if (!http_request) {
        return false;
    }
    
    //http_request.onreadystatechange = eventToFire;
    http_request.open('GET', url, true);
	http_request.send(null);
}

function showTechClip(obj)
{
    //alert(obj.getElementsByTagName('span')[1].className);
    var spans = obj.parentNode.getElementsByTagName('span');
    for ( var i=0; i<spans.length; i++ )
    {
        if ( spans[i].className == 'techClip' ) 
        {
            spans[i].className = 'techClipShow';
        }
    }
    var elements = document.documentElement.getElementsByTagName('select');	
    for ( var i=0; i<elements.length; i++ ) {
        elements[i].style.visibility = 'hidden';
    }
}

function closeTechClip(obj)
{
    var elements = document.documentElement.getElementsByTagName('select');	
    for ( var i=0; i<elements.length; i++ ) {
        elements[i].style.visibility = 'visible';
    }
    obj.parentNode.className = 'techClip';
}



function toggleOver(element)
{
    var cn = element.className.toString();        

    element.className = cn.replace(/\sovr\b|\bovr\b/g,"") + " ovr";

    return true;

}



function toggleOut(element)
{

    var cn = element.className.toString();        

    element.className = cn.replace(/\sovr\b|\bovr\b/g,"");

    return true;

}

// movie player

// Usage: moviePlayerPopUp.open(pathtoflv)


var moviePlayerPopUp = new function moviePlayerPopUpObj()
{
    var _this = this;
    this.u = "undefined";
    this.selectsHidden = false;
    this.toggleSelects = function(enforce, within){if((typeof document.all!=_this.u)&&(typeof document.body.style.maxHeight==_this.u)){if(typeof enforce==_this.u){enforce="toggle";}if(enforce=="hide"){_this.selectsHidden=false;}else if(enforce=="show"){_this.selectsHidden=true;}if(typeof within==_this.u){within=document;}var boxes=within.getElementsByTagName("select");for(var s=0;s<boxes.length;s++){boxes[s].style.visibility=(_this.selectsHidden)?"":"hidden";}_this.selectsHidden=!_this.selectsHidden;}};
    this.getOffsetTop = function(node){var t=0;while(node){if(typeof node.offsetTop!=_this.u){t+=node.offsetTop;}node=(typeof node.offsetParent!=_this.u)?node.offsetParent:null;}return parseInt(t);};
    this.getOffsetLeft = function(node){var l=0;while(node){if(typeof node.offsetLeft!=_this.u){l+=node.offsetLeft;}node=(typeof node.offsetParent!=_this.u)?node.offsetParent:null;}return parseInt(l);};
    this.getWinHeight = function(){ return (typeof window.innerHeight=="number")?parseInt(window.innerHeight):(document.documentElement && document.documentElement.clientHeight)?parseInt(document.documentElement.clientHeight):parseInt(document.body.clientHeight);};
    this.getWinWidth = function(){ return (typeof window.innerWidth=="number")?parseInt(window.innerWidth):(document.documentElement && document.documentElement.clientWidth)?parseInt(document.documentElement.clientWidth):parseInt(document.body.clientWidth);};
    this.getScrollTop = function(){ return (typeof window.pageYOffset=="number")?parseInt(window.pageYOffset):(document.body && document.body.scrollTop)?parseInt(document.body.scrollTop):parseInt(document.documentElement.scrollTop);};
    this.make = function(tag,attr,txt,cmt,data){var el=document.createElement(tag),u=_this.u;if(typeof attr!=u&&attr!=null){for(prop in attr){if(prop.toString()=="cn"){el.className=attr[prop];}else if(prop.toString()=="style"){for(style in attr[prop]){if(style.toString()=="float"){if(typeof el.style.styleFloat!="undefined"){el.style.styleFloat=attr[prop][style];}else{el.style.cssFloat=attr[prop][style];}}else{el.style[style.toString()]=attr[prop][style];}}}else if(prop.toString()=="frameborder"){el.frameBorder=attr[prop];}else{el.setAttribute(prop.toString(),attr[prop]);}}}if(typeof txt!=u&&txt!=null){el.appendChild(document.createTextNode(txt));}if(typeof cmt!=u&&cmt!=null){el.appendChild(document.createComment(cmt));}if(typeof data!=u&&data!=null){el.innerHTML=data;}return el;};
	this.popout = null;
	this.washout = null;
	this.opened = false;
	//this.conf = {width: 378, height: 245};
	this.conf = {width: 535, height: 320};

	this.close = function()
	{

		if(_this.opened)
		{
			//swfobject.removeSWF("moviePopUpSwf");
			document.body.removeChild(_this.popout);
			document.body.removeChild(_this.washout);
			_this.popout = null;
			_this.washout = null;
			_this.opened = false;
		
			_this.toggleSelects("show");
		}
	};
    
	this.open = function(flv)
	{
		_this.close();
		_this.toggleSelects("hide");
		
		var offset = (typeof document.all != "undefined") ? 2 : 0;
		
		_this.conf.top = (parseInt(_this.getWinHeight()/2) - parseInt(_this.conf.height/2)) + _this.getScrollTop();
		_this.conf.left = parseInt(_this.getWinWidth()/2) - parseInt(_this.conf.width/2);

		_this.conf.top = (_this.conf.top < 0) ? "0px" : _this.conf.top + "px";
		_this.conf.left = (_this.conf.left < 0) ? "0px" : _this.conf.left + "px";

		_this.conf.params = {allowScriptAccess:'Always',allowFullScreen:'True',menu:'false'};
		_this.conf.flashvars = {autoPlay:"true",closeFunction:"moviePlayerPopUp.close",videoSource:escape(flv),controlSkin:"/assets/flash/ShockVideo.swf",playImage:"/assets/flash/Video_StaticImage.jpg"};

		_this.washout = _this.make("div", {cn:"moviePopupWashout",style:{zIndex:"450",clear:'both',height:document.body.offsetHeight+"px"}});		
		_this.popout = _this.make("div", {style:{zIndex:"500",clear:'both',position:'absolute',width:_this.conf.width+"px",height:_this.conf.height+"px",top:_this.conf.top,left:_this.conf.left}});
		_this.popout.appendChild(_this.make("div", {id:"moviePopUpSwf",style:{color:'white'}}, "You must have Adobe Flash 9 or later"));

		document.body.appendChild(_this.washout);
		document.body.appendChild(_this.popout);

		swfobject.embedSWF("/assets/flash/VideoPlayer.swf", "moviePopUpSwf", _this.conf.width, _this.conf.height, "9.0.0", "expressInstall.swf", _this.conf.flashvars, _this.conf.params, {name:"moviePopUpSwf"});
		
		_this.opened = true;
		return false;
	};
};