// top menu
function state_ch(obj){
	if (navigator.userAgent.toLowerCase().indexOf("msie")!=-1)
		obj.filters[0].Apply();
	
	obj.style.backgroundColor="#ADB8C6";
	obj.style.color="white";
	obj.onmouseout=function(){
		obj.style.backgroundColor="transparent";
		obj.style.color="#29658A";
		}

	if (navigator.userAgent.toLowerCase().indexOf("msie")!=-1)
		obj.filters[0].Play(duration=0.5);	
}
// ********** SERVER INTERACTION *****************************************
var http_request;
var div_id;
var word=evnt=null;
function load_data(val,page) {
	if (http_request!=null){
		alert("Another instance is in ancion, please wait...");
		return false;
		}
	http_request=null;
	run=true;
	div_id="pop_win";

	if (page=="dic"){
		if (document.getElementById('dic_w').value=="")
			run=false;
		else{
			evnt=page;
			obj=document.getElementById('dic_w');
			word=obj.value;
			methods=document.getElementById('cntrans').checked?"&method=trans":"";
			url="dic_bridge.php?word="+word+methods;
			obj.style.color="#990000";
			obj.value="Searching, Please wait...";
			}
		}
	
	if (page=="currency"){
		evnt=page;
		obj=document.getElementsByName('amount_currency')[0];
		url="currency_bridge.php?amount="+obj.value+"&from="+document.getElementsByName('from_currency')[0].value+"&to="+document.getElementsByName('to_currency')[0].value;
		word=obj.value;
		obj.style.color="#990000";
		obj.value="Converting...";
		}
// ---------------------------------------------------------------------------------------		
	if (page=="currency" || page=="dic"){
		if (!(document.getElementById('pop_win'))){
			var a = document.createElement('div');
			a.innerHTML = "<div id='pop_bar' class='drag'><a href='javascript:close_pop();'><img src='close_btn.gif' alt='Close' /></a></div><div id='scroll_bar'><div id='pop_txt'></div></div>";
			a.setAttribute('id','pop_win');
			a.style.top=300+'px';
			a.style.left=500+'px';
		//	a.setAttribute('style','top: 300px; left: 500px;');
			document.getElementById('currency').appendChild(a);
			}
		}
// ---------------------------------------------------------------------------------------		
	
	if (page=="news"){
		url="news_bridge.php?home";
		div_id="content_r";
		document.getElementById('content_r').innerHTML="<p class='loading'><object classid='clsid:d27cdb6e-ae6d-11cf-96b8-444553540000' codebase='http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0' width='64' height='41' id='loading_swf' align='middle'><param name='allowScriptAccess' value='sameDomain' /><param name='movie' value='loading.swf' /><param name='wmode' value='transparent' /><param name='quality' value='high' /><param name='bgcolor' value='#ffffff' /><embed src='loading.swf' quality='high' bgcolor='#ffffff' width='64' height='41' name='loading' align='middle' allowScriptAccess='sameDomain' type='application/x-shockwave-flash' pluginspage='http://www.macromedia.com/go/getflashplayer' /></object></p>";
		}	
	
	if (run){
		if (window.XMLHttpRequest) { 
			http_request = new XMLHttpRequest();
			if (http_request.overrideMimeType) {
				http_request.overrideMimeType('text/html');
				}
		} else if (window.ActiveXObject) { 
			try {
				http_request = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					http_request = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
		if (!http_request) {
			alert('Fail to load data, please refresh page and try again.');
			return false;
		}
		url+="&"+new Date().getTime();
		http_request.onreadystatechange = getContents;
		http_request.open('GET',url, true);
		http_request.send(null);
		}
}

function getContents() {
	obj=document.getElementById(div_id);
	if (http_request.readyState == 4) {
		if (http_request.status == 200) {
			if (evnt=="dic"){
				document.getElementById('dic_w').value=word;
				document.getElementById('dic_w').style.color="#666666";
				}
			else if (evnt=="currency"){
				document.getElementsByName('amount_currency')[0].value=word;
				document.getElementsByName('amount_currency')[0].style.color="#666666";
				}
			else 	
				obj.innerHTML="";
			
			start(obj);
			
			if (div_id=="pop_win"){
				obj.style.display="block";
				document.getElementById('pop_txt').innerHTML=http_request.responseText;
				}
			else{
				obj.innerHTML=http_request.responseText;
				}
			play(obj,0.3);
			http_request=null;
		} else {
			obj.innerHTML="Fail to load data, please refresh page and try again.";
		}
	}
}
// ********** SERVER INTERACTION *****************************************
function close_pop(){document.getElementById('pop_win').style.display='none';}

function start(obj){if (navigator.userAgent.toLowerCase().indexOf("msie")!=-1)	obj.filters[0].Apply();}
function play(obj,time){if (navigator.userAgent.toLowerCase().indexOf("msie")!=-1)	obj.filters[0].Play(duration=time);}

function show_chart(){
	obj=document.getElementById('pop_win');
	start(obj);
	obj.style.display="block";
	document.getElementById('pop_txt').innerHTML="<img src='currency_chart.php' alt='NZD Chart' />";
	play(obj,0.3);
}

function drag(e){
	if (!e) var e=window.event;
	obj=e.target?e.target:e.srcElement;
	if (obj.className=="drag"){
		obj=document.getElementById('pop_win');
		move = true;
		x = parseInt(obj.style.left+0);
		y = parseInt(obj.style.top+0);
		ox = e.clientX;
		oy = e.clientY;
		document.onmouseup=function(){
			move=false;
			obj.style.opacity=1;
			obj.style.filter='alpha(opacity=100)';
			};
		obj.style.opacity=.5;
		obj.style.filter='alpha(opacity=50)';
		document.onmousemove=function (){
			  if (move){
				obj.style.left = x + e.clientX - ox+'px';
				obj.style.top  = y + e.clientY - oy+'px';
			//	return false;
				}
			};
	//	return false;
		}
}
document.onmousedown=drag;

function play_radio(obj){
	code=obj.value!="stop"?"<OBJECT height='0' width='0' CLASSID='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6'><PARAM name='uiMode' value='mini'><PARAM name='URL' value='"+obj.value+"'><PARAM NAME='AutoStart' VALUE='1'><embed height='0' width='0' type='application/x-mplayer2' pluginspage='http://www.microsoft.com/windows/windowsmedia/download/AllDownloads.aspx/' src='"+obj.value+"' ShowStatusBar='1' autostart='1' ></embed></OBJECT>":"";
	document.getElementById('player').innerHTML=code;
}