var f = '';
var imgL = 'http://images.barchart.com/equities';
var mainSrv = 'http://www2.barchart.com';
var browser = navigator.appName; var version=parseInt(navigator.appVersion);
defaultStatus = 'Barchart.com - Equities Service';

var w = screen.width;
if (w > 800) { f = 'large'; }

var cookieSet = new String(document.cookie);
var cookiePairs = cookieSet.split(';');
var bot, msie;
msie = 0;

if (browser == 'Microsoft Internet Explorer') {
	msie=1; document.write('<link href="'+imgL+'/bcs.css" rel="stylesheet" type="text/css">');
}
else {
	if(version >= 5) {
		document.write('<link rel="stylesheet" href="' + imgL + '/f2.css" type="text/css">\n');
		document.write('<link rel="stylesheet" href="' + imgL + '/bcs.css" type="text/css">');
	}
	else {
		document.write('<link rel="stylesheet" href="' + imgL + '/f2.css" type="text/css">\n');
		document.write('<link rel="stylesheet" href="' + imgL + '/bcs1.css" type="text/css">');
	}
}

function openWin(w) { window.open(w,'_blank','scrollbars,resizable,toolbar,menubar,location,status,width=785,height=430,left=5,top=0'); }

function openWin2(w) { window.open(w,'_blank','scrollbars,resizable,width=450,height=450,left=5,top=0'); }

function openSupport() { document.location = mainSrv+'/support/'; }

function OpenFlipbook(u,p) {
	if(u == 1) { if(msie == 1) { var w='635'; var h='440'; } else { var w='635'; var h='449'; } }
	else if (u == 0) { if(msie == 1) { var w='635'; var h='500'; } else { var w='635'; var h='540'; } }
	window.open(p,'_nova','width='+w+',height='+h+',left=25,top=10');
}

function OpenTextFile(p) { window.open(p,'_New','scrollbars,resizable,toolbar,menubar,location,status,width=800,height=450,left=25,top=10'); }

function MM_displayStatusMsg(msgStr) { status = msgStr; document.MM_returnValue=true; }

function verifyDate(f) {
	var date=new String(f.date.value);
	if(date.length != 8) { alert('Please enter date in the following format: mm/dd/yy; where mm = month of the year; dd = day of the month; yy = year code. For example July 31st, 2002 will be represented as: 07/31/02.'); f.date.focus(); f.date.select(); return false; }
	else {
		var pairs = date.split('/'); var count = 0;
		for(var k = 0; k <= pairs.length - 1; k++) {
			var n1 = new String(pairs[k].substring(0,1)); var n2 = new String(pairs[k].substring(1,2));
			if((n1.search(/[0-9]/) != -1) && (n2.search(/[0-9]/) != -1)) { count++; }
			else { alert('Please enter date in the following format: dd/mm/yy; where dd = day of the month; mm = month of the year; yy = year code. For example December 15, 2002 will be represented as: 15/12/02.'); f.date.focus(); f.date.select(); return false; }
		}
		if(count == 3) { return true; }
		else { alert('Please enter date in the following format: dd/mm/yy; where dd = day of the month; mm = month of the year; yy = year code. For example December 15, 2002 will be represented as: 15/12/02.'); f.date.focus(); f.date.select(); return false; }
	}
}

function setFonts(title, reset) {
	if(msie == 1) {
		var i, a, main;
		for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
			if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
				a.disabled = true;
				if(a.getAttribute("title") == title) a.disabled = false;
			}
		}
		if (reset == 1) setCookie("style", title);
	}
}

function setStyle() { var style=readCookie("style"); setFonts(style, 1); }

function setCookie(key,val) { document.cookie=key+"="+val+";domain=.barchart.com;path=/;expires=Thu, 01-Jan-09 00:00:01 GMT;"; }

function readCookie(key) {
	var cookieArray = document.cookie.split(';');
	for(var i = 0; i < cookieArray.length; i++) {
		if(document.cookie.length != 0) {
			var cookieVals = cookiePairs[i].split('=');
			cookieVals[0] = cookieVals[0].replace(/\s/gi,"");
			if(cookieVals[0] == key) return cookieVals[1];
		}
	}
	return 'Large Text';
}

function setUser(k) { document.cookie="user="+k+";domain=.barchart.com;path=/;"; }

function getCurrentPage() {
  var p = document.location.pathname.lastIndexOf('/');
  if (p < 0) p = 0;
  return document.location.pathname.substring(p + 1);
}

function setQuickForm(f) {
  var fl = getCurrentPage();
  if((fl == 'quote.asp') || (fl == 'texpert.asp') || (fl == 'techrept.asp') || (fl == 'texsnap.asp') || (fl == 'texadv.asp') || (fl == 'performance.asp'))
    f.action = 'http://quotes.barchart.com/' + fl;
  else if ((fl == 'chart.asp') || (fl == 'profile.asp') || (fl == 'news.asp') || (fl == 'prhistory.asp') || (fl == 'prdetails.asp'))
    f.action = 'http://www2.barchart.com/' + fl;
  else if (fl == 'procal.asp')
    f.action = 'http://charts3.barchart.com/' + fl;
  return true;
}

function openMulti(u,k) {
  var f = document.createElement('FORM');
  document.body.appendChild(f);
  f.name = 'sranje';
  f.method = 'get';
  f.target = k;
  f.action = u;

//  try {
//    f.submit();
//  }
//  catch (e) {
//    alert(e.name + " - " + e.message);
//  }
//  window.open(u, k, 'scrollbars,resizable,screenX=100,screenY=200,top=25,left=25');
}

