// JavaScript Document
startList = function() {
	if (document.all&&document.getElementById) {
		//navRoot = document.getElementById("menu");
		navRoot = document.getElementsByTagName("UL");
		for (n=0; n<navRoot.length; n++) {
			for (i=0; i<navRoot[n].childNodes.length; i++) {
				node = navRoot[n].childNodes[i];
				if (node.nodeName=="LI") {
					node.onmouseover=function() {
						this.className+=" over";
					}
					node.onmouseout=function() {
						this.className=this.className.replace(" over", "");
					}
				}
			}
		}
		var currentLocation;
		var pattern;
		var result;
		var menuRoot = document.getElementById("menu");
		
		for (i=0; i<menuRoot.childNodes.length; i++) {
				node = menuRoot.childNodes[i];
				node.className.replace(" on", "");
		}
		
		currentLocation = 9;
		// result = "You're at the homepage!";
		
		pattern = /summary/i;
		
		if (pattern.test(document.location)) {
			currentLocation = 0;
			// result = "You're in the EDGAR Software section!";
		}
		
		pattern = /edit_account/i;
		
		if (pattern.test(document.location)) {
			currentLocation = 1;
			// result = "You're in the EDGAR Filing Service section!";
		}
		
		pattern = /entities/i;
		
		if (pattern.test(document.location)) {
			currentLocation = 2;
			// result = "You're in the EDGAR Forms section!";
		}
		
		pattern = /filing_service/i;
		
		if (pattern.test(document.location)) {
			currentLocation = 3;
			// result = "You're in the EDGAR Forms section!";
		}
		pattern = /sales/i;
		
		if (pattern.test(document.location)) {
			currentLocation = 4;
			// result = "You're in the EDGAR Forms section!";
		}
		/*
		pattern = /training/i;
		
		if (pattern.test(document.location)) {
			currentLocation = 5;
			// result = "You're in the EDGAR Forms section!";
		}
		*/
		
		pattern = /tech_support/i;
		
		if (pattern.test(document.location)) {
			currentLocation = 5;
			// result = "You're in the EDGAR Forms section!";
		}
		pattern = /reports/i;
		
		if (pattern.test(document.location)) {
			currentLocation = 6;
			// result = "You're in the EDGAR Forms section!";
		}
		pattern = /billing/i;
		
		if (pattern.test(document.location)) {
			currentLocation = 7;
			// result = "You're in the EDGAR Forms section!";
		}
		// alert(result);
		if ((menuRoot.childNodes != null) && (menuRoot.childNodes.length > 0))
			menuRoot.childNodes[currentLocation].className+=" on";
	}
}

function GeneratePassword() {

    if (parseInt(navigator.appVersion) <= 3) {
        alert("Sorry this only works in 4.0+ browsers");
        return true;
    }

    var length = 8;
    var sPassword = "";
    //length = document.aForm.charLen.options[document.aForm.charLen.selectedIndex].value;

    var noPunction = false;
    var randomLength = false;

    if (randomLength) {
        length = Math.random();

        length = parseInt(length * 100);
        length = (length % 7) + 6
    }


    for (i=0; i < length; i++) {

        numI = getRandomNum();
        if (noPunction) { while (checkPunc(numI)) { numI = getRandomNum(); } }

        sPassword = sPassword + String.fromCharCode(numI);
    }
    
    return sPassword;
};

function getRandomNum() {

    // between 0 - 1
    var rndNum = Math.random()

    // rndNum from 0 - 1000
    rndNum = parseInt(rndNum * 1000);

    // rndNum from 33 - 127
    rndNum = (rndNum % 94) + 33;

    return rndNum;
}

function checkPunc(num) {

    if ((num >=33) && (num <=47)) { return true; }
    if ((num >=58) && (num <=64)) { return true; }
    if ((num >=91) && (num <=96)) { return true; }
    if ((num >=123) && (num <=126)) { return true; }

    return false;
}

// Build the ToolTip Object
function buildToolTip(title, text) {
	var toolTip = DIV({'id' : 'toolTip'}, 
		H3({'class' : 'title'}, title), 
		P({'id' : 'tipText'}, text));
	
	return toolTip;
}
	
var showTip = function() {
	var divMain = $('main');
	
	appendChildNodes(divMain, buildToolTip(this.innerHTML, this.title));
	
	this.title = "";
	
	var myTip = $('toolTip');
	
	var linkPos = getElementPosition(this);
	var linkDim = getElementDimensions(this);
	var tipDim = getElementDimensions(myTip);
	
	var tipX = linkPos.x - (tipDim.w + 15);
	var tipY = linkPos.y - (tipDim.h/2);
	
	if (tipY < 0) {
		//tipY = linkPos.y + (linkDim.h);
		}
		
	if (tipX < 0) {
		tipX = 0;
		}
	
	var tipPos = new MochiKit.Style.Coordinates(
		tipX,
		tipY);
		
	setElementPosition(myTip, tipPos);
};
	
var destroyTip = function() {
	var divTip = $('toolTip');
	var pTip = $('tipText');
	
	this.title = pTip.innerHTML;
	
	removeElement(divTip);
};

var checkCIK = function() {
	var reCIK = /\d{10}/;
	
	if(reCIK.test(this.value)) {
		addElementClass(this, "validated");
	}
	else
	{
		removeElementClass(this, "validated");
	}	
};

function setNavigation(navText)
{
	var oMenu = getElementsByTagAndClassName("a", null, "menu");
				
	for (i=0; i < oMenu.length; i++)
	{
		if (oMenu[i].innerHTML == navText)
		{
			oList = oMenu[i].parentNode.parentNode;
			addElementClass(oList, "on");
		}
	}
}

String.prototype.trim = function ()
{
	return this.replace(/^\s*|\s*$/g, "");
};

function keyPressed()
    {
    //alert(event.keyCode);
    
		if(event.keyCode == 78 && event.ctrlKey) 
		 {
			 alert("This website doesnot allow this command");
		 }
    }

function StringBuffer ()
{
	this._strings_ = new Array;
	
	if (typeof this._initialized == "undefined")
	{
		StringBuffer.prototype.append = function (str)
		{
			this._strings_.push(str);
		};
		
		StringBuffer.prototype.toString = function ()
		{
			return this._strings_.join(" ");
		};
		
		StringBuffer.prototype.clear = function ()
		{
			return this._strings_.length = 0;
		};
		
		this._initialized = true;
	}
}

function counterUpdate(opt_countedTextBox, opt_countBody, opt_maxSize) {
        var countedTextBox = opt_countedTextBox;
        var countBody = opt_countBody ? opt_countBody : "countBody";
        var maxSize = opt_maxSize ? opt_maxSize : 1024;
        var field = document.getElementById(countedTextBox);
       
        if (field && field.value.length >= maxSize) {
                field.value = field.value.substring(0, maxSize);
        }
        var txtField = document.getElementById(countBody);
         if (txtField) { 
                txtField.innerHTML = field.value.length;
        }
}