


//------------------------------------------------------------------
// call by update_userstatus()
function loginUser()
{
    if ( en.indexOf('S448') != -1 ) ut = 1;
    else if ( en.indexOf('S941') != -1 ) ut = 1;
    else if ( en.indexOf('S940') != -1 ) ut = 2;
    else if ( en.indexOf('6590') != -1 ) ut = 3;
    else if ( en.indexOf('6581') != -1 ) ut = 3;
    else ut = 0;

    return ut;
}



//-----------------------------------------------------------------
// check have RNGuide cookie, drop cookie if not found
function drop_RNGuide(){

    if(GetCookie('RNGuide') == null) {
	// rid value
	var now     = new Date();
        var random  = Math.round(1000+8999*Math.random());
	var value   = Math.round(now.getTime()) + '' + random;
	// expires
	var expdate = new Date (); 
	expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365 * 10)); 
	var path    = "/";

	// drop cookie 
	var name    = 'RNGuide';
	var domain  = ".real.com";
	SetCookie(name,value,expdate,path,domain,false);

	var name    = 'RNGuide2';
	var domain  = ".real.com";
	SetCookie(name,value,expdate,path,domain,false);
    } 
}


//-----------------------------------------------------------------
// check have RNGuide2 cookie, drop cookie if not found
function drop_RNGuide2(){

    if (GetCookie('RNGuide2') == null) {
	// get rid value from RNGuide
	var value   =  GetCookie('RNGuide');
	var expdate = new Date ();
	expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000 * 365 * 10));
	var path    = "/";
	var name    = 'RNGuide2';
	var domain  = ".real.com";
	SetCookie(name,value,expdate,path,domain, false);
    }
}


//----------------------------------------------------------------
// call by drop_RNGuide & drop_RNGuide2 to get cookie value
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;
}

// call by GetCookie
function getCookieVal (offset)   {
   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
      endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}


//-------------------------------------------------------------------
// call by drop_RNGuide & drop_RNGuide2 to set cookie
function SetCookie (name, value){

    var argv    = SetCookie.arguments;
    var argc    = SetCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var path    = (argc > 3) ? argv[3] : null;
    var domain  = (argc > 4) ? argv[4] : null;
    var secure  = (argc > 5) ? argv[5] : false;

    document.cookie = name + "=" + escape (value) +
        ((expires == null)  ? "" : ("; expires=" + expires.toGMTString()))+
        ((path == null)     ? "" : ("; path=" + path)) +
        ((domain == null)   ? "" : ("; domain=" + domain)) +
        ((secure == true)   ? "; secure" : "");
}


//-------------------------------------------------------------------
// to get value of en, and uid
// uds or sponsored user
function usertrack(){

    if (GetCookie("R1EuropeAuth_UDS")){

	cont = GetCookie("R1EuropeAuth_UDS"); 		//alert("363 UDS="+cont);
	enconts = cont.split(':');
	en="";
	for (var i=0; i<enconts.length; i++) {
	    var temp = new Array();

	    if (enconts[i].indexOf('@') != -1) { temp = enconts[i].split('@'); ens = temp[1].split('/'); }
	    else { temp = enconts[i].split('%40'); ens = temp[1].split('%2F'); }
	    
	    uid = temp[0];
	    en += ens[0]+"|";
	}
	en = en.substr(0,en.length-1);
	cn='';

    }else if (GetCookie("R1EuropeAuth_SingTel")){

	cont = GetCookie("R1EuropeAuth_SingTel");	//alert("SingTel="+cont);
	enconts = cont.split(':');
	en="";
	for (var i=0; i<enconts.length; i++) {
	    var temp = new Array();

	    if (enconts[i].indexOf('@') != -1) { temp = enconts[i].split('@'); ens = temp[1].split('/'); }
	    else { temp = enconts[i].split('%40'); ens = temp[1].split('%2F'); }

	    uid = temp[0];
	    en += ens[0]+"|";
	}
	en = en.substr(0,en.length-1);
	cn = '';

    }else if (GetCookie("R1EuropeAuth_Spons")){

	cont = GetCookie("R1EuropeAuth_Spons");		//alert("Spons="+cont);
	enconts = cont.split(':');
	en="";
	for (var i=0; i<enconts.length; i++) {
	    var temp = new Array();

	    if (enconts[i].indexOf('@') != -1) { temp = enconts[i].split('@'); ens = temp[1].split('/'); }
	    else { temp = enconts[i].split('%40'); ens = temp[1].split('%2F'); }

	    uid = temp[0];
	    en += ens[0]+"|";
	}
	en = en.substr(0,en.length-1);
	cn = '';

    }else{
	uid = '';
	en='';
	cn='';
    }
    return en;
}


//----------------------------------------------------------------
// run this in every page - rid
drop_RNGuide(); 
drop_RNGuide2();

// define value for rid, en, cn and uid
var rid = GetCookie('RNGuide') ? GetCookie('RNGuide') : GetCookie('RNGuide2');
var en='';
// MUST read RealPlayer cookie first
if (cookie = getCookieValue("RNPlayer")){
    en  = getValue(cookie,"SN");
    cn  = getValue(cookie,"CN");
    uid = getValue(cookie,"CI");
}
if (!en){
    en=usertrack();
}
//----------------------------------------------------------------
//----------------------------------------------------------------



//---------------------------------------------------------------------------------------
// call by usertrack()
function getCookieValue( cookieName ){
    var cookieArray = new Array();
    var cRE = new RegExp("(\;|^)[^;]*("+cookieName+")\=([^;]*)(;|$)");
    cookieArray = cRE.exec(document.cookie);
    if( cookieArray != null ){
        return cookieArray[3];
    }
    return "";
}

function getValue(c,v){
    if(c.indexOf(v) < 0) return "";
    var cV = new RegExp(".*" + v +"=([^&]*)(&|$).*");
    return c.replace(cV,"$1");
}

if (uid=='del'){
    uid='';
    en='';
    cn='';
}



