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 );
  }
}

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;
     }
}

ReadCookie();
checkPageRedirect();


