function submitWebSiteSearch()
{
 if (trim(document.search.q.value) == 'Type Website Search Text')
 {
     document.search.q.value = "";
 }
 document.search.submit();
}

/* Open a new window */
function NewWindow(mypage, myname, w, h, pos, infocus)
{
         var win = null;
         if (pos == "random") {
             myleft = (screen.width) ? Math.floor(Math.random() * (screen.width-w)):100;
             mytop = (screen.height) ? Math.floor(Math.random() * ((screen.height-h)-75)):100;
         }
         if (pos == "center") {
             myleft = (screen.width) ? (screen.width-w) / 2:100;
             mytop = (screen.height) ? (screen.height-h) / 2:100;
         } else if ((pos !='center' && pos != "random") || pos == null) {
           myleft = 0; mytop = 20
         }
         settings = "width=" + w + ", height=" + h + ",top=" + mytop + ",left=" + myleft + ", scrollbars=yes, location=no, directories=no, status=no, menubar=no, toolbar=no, resizable=yes";
         win = window.open(mypage, myname, settings);
         win.focus();
}

function NewWindowOptions(mypage, myname, w, h, pos, infocus, scroll, resize)
{
         var win = null;
         if (pos == "random") {
             myleft = (screen.width) ? Math.floor(Math.random() * (screen.width-w)):100;
             mytop = (screen.height) ? Math.floor(Math.random() * ((screen.height-h)-75)):100;
         }
         if (pos == "center") {
             myleft = (screen.width) ? (screen.width-w) / 2:100;
             mytop = (screen.height) ? (screen.height-h) / 2:100;
         } else if ((pos !='center' && pos != "random") || pos == null) {
           myleft = 0; mytop = 20
         }
         settings = "width=" + w + ", height=" + h + ",top=" + mytop + ",left=" + myleft + ", scrollbars= "+scroll+", location=no, directories=no, status=no, menubar=no, toolbar=no, resizable="+resize;
         win = window.open(mypage, myname, settings);
         win.focus();
}

function openNewWindow(theURL,winName,features) //v2.0
{
  window.open(theURL,winName,features);
}

function getPrintPDFURL()
{
         return 'http://206.106.137.34/MktServices/servlet/CreatePdf?f=';
}

function getPrintPDFLink(uri, date)
{
         window.location.href = getPrintPDFURL()+escape(uri)+'&lm='+date;
}

function trim(string)
{
         return(string.replace(/^\s+|\s+$/g,''));
}

function validName(name)
{
         ok = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM' ";
         for(i=0;i < name.length; i++)
         {
             if(ok.indexOf(name.charAt(i)) < 0)
             {
                return false;
             }
          }
          return true;
}

function validEmail(email)
{
         if(email.length < 7)
         {
            return false;
         }
         else
         {
            ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
            for(i=0;i < email.length; i++)
            {
                if(ok.indexOf(email.charAt(i)) < 0)
                {
                   return false;
                }
            }
        }
        return true;
}

function validURL(url)
{
         if(url.length < 9)
         {
            return false;
         }
         else
         {
            ok = "1234567890qwertyuiopasdfghjklzxcvbnm.-_QWERTYUIOPASDFGHJKLZXCVBNM/~";
            for(i=0;i < url.length; i++)
            {
                if(ok.indexOf(url.charAt(i)) < 0)
                   return false;
                }
          }
          return true;
}

function stringContainsDigits(str, min)
{
         var ok = "1234567890";
         var c = 0;
             for(i=0;i < str.length; i++)
             {
                if(ok.indexOf(str.charAt(i)) != -1)
                {
                   c ++;
                }
             }

          if (c > min)
          {
                return true;
          }
          return false;
}

function isRadioSelected(r)
{
   for(i=0; i<r.length; i ++)
   {
       if (r[i].checked)
       {
           return true;
       }
   }
   return false;
}

function eMailCheck(str) {

		var at="@";
		var dot=".";
		var lat=str.indexOf(at);
		var lstr=str.length;
		var ldot=str.indexOf(dot);
		if (str.indexOf(at)==-1){
		   return false;
		}

		if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
		   return false;
		}

		if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		    return false;
		}

		if (str.indexOf(at,(lat+1))!=-1){
		    return false;
		}

		if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		   return false;
		}

		if (str.indexOf(dot,(lat+2))==-1){
		   return false;
		}
		
		if (str.indexOf(" ")!=-1){
		    return false;
		}

 		 return true;				
}

function cookieIsEnabled(name, value, days)
{
         setCookie(name, value, days);
         if (document.cookie.indexOf(name) != -1)
         {
             setCookie(name, value, 0);
             return true;
         }
         return false;
}

function setCookie(name, value, days, domain)
{
      var v = name + "=" + value;
      if (days){
          var exp = new Date();
          exp.setTime(exp.getTime() + (3600000*24*days));
          v += ";expires="+exp.toGMTString();
      }
      v += ";path=/";
      if (domain){ v += ";domain="+domain; }
      else { v += ";domain=.interactivebrokers.com"; }

      document.cookie = v;
}

function hasCookie(name, value)
{
         if (value == getCookie(name))
         {
             return true;
         }
         return false;
}

function deleteCookie(name)
{
         setCookie(name,"1",0);
}

function getCookie(name) {
         var dc = document.cookie;
         var prefix = name + "=";
         var begin = dc.indexOf("; " + prefix);

         if (begin == -1) {
             begin = dc.indexOf(prefix);
             if (begin != 0) return null;
         } else
             begin += 2;
             var end = document.cookie.indexOf(";", begin);

         if (end == -1)
             end = dc.length;
             return unescape(dc.substring(begin + prefix.length, end)); 
}

function addSiteLocationCookie(name, value, days)
{
         if (hasCookie(name, value))
         {
             alert("You have already set this site as your default IB site.");
         }
         else {
             if (cookieIsEnabled('t',1,1))
             {
                 setCookie(name, value, days);
                 if (document.cookie.indexOf(name) != -1)
                 {
                     alert("You have set this site as your default IB site.");
                 }
             }
             else {
                 alert("Please enable cookies to set your default IB site.");
             }
         }
}

function getEventXYCoordinates(e)
{
         if (isie){ e = event; }
         if (navigator.appName == "Microsoft Internet Explorer") {
             y = (e.clientY + document.body.scrollTop);
             x = e.clientX;
         }
         else {
              y = e.pageY;
              x = e.pageX;
         }
         return new Array(parseInt(x), parseInt(y));
}

function showExpandContract(div)
{
         var c = div.childNodes;
         if (c.item(1).firstChild.nodeValue == ' Expand')
         {
             c.item(1).firstChild.nodeValue = ' Contract';
             c.item(0).src = 'http://www.interactivebrokers.com/images/common/minus_symbol.gif';
             c.item(2).style.display = 'block';
         }
         else {
             c.item(1).firstChild.nodeValue = ' Expand';
             c.item(0).src = 'http://www.interactivebrokers.com/images/common/plus_symbol.gif';
             c.item(2).style.display = 'none';
         }
}

/* Dropdown for Open account - replaces dropdown.js */
sfHover = function() {
	if (document.getElementById("navigation"))
        {
        var sfEls = document.getElementById("navigation").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" over";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" over\\b"), "");
		}
	}
        }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);