﻿function getobj( id )
{
	return document.getElementById(id);
}

function getNodeString(key, ostr) {
	var reg = new RegExp("<<" + key + ">>([\\s\\S]*)<</" + key + ">>", "i");
	if (reg.test(ostr))
		return unescape(RegExp.$1);
	return "";
}

function npssort(num3, url)
{
	ajaxurl = url;
	var leftnum = 2;
	var value = num3;
	var titles;
	
	this.initselecttable = function()
	{
		var obj = getobj( "selecttable1" );
		var table = getobj( "npstable1" );
		var n = table.rows.length;
		var bbnames = getobj( "mybrokernames" ).value;
		var cellnum = table.rows[0].cells.length - 1;
		if( obj != null )
		{			
			var htmstr = "<table cellpadding='0' cellspacing='0' border='0'>" +
				"<tr><td class='s2' onclick='nps.selectitem(0)'>&nbsp;</td></tr>";
			for( var i = 1; i < n; i++ )
				htmstr += "<tr><td onclick='nps.selectitem(" + i + ")'>&nbsp;</td></tr>";
			htmstr += "</table>";
			obj.innerHTML = htmstr;
			
			for( i = 0; i < n; i++ )
			{
				if( bbnames.indexOf( table.rows[i].cells[cellnum].innerHTML + "|" ) >= 0 )
					this.selectitem( i );
			}
		}
		else if( bbnames != null )
		{
			var m = table.rows[0].cells.length;
			for( i = 0; i < n; i++ )
			{
				if( bbnames.indexOf( table.rows[i].cells[cellnum].innerHTML + "|" ) >= 0 )
				{
					for( var j = 1; j < m; j++ )
						table.rows[i].cells[j].className += " s21s";
				}
			}
		}
	}
	
	this.selectitem = function( num )
	{
		var obj1 = getobj( "selecttable1" ).getElementsByTagName("table")[0];
		obj1 = obj1.rows[num].cells[0];
		if( obj1.selected == null )
		{
			obj1.className += " s1s";
			obj1.selected = true;
			
			obj1 = getobj( "npstable1" );
			var n = obj1.rows[num].cells.length;
			for( var i = 1; i < n; i++ )
				obj1.rows[num].cells[i].className += " s21s";
		}
		else
		{
			obj1.className=obj1.className.replace(new RegExp("\\ss1s", "g"), "");
			obj1.selected = null;
			
			obj1 = getobj( "npstable1" );
			n = obj1.rows[num].cells.length;
			for( i = 1; i < n; i++ )
				obj1.rows[num].cells[i].className = obj1.rows[num].cells[i].className.replace(new RegExp("\\ss21s", "g"), "");
		}
	}
	
	this.initselecttable();
	
	if( getobj("npstitle") != null )
		titles = getobj("npstitle").getElementsByTagName("div");
	
	if( num3 != null )
	{
		titles[num3].className = "active";
		setcellcolor( num3 );
	}
	
	function setcellcolor( num )
	{
		var table = getobj( "npstable1" );
		var cel = num + leftnum;
		for( var i = 0, n = table.rows.length; i < n; i++ )
			table.rows[i].cells[cel].className += " s20";
	}
	
	this.setactive = function( num )
	{
		if( num == value )
			return;
			
		var my = this;
		ajaxrequest( ajaxurl + titles[num].innerHTML, doContents );
		setcellcolor( num );
		function doContents( str )
		{
			getobj("npscontent").innerHTML = str;
			titles[num].className = "active";
			if( value != null )
				titles[value].className = "";
			value = num;
			setcellcolor( num );
			my.initselecttable();
		}
	}
	
	this.addmybrokers = function( doContents2 )
	{
		var obj1 = getobj( "selecttable1" ).getElementsByTagName("table")[0];
		var obj2 = getobj( "npstable1" );
		var str = "";
		var cellnum = obj2.rows[0].cells.length - 1;
		for( var i = 0, n = obj1.rows.length; i < n; i++ )
		{
			if( obj1.rows[i].cells[0].selected )
				str += obj2.rows[i].cells[cellnum].innerHTML + ",";
		}
		
		ajaxrequest( "brokerajax.aspx?cmd=addmybrokers&ids=" + str, doContents2);
	}
}

function logined()
{
	return (
		((getobj("logineduserid") != null) && (getobj("logineduserid").value.length > 0)) ||	//aspx files
		(getobj("iduserlogined") != null) //?? html files. maybe the ajax have not return the log infomation;
		);
}

function loginkeypriess()
{
	if(window.event.keyCode == 13)
		login( getobj("htxtUsername").value,  getobj("htxtPassword").value );
}

function verify()
{
	this.message = "One or more required fields are empty. Please fill out the form completely. Thank you";
	this.obj = null;
	this.empty = function( id )
	{
		this.obj = getobj( id );
		if( this.obj.value.length == 0 )
			throw( new Error( this.message ) );
	}
	
	this.password = function( id1, id2 )
	{
		this.empty( id1 );
		this.empty( id2 );

		if(getobj(id1).value != getobj(id2).value)
			throw( new Error( "Twice Password is Different." ) );
	}
	
	this.date = function( id )
	{
		this.empty( id );

		var strdate = this.obj.value;
		var regu ="^(((0[1-9]|[12][0-9]|3[01])/((0[13578]|1[02]))|((0[1-9]|[12][0-9]|30)/(0[469]|11))|(0[1-9]|[1][0-9]|2[0-8])/(02))/([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3}))|(29/02/(([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00)))$";
		var re = new RegExp(regu);   
		if( strdate.search(re) == -1 )
			throw( new Error( "Is not validate date format (DD/MM/YYYY)." ) );
	}
	
	this.email = function( id )
	{
		this.empty( id );

		var stremail = this.obj.value;
		if( stremail.length > 100 )
			throw( new Error( "E-mail is too long." ) );
		
		var regu ="^(([0-9a-zA-Z]+)|([0-9a-zA-Z]+[_.0-9a-zA-Z-]*[0-9a-zA-Z]+))@([a-zA-Z0-9-]+[.])+([a-zA-Z]{2}|net|NET|com|COM|gov|GOV|mil|MIL|org|ORG|edu|EDU|int|INT)$";
		var re = new RegExp(regu);   
		if( stremail.search(re) == -1 )
			throw( new Error( "Is not validate E-mail address." ) );
	}

	this.isfloat = function( id )
	{
		this.empty( id );

		var reg = /^(([0-9]+\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\.[0-9]+)|([0-9]*[1-9][0-9]*))$/;
		if( !reg.test( this.obj.value ) )
			throw( new Error( this.message ) );
	}
	
	this.checked = function( id )
	{
		this.obj = getobj( id );
		if( !this.obj.checked )
			throw( new Error( this.message ) );
	}
}

function ratediv(id, interval)
{
    var num = 0;
    var tt = setInterval( change, interval );
    
    function change()
    {
        getobj( id + num ).className = "hidden";
        
        ++num;
        if( getobj( id + num ) == null )
            num = 0;
        
        getobj( id + num ).className = "visble";
    }
}

function ratediv2(id, interval, id2)
{
    var num = 0;
	getobj( id2 + num ).style.backgroundColor = "#b00";
    
    var tt = setInterval( change, interval );
    
    function change()
    {
		getobj( id2 + num ).style.backgroundColor = "";
        getobj( id + num ).className = "hidden";
        
        ++num;
        if( getobj( id + num ) == null )
            num = 0;
        
        getobj( id + num ).className = "visble";
		getobj( id2 + num ).style.backgroundColor = "#b00";
    }
    
    this.setnum = function( nn )
    {
		clearInterval( tt );
		
		getobj( id2 + num ).style.backgroundColor = "";
        getobj( id + num ).className = "hidden";
        num = nn;
        getobj( id + num ).className = "visble";
		getobj( id2 + num ).style.backgroundColor = "#b00";
        tt = setInterval( change, interval );
    }
}

function setHeader()
{
	var edition = "US Edition";
	var language = navigator.browserLanguage;
	if( language == null )
		language = navigator.language;
	if( language.toLowerCase() != "en-us" )
		edition = "International Edition";
		
	document.write("<div style='width:1000px; height:25px'><div class='edition'>" + edition + "</div>" +
	"<div id='iddate'>" + Date().toString() + "</div>" +
	"<div onclick='SetHome(this,window.location)' class='home'>Set Forexds.com as your homepage</div></div>");
	
	this.settime = function()
	{
		getobj("iddate").innerHTML = Date().toString();
	}
	setInterval( "this.settime()", 1000 );
}

function setNavigation()
{	
	var str = "<div style='margin-top:10px; width:1000px;'><ul id='navtop'>" +
		"<li><a href='/'>HOME</a></li>" +
		"<li><a href='/services/services.htm'>SERVICES</a>" +
			"<ul>" +
				"<li><a href='/services/services.htm'><b>SERVICES HOME</b></a></li>" +
				"<li><a href='/services/education.aspx'>TRADER EDUCATION</a></li>" +
				//"<li><a href='/services/ForexdsProsperTeam.aspx'>FOREXDS PROSPER TEAM</a></li>" +
				"<li class='pb2b'><br />INSTITUTIONAL</li>" +
				"<li><a href='/services/marketresearch.htm'>FX MARKET RESEARCH</a></li>" +
				"<li><a href='/services/licensing.htm'>LICENSE FROM FOREXDS</a></li>" +
			"</ul>" +
		"</li>" +
		"<li><a href='/news/news.aspx'>NEWS</a>" +
			"<ul>" +
				"<li><a href='/news/news.aspx'>GO TO NEWS HOME</a></li>" +
				"<li><a href='/news/options.aspx'>EDIT MY NEWS FEEDS</a></li>" +
				"<li><a href='/news/options.aspx'>EDIT MY PRICE ALERTS</a></li>" +
				"<li><a href='/news/mostpopular.aspx'>MOST  POPULAR NEWS</a></li>" +
			"</ul>" +
		"</li>" +
		"<li><a href='/brokers/broker.aspx'>BROKER RESEARCH</a>" +
			"<ul>" +
				"<li><a href='/brokers/broker.aspx'>BROKER RESEARCH HOME</a></li>" +
				"<li><a href='/brokers/brokerranking.aspx'>BROKER RANKING</a></li>" +
				"<li><a href='/brokers/brokercomparedetail.aspx'>BROKER COMPARISON</a></li>" +
				"<li><a href='/brokers/brokerprofile.aspx'>BROKER PROFILE</a></li>" +
				"<li><a href='/brokers/brokercomparedetail.aspx'>MY TOP FX BROKER LIST</a></li>" +
			"</ul>" +
		"</li>" +
			"<li><a href='/blog/blog.aspx'>FOREXDS BLOG</a>" +
				"<ul>" +
					"<li><a href='/blog/moreforexds.aspx'>FOREXDS ENTRIES</a></li>" +
					//"<li><a href='/blog/popular.htm'>MOST VIEWED ENTRIES</a></li>" +
					"<li><a href='/blog/moreentries.aspx?title=LATEST%20ENTRIES%20FROM%20VISITORS%20%26%20FANS'>LATEST ENTRIES</a></li>" +
					"<li><a href='/blog/blog.aspx'>POST AN ENTRY</a></li>" +
					"<li><a href='/blog/moreentries.aspx?state=PICK&title=EDITOR%20PICKS%3a%20INTERESTING%20OR%20CONTROVERSIAL'>EDITOR'S PICKS</a></li>" +
				"</ul>" +
			"</li>" +
		"<li><a href='/technology/technology.htm'>TECHNOLOGY</a>" +
			"<ul>" +
				"<li><a href='/technology/technology.htm'>FX HOUND - DESKTOP APP</a></li>" +
				"<li><a href='/technology/technology.htm'>VT Mobile - IPHONE APP</a></li>" +
				"<li><a href='/technology/technology.htm'>DOWNLOAD PAGE</a></li>" +
				"<li><a href='/services/licensing.htm'>LICENSE OUR TECHNOLOGY</a></li>" +
			"</ul>" +
		"</li>" +
		"<li><a href='/aboutus/aboutus.htm'>ABOUT US</a>" +
			"<ul>" +
				"<li><a href='/aboutus/aboutus.htm'>ABOUT US</a></li>" +
				"<li><a href='/aboutus/contactus.aspx'>CONTACT US</a></li>" +
				"<li><a href='/aboutus/partners.htm'>STRATEGIC PARTNERS</a></li>" +
				"<li><a href='/aboutus/jobs.htm'>JOBS</a></li>" +
				"<li><a href='/aboutus/investors.htm'>INVESTORS</a></li>" +
			"</ul>" +
		"</li>" +
		"<li><a href='/registration.aspx'>REGISTER</a></li>" +
		"<li><a href='/login.aspx'>LOGIN</a></li>" +
	"</ul></div>" +
	"<div id='idnavbelow' class='navbelow'></div>";
	
	document.write( str );
	
	function menuFix() { 
	
		var sfEls = document.getElementById("navtop").getElementsByTagName("li"); 
		for (var i=0; i<sfEls.length; i++) { 
			sfEls[i].onmouseover=function() {
				function doSomething(obj){
					return (function(){
						obj.actived = true;
						obj.timerid = null;
						obj.className+=(obj.className.length>0? " ": "") + "sfhover";
					});
				}
				
				if( this.actived == true )
				{
					clearTimeout(this.timerid2);
					return;
				}

				var functRef = doSomething(this);
				this.timerid = setTimeout(functRef, 300);	////
			} 
			//sfEls[i].onMouseDown=function() {
			//	this.className+=(this.className.length>0? " ": "") + "sfhover"; 
			//} 
			//sfEls[i].onMouseUp=function() { 
			//	this.className+=(this.className.length>0? " ": "") + "sfhover"; 
			//} 
			sfEls[i].onmouseout=function() { 
				if( this.timerid != null )
				{
					clearTimeout(this.timerid);
					return;
				}
				
				function doSomething(obj){
					return (function(){
						obj.actived = false;
						obj.className=obj.className.replace(new RegExp("( ?|^)sfhover\\b"), ""); 
					});
				}
				
				if( this.actived == true )
				{
					var functRef = doSomething(this);
					this.timerid2 = setTimeout(functRef, 300);	////
				}

			} 
		} 
	} 
	
	menuFix();
	
	updatealertprices();
}

function updatealertprices()
{
	ajaxrequest( "/news/optionsajax.aspx?cmd=getalertprices", doContents);
		
	function doContents( str )
	{
		getobj("idnavbelow").innerHTML = str;
		if( logined() )
			setTimeout( "updatealertprices()", 15000 );
	}
}


function logout()
{
	ajaxrequest( "/defaultajax3.aspx?cmd=Logout", doContents);
		
	function doContents( str )
	{
		window.location = "/";
	}
}

function login( username, password, url )
{
	ajaxrequest( "/defaultajax3.aspx?cmd=Login&UserName=" + username + "&Password=" + password, doContents);
		
	function doContents( str )
	{
		if( str == "OK" )
		{
			var ur = url;
			if( url == null )
				ur = window.location.href;
				
			var n = ur.indexOf("#");
			if( n > 0 )
				ur = ur.substring(0, n);

			window.location = ur;
		}
		else if( str.length > 0 )
			alert( str );
	}
}

function writegooglecode()
{
	document.write("<div class='pagebottom'><div style='float:right'>Copyright &copy; Forex Datasource, LLC 2007-2011.</div><a href='/aboutus/risk.htm'>Risk Disclosure</a></div>");
	writetrackercode();
}

function writetrackercode()
{	
	// google tracker code
	document.write('<script src="http://www.google-analytics.com/urchin.js" type="text/javascript"></script>');
	setTimeout( '_uacct = "UA-1466362-5";urchinTracker()', 1000 );	//?? 上一句调入urchin.js有延时
	//<!-- Start Quantcast tag -->
	document.write('<script src="http://edge.quantserve.com/quant.js" type="text/javascript"></script>' +
	'<noscript>' +
		'<a href="http://www.quantcast.com/p-46vEmRuFWvlAY" target="_blank">' +
			'<img style="display: none" height="1" alt="Quantcast" src="http://pixel.quantserve.com/pixel/p-46vEmRuFWvlAY.gif"' +
				'width="1" border="0"></a>' +
	'</noscript>' );
	setTimeout( '_qacct="p-46vEmRuFWvlAY";quantserve();', 1000 );	//?? 上一句调入urchin.js有延时
}

function googletrack()
{
	document.write("<div class='pagebottom2'>" +
		"<ul>" +
			"<li><a href='/'>HOME</a>" +
				"<ul>" +
					"<li class='pb2a'><a href='/registration.aspx'>REGISTER</a> - free<br /><br />to customize news<br />feeds, to view / print<br />broker comparison<br />reports, and to<br />participate in the<br />Forexds Blog</li>" +
				"</ul>" +
			"</li>" +
			"<li><a href='/services/services.htm'>SERVICES</a>" +
				"<ul>" +
					"<li><a href='/services/services.htm'><b>SERVICES HOME</b></a></li>" +
					"<li><a href='/services/education.aspx'>TRADER EDUCATION</a></li>" +
					//"<li><a href='/services/ForexdsProsperTeam.aspx'>FOREXDS PROSPER TEAM</a></li>" +
					"<li>&nbsp;</li>" +
					"<li class='pb2b'><br />INSTITUTIONAL</li>" +
					"<li><a href='/services/marketresearch.htm'>FX MARKET RESEARCH</a></li>" +
					"<li><a href='/services/licensing.htm'>LICENSE FROM FOREXDS</a></li>" +
				"</ul>" +
			"</li>" +
			"<li><a href='/news/news.aspx'>NEWS</a>" +
				"<ul>" +
					"<li><a href='/news/news.aspx'>GO TO NEWS HOME</a></li>" +
					"<li><a href='/news/options.aspx'>EDIT MY NEWS FEEDS</a></li>" +
					"<li><a href='/news/options.aspx'>EDIT MY PRICE ALERTS</a></li>" +
					"<li><a href='/news/mostpopular.aspx'>MOST  POPULAR NEWS</a></li>" +
				"</ul>" +
			"</li>" +
			"<li><a href='/brokers/broker.aspx'>BROKER RESEARCH</a>" +
				"<ul>" +
					"<li><a href='/brokers/broker.aspx'>BROKER RESEARCH HOME</a></li>" +
					"<li><a href='/brokers/brokerranking.aspx'>BROKER RANKING</a></li>" +
					"<li><a href='/brokers/brokercomparedetail.aspx'>BROKER COMPARISON</a></li>" +
					"<li><a href='/brokers/brokerprofile.aspx'>BROKER PROFILE</a></li>" +
					"<li><a href='/brokers/brokercomparedetail.aspx'>MY TOP FX BROKER LIST</a></li>" +
				"</ul>" +
			"</li>" +
			"<li><a href='/blog/blog.aspx'>FOREXDS BLOG</a>" +
				"<ul>" +
					"<li><a href='/blog/moreforexds.aspx'>FOREXDS ENTRIES</a></li>" +
					//"<li><a href='/blog/popular.htm'>MOST VIEWED ENTRIES</a></li>" +
					"<li><a href='/blog/moreentries.aspx?title=LATEST%20ENTRIES%20FROM%20VISITORS%20%26%20FANS'>LATEST ENTRIES</a></li>" +
					"<li><a href='/blog/blog.aspx'>POST AN ENTRY</a></li>" +
					"<li><a href='/blog/moreentries.aspx?state=PICK&title=EDITOR%20PICKS%3a%20INTERESTING%20OR%20CONTROVERSIAL'>EDITOR'S PICKS</a></li>" +
				"</ul>" +
			"</li>" +
			"<li><a href='/technology/technology.htm'>TECHNOLOGY</a>" +
				"<ul>" +
					"<li><a href='/technology/technology.htm'>FX HOUND - DESKTOP APP</a></li>" +
					"<li><a href='/technology/technology.htm'>VT Mobile - IPHONE APP</a></li>" +
					"<li><a href='/technology/technology.htm'>DOWNLOAD PAGE</a></li>" +
					"<li><a href='/services/licensing.htm'>LICENSE OUR TECHNOLOGY</a></li>" +
				"</ul>" +
			"</li>" +
			"<li>&nbsp;" +
				"<ul class=pb2c>" +
					"<li class=pb2d><a href='/aboutus/aboutus.htm'>ABOUT US</a></li>" +
					"<li><a href='/aboutus/aboutus.htm'>ABOUT US</a></li>" +
					"<li><a href='/aboutus/contactus.aspx'>CONTACT US</a></li>" +
					"<li><a href='/aboutus/partners.htm'>STRATEGIC PARTNERS</a></li>" +
					"<li><a href='/aboutus/jobs.htm'>JOBS</a></li>" +
					"<li><a href='/aboutus/investors.htm'>INVESTORS</a></li>" +
				"</ul>" +
			"</li>" +
		"</ul>" +
	"</div>");

	writegooglecode();
}

function ajaxrequest( urlall, parameter )
{
	var url;
	var sendstr;
	var n = urlall.indexOf( "?" );
    if( n > 0 )
    {
        url = urlall.slice(0,n);
        sendstr = urlall.slice(n+1);
    }
 
	var xmlhttp = createXMLHttpRequest();

	xmlhttp.open('post', url, true); 
	xmlhttp.onreadystatechange = doContents;
	xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 
	xmlhttp.send( sendstr ); 

	function doContents()
	{
		if (xmlhttp.readyState != 4) 
			return;
		
		if (xmlhttp.status != 200)
			return;
		
		if( typeof(parameter) == "function" )
			parameter( xmlhttp.responseText );
		else if( parameter == null )
		    return;
		else
			document.getElementById(parameter).innerHTML = xmlhttp.responseText;
	}
	
	function createXMLHttpRequest()
	{ 
		if(window.ActiveXObject) 
		{ 
			var aVersions = ["MSXML2.XMLHttp.7.0","MSXML2.XMLHttp.6.0","MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp","Microsoft.XMLHttp"]; 
			for( i=0;i<aVersions.length;i++) 
			{ 
				try 
				{
					return new ActiveXObject(aVersions[i]); 
				} 
				catch(oError){} 
			} 
		} 
		else if(window.XMLHttpRequest) 
		{ 
			return new XMLHttpRequest(); 
		} 

		throw new Error("XMLHttp object could not be created."); 
	}
}

function SetHome(obj,vrl)
{
    try
    {
		obj.style.behavior='url(#default#homepage)';obj.setHomePage(vrl);
    }
    catch(e){
        if(window.netscape) {
            try {
                    netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); 
            } 
            catch (e) { 
               alert("This action was aviod by your browser. If you want to enable, please enter 'about:config' in your address line, and change the value of 'signed.applets.codebase_principal_support' to true."); 
            }
            var prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefBranch);
            prefs.setCharPref('browser.startup.homepage',vrl);
         }
    }
}

function LocalTime( obj, fmt )
{
	var ostr = obj.innerHTML;
	return strLocalTime( ostr, fmt );
}

function strLocalTime( ostr, fmt )
{
	var reg = new RegExp('(\\d{6}\\s\\d{6}?)','g');	//源格式是 yyMMdd HHmmss
	return ostr.replace( reg, changeone );
	
	function changeone( $1 )
	{
		var str = $1;
		var da = new Date( '20' + str.substr(0,2), str.substr(2,2)-1, str.substr(4,2), str.substr(7,2), str.substr(9,2), str.substr(11,2) );
		da = new Date( da.valueOf() - da.getTimezoneOffset() * 60000 );
		return datetimeFormat( da, fmt );
	}
}

function setLocalTime( obj, fmt )
{
	var o = obj;
	if( typeof(obj) == "string" )
		o = getobj( obj );

	o.innerHTML = LocalTime( o, fmt );
}

function datetimeFormat( da, format )
{
	var o = {
		//"M+" : da.getMonth()+1, //month
		"d+" : da.getDate(), //day
		"h+" : da.getHours(), //hour
		"m+" : da.getMinutes(), //minute
		"s+" : da.getSeconds(), //second
		"q+" : Math.floor((da.getMonth()+3)/3), //quarter
		"S" : da.getMilliseconds() //millisecond
	}
	
	var mon = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");  
	if(/(y+)/.test(format))
		format=format.replace(RegExp.$1,(da.getFullYear()+"").substr(4 - RegExp.$1.length));
	for(var k in o)
		if(new RegExp("("+ k +")").test(format))
			format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] :("00"+ o[k]).substr((""+ o[k]).length));
	format = format.replace( /MMM/g, mon[da.getMonth()] );
	return format;
}

function ShowAD468X60()
{
	var num = Math.random() * 1000000000000000000;
	var adslist = new Array(
		'<embed pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"' +
		'src="/images/ads/goma468x60.swf" width="468" height="60" type="application/x-shockwave-flash"' +
		'wmode="opaque" quality="high">'

		//'<script type="text/javascript" src="http://ad.doubleclick.net/adj/N5627.288194.VARATRADE.COM/B4721821.4;sz=468x60;ord=' + num + '?"></script>'
		);
	var n = Math.floor(Math.random() * adslist.length)
	document.write(adslist[n]);
}

function ShowAD300X250()
{
	var num = Math.random() * 1000000000000000000;
	var adslist = new Array(
		'<embed pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"' +
		'src="/images/ads/goma300x250.swf" width="300" height="250" type="application/x-shockwave-flash"' +
		'wmode="opaque" quality="high">'
		
		//'<script type="text/javascript" src="http://ad.doubleclick.net/adj/N5627.288194.VARATRADE.COM/B4721821.3;sz=300x250;ord=' + num + '?"></script>'
		);
	var n = Math.floor(Math.random() * adslist.length)
	document.write(adslist[n]);
}

function ShowAD234X60()
{
	var num = Math.random() * 1000000000000000000;
	var adslist = new Array(
		'<a href="http://ad.doubleclick.net/clk;232607623;56471838;m" target="_blank"><img src="/images/ibfx-234x50.png"></a>'
		);
	var n = Math.floor(Math.random() * adslist.length)
	document.write( adslist[n] );
}

function getURLparameter( name )
{
  var reg = new RegExp("(^|\\?|&)"+ name +"=([^&|#]*)(\\s|&|$|#)", "i");  
  if (reg.test(window.location))
	return unescape(RegExp.$2);
  return "";
}

function getUtcDate()
{
	var da = new Date();
	return new Date( da.valueOf() + da.getTimezoneOffset() * 60000 );
}

function textPrompt( id )
{
	var obj = getobj( id );
	obj.style.color = "#aaa"
	var ostr = obj.value;
	
	obj.onfocus = function()
	{
		if( obj.value != ostr )
			return;
			
		obj.style.color = "#444";
		obj.value = "";
	}
}

function priceformat( pair, price )
{
	var pr = Number(price);
	
	if( pair.toUpperCase().indexOf( "JPY" ) >= 0 )
		return pr.toFixed(2);
	else
		return pr.toFixed(4);
}

// need jQuery
function _getPageSize() {
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {    
        xScroll = window.innerWidth + window.scrollMaxX;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    var windowWidth, windowHeight;
    if (self.innerHeight) {    // all except Explorer
        if(document.documentElement.clientWidth){
            windowWidth = document.documentElement.clientWidth; 
        } else {
            windowWidth = self.innerWidth;
        }
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }    
    // for small pages with total height less then height of the viewport
    if(yScroll < windowHeight){
        pageHeight = windowHeight;
    } else { 
        pageHeight = yScroll;
    }
    // for small pages with total width less then width of the viewport
    if(xScroll < windowWidth){    
        pageWidth = xScroll;        
    } else {
        pageWidth = windowWidth;
    }
    arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight);
    return arrayPageSize;
}

