




function getCookieVal (offset)
{
  var endstr = document.cookie.indexOf (';', offset);
      if (endstr == -1)
      {
          endstr = document.cookie.length;
      }
  return unescape(document.cookie.substring(offset, endstr));
}

function FixCookieDate (date) {
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)
  {
      date.setTime (date.getTime() - skew);
  }
}


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 SetCookie (name,value,expires,path,domain,secure)

{

  document.cookie = name + '=' + escape (value) + ((expires) ? '; expires=' + expires.toGMTString() : '') + ((path) ? '; path=' + path : '') + ((domain) ? '; domain=' + domain : '') + ((secure) ? '; secure' : '');

}



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 cookieValue(tag)



{



  var value = null;

  var myCookie = document.cookie +";";

  var findTag = tag + "=";

  var endPos;



  if (myCookie.length > 0)

  {

     var beginPos = myCookie.indexOf(findTag);

     if (beginPos != -1)

       {

          beginPos = beginPos + findTag.length;

          endPos = myCookie.indexOf(";", beginPos);

          if (endPos == -1)

            endPos = myCookie.length;

          value = unescape(myCookie.substring(beginPos, endPos));

       }

  }

  return value;

}



function link(myType)
{
  if (GetCookie('mktad'))
  {
      document.Form1.adkey.value = cookieValue('mktad');
  }
  else
  {
      document.Form1.adkey.value = '       ';
  }
  document.Form1.type.value = myType;
    if (myType == 2)
  { 
      document.Form1.action = 'https://enroll.pennfoster.com/eng/personal_info.aspx';
  }
  else if (myType == 1)
    { 
	  document.Form1.action = 'http://enroll.pennfoster.com/eng/personal_info.aspx';
    }
  else if (myType == 4)
  {
  	  document.Form1.action = 'http://shop.pennfosterhighschool.com';
  }
document.Form1.submit();
  return false;
}


function linkAdkey(url)
{
  if (GetCookie('mktad'))
  {
      document.Form1.adkey.value = cookieValue('mktad');
  }
  else
  {
      document.Form1.adkey.value = '       ';
  }
  
       document.Form1.action = url;
  
       document.Form1.submit();
       return false;
}





function redirect(redirectLink)
{
  var adkeyValue = 'RSCS18T';
  if (GetCookie('mktad'))
  {
     adkeyValue = cookieValue('mktad');
  }
  var fullLink = redirectLink + '&adkey=' + adkeyValue;
  location.href = fullLink;
  return false;
}

function redirectPennFoster(redirectLink)
{
 
 var srchindx = 0;
  while (srchindx != -1)
    {
    	srchindx = redirectLink.search("&");
  		if (srchindx != -1)
  			{
  				redirectLink = redirectLink.replace("&","%26");
  			}
  }
 
 var adkeyValue = 'RSCS18T';
  if (GetCookie('mktad'))
  {
     adkeyValue = cookieValue('mktad');
  }
  var fullLink = 'http://www.pennfoster.edu/urm.php?source=' + adkeyValue + '&url=' + redirectLink;
  location.href = fullLink;
  return false;
}




function redirectCollege(domain, redirectLink)
{
  var setDomain = 'www.pennfoster.edu';
  if (domain == 1)
  {
  	setDomain = 'www.pennfostercollege.edu';  
  }
  else if (domain == 2)
  {
  	setDomain = 'www.pennfostercollegeintl.com';
  }
  else if (domain == 3)
  {
  	setDomain = 'www.pennfostercollegeonline.com';
  }
  else if (domain == 4)
  {
  	setDomain = 'www.pennfosteronline.com';
  }
  else if (domain == 5)
  {
  	setDomain = 'www.pennfoster.edu';
  }
  var adkeyValue = 'RAAS19T';
  if (GetCookie('mktad'))
  {
     adkeyValue = cookieValue('mktad');
  }
  
  var fullLink = 'http://' + setDomain + '/urm.php?source=' + adkeyValue + '&url=' + redirectLink;
  location.href = fullLink;
  return false;
}












/* ------------------ Start Country Dropdown adkey tracking ----------------------*/

function openDir(form) {
if ( form.dir.options[form.dir.selectedIndex].value.indexOf('http://www.icslearn.ca/') >= 0)
{
  if (GetCookie('mktad'))
  {
     var adkeyValue = cookieValue('mktad');
  	 var fullLink = 'http://www.icslearn.ca/urm.php?source=' + adkeyValue + '&url=' + form.dir.options[form.dir.selectedIndex].value ;
     location.href = fullLink;
  	 return false;
  }
}

else if (form.dir.options[form.dir.selectedIndex].value.indexOf('http://www.pennfoster.edu/') >= 0)
{
  if (GetCookie('mktad'))
  {
     var adkeyValue = cookieValue('mktad');
     var fullLink = 'http://www.pennfoster.edu/urm.php?source=' + adkeyValue + '&url=' + form.dir.options[form.dir.selectedIndex].value;
     location.href = fullLink;
  	 return false;
  }


}

else if (form.dir.options[form.dir.selectedIndex].value.indexOf('http://www.pennfosterglobal.com/') >= 0)
{
  if (GetCookie('mktad'))
  {
     var adkeyValue = cookieValue('mktad');
  	 var fullLink = 'http://www.pennfosterglobal.com/urm.php?source=' + adkeyValue + '&url=' + form.dir.options[form.dir.selectedIndex].value;
  	 location.href = fullLink;
  	 return false;
  }
}
window.location =(form.dir.options[form.dir.selectedIndex].value);
}

/* ------------------ End Country Dropdown adkey tracking ----------------------*/


