function isCookieEnabled() {    
	var status = false;
      var brwsrVer = navigator.appVersion;
	  var arr1 = brwsrVer.split(" ");
	  var brversion = parseFloat(arr1[3]);
   if (navigator.appName == "Microsoft Internet Explorer") {   
      
      if (brversion >= 4.0 ) { 
         this.cookieEnabled = window.navigator.cookieEnabled;  
       
         if (this.cookieEnabled) {
           //alert ("cookie enabled");
           status = true;
         } else {
            status = false;
           //alert ("cookie disbaled");
         } 
      } else {
        if (cookieCheck()) {
          status=true;
        } else {
         status=false;
        }
      }
  } else {
    if (navigator.appName == "Netscape") {
      if (cookieCheck()) {
          status=true;
      } else {
         status=false;
      }
    }    
  }
 return status;
}

function setCookie(name, value, expirytime) {  
    var cookieDate = new Date();
    if (expirytime == "never") {
	  expirytime = 1000;
    } else {
	  expirytime = 60 * expirytime;
    }

    cookieDate.setTime (cookieDate.getTime() + (1000 * 60 * expirytime));

	testcookie = name + "=" + escape(value);

	if (expirytime != 0) { 
    	testcookie += "; expires=" + cookieDate.toGMTString();
	}

    testcookie += "; path=/;";

    testcookie += "; domain=.branders.com;";

	document.cookie = testcookie;

}

function deleteCookie(name,path,domain) {
    if (getCookie(name)) document.cookie = name + "=" +
        ( (path) ? ";path=" + path : "") +
        ( (domain) ? ";domain=" + domain : "") +
        ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

function getCookieValue (offset) {

	var endstr = document.cookie.indexOf (";", offset);
	
	if (endstr == -1) {
		endstr = document.cookie.length;
	}
	return unescape(document.cookie.substring(offset, endstr));
}


function getCookie(name) {
    var status = false;
	var arg = name + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while (i < clen) {
		var j = i + alen;
		if (document.cookie.substring(i, j) == arg)
		
		var cookievalue = getCookieValue (j);
		
		if (cookievalue !="") {
         status = true;
		} else {
		 status = false;
		}
				
		i = document.cookie.indexOf(" ", i) + 1;
		
		if (i == 0) {
		  break; 
	    }
	}
   	return status;
}

function cookieCheck()
{
  var status=false;
  if (document.cookie == "CookiesEnabled")
  {
  }
  
  setCookie('CookiesEnabled','yes',2); 
  if (getCookie('CookiesEnabled')) {
     status = true;
  } else {
    status=false;
  }
  return status;
}

function setClientCookie(name, value, expires, path, domain, secure) {
  var curCookie = name + "=" + escape(value) +
      ((expires) ? "; expires=" + expires.toGMTString() : "") +
      ((path) ? "; path=" + path : "") +
      ((domain) ? "; domain=" + domain : "") +
      ((secure) ? "; secure" : "");
  document.cookie = curCookie;
}
function getCookie2(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 setBrandersPageCookie() {
	if (isCookieEnabled()) {
		setCookie("brandersPage","true",0);
	}
}

function deleteBrandersPageCookieandLaunchPopup() {
	if (isCookieEnabled()) {
	        //alert('deleting cookie');
		setCookie('brandersPage',"false",0);
		//alert(navigator.appName);
		if (navigator.appName == "Netscape") {
	            //var hBaby = window.open ( "/promo/lastchance_test.jsp", "babyWindow", "innerWidth=101,innerHeight=101,top=3000,left=3000" );
	            //var hBaby = window.open ( "/promo/lastchance_test.jsp", "babyWindow", "innerWidth=101,innerHeight=101,top=3000,left=3000" );
	           realTestforBrandersPage();
	            
		} else {
		
		}
	}
}

function testBrandersPageandFocusPopup() {
	if (isCookieEnabled()) {
		setTimeout('realTestforBrandersPage()',4000);
	}
}
/*added this function to fix bug 15203*/

var screenwidth = screen.width;
var screenheight = screen.height;

function NewWindow(mypage,myname,w,h,scroll){
var win= null;
var winl = ((screenwidth>0?screenwidth:1024)-w)/2;
var wint = ((screenheight>0?screenheight:768)-h)/2;
var settings ='height='+h+',';
settings +='width='+w+',';
settings +='top='+wint+',';
settings +='left='+winl+',';
settings +='scrollbars='+scroll+',';
settings +='resizable=yes';
win=window.open(mypage,myname,settings);
if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}

function realTestforBrandersPage() {
	if (isCookieEnabled()) {
		brandersPage = getCookie2('brandersPage');
		//alert('cookie value is ' + brandersPage);
		if (brandersPage == 'false') {
			// want to set the cookie for newWindow seen
			setCookie("newWindow","true","never");
			// want to focus and reposition
			//alert('about to move and focus');
			
			/*added by mwong Jan 17, 2006 for bug 12537*/
			lastPopup=checkCookie('lastPopup');
			//alert('lastpopup ');
			if(lastPopup!=null){
					if(lastPopup=="lastChancePopup"){
						var hNewBabyWindow = NewWindow( "/promo/last_chance_reg_form.jsp", "hNewBabyWindow", '290','530','no');
						setCookie("lastPopup", "surveyInvitationPopup", "never");
					}
					if(lastPopup=="emailPopup"){
					    var hNewBabyWindow = NewWindow( "/promo/lastchance.jsp", "hNewBabyWindow", '407','207','no');
						setCookie("lastPopup", "emailPopup", "never");
					}
					if(lastPopup=="surveyInvitationPopup"){
						 var hNewBabyWindow = NewWindow( "/promo/last_chance_email_pop.jsp", "hNewBabyWindow", '4500','200','no');
						setCookie("lastPopup", "lastChancePopup", "never");			
					}
		    } else {
			var hNewBabyWindow = NewWindow( "/promo/lastchance.jsp", "hNewBabyWindow", '407','207','no');
			setCookie("lastPopup", "lastChancePopup", "never");
		    }
		    //}
		    /*end added by mwong*/
			
		    hNewBabyWindow.focus();
	            this.window.close();
		} else {
			this.window.close();
		}
	}

}



//added by mwong Jan 17, 2006 for bug 12537
//checks if a cookie is stored at all the document.cookie
//object, if yes return, else return null
function checkCookie(c_name)
{
//alert(c_name);
if (document.cookie.length>0)
//alert('cookie');
  {
  c_start=document.cookie.indexOf(c_name + "=");
  //alert(c_start);
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
  return null
}
//end added by mwong

