var isLCIndexTicker=false;
/*
 * Get values from URl
 */
function getQueryVariable(variable, query) {
	if (query == null || query == '')
		return null;
	var vars = query.split("&");
	for (var i=0;i<vars.length;i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return unescape(pair[1]);
		}
	} 
	return null;
}

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 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);
			if(Name=="indices"){
				//alert(document.cookie.substring(offset, end));
				return updateIndices(document.cookie.substring(offset, end))
				//swapIndices(document.cookie.substring(offset, end));
			}else{
				return unescape(document.cookie.substring(offset, end))
			}
		}
	}
}

var jsSwapValue = [['COMPX','COMP'],['DJI','DJI'],['INX','SPX.I'],['NYA.X','NYA'],['RUT.X','RUT.I']];

//This function will retuen the new ticket symbol value.
function getNewIndicesValue(oldValue){
	var newValue="";
	for(j=0;j<jsSwapValue.length;j++){
 		var arrayoptiontext = jsSwapValue[j][0];
		if(oldValue!=""){
			if (arrayoptiontext==oldValue){
				newValue=jsSwapValue[j][1]; 
				return newValue;
			}
		}
	}
	return oldValue;
}

//This function is use to split the indices value and replace the old ticker symbol to 
// a new value and return the updated Indices value.
/*function updateIndices(portfolioString){
		str = unescape(portfolioString);
		myString = new String(str);
		//document.write("<BR>" +myString);

		splitString = myString.split("|")
		var finalString = "";
	
		for(count=0;count<splitString.length;count++){
		
			temp = splitString[count];
			newString = new String(temp);
			splitString2 = newString .split(";");
			
			for(count2=0;count2<splitString2.length;count2++){
				finalString = finalString + getNewIndicesValue(splitString2[count2]) + ";";
			}
	 }
	//	document.write("<BR> New String is " +finalString );
	return finalString;
}
*/

//new method added on 05-02-04
	function updateIndices(portfolioString){
       str = unescape(portfolioString);
		myString = new String(str);
		splitString = myString.split(";")
		var finalString = "";
	
		for(count=0;count<splitString.length;count++){
		
			temp = splitString[count];
			newStr = "";
			newString = new String(temp);
			splitString2 = newString.split("|");
			if(splitString2.length > 1){
				for(count2=0;count2<splitString2.length;count2++){
					if(count2 > 0){
							finalString = finalString + getNewIndicesValue(splitString2[count2]) + ";";
						}else{
							finalString = finalString + getNewIndicesValue(splitString2[count2]) + "|";
						}
				}
			}else{
				finalString = finalString + getNewIndicesValue(splitString[count]) + ";";
			}
			
	 }
	return finalString;				
	}
// end of new method added on 05-02-02

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);
			}
       	}
	}
}
