I have been banging my head against the wall with this one for a couple of days now. What I am trying to do is take a URL parameter and use it to set a cookie that will cause the phone number to change in the head when it is read. Any help would be greatly appreciated. Here is the code:
Code:
    function getUrlParams() {
        var params = {};
		window.location.search.replace(/[?&]+([^=&]+)=([^&]*)/gi, function(str,key,value) {
		params[key] = value;
  });
 
  return params;
}

function setCookie() {
if(arguments.length < 2) { return; }
var n = arguments[0];
var v = arguments[1];
var d = 0;
if(arguments.length > 2) { d = parseInt(arguments[2]); }
var exp = '';
if(d > 0) {
	var now = new Date();
	then = now.getTime() + (d * 24 * 60 * 60 * 1000);
	now.setTime(then);
	exp = '; expires=' + now.toGMTString();
	}
document.cookie = n + "=" + escape(String(v)) + '; path=/' + exp;
} // function SetCookie()

function getCookie(n) {
var cookiecontent = new String();
if(document.cookie.length > 0) {
	var cookiename = n+ '=';
	var cookiebegin = document.cookie.indexOf(cookiename);
	var cookieend = 0;
	if(cookiebegin > -1) {
		cookiebegin += cookiename.length;
		cookieend = document.cookie.indexOf(";",cookiebegin);
		if(cookieend < cookiebegin) { cookieend = document.cookie.length; }
		cookiecontent = document.cookie.substring(cookiebegin,cookieend);
		}
	}
return unescape(cookiecontent);
}
 var pid = getUrlParams();

    if (pid == 1) {
        setCookie("TrackingNumber1", "sourcePPC1", ()+60*60*24*30, "/", "www.mysite.com");
    }
    else if (pid == 2) {
        setCookie("TrackingNumber2", "sourcePPC2", ()+60*60*24*30, "/", "www.mysite.com");
    }
    else if (pid == 3) {
        setCookie("TrackingNumber3", "sourcePPC3", ()+60*60*24*30, "/", "www.mysite.com");
    }
    else if (pid == 4) {
        Mage.Cookies.set("TrackingNumber4", "sourcePPC4", ()+60*60*24*30, "/", "www.mysite.com");
    }
    else if (pid == 5) {
        setCookie("TrackingNumber5", "sourcePPC5", ()+60*60*24*30, "/", "www.mysite.com");
    }
    else {
        setCookie("TrackingNumber1", "TrackingNumber2", "TrackingNumber3", "TrackingNumber4", "TrackingNumber5");
    }
var cookiename = getCookie;

	if (cookiename == "TrackingNumber1") {
	    var phone = '(888)888-8888';
		}
	else if (cookiename == "TrackingNumber2") {
		var phone = '(888)888-8888';
		}
	else if (cookiename == "TrackingNumber3") {
		var phone = '(888)888-8888';
		}
	else if (cookiename == "TrackingNumber4") {
		var phone = '(888)888-8888';
		}
	else if (cookiename == "TrackingNumber5") {
		var phone = '(888)888-8888';
		}
	else {
		var phone = '(888)888-8888';
		}
//-->
Then to get the dynamic content I am using a simple
Code:
<script type="text/javascript">document.write(phone);</script>
This is on a Magento site.

Needless to say, for some reason, it is not setting or reading the cookies from the script. It is reading the pid just fine, based on the DOM testing I have done, but I am not seeing any values for the cookies. Almost as if either the 'pid' value wasn't being passed to the "setCookie". Please help.