﻿
//this function return to Flash ActiveX Object or Plugin depending upon browser
//it takes care for browser type and returns the proper reference.
//Accepts the id or name of <OBJECT> or <EMBED> tag respectively
//source taken from: www.moock.org

function thisMovie(movieName)
 {
        // IE and Netscape refer to the movie object differently.
        // This function returns the appropriate syntax depending on the browser.
        
        if (window[movieName] != undefined)
        {
                return window[movieName];
                
        }
        else
        {
            if (window.document != undefined)
                return window.document[movieName];
            else
                return null;
        }
}

//this function would call a flash/flex function.
function callFlashFunction(functionName , args)
{
    //Get the reference so activeX or Plugin. flexApp is id/name of OBJECT/EMBED tags
    var flashObject  = thisMovie("ParagonexTrading");
    if (flashObject != null)
    {
        if (args == undefined)
            eval("flashObject." + functionName + "();");
        else
        {
            eval("flashObject." + functionName + "(" + args + ");");
        }
    }
        
}


//
// Set the Flash object height
//
function ChangeTradingStageHeight(objectID , newHeight)
{
    var obj = document.getElementById(objectID);
    if (obj != null)
        obj.height = newHeight;
}
function PrintWindow(){

window.print();

}


//
// functions that obtain the width of an HTML element.
//
function GetOBJWidth(obj)
{
	var width = obj.offsetWidth;
	if (width > 0 || !cmIsTRNode (obj))
		return width;
	if (!obj.firstChild)
		return 0;
	// use TABLE's length can cause an extra pixel gap
	//return obj.parentNode.parentNode.offsetWidth;

	// use the left and right child instead
	return obj.lastChild.offsetLeft - obj.firstChild.offsetLeft + GetOBJWidth (obj.lastChild);
}

//
// functions that obtain the height of an HTML element.
//
function GetOBJHeight (obj)
{
	var height = obj.offsetHeight;
	if (height > 0 || !cmIsTRNode (obj))
		return height;
	if (!obj.firstChild)
		return 0;
	// use the first child's height
	return obj.firstChild.offsetHeight;
}

//
// functions that obtain the coordinates of an HTML element
//
function GetOBJX (obj)
{
	var x = 0;

	do
	{
		x += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	while (obj);
	return x;
}

function GetOBJXAt (obj, elm)
{
	var x = 0;

	//getOBJ(obj)
	while (obj && obj != elm)
	{
		x += obj.offsetLeft;
		obj = obj.offsetParent;
	}
	if (obj == elm)
		return x;
	return x - GetOBJX (elm);
}

function GetOBJY (obj)
{
	var y = 0;
	do
	{
		y += obj.offsetTop;
		obj = obj.offsetParent;
	}
	while (obj);
	return y;
}

function cmIsTRNode (obj)
{
	var tagName = obj.tagName;
	return tagName == "TR" || tagName == "tr" || tagName == "Tr" || tagName == "tR";
}

//
// get the Y position of the object.  In case of TR element though,
// we attempt to adjust the value.
//
function GetOBJYAt (obj, elm)
{
	var y = 0;

	if (!obj.offsetHeight && cmIsTRNode (obj))
	{
		var firstTR = obj.parentNode.firstChild;
		obj = obj.firstChild;
		y -= firstTR.firstChild.offsetTop;
	}

	while (obj && obj != elm)
	{
		y += obj.offsetTop;
		obj = obj.offsetParent;
	}

	if (obj == elm)
		return y;
	return y - GetOBJY (elm);
}
















function getOBJ(obj,iTitle)
{
	var str;
	str = obj +"";
	obj = eval(obj)
	var i;
	var msg = "";
	msg = "<table>";
		
	for(i in obj)
			{

			msg += "<tr><td> " + i + " </td>" ;
			try{msg += "<td> &nbsp;&nbsp;&nbsp;" + eval("obj." + i ) + "</td>" }
			catch(e){msg += "<td> &nbsp;&nbsp;</td>" }
			msg += "</tr>" ;
			}

	msg += "</table>"
	var win = window.open("about:blank","","")
	msg = "<br><strong><u>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"+str+"</u></strong><br>" + msg
	win.document.write( msg);
	return;


}


function px_navigation(nav, w) {

    if (ie) {
        navbar = document.getElementById("top_nav_main2").childNodes;
    } else {
        navbar = document.getElementById("top_nav_main2").childNodes;
    }

    for (i = 0; navbar[i]; i++) {
        if (navbar[i].id == "nav" + nav) {
            navbar[i].className = "top_nav2active";
        } else {
            navbar[i].className = '';
        }
    }

    navbar = document.getElementById("top_nav3").childNodes;
    document.getElementById("top_nav3").style.right = w + 'px';
    document.getElementById("top_nav3").style.display = "block";
    for (i = 0; navbar[i]; i++) {
        if (navbar[i].id == "top_nav_sec" + nav) {
            navbar[i].style.display = "block";
        } else {
            navbar[i].style.display = "none";
        }
    }

    return false;

}

function px_hide_nav() {
    document.getElementById("top_nav3").style.display = "none";
}









function formatCurrency(num) {
	num1 = num.toString().replace(/\$|\,/g,'');
	
	if(isNaN(num1)) num1 = "0";
	
	sign = (num1 == (num = Math.abs(num)));
	
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	
	num = Math.floor(num/100).toString();
	
	if(cents<10) cents = "0" + cents;
	
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
	        num = num.substring(0,num.length-(4*i+3))+','+ num.substring(num.length-(4*i+3));
	return  num + '.' + cents;
}


// String.Format
String.format = function() {
    var s = arguments[0];
    for (var i = 0; i < arguments.length - 1; i++) {
        var reg = new RegExp("\\{" + i + "\\}", "gm");
        s = s.replace(reg, arguments[i + 1]);
    }

    return s;
}

String.prototype.format = function() {
    var s = this;
    for (var i = 0; i < arguments.length; i++) {
        var reg = new RegExp("\\{" + i + "\\}", "gm");
        s = s.replace(reg, arguments[i]);
    }

    return s;
}


