function setCookie(name, value, expires, path, domain, secure) {
	//alert("In SetCookie " + name +" value is " + value +" expire time = " + expires);
	document.cookie = name + "=" + escape(value) +
	((expires == null) ? "" : "; expires=" + expires.toGMTString()) +
	((path == null) ? "" : "; path=" + path) +
	((domain == null) ? "" : "; domain=" + domain) +
	((secure == null) ? "" : "; secure");
	//alert("Set Cookie value = " + document.cookie);
}


function getCookie(Name) {

	var search = Name + "="
	if (document.cookie.length > 0) { // if there are any cookies
		offset = document.cookie.indexOf(search)
		if (offset != -1) { // if cookie exists
			offset += search.length                    // set index of beginning of value
			end = document.cookie.indexOf(";", offset)      // set index of end of cookie value
			if (end == -1)
				end = document.cookie.length
			//alert(Name + " = " + offset +  " end = " + end);
			return unescape(document.cookie.substring(offset, end))
		}
	}
}

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 doSplit(str, delimiter) {
        var ret = null;
        var isIE3 = navigator.userAgent.toUpperCase().indexOf('MSIE 3');
        if(isIE3 == -1)
                ret = str.split(delimiter);
        else
        {
                ret = new Array();
                var l = 0;
                var index = 0;
                var lastIndex = 0;
                var max = 60;
                
                while(index != -1 && max-- > 0)
                        if((index = str.indexOf(delimiter, lastIndex)) != -1)
                        {
                                ret[l++] = str.substring(lastIndex, index);
                                lastIndex = index + 1;
                        }
        }
        return ret;             
}

// used in the left page (*l.html), not in the privacypolicy.html page
function getURL() {

        var registered = getCookie("registered");
        
	if(registered == null)
        {
				//http://cmsqa.websys.nyse.com/p1020773188697.html?displayPage=/portfolio/1035929252527.html
                window.parent.location.href = "/p1020773188697.html?displayPage=/portfolio/1035929252527.html";
        }
        else
        {

		var timeVal= doSplit(registered, "|");
		var ppTime= timeVal[1];
		var regTime= timeVal[0];
		//alert (ppTime);
		var today = new Date();
		var todayTime = today.getTime();
		//alert (todayTime);

		// if old format
		if (isNaN(regTime)) {
		        // need to convert to number in order to find out if older than one year
			// alert(regTime);
		        regTime = new Date(regTime);
		        regTime = regTime.getTime();
			ppTime = 0;
        		registered = regTime + "|" + ppTime;
        		var expiration = new Date();
			expiration.setTime(1293857999084);
			// alert(registered);
			setCookie("registered", registered, expiration, "/");
		}

		if (ppTime == null) {
			ppTime=0;
		}

		ppTime = parseInt(ppTime)+ 365 * 24 * 60 * 60 * 1000;
		//alert (ppTime);

		if (todayTime > ppTime) {
			//alert ("ppTime is older than 1 year");
			//http://cmsqa.websys.nyse.com/p1020773188697.html?displayPage=/portfolio/1035929252527.html
			window.parent.location.href="/p1020773188697.html?displayPage=/portfolio/1035929252527.html";
		}
		else 
		{
			var typeURL =  getCookie("typeURL");
			var typeNAME =  getCookie("typeNAME");
			var typeFEATURES =  getCookie("typeFEATURES");

			if(typeURL == null || typeNAME == null || typeFEATURES == null)
			{
					window.parent.location.href = 	"/p1020773188697.html?displayPage=/portfolio/1022221393101.html";			
			}
			else
			{
				open_window(typeURL,typeNAME,typeFEATURES);
			}
       	}
	}
}

