function GetLocalCookie (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 getCookieVal (offset) {
	var endstr = document.cookie.indexOf (";", offset);
	if (endstr == -1) {endstr = document.cookie.length;}
	return unescape(document.cookie.substring(offset, endstr));
}

function toUnhexedString(value){
	// 'hexString' is a copy of 'value'
	var hexString = new String( value );
	// 'result' will be the "unhexed" string
	var result = "";

	// add a "0" to the front of the hex string if it does not have an even
	// number of hex characters
	if( hexString.length % 2 != 0 )
		hexString = "0" + hexString;

	// "unhex" the string
	for( var index = 0; index < hexString.length; index += 2 )
		result += String.fromCharCode( parseInt( hexString.substring( index, index + 2 ), 16 ) );

	return result;
}

//****************  Code starts

var agt=navigator.userAgent.toLowerCase();
if(agt.indexOf("aol") != -1) {
	var partner = "AOL"; 
}
else {
	var partner = "UNIVISION";
}

var isCobrand = GetLocalCookie('aoluolsite');

if(isCobrand == 'AOL') {
	var client = "&CLIENT=AOL"; 
}
else {
	var client = "";
}

var favorite = GetLocalCookie('d');
var unhexed = toUnhexedString(favorite);
var arr1 = unhexed.split('|');

for(var i=0; i < arr1.length; i++){
	var temp = arr1[i];
	//Gender
	if(temp.indexOf('P=')!=-1) {
		var gender = temp.substring(2, temp.length); 
	}
	//Age group
	if(temp.indexOf('A=')!=-1) {
		var ageGroup = temp.substring(2, temp.length); 
	}
	//Country of residence
	if(temp.indexOf('R=')!=-1) {
		var countryResidence = temp.substring(2, temp.length);
	}
}

if(favorite != null) {
	var personalTag = '&P=' + gender + '&A=' + ageGroup + '&R=' + countryResidence;
}
else {
	var personalTag = '';
}