// cookies.js
// Derived from the Bill Dortch code at http://www.hidaho.com/cookies/cookie.txt

var today = new Date();
var expiry = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000);
var expiry60 = new Date(today.getTime() + 60 * 24 * 60 * 60 * 1000);
var expiry1 = new Date(today.getTime() + 1 * 24 * 60 * 60 * 1000);
var expiry2 = new Date(today.getTime() + 2 * 24 * 60 * 60 * 1000);

var expdate = new Date();
expdate.setTime(expdate.getTime() + (30 * 24 * 60 * 60 * 1000));
var dslAddr = "http://dslhelp.att.net/iw/dsl/homePage.jsp";
var dialAddr = "http://help.att.net/iw/ci/homePage.jsp";

function getCookieVal (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 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) {
			return getCookieVal (j);
			}
		i = document.cookie.indexOf(" ", i) + 1;
		if (i == 0) break; 
		}
	return null;
	}

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

function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
	}

// modify cookie to dial page from dsl homepage cross over link 

function doSelect(form) {

	var msg1 = "\n You do not currently have a default service selected." + "\n\n\n Remember AT&T Worldnet Dial-up" + "\n service as your default?";

	var msg2 = "\n To make AT&T Worldnet dial-up your default service, select OK." + "\n\n\n To keep AT&T DSL Internet as your default service, select Cancel.";

	if((GetCookie('service') != null) && (GetCookie('service') == 'dsl')) {
		if(!confirm(msg2)) {
			window.location = dialAddr;
		}
		else {
			SetCookie('service', 'dial', expdate, "/", ".att.net");	

			window.location = dialAddr;
		}
	}
	else if((GetCookie('service') == null) || (GetCookie('service') == '')) {
		if(!confirm(msg1)) {
			window.location = dialAddr;
		}
		else {
			SetCookie('service', 'dial', expdate, "/", ".att.net");
			window.location = dialAddr;
		}
	}
	else {
		window.location = dialAddr;
	}
}

// modify cookie to dsl from dial homepage cross over link

function doDSLSelect(form) {
	var msg1 = "\n You do not currently have a default service selected." + "\n\n\n Remember AT&T DSL service as your default?";

	var msg2 = "\n To make AT&T DSL your default service, select OK." + "\n\n\n To keep AT&T Worldnet Dial-up as your default service, select Cancel.";

	if((GetCookie('service') != null) && (GetCookie('service') == 'dial')) {

		if (!confirm(msg2)) {
			window.location = dslAddr;
		}
		else { 
			SetCookie('service', 'dsl', expdate, "/", ".att.net");
			window.location = dslAddr;
		}
	}
	else if((GetCookie('service') == null) || (GetCookie('service') == '')) {
		if(!confirm(msg1)) {
			window.location = dslAddr;
		}
		else {
			SetCookie('service', 'dsl', expdate, "/", ".att.net");
			window.location = dslAddr;
		}
	}
	else {
		window.location=dslAddr;
	}
}

// the following functions are used by page level redirects
// the dslAddress and dialAddress variables are defined in each HTML file - PJM
	
function page_redirect() {
    var cookieStr = GetCookie('service');
    if(cookieStr == "dial") {
        window.location = dialAddress;
    }
    else if(cookieStr == "dsl") {
        window.location = dslAddress;
    }
    return true;
} 

function set_dial() {
    var expdate = new Date();
expdate.setTime(expdate.getTime() + (180 * 24 * 60 * 60 * 1000)); // 6 months from now
    SetCookie('service', 'dial', expdate, "/", "att.net"); 
window.location = dialAddress;
}
function set_dsl() {
    var expdate = new Date();
expdate.setTime(expdate.getTime() + (180 * 24 * 60 * 60 * 1000)); // 6 months from now
    SetCookie('service', 'dsl', expdate, "/", "att.net"); 
window.location = dslAddress;
}
