/*================================

Cube Trader v2 Javascript
Copyright: Marcus Davidson 5-July-2003

=================================*/

//Global Variables
var DEBUG=true;
var APPLOCATION = "/cubetrader";
var PAGELOCATION = document.location.href;
var SCREEN_WIDTH = screen.width;
var SCREEN_HEIGHT = screen.height;

//Attach Some Events
window.onhelp = Helper;
window.onload = Init;
//window.document.oncontextmenu = function Dummy(){return false;}

function Init(){
	//GetMessages()
	self.focus();
	if(self.document.forms[0]==null){return;}
	self.document.forms[0].focus();
}

/*=================================
	Toolbar Functions
==================================*/
function showHide(section){
	var oContent = document.all.item(section);
	if (oContent.style.display == "none"){
		oContent.style.display = "";
	}else {
		oContent.style.display = "none";
	}
}

var memory;
function showCollapse(section){
	var oContent = document.all.item(section);
	if(memory!=null){showHide(memory);}
	if (oContent.style.display == "none"){
		oContent.style.display = "";		
		memory=section;
	}else {
		oContent.style.display = "none";	
	}
}


/*=================================
	Order Helper Functions
==================================*/
function getTarget(obj){
	if(obj == null){return null;}
	if(obj.target ==null){return getTarget(obj.parentElement);}
	return obj.target;
}

function getHideTarget(obj){
	if(obj == null){return null;}
	if(obj.hidetarget ==null){return getHideTarget(obj.parentElement);}
	return obj.hidetarget;
}

function ShowPurchase(obj){
	if(obj.checked){
		oTarget = getTarget(obj);		
		document.all.item(oTarget).style.visibility='visible';
	}else{
		oTarget = getTarget(obj);
		document.all.item(oTarget).style.visibility='hidden';
	}
}

function LoadSymbol(symbol){
	if(window.dialogArguments !=null){
		window.dialogArguments.value=symbol;
	}
}
/*=================================
	Help F1 Functions
==================================*/
function Helper(message){
if(message==null){
	var needHelp = confirm('Click OK to view CubeTrader Pro\'s help file or Cancel to view your browsers helpfile.');
	if(needHelp){
		Help(message);
		return false;
	}else{
		return false;
	}
	}else{
	Help(message);
	}
}

function Help(message){
window.open(APPLOCATION+"/help/default.aspx?topic="+message,"cthelp","height=500,width=350,status=no,toolbar=no,menubar=no,location=no,resizeable=no,scrollbars=no");

}

function GoTo(topic,parameters){
	alert('Coming Soon');
}

function showCalender(obj){
window.showModalDialog(APPLOCATION+'/library/scripts/calender.htm',document.all.item(obj),'dialogHeight: 230px; dialogWidth: 180px; edge: Raised; center: Yes; help: No; resizable: no; status: no;');
}
function showImage(obj){
window.open(obj,"ctimages","height=300,width=560,status=no,toolbar=no,menubar=no,location=no,resizeable=yes,scrollbars=no");
}

function findSymbol(obj){
window.showModalDialog(APPLOCATION+'/Research/find.aspx?action=symbols',obj,'dialogHeight: 300px; dialogWidth: 500px; edge: Raised; center: Yes; help: Yes; resizable: no; status: no;');
}

function showSymbol(hrefl){
window.open(hrefl,"ctsymbol","height=300,width=600,status=no,toolbar=no,menubar=no,location=no,resizeable=yes,scrollbars=yes");
}

/*=================================
	Portfolio Functions
==================================*/
function AddTo(targetBox,val){
	oTarget = document.all.item(targetBox);
	if(oTarget==null){alert("An error has occured");return;}
	
	oItem = event.srcElement;
	if(oItem.checked==false){
		//Remove an item form the delete list
		if(oTarget.value != null && oTarget.value !=""){
		oTarget.value = oTarget.value.replace(';'+val+';','');
		}
	}else{
		//Adding Item to list
		oTarget.value = oTarget.value+ (';'+val+';');
	}
}

/*=================================
	Debugging Functions
==================================*/
function Debug(message){
	if(pdebug==true){
		alert(message);
	}
}

/*=================================
	Messaging Functions
==================================*/
var xmlDoc;
var lc=new Date();
var errors=false;
var IE5plus;

function GetMessages(){

	isMac = (navigator.appVersion.indexOf("Mac")!=-1) ? true : false;
	NS4 = (document.layers) ? true : false;
	IEmac = ((document.all)&&(isMac)) ? true : false;
	IE4plus = (document.all) ? true : false;
	IE4 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 4.")!=-1)) ? true : false;
	IE5 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 5.")!=-1)) ? true : false;
	IE6 = ((document.all)&&(navigator.appVersion.indexOf("MSIE 6.")!=-1)) ? true : false;
	ver4 = (NS4 || IE4plus) ? true : false;
	NS6 = (!document.layers) && (navigator.userAgent.indexOf('Netscape')!=-1)?true:false;

	IE5plus = IE5 || IE6;
	if(IE5plus){Notifications();}
}

function printer(){
	parent.contents.focus();
	window.print();
}

 function Notifications(){
	parent.status = "Checking Orders";	
	xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
	var xml = APPLOCATION+"/Messages/Notify.aspx?action=check&lastchecked="+lc.toLocaleDateString()+" "+lc.toLocaleTimeString();
	xmlDoc.async=true;	
    xmlDoc.onreadystatechange = NotificationReady;
	xmlDoc.load(xml);
}


function NotificationReady(){		
		if (xmlDoc.readyState==4 && errors==false){
			if(xmlDoc.documentElement.firstChild.firstChild.text!="0"){
				window.showModalDialog(APPLOCATION+'/Messages/Notify.aspx?action=display&lastchecked='+lc.toLocaleDateString()+' '+lc.toLocaleTimeString(),null,'dialogHeight: 200px; dialogWidth: 400px; edge: Raised; center: Yes; help: No; resizable: no; status: no;');
			}	
			setTimeout("Notifications()",60000);
			lc = new Date();
			parent.status = "Checking Orders Complete";	
		}
		setTimeout("parent.status = ''",2000)
}
