/*/////////////////////////////////////				gray.js		version 200706

What:	JS minimum required on every page.
Usually in conjunction with a dedicated site file such as graysite_200709.js
file size < 4k

How:		Header of every page on site: 
<script language="JavaScript" type="text/JavaScript" src="inc/gray.js"></script>
<script language="JavaScript" type="text/JavaScript" src="inc/graysite_200709.js"></script>

*/
////////////////////////////////////////				Default Vars
var Version = 200709; 		///	Keep numerical.:arithmetic checking.
var ThisURL = document.URL;
var ThisDomain = document.domain.split('www.'); ThisDomain = (ThisDomain[1]) ? ThisDomain[1] : document.domain;
var isServed = (ThisURL.indexOf("http://") == 0);
var isLocal = (ThisURL.indexOf("http://localhost") == 0) || (ThisURL.indexOf("file://") == 0);


////////////////////////////////////////				Window.onload replacement
function addLoadEvent(f) {
    var oldf = window.onload;
    if (typeof window.onload != 'function') { window.onload = f; }
    else { window.onload = function () { if (oldf) { oldf() }; f(); } }
}
///	example: addLoadEvent(doSomeFunction);
///	example: addLoadEvent(function() {addmore=code;});
///	example: addLoadEvent(function() {doSomeFunction(SomeArg);});


////////////////////////////////////////				Default onload extentions
var aLink, LinkQTY
function loadPageVars() {
    var BugMSG = "loadPageVars()/n";
    aLink = document.getElementsByTagName("a");
    LinkQTY = aLink.length;

    //alert(BugMSG);	
}
addLoadEvent(loadPageVars);

function styleLocal() {
    var p = "";
 if (isLocal) p = document.body.style; p.borderLeft = "solid #f33 8px"; p.borderRight = "solid #f33 8px"; p.padding = "0px 8px"; p.margin = "0px" }
addLoadEvent(styleLocal);


////////////////////////////////////////				Utility Functions
Array.prototype.getIDX = function (value) {
    for (var i = 0; i < this.length; i++) { if (this[i] === value) { return i; } }
    return -1; ///	!=false
}
///	Usage: 

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////				Active Review. OK to delete or test.
function restyleExternalLinks()
// Finds outbound links and sets target="_blank" and a custom style. 
{
    for (var i = 0; i < LinkQTY; i++) {
        if (aLink[i].href.indexOf(ThisDomain) == -1 && aLink[i].href != '') { aLink[i].target = '_blank'; aLink[i].className += ' linkExternal'; }
    }
}
function setWindowStatus(s, p) {
    window.status = s;
    p.onmouseout = function () { window.status = window.defaultStatus; };
    return true;
}



function captureKey(e) {
    var code
    if (!e) var e = window.event;
    if (e.keyCode) code = e.keyCode; 		//	modern browser
    else if (e.which) code = e.which; 				//	old Netscape
    var character = String.fromCharCode(code);
    alert("character = " + character);
}
function getElementWithEvent(e) {
    var targ;
    if (!e) var e = window.event;
    if (e.target) targ = e.target;
    else if (e.srcElement) targ = e.srcElement;
    if (targ.nodeType == 3) targ = targ.parentNode; 	//	Safari hack
}

function slide(o, p, ms, t, f) {
}


////	DOM Access,Editing
function $() {
    var els = new Array();
    for (var i = 0; i < arguments.length; i++) {
        var el = arguments[i];
        if (typeof el == 'string') el = document.getElementById(el);
        if (arguments.length == 1) return el;
        els.push(el);
    }
    return els;
}

function getParent(el, pTagName) {
    if (el == null) { return null; }
    else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase()) {    // Gecko bug, supposed to be uppercase
        return el;
    }
    else { return getParent(el.parentNode, pTagName); }
}

//function insertAfter(parent, node, referenceNode) {parent.insertBefore(node, referenceNode.nextSibling);}
function insertAfter(parent, node, referenceNode) {
    if (referenceNode.nextSibling) { parent.insertBefore(node, referenceNode.nextSibling); }
    else { parent.appendChild(node); }
}

////	DOM Effects
function toggle(obj) {
    var el = document.getElementById(obj);
    if (el.style.display != 'none') { el.style.display = 'none'; }
    else { el.style.display = ''; }
}

