//-----------------------------------------------------------------------
// popup feedback form
function feedbackform() {

    dest= "http://prog.real.com.sg/feedbackform.html";
    window.open(dest,null,"top=150,left=150,height=500,width=450,status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
}

//-----------------------------------------------------------------------
// for change default purpose

/* set Default in Edition Cookie and redirect to selected Edition */
function setDef() {
        var newdef = "asia-en";
        var editionCookie = getCookieValue("Edition");
        if(editionCookie == '') {
                editionCookie = "CV=1&ED=" + newdef + "&TR=0&SET=user_session";
        } else {
                var editionCookieArray = new Array();
                editionCookieArray = editionCookie.split("&");
                for(i=0; i<editionCookieArray.length; i++)
                        if(editionCookieArray[i].substr(0,3) == "ED=")
                                editionCookieArray[i] = "ED=" + newdef;
                editionCookie = editionCookieArray.join("&");
        }
	setCookie("Edition", editionCookie, 2000);
	edt = getCookieValue('Edition');
}

function setCookie( name, value, days ) {
        var exp = new Date();
        var days2Live = exp.getTime() + (24 * 60 * 60 * 1000 * days);
        exp.setTime(days2Live );
        var domname=".real.com.au";

        document.cookie = name+"="+value+"; expires=" + exp.toGMTString() + "; domain=" + domname+"; path=/";
}


//--------------------------------------------------------------------------


function loginOpen(){
	url = "http://login.real.com.au/login/index.html";
        window.open(url,null,"top=150,left=150,height=360,width=480,status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no");
}


//-------------------------------------------------------------------
// for third party logout
function logout()
{
    if (confirm('Are you sure you want to sign out? \nSigning out will remove access to premium \ncontent, features and personalized services. \nIn order to access premium content and \nfeatures you will be required to sign in.')){
    var uds=0;
    var cookies = document.cookie.split('; ');
    for (var i=0; i<cookies.length; i++) {
        cookies[i] = cookies[i].split('=');
        var cookieName = cookies[i][0];
        var cookieValue = cookies[i][1];
	if (cookieName.indexOf('R1EuropeAuth_UDS') == 0 || cookieName.indexOf('RNPlayer') == 0) uds =1;

	if((cookieName.indexOf('R1EuropeAuth_') == 0 && cookieName != 'R1EuropeAuth_langloc')|| (cookieName.indexOf('RN') == 0 && cookieName != 'RNSurvey' && cookieName != 'RNGuide')){
            document.cookie= cookieName+'=; path=/; domain=.real.com.au; expires=;';
        }
    }

    issafari=false;
    if (((navigator.userAgent).indexOf("Macintosh")!=-1)&&((navigator.userAgent.match(/Safari/ig))||(navigator.userAgent.match(/Mozilla/ig)))){
	issafari=true
    }
    

   // clear player cookies for .real.com
    if (issafari){
	clearPlayerAuthUrl(1);
	// modified on 12 apr 2007
	playerCookies = get_cookiesName();
	RealCookies(rid,playerCookies);

    }else if (uds){
	clearPlayerAuthUrl(2);
	// modified on 12 apr 2007
	playerCookies = get_cookiesName();
        RealCookies(rid,playerCookies);
    }

    alert('You are now signed out.');
    setTimeout('window.location.reload();',4000);
}
}
//------------------------------------------------------------------


// Clear RealPlayer cookies
function clearPlayerAuthUrl(id){

    var playerAuthUrl = ['a=removeallcookies'];
    if (id ==1)
	playerAuthUrl = 'http://login.sg.real.com/inc/auth_smi.ram?'+playerAuthUrl.join('&');
    else if (id==2)
	playerAuthUrl = 'http://login.sg.real.com/inc/auth_smi.ram?'+playerAuthUrl.join('&');

    var playerAuthDIV = document.getElementById('clearplayerAuthDIV_ID');
    if (playerAuthDIV) Element.remove(playerAuthDIV);
    playerAuthDIV = document.createElement('div');
    playerAuthDIV.id = 'clearplayerAuthDIV_ID';
    playerAuthDIV.setAttribute('style','position:absolute;right:0;top:0;overflow:hidden;height:0;width:0;margin:0;padding:0;');
    playerAuthDIV.innerHTML = '<OBJECT CLASSID="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" WIDTH=0 HEIGHT=0><PARAM NAME="SRC" VALUE="'+playerAuthUrl+'"><PARAM NAME="AUTOSTART" VALUE="true"></OBJECT><embed src="'+playerAuthUrl+'" type="audio/x-pn-realaudio-plugin" width="0" height="0" autostart="true" />';

    if (document.body) document.body.appendChild(playerAuthDIV);

}



function getCookieVal (offset)   {

   var endstr = document.cookie.indexOf (";", offset);
   if (endstr == -1)
      endstr = document.cookie.length;
   return unescape(document.cookie.substring(offset, endstr));
}

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;
}


function getValue(c,v){

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



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 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" : "");
   }

function deleteCookie(name, path, domain) {

    SetCookie(name,"",null,path,domain);
}


if(GetCookie('RNGuide') == null) {

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

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

var rid = GetCookie('RNGuide');
//alert("rid "+rid+" uid "+uid+ " en "+en);

 
if (cookie = getCookieValue("RNPlayer")){
    en  = getValue(cookie,"SN");
    cn  = getValue(cookie,"CN");
    uid = getValue(cookie,"CI");
 
}else if (GetCookie("R1EuropeAuth_UDS")){
    cont = GetCookie("R1EuropeAuth_UDS");
    enconts = cont.split(':');
    en="";
    for (var i=0; i<enconts.length; i++) {
        var temp = new Array();
        temp = enconts[i].split('@');
        uid = temp[0];
        ens = temp[1].split('/');
        en += ens[0]+"|";
    }
    en = en.substr(0,en.length-1);

    // modified on 12 apr 2007
    playerCookies = get_cookiesName();
    setTimeout("RealCookies(rid,playerCookies);",2000);
    setCookie('RNVerify', 1, 14 );

}else if (GetCookie("R1EuropeAuth_SingTel")){
    uid = GetCookie("R1EuropeAuth_SingTel");
    ents = uid.indexOf('@6581');
    uid = uid.substr(0,ents);
    en='6581';

    // modified on 12 apr 2007
    playerCookies = get_cookiesName();
    setTimeout("RealCookies(rid,playerCookies);",2000);
    setCookie('RNVerify', 1, 14 );


}else if (GetCookie("R1EuropeAuth_QuickFlix")){
    uid = GetCookie("R1EuropeAuth_QuickFlix");
    ents = uid.indexOf('@6590');
    uid = uid.substr(0,ents);
    en='6590';

    // modified on 12 apr 2007
    playerCookies = get_cookiesName();
    setTimeout("RealCookies(rid,playerCookies);",2000);
    setCookie('RNVerify', 1, 14 );

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

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




function get_cookiesName(){
    var cookies = document.cookie.split('; ');
    var hasPlayerCookies = false;
    var playerCookies = [];
    for (var i=0; i<cookies.length; i++) {
        cookies[i] = cookies[i].split('=');
        var cookieName = cookies[i][0];
        var cookieValue = cookies[i][1];
        if ((cookieName.indexOf('R1EuropeAuth_') == 0 && cookieName != 'R1EuropeAuth_langloc' && cookieValue != '')|| cookieName.indexOf('RNSurvey') == 0) {
            playerCookies.push({key:cookieName,value:cookieValue});
        }
    }
    return playerCookies;
}

function RealCookies(rid,listOfCookies){
    var playerAuthUrl = ['rid='+rid];
    for (var i=0; i<listOfCookies.length; i++) {
        playerAuthUrl.push('c['+listOfCookies[i].key+']='+escape(listOfCookies[i].value));
    }
    playerAuthUrl = "http://login.sg.real.com/xrealck.php?"+playerAuthUrl.join('&');
    if (frames['realhome'])
        frames['realhome'].location.href=playerAuthUrl;
}

playerCookies = get_cookiesName();
if(GetCookie('RNVerify') == null){
    setTimeout("RealCookies(rid,playerCookies);",3000);
}
