//PI preload images
//SI swap images

//doesn't care how many arguments you pass
// set .src path of url up to image name
function PI(){var d=document;if(d.images){if(!d.MM_p)d.MM_p=new Array();var i,j=d.MM_p.length,a=PI.arguments;for(i=0;i<a.length;i++)if(a[i].indexOf("#")!=0){d.MM_p[j]=new Image;d.MM_p[j++].src="images/"+a[i];}}}
function SI(i,s){eval("document."+i+".src='images/"+s+"';");}

function PI_sub(){var d=document;if(d.images){if(!d.MM_p)d.MM_p=new Array();var i,j=d.MM_p.length,a=PI_sub.arguments;for(i=0;i<a.length;i++)if(a[i].indexOf("#")!=0){d.MM_p[j]=new Image;d.MM_p[j++].src="http://promo.sbcglobal.net/sbcyahoodsl/images/"+a[i];}}}

function SI_sub(i,s){eval("document."+i+".src='http://promo.sbcglobal.net/sbcyahoodsl/images/"+s+"';");}

function flipper(loc, img)
{
   document.images[loc].src=t_images[img].src;
}

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_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_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 openBrWindowPrize(theURL,winName) {
//  var popup = window.open(theURL,winName,'width=510,height=450');
//  popup.focus();
//  old values: width=754,height=452
//  new values: width=848,height=561
//}

function openBrWindowTour(theURL,winName) {
  var popup = window.open(theURL,winName,'width=864,height=614');
  popup.focus();
}

function refreshWindow() {
  var popup2 = window.location.reload();
}

/* Old Choose Your Region Code
   Removed 021011
   
   
var cookieName = "localRegion";
var region,selectedRegion,radio_selection;
var expdate = new Date ();

expdate.setTime (expdate.getTime() + (8 * 12 * 30 * 24 * 60 * 60 * 1000)); // 8 years from now 

// FUNCTION INSTRUCTIONS
// "Internal" function to return the decoded value of a cookie
//
function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  
  return unescape(document.cookie.substring(offset, endstr));
}

// getRegion Function Description written by SK
// get local-region from cookie or set trigger for redirect to user query(manual select)
// executed after page loads
// Details: DO NOT FOLLOW THESE DETAILS, I CHANGED THE FUNCTION I REPEAT! FUNCTION HAS CHNAGED 
// 	check for page cookie: return var = index DO NOT FOLLOW THESE DETAILS, I CHANGED THE FUNCTION I REPEAT! FUNCTION HAS CHNAGED
// 	  true - return start location #DO NOT FOLLOW THESE DETAILS, I CHANGED THE FUNCTION I REPEAT! FUNCTION HAS CHNAGED
//    false - return -1 to trigger CYR pageDO NOT FOLLOW THESE DETAILS, I CHANGED THE FUNCTION I REPEAT! FUNCTION HAS CHNAGED
// 	  if local-region cookie already there: return var = region to be used in path of linkDO NOT FOLLOW THESE DETAILS, I CHANGED THE FUNCTION I REPEAT! FUNCTION HAS CHNAGED
//	  false - set region to none, will trigger redirect to manual user input page (CYR)DO NOT FOLLOW THESE DETAILS, I CHANGED THE FUNCTION I REPEAT! FUNCTION HAS CHNAGED
//	  true - return user region, stored in cookieDO NOT FOLLOW THESE DETAILS, I CHANGED THE FUNCTION I REPEAT! FUNCTION HAS CHNAGED
//		DO NOT FOLLOW THESE DETAILS, I CHANGED THE FUNCTION I REPEAT! FUNCTION HAS CHNAGED
function getRegion() {
	region = GetCookie(cookieName);
	if (region == null) {
		region = "none";
	} else {
		return region;
	}
}

// Author: Sebastian Kulma e-mail: skulma@corp.prodigy.com 
//  Function to return url path for clicked link button
//	Executed when user clicks on "questions?" or "new benefits" while passing filename (no extention) of destination
//	  Details: check conditions then return fullpath based on passed string: returns string
//	  faq or   
//	  benefits	  - check region validity and redirect
// 	  void pass   - display appology and reload page
//	  region	  - if condition is false, display redirect to manual input page and redirect
//				  - if true, merge strings and redirect to requested page
//	  goHere	  - identifies what page did the call come from, determines what page to go to when all done
// 			
function goRegion(goHere) {
	if (goHere == "faq") {
		// define domain, myclicks etc for faq
		urlDomain = "http://promo.sbcglobal.net/sbcyahoodsl/"; // must end with /
	} else if (goHere == "benefits") {
		// define domain, myclicks etc for benefits
		urlDomain = "http://promo.sbcglobal.net/sbcyahoodsl/"; // must end with /
	} else {		// no page name was passed to function, show alert and reload page
		if (!confirm("This page has encountered an unexpected error.\nClick OK to try again, the page will reload.\nIf this message returns click Cancel and contact us for assistance.\n\nTry again?")) {
			history.back();
			window.blur();
		} else {
			window.location.reload(); // reload page to attempt repair of missing definitions
		}
	}
	localCookieCheck = GetCookie(cookieName);
	if (!localCookieCheck) {
		if (region == "ait" | region == "pbnb" | region == "prodigy" | region == "snet" | region == "swbell") {
			urlDir = region + "/";
			urlFile = goHere + ".html";
			redirURL = urlDomain + urlDir + goHere + ".html";
			self.location.href = redirURL;
		} else {
			//alert("We could not determine what region your account belongs to.\n\nYou will be redirected to a page where you can manually select your region.\n\nClick OK to continue."); // part of testing - okay to remove
			window.location.replace(urlDomain + "cyr_" + goHere + ".html");
		}
	} else {
		region_LC = GetCookie(cookieName);
		if (region_LC == "ait" | region_LC == "pbnb" | region_LC == "prodigy" | region_LC == "snet" | region_LC == "swbell") {
			urlDir = region_LC + "/";
			urlFile = goHere + ".html";
			redirURL = urlDomain + urlDir + goHere + ".html";
			self.location.href = redirURL;
		} else {
			window.location.replace(urlDomain + "cyr_" + goHere + ".html");
		}
	}
}

// Author: Sebastian Kulma e-mail: skulma@corp.prodigy.com 
//  Function to write cookie based on user's choice.
//  Executed when user submits form in cyr_benefits.html or cyr_faq.html
// 	  Details: check if radio button has been selected write cookie, and finally redirect based on checked choice
//	  false 	  -	display error msg asking user to choose their region
//	  true		  - write cookie with new region value
//			   		  redirect to regional faq or benefits page based on passed value into function
function setRegion(goingHere, selectedRegion) {
	if (selectedRegion) {
		SetCookie (cookieName, selectedRegion, expdate,"/");
		urlDomain = "http://promo.sbcglobal.net/sbcyahoodsl/"; // no need to add myclicks again, already executed once when clicked on generic page, leaving option here, in case need to swap places, since it would be more accurate to track clicks from here, talk to me if you need clarification
		self.location.href = urlDomain + selectedRegion + "/" + goingHere + ".html"; // redirect to final destination, YEY! THE END, FIN, KONIEC, ENDE, FINITO
	} else {
		// make sure to modify the following alert message:
		alert("To get region specific information, please select the domain name of your Internet service provider.\n\nClick OK to try again.");
		// window.location.reload(); // reset page in case user did select and unknown error occured - okay to remove
	}
}

//  Function to write cookie when user hit benefits.html page or faq.html page.
//  Put there to catch users coming in straight from the email
// 	Just a quick-fix rework of the above SetRegion function
function setRegionDirect(selectedRegion) {
	if (selectedRegion) {
		SetCookie (cookieName, selectedRegion, expdate,"/");
	} else {
		alert("Error.  Press 'OK' to continue.");
	}
}


// Author: Paul Schofield  e-mail: pauls@7thlevel.com
// Modified by: Sebastian Kulma e-mail: skulma@corp.prodigy.com 
//  Function to return the value of the cookie specified by "name".
//    name - String object containing the cookie name.
//    returns - String object containing the cookie value, or null if
//      the cookie does not exist.
//
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;
}

// Author: Paul Schofield  e-mail: pauls@7thlevel.com
// Modified by: Sebastian Kulma e-mail: skulma@corp.prodigy.com 
//  Function to create or update a cookie.
//    name - 		String object containing the cookie name.
//    value - 		String object containing the cookie value.  May contain
//					  any valid string characters.
//    [expires] -	Date object containing the expiration data of the cookie.  If
//					  omitted or null, expires the cookie at the end of the current session.
//    [path] - 		String object indicating the path for which the cookie is valid.
//					  If omitted or null, uses the path of the calling document.
//    [domain] - 	String object indicating the domain for which the cookie is
//					  valid.  If omitted or null, uses the domain of the calling document.
//    [secure] - 	Boolean (true/false) value indicating whether cookie transmission
//					  requires a secure channel (HTTPS).  
//
//  The first two parameters are required.  The others, if supplied, must
//    be passed in the order listed above.  To omit an unused optional field,
//      use null as a place holder.  For example, to call SetCookie using name,
//        value and path, you would code:
//
//      SetCookie ("myCookieName", "myCookieValue", null, "/");
//
//  Note that trailing omitted parameters do not require a placeholder.
//    To set a secure cookie for path "/myPath", that expires after the
//      current session, you might code:
//
//      SetCookie (myCookieVar, cookieValueVar, null, "/myPath", null, true);
//
function SetCookie (name,region,expires,path,domain,secure) {
	document.cookie = name + "=" + escape (region) +
		((expires) ? "; expires=" + expires.toGMTString() : "") +
		((path) ? "; path=" + path : "") +
		((domain) ? "; domain=" + domain : "") +
		((secure) ? "; secure" : "");
}

// Author: Paul Schofield  e-mail: pauls@7thlevel.com
// Modified by: Sebastian Kulma e-mail: skulma@corp.prodigy.com 
//  Function to delete a cookie. (Sets expiration date to start of epoch)
//    name -   		String object containing the cookie name
//    path -   		String object containing the path of the cookie to delete.  This MUST
//             		  be the same as the path used to create the cookie, or null/omitted if
//             		    no path was specified when creating the cookie.
//    domain - 		String object containing the domain of the cookie to delete.  This MUST
//             		  be the same as the domain used to create the cookie, or null/omitted if
//             			no domain was specified when creating the cookie.
//
function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? "; path=" + path : "; path=/;") +
      ((domain) ? "; domain=" + domain : "") +
      "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}

*/
