// lib.js -- library functions for www.marketbright.com


function drawWelcome()
{
  var Str = '<SPAN class="HelpTextG">welcome';
  
  if ( CookieValid && UserCookie[CookieUser_Id] != '1' )    
  {
    Str += ' <b>' + UserCookie[CookieName];
    Str += '</b>,<br></SPAN> <A class="HelpTextG" href="/services/web/Update_Users.Logout?Action=/index.html" class="HelpText">sign out</A>&nbsp;' +
           '|&nbsp;<A class="HelpTextG" href="/pages/account/edit.html" class="HelpText">my account</A>&nbsp;';
  }
  else
    Str += ',</SPAN> <A class="HelpTextG" href="/pages/account/login.html?Action=edit.html" class="HelpText">sign in</A>&nbsp;';
  
//  Str += '|&nbsp;<a class="HelpTextG" href="javascript:getHelp()" class="HelpText" onmouseover="window.status=\'Get Help for this Screen\'" onmouseout="window.status=\'\'" >help</A>&nbsp';

//  if ( CookieValid && UserCookie[CookieGroup_Id] != '1' )    
//  {
//    var URL = document.location.pathname;
//    if ( document.location.search ) URL += document.location.search;
//    URL = escape( URL.replace( /\/pages/, '' ) );
//    Str += '|&nbsp;<a class="HelpTextG" href="javascript:helpPopup(\'/pages/help/support.html?p_Type=Feedback&p_Title=Online%20Support&p_URL='+URL+'\');" class="HelpText" onmouseover="window.status=\'Get Online Support\'" onmouseout="window.status=\'\'">support</A>&nbsp';
//  }
  if ( CookieValid && UserCookie[CookieGroup_Id] == '0' && ( UserCookie[CookieEmail].indexOf( '@'+'marketbright.com' ) > -1 ) )
  {
    var thisPageDebug = window.location.href;
    if ( thisPageDebug.indexOf( 'Debug=Y' ) > -1 ) thisPageDebug = thisPageDebug.replace( /Debug\=Y/, 'Debug=N' );
    else if ( thisPageDebug.indexOf( '?' ) > -1 ) thisPageDebug += '&Debug=Y';
    else thisPageDebug += '?Debug=Y';
    Str += '|&nbsp;<A class="HelpTextG" href="'+thisPageDebug+'" class="HelpText">debug</A>&nbsp;';

//    var thisPageEdit = window.location.href;
//    if ( thisPageEdit.indexOf( 'Edit=Y' ) > -1 ) thisPageEdit = thisPageEdit.replace( /Edit\=Y/, 'Edit=N' );
//    else if ( thisPageEdit.indexOf( '?' ) > -1 ) thisPageEdit += '&Edit=Y'; 
//    else thisPageEdit += '?Edit=Y';
//    Str += '|<A class="HelpTextG" href="'+thisPageEdit+'" class="HelpText">edit</A>';
  }
  document.write( Str );
  document.close();
}


function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function checkNumeric(objName,minval, maxval,comma,period,hyphen)
{
	var numberfield = objName;
	if (chkNumeric(objName,minval,maxval,comma,period,hyphen) == false)
	{
		numberfield.select();
		numberfield.focus();
		return false;
	}
	else
	{
		return true;
	}
}


function ValidateFreeEmail()

{
	    var em = document.getElementById('Item_2').value;
            em = em.toLowerCase();

            var foundmatch = false;
            if(!foundmatch) foundmatch = em.match(/yahoo.com$/);
            if(!foundmatch) foundmatch = em.match(/msn.com$/);
            if(!foundmatch) foundmatch = em.match(/hotmail.com$/);
            if(!foundmatch) foundmatch = em.match(/gmail.com$/);
            if(!foundmatch) foundmatch = em.match(/roadrunner.com$/);
            if(!foundmatch) foundmatch = em.match(/aol.com$/);
            if(!foundmatch) foundmatch = em.match(/comcast.net$/);
            if(!foundmatch) foundmatch = em.match(/mail.com$/);
            if(!foundmatch) foundmatch = em.match(/inbox.com$/);
            if(!foundmatch) foundmatch = em.match(/fastmail.com$/);
            if (foundmatch){

     //frmvalidator.AppendError(errormessage);
     alert("You are using a free email account, please provide a work email address");
     document.getElementById('Item_2').value = "";
     return false;

     }

else

     {

     return true;

     }

}

var UserCookie = new Array(30);
var CookieValid = false;
var CookieUsername = 1, CookieUser_Id = 2, CookieGroup_Id = 3, CookieContact_Id = 4, 
    CookieName = 5, CookieEmail = 6, CookiePrefs = 7, CookiePrivs = 8;

function getCookie( name )
{
  var arg = name + '=';
  if ( document.cookie && document.cookie.length != 0 )
  {
  	var cstart = document.cookie.indexOf( arg );
    if ( cstart == -1 )
      return null;
    else
    {
      var tmpStr = document.cookie.substring( cstart, ( document.cookie.length + 1 ) );
    	var cend = tmpStr.indexOf( ';' );
      if ( cend == -1 ) cend = tmpStr.length + 1;
	  	tmpStr = unescape( tmpStr.substring( arg.length, cend ) );
      return tmpStr;
    }
  }
  else
    return null;
}

function ReadCookie()
{
	CookieValid = false;
  var j=1, i=0;
  var str = getCookie( 'Marketbright_Cookie' );
  
	if ( str == null || str == "" ) return false;
  
	if ( str.indexOf( "/" ) != -1 )
  {
		while ( str.substring( i, str.length ).indexOf( "/" ) != -1 && j < 50 )
    {
      cStr = "";
      for ( var i; str.substring( i, i + 1 ) != "/"; i++ ) cStr += str.charAt(i);
      i++;
      UserCookie[j] = cStr;
      j++
		}
	}
 	UserCookie[j] = str.substring( i, str.length );
 	UserCookie[0] = j-1;
	CookieValid = true;

  return true;
}

function checkPageRedirect()
{
  if ( document.location.protocol == 'http:' && document.location.pathname.indexOf( '/' + 'pages/' ) == -1 )
  {
    var URL = document.location.protocol + '//' + document.location.hostname;
    if ( document.location.port ) URL += ':' + document.location.port;
    URL += '/' + 'pages';
    if ( document.location.pathname.substring( 0, 1 ) != '/' ) URL += '/';
    URL += document.location.pathname;
    if ( document.location.search ) URL += document.location.search;
    if ( document.location.hash ) URL += document.location.hash;
    document.location.replace( URL );
  }
}




