////////////////////////////////////////////////////////////////////////////////////
//  @author	$Author: jxie $
//  @version	$Revision: 1.11 $
//  $Log: ClientCommon.js,v $
//  Revision 1.11  2009/06/16 15:15:03  jxie
//  DR3090 - Symbol field on Quick Quote and Quotes+ does not accept numbers for Indices, but some Index symbols have numbers
//
//  Revision 1.10  2009/05/14 14:37:26  jxie
//  DR3076 - Add scrollbar to streamer popup message
//
////////////////////////////////////////////////////////////////////////////////////

function openWindow(url, urlType, height, width) {
//		top.name = "mainWindow";
		switch (urlType){
			case "tango" :
				var popupurl = url ;
				var controls = "toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=no,copyhistory=no,height=" + height + ",width=" + width;
				var winname  = 'popup_t';
				break;
			case "help" :
				var popupurl = url ;
				var controls = "toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,height=" + height + ",width=" + width;
				var winname  = 'popup_help';
				break;
			case "qquote" :
				var popupurl = url ;
				var controls = "toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,height=" + height + ",width=" + width;
				var winname  = 'popup_qquote';
				break;
			case "fixed" :
				var popupurl = url ;
				var controls = "toolbar=no,location=no,directories=no,status=no,scrollbars=no,resizable=no,copyhistory=no,height=" + height + ",width=" + width;
				var winname  = 'popup_fixed';
				break;
			case "link" :
				var popupurl = url ;
				var controls = "menubar=yes,toolbar=yes,location=yes,directories=yes,status=yes,scrollbars=yes,resizable=yes,copyhistory=no,height=" + height + ",width=" + width;
				break;
			case "infowin" :
				var popupurl = url ;
				var controls = "menubar=no,toolbar=yes,location=no,directories=yes,status=yes,scrollbars=yes,resizable=yes,copyhistory=no,height=" + height + ",width=" + width;
				var winname  = 'popup_info';
				break;
			case "retire" :
				var popupurl = url ;
				var controls = "menubar=yes,toolbar=yes,location=no,directories=yes,status=yes,scrollbars=yes,resizable=yes,copyhistory=no,height=" + height + ",width=" + width;
				var winname  = 'popup_retire';
				break;
			case "streaming" :
				var popupurl = url ;
				var controls = "toolbar=no,location=no,directories=no,status=no,scrollbars=yes,resizable=yes,copyhistory=no,height=" + height + ",width=" + width;
				var winname  = 'popup_streaming';
				break;
			default :
				var popupurl = url ;
				var controls = "alwaysLowered=0,alwaysRaised=0,channelmode=0,dependent=0,directories=1,fullscreen=0,hotkeys=1,location=1,menubar=1,resizable=1,scrollbars=1,status=1,titlebar=1,toolbar=1,z-lock=0,height=" + height + ",width=" + width;
				var winname  = 'popup';
				break;
		}
		if (urlType == 'link') {
			var theUrl = '';
			for (count = 0; count < url.length; count++) {
				if ((url.charCodeAt(count) >= '97') && (url.charCodeAt(count) <= '122')) {
					theUrl += url.substr(count,1);
					}
				}
			popup = window.open(popupurl,theUrl,controls);  //always opens new window
			}
		else {
			popup = window.open(popupurl,winname,controls);  //opens link in same window based on type of link
			}
		if (navigator.appVersion.substring(0,1) != '2')	popup.focus();
	}

var exchanges = new Array();

function makeExchange(code, description) {
	this.code = code;
	this.description = description;
}

function writeExchanges(currentExchange) {
	returnValue = '';
	for(i=0;i<exchanges.length;i++) {
		if((currentExchange)&&(currentExchange==exchanges[i].code)) selected = ' selected';
		else selected = '';
		returnValue +="<option value='"+exchanges[i].code+"'"+selected+">"+exchanges[i].description;
	}
	return returnValue;
}
exchanges[0] = new makeExchange('C', 'Canadian');
exchanges[1] = new makeExchange('U', 'US');
exchanges[2] = new makeExchange('', '- Exchanges -');
exchanges[3] = new makeExchange('T', 'Toronto');
exchanges[4] = new makeExchange('V', 'TSX Venture');
exchanges[5] = new makeExchange('N', 'New York');
exchanges[6] = new makeExchange('A', 'AMEX');
exchanges[7] = new makeExchange('Q', 'NASDAQ');
exchanges[8] = new makeExchange('X', 'Other US Stocks');

function checkSymbol(theSymbol) {
	for (i = 0; i < theSymbol.length; i++) {
		s = theSymbol.charCodeAt(i);
		if (((s >= 65) && (s <= 90)) || (s == 44) ||  (s == 46) || ((s >= 97) && (s <= 122)) || ((s>=48) && ( s<=57)) ) var isValid = true;
		else {
			var isValid = false;
			break;
			}
		}
	if(theSymbol.length==0) isValid = false;
	return isValid;
	}
	
function trim(str)
{
   return str.replace(/^\s*|\s*$/g,"");
}


// Return data for a particular cookie
function getCookieData(cookieName) {
    var         cookies = document.cookie.split(";");
    var         value = null;
          
    for (i = 0; i < cookies.length; i++) {
        var singleCookie = cookies[i].split("=");
        if (trim(singleCookie[0]) == trim(cookieName)) {
            if (singleCookie.length == 1)
                value = null;
            else
                value = trim(singleCookie[1]);
        } 
    }
    
    return value;
}