
//-----------------------------------------------------------------
// write icon dock
function icon_dock(){
    
    dflash = "<script type=\"text/javascript\">var swfURL = \"Dock.swf?q=\"+Math.random()*100000;var flashvars = {};";
    dflash += "flashvars.platform = osDetect.OS; var params = {}; params.wmode = \"transparent\"; var attributes = {};";
    dflash += "swfobject.embedSWF(swfURL, \"icon_dock\", \"280\", \"110\", \"8.0.0\", false, flashvars, params, attributes);";
    dflash += "</script>";
    dflash += "<div id=\"icon_dock\"><a href=\"http://www.adobe.com/go/getflashplayer\"><img src=\"http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif\" alt=\"Get Adobe Flash player\" /></a></div>";
    document.write(dflash);

}

//-----------------------------------------------------------------
// write genre nav flash
function genrenav_flash(){

    gflash = "<script type=\"text/javascript\">var swfURL = \"genre_nav.swf?q=\"+Math.random()*100000;var flashvars = {};";
// for top movie auto run - as top movie move to below the genre nav
//    gflash += "flashvars.KB_sessionExist = (document.cookie.indexOf(\"session=exists\")!=-1) ? \"true\" : \"false\";";
    gflash += "var params = {};params.wmode = \"transparent\";var attributes = {};swfobject.embedSWF(swfURL, \"genre_nav\", \"540\", \"326\", \"8.0.0\", false, flashvars, params, attributes);";
//    gflash += "document.cookie = \"session=exists;\";</script>";
    gflash += "</script>";
    gflash += "<div id=\"genre_nav\"><a href=\"http://www.adobe.com/go/getflashplayer\"><img src=\"http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif\" alt=\"Get Adobe Flash player\" /></a></div>";

    document.write(gflash);
}

//-----------------------------------------------------------------
// write top movie flash
function topmovie_flash(){

    tflash = "<script type=\"text/javascript\">var swfURL = \"top_movies.swf\";var flashvars = {};flashvars.KB_sessionExist = (document.cookie.indexOf(\"session=exists\")!=-1) ? \"true\" : \"false\";flashvars.showtopmv = showtopmovie();var params = {};";
    tflash += "params.wmode = \"transparent\";var attributes = {};swfobject.embedSWF(swfURL, \"top_movies\", \"854\", \"332\", \"8.0.0\", false, flashvars, params, attributes);";
    tflash += "document.cookie = \"session=exists;\";</script>";
    tflash += "<div id=\"top_movies\"><a href=\"http://www.adobe.com/go/getflashplayer\"><img src=\"http://www.adobe.com/images/shared/download_buttons/get_flash_player.gif\" alt=\"Get Adobe Flash player\" /></a></div>";

    document.write(tflash);
}


//------------------------------------------------------------------
// mouse event action on search Go button
function mouseEvent(xid,imgnum) {
        document[xid].src = eval("imageRoll["+imgnum+"].src");
}



//------------------------------------------------------------------
// submit search function
function chksearch(){
    if (search.query.value == "" || search.query.value == "Search for Video") search.query.value = "all";
}


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


//------------------------------------------------------------------
// display sponsored_signup.html offer in signup.htm
function update_offer(){

//    usercountry = getCountry();
    if(usercountry == "SGG"){
	// show sponsored access div
        doSomethingWithClasses("table_center_container","block");
    }
}


//------------------------------------------------------------------
// display login status in userstatus.htm
function update_userstatus(){

    var cookies = document.cookie.split('; ');
    var uds = 0;
    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 && cookies[i][1]!='') || (cookieName.indexOf('RNPlayer') ==0 && cookies[i][1])){
             uds =1;
        }
    }//for

//put on top
//    ut = loginUser();

    // greeting
    if (ut==1)
	document.getElementById("account_container").innerHTML = "Hello, RealPlayer SuperPass &nbsp;&nbsp;&nbsp;&nbsp;";
    else if (ut==2)
	document.getElementById("account_container").innerHTML = "Hello, RPSP User &nbsp;&nbsp;&nbsp;&nbsp;";
    else if (ut==3)
        document.getElementById("account_container").innerHTML = "Hello, Sponsored User &nbsp;&nbsp;&nbsp;&nbsp;";
    else
	document.getElementById("account_container").innerHTML = "Hello, Guest &nbsp;&nbsp;&nbsp;&nbsp;";

    // login / logout
    if(uds && (ut==1||ut==2||ut==3))
        document.getElementById("link_container").innerHTML = "<a href=\"javascript:logout();\">Logout</a>&nbsp;&nbsp;|";
    else
        document.getElementById("link_container").innerHTML = "<a href=\"javascript:loginOpen();\">Login</a>&nbsp;&nbsp;|";
    
//put on below
    // show legend if is AU / Sponsored User
//    usercountry = getCountry();

//alert("country="+usercountry+" user="+ut);
//    if(usercountry == "AU" || ut==3){
    if((usercountry == "AU" && ut==0) || ut==3){
	doSomethingWithClasses("title_icon_play","none");
	doSomethingWithClasses("legend_container","block");
	doSomethingWithClasses("title_icon","block");
    }

}


//---------------------------------------------------------------------
// call by update_userstatus
function doSomethingWithClasses(theClass, act) {

    //Create an array
    var allPageTags = new Array();
    //Populate the array with all the page tags
    var allPageTags=document.getElementsByTagName("*");
    //Cycle through the tags using a for loop
    for (var i=0; i<allPageTags.length; i++) {
        //Pick out the tags with our class name
        if (allPageTags[i].className==theClass) {
            //Manipulate this in whatever way you want
            allPageTags[i].style.display=act;
        } //if
    } //for

} // function



//--------------------------------------------------------------------------
// link for login form
function loginOpen(mvid){

    // get domain to get to know login from dev or live server
    url = document.location;
    url = url.toString();
    dnm1 = url.indexOf("http://") + 7;
    dnm2 = url.indexOf("real.com") + 8;
    dnm = url.substring(dnm1,dnm2);

    // to resize window if login from dualoffer
    p="";
    rr= url.indexOf('dualoffer');
    if (rr != -1) p = "dualoffer";

    // get movie id
    mv1 = url.indexOf('?id=') + 4;
    mv2 = url.indexOf('&pcode');
    m = url.substring(mv1,mv2);
    var valid = "0123456789";
    for (var i=0; i<m.length; i++) {
	temp = "" + m.substring(i, i+1);
	if (valid.indexOf(temp) == "-1") m=0;
    }
    // user who login from upsell page in synopsis page
    if (m == 0 && mvid ) m = mvid;

    // to check open in web or RP
    var agt=navigator.userAgent.toLowerCase();
    var rp  = (agt.indexOf("r1") != -1 || agt.indexOf("realplayer") != -1);

    // false - not in player
    // Close for login option - spons or sub user
//    if (!rp)
//	url = "http://login.sg.real.com/login/loginoption.html?ref="+dnm+"&p="+p+"&m="+m;
//    else
	url = "http://login.sg.real.com/login/index_v3.html?ref="+dnm+"&p="+p+"&m="+m;
	if (popupsz()) { w=404; h=480; }
	else { w=380; h=400; }
        window.open(url,'loginform',"top=150,left=150,height="+h+",width="+w+",status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no");

}


//------------------------------------------------------------------
// link for logout function
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 != 'RNGuide' && cookieName != 'RNGuide2')){
		document.cookie= cookieName+'=; path=/; domain=.real.com; expires=;';
	    }
	} // for

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

	// clear cookie in RealPlayer ** IMPORTANT - not working in RP11 yet
	if (issafari){
	    clearPlayerAuthUrl(1);
	}else if (uds){
	    clearPlayerAuthUrl(2);
	}
	alert('You are now signed out.');
	setTimeout('window.location.reload();',3000);
    }
}

//-----------------------------------------------------------------------
// 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);

}

//-----------------------------------------------------------------------
// get user's country
function getCountry()
{
    req = false;
    dataResult = '';

    if ( window.XMLHttpRequest ) {
        try {
            req = new XMLHttpRequest();
        } catch(e) {
            req = false;
        }
    } else if ( window.ActiveXObject ) {
        try {
            req = new ActiveXObject("Msxml2.XMLHTTP");
        } catch(e) {
            try {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            } catch(e) {
                req = false;
            }
        }
    }
    if ( req ) {
        req.open("GET", "http://"+location.host+"/chkcountry.php", false);
        req.send("");
        dataResult = req.responseText;
    }
    return dataResult;
}



//-----------------------------------------------------------------------
// link for See others regions
function other_region() {

    if (location.host == 'au.real.com' || location.host == 'video.au.real.com')
        dest= "http://au.real.com/othersregion.htm";
    else
        dest= "http://"+location.host+"/othersregion.htm";

    if (popupsz()) { w=240; h=409; }
    else { w=220; h=320; } // mac
    window.open(dest,'otherregions',"top=150,left=150,height="+h+",width="+w+",status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=no");
}

//-----------------------------------------------------------------------
// link for customer feedback form
function feedbackform() {
    dest= "http://prog.real.com.sg/feedbackform_v3.html";
    if (popupsz()) { w=405; h=570; }
    else { w=390; h=490; }
    window.open(dest,'custfeedback',"top=150,left=150,height="+h+",width="+w+",status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
}

//-----------------------------------------------------------------------
// link for customer feedback radio form
function feedbackform_radio() {
    dest= "http://prog.real.com.sg/feedbackform_v3.html?subject=Radio";
    if (popupsz()) { w=405; h=570; }
    else { w=370; h=500; }
    window.open(dest,'custfeedbackradio',"top=150,left=150,height="+h+",width="+w+",status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
}

//-----------------------------------------------------------------------
// link for advertise with us
function adsform() {
    dest= "http://prog.real.com.sg/adsrequestform.html";
    if (popupsz()) { w=560; h=450; }
    else { w=520; h=400; }
    window.open(dest,'adsform',"top=150,left=150,height="+h+",width="+w+",status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
}

//-----------------------------------------------------------------------
// SuperPass Support
function supportpage(){
    url = "http://service.real.com/realplayer/";
    window.open(url,"_blank");
}


//-----------------------------------------------------------------------
// link for real LOGO
function landingpage(){
    url = "http://www.real.com/?country=my&language=en&src=apacguide_reallogo&rsrc=apacguide_reallogo&pcode=rn_apac&cpath=CNT";
    window.open(url,"_blank");
}

//-----------------------------------------------------------------------
// link for signup button on guide
function signuppage(){

    if (location.host == 'au.real.com' || location.host == 'video.au.real.com')
        url= "http://au.real.com/signup.htm";
    else
        url= "http://"+location.host+"/signup.htm";

    if (popupsz()) { w=506; h=539; } // w=576
    else { w=506; h=480; }
    window.open(url,'signup',"top=150,left=150,height="+h+",width="+w+",status=yes,toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes");
}

//----------------------------------------------------------------------
// for signup.htm page  - 28 May 2009
function get_mkt(rsrc){

var cpath = 'CNT';
var pcode = 'rn_apac';
var url="";

    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 (cookieValue !='' && cookieName.indexOf('RNMKT') == 0)
        {
                c = unescape(cookieValue);
                v = "rsrc";
                if(c.indexOf(v) < 0) rsrc = '';
                else {
                    var cV = new RegExp(".*" + v +"=([^&]*)(&|$).*");
                    rsrc = c.replace(cV,"$1");
                }
                v = "cpath";
                if(c.indexOf(v) < 0) cpath = '';
                else {
                    var cV = new RegExp(".*" + v +"=([^&]*)(&|$).*");
                    cpath = c.replace(cV,"$1");
                }
        }
    }
    url = "https://order.real.com/pt/order.html?ppath=cpspapc101807a&language=EN&country=AU&src="+rsrc+"&rsrc="+rsrc+"&pcode="+pcode+"&cpath="+cpath;
//    url = "https://globalstore.real.com/rn/1002/spnt/au/?pcode="+pcode+"&cpath="+cpath+"&rsrc="+rsrc+"&src="+rsrc;
    //alert(url);
    return url;
}


// in signup.htm - 28 May 2009 
function orderpath(){
    url = get_mkt("apacguide_signupbtn");
    window.open(url,"_blank");
}


//-----------------------------------------------------------------------
// call by Main page - new arrival, coming soon and others div
function moviepage(url,div){

    if (!div){
	div="genrediv";
    }
    // .htm page
    if (url.indexOf('.htm') != -1){
	    window.location=url+"?"+div;
    // .php page
    }else{
	window.location=url;
    }
}




//-----------------------------------------------------------------------
// detect the content_container div to slide down the genre navigation
function init_topmovie() {

    n = (document.layers) ? 1:0
    ie = (document.all) ? 1:0
    opera = (document.getElementById) ? 1:0
    ff = (document.getElementById) ? 1:0

/*        if (n) {
                genrenav = document.content_container;
        }else if (ie || ff) {
                genrenav = document.getElementById('content_container').style;
                //genrenav.top = 245+'px';
		//alert("genrenav loaded "+genrenav.top);
        }else if (opera){
                genrenav = document.getElementById('content_container');
        }
*/
}


var dtopmv=0;
//-----------------------------------------------------------------------
// call by Main page - to show top movie flash - 2008-jun-19
function slidedw_showtopmovie(){

    downpos = 244;
    //alert("call showtopmovie "+downpos); 
    showtopmv = showtopmovie();
    if(!showtopmv){
/*
	if (detectos()) // in mac
	    slidedown_genrenav_mac();
	else
	    slidedown_genrenav();
*/
	// drop cookie
	dropck_showtopmovie(); 
    }
    dtopmv=1;
}


// slide down genre nav immediately for mac
function slidedown_genrenav_mac(){
    if(downpos < 436){
	downpos = 436;
        if(document.getElementById('content_container').style)
            document.getElementById('content_container').style.top = downpos+'px';
    }
}


// slowly slide down genre nav for win
function slidedown_genrenav(){
/*    
    if(downpos < 436){
	downpos += 16;
	genrenav.top = downpos+'px';
	setTimeout("slidedown_genrenav()",5);
    } // if
*/
}


// call in index_.htm to check hv cookie showtopmovie
function slidedw_showtopmovie_ck(){
/*
    // detect the genrenav again
    init_topmovie();
    // slowly slide down
    downpos = 244;
    if (detectos()) // in mac
        slidedown_genrenav_mac();
    else
	slidedown_genrenav();
*/
}


//--------------------------------------------------------------------------
// drop cookies if user click on Show Top Movie
function dropck_showtopmovie(){

    var value   = 1;
    // expires
    var expdate = new Date ();
    expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 60)); // 1 day

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


//--------------------------------------------------------------------------
// for goback() to return home / genre
// only put in index.php & genre.php
function pg_status(){

    var value   = window.location;
    // expires
    var expdate = new Date ();
    expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 60)); // 1 day

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

}

//--------------------------------------------------------------------------
// for goback() to return genre
// only put in subpage.php only
function subpg_status(){

    var value   = window.location;
    // expires
    var expdate = new Date ();
    expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 60)); // 1 day

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

}

//--------------------------------------------------------------------------
// read showtopmovie cookies
function showtopmovie(){
/*
	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(GetCookie('showtopmovie'))
	return 1;
    else
	return 0;
}


//-----------------------------------------------------------------------
// for Main page - fade movie poster
function initImage(imageId) {
//    for(var i=1;i<=12;i++){
//	imageId = "poster_loading"+i;
	image = document.getElementById(imageId);
	setOpacity(image, 0);
	image.style.visibility = "visible";
	fadeIn(imageId,0);
//    }//for
}

function fadeIn(objId,opacity) {
    if (document.getElementById) {
        obj = document.getElementById(objId);
        if (opacity <= 100) {
            setOpacity(obj, opacity);
            opacity += 10;
            window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 80);
        }
    }
}

function setOpacity(obj, opacity) {
    opacity = (opacity == 100)?99.999:opacity;
    // IE/Win
    obj.style.filter = "alpha(opacity:"+opacity+")";
    // Safari<1.2, Konqueror
    obj.style.KHTMLOpacity = opacity/100;
    // Older Mozilla and Firefox
    obj.style.MozOpacity = opacity/100;
    // Safari 1.2, newer Firefox and Mozilla, CSS3
    obj.style.opacity = opacity/100;
}


// fot icon dock - Movie icon 
//note: index_.htm hv genrenav slidedown
// 	index.htm not hv genrenav slidedown
function goback()
{
    // check whether from google search
    var grsrc="";
    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=="RNMKT"){
	    if (cookieValue.indexOf('realmovie') != -1)
		grsrc="realmovie";
	}
    }//alert(grsrc);

    // google movie search - 20Apr09
    if (grsrc.indexOf('realmovie') != -1){
	if (location.host == 'au.real.com' || location.host == 'video.au.real.com' || location.host == 'sg.real.com')
	    window.location = 'http://'+location.host+"/realmovie.htm";
	 else window.location = 'http://'+location.host+"/preview/realmovie.htm"; //dev server

    // from realplayer
    }else{
	if (location.host == 'au.real.com' || location.host == 'video.au.real.com' || location.host == 'sg.real.com')
	    window.location = 'http://'+location.host+"/index.htm";
	else window.location = 'http://'+location.host+"/preview/index.htm"; //dev server
    }
}


//-----------------------------------------------------------------------
// update ads in subpage.php
function updateAds300() {
    var ord = Math.random()*10000000000000000;
    adslink=ads[num]+ ord + "?";
    rotateAds300(adslink);
    num++;
    if (num == ads.length) num = 0;
}

function rotateAds300(adslink) {
    //var b = window.parent.getElementById("ad_banner");
    //b.src=adslink;
alert(window.parent.getElementById("ad_banner"));
}



//-----------------------------------------------------------------------
// update header if user has not installed RP yet
function update_warning() {

    // detect RealPlayer
    var agt=navigator.userAgent.toLowerCase();
    var ie  = (agt.indexOf("msie") != -1);
    var ns  = (navigator.appName.indexOf("Netscape") != -1);
    var win = ((agt.indexOf("win")!=-1) || (agt.indexOf("32bit")!=-1));
    var mac = (agt.indexOf("mac")!=-1);

    if (ie && win) {
        pluginlist = detectIE("rmocx.RealPlayer G2 Control.1","RealPlayer");
    }
    if (ns || !win) {
        nse = ""; for (var i=0;i<navigator.mimeTypes.length;i++) nse += navigator.mimeTypes[i].type.toLowerCase();
        pluginlist = detectNS("audio/x-pn-realaudio-plugin","RealPlayer");
    }

    pluginlist += navigator.javaEnabled() ? "Java," : "";
    if (pluginlist.length > 0) pluginlist = pluginlist.substring(0,pluginlist.length-1);

    //player exists
    if (pluginlist.indexOf("RealPlayer")!=-1){
	//alert("hv rp");
	return false;
    }else{
	//alert("no rp");
	return true;
    } 
}

// call by update_warning
function detectIE(ClassID,name) {
    result = false; 
    document.write('<SCRIPT LANGUAGE=VBScript>\n on error resume next \n result = IsObject(CreateObject("' + ClassID + '"))</SCRIPT>\n'); 
    if (result) return name+','; else return '';
}

// call by update_warning
function detectNS(ClassID,name) {
    n = ""; if (nse.indexOf(ClassID) != -1) if (navigator.mimeTypes[ClassID].enabledPlugin != null) n = name+","; return n;
}


//-----------------------------------------------------------------------
// link for download_rp_btn.gif in header_warning_containe
function download_warn(){
	
    rdir = getrandomdir();
    issafari=false;
    if (((navigator.userAgent).indexOf("Macintosh")!=-1)&&((navigator.userAgent.match(/Safari/ig))||(navigator.userAgent.match(/Mozilla/ig)))){
        issafari=true
    }
    if (issafari){
        url = "http://software-download.real.com/"+ rdir +"/mac/RealPlayer11GOLD.dmg";
    }else{
	// stub installer
	url = "http://www.real.com.au/twe/rp12/link.html?src=rpv12&frm=apacguide";
    }

    window.open(url,'download',"top=150,left=150,height=50,width=50,status=no,toolbar=no,menubar=no,location=no,scrollbars=no,resizable=no");
}

function getrandomdir()
{
    req = false;
    dataResult = '';

    if ( window.XMLHttpRequest ) {
        try {
            req = new XMLHttpRequest();
        } catch(e) {
            req = false;
        }

    } else if ( window.ActiveXObject ) {
        try {
            req = new ActiveXObject("Msxml2.XMLHTTP");
        } catch(e) {
            try {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            } catch(e) {
                req = false;
            }
        }
    }
    if ( req ) {
        loc = "http://"+location.host+"/snot.txt";
        req.open("GET", loc, false);
        req.send("");
        dataResult = req.responseText;
    }
    return dataResult;
}


//-----------------------------------------------------------------
// 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();
}
//----------------------------------------------------------------
//----------------------------------------------------------------
//alert("rid "+rid+" uid "+uid+ " en "+en+ " cn "+cn);


// GLOBAL use

// to know is sub / nonsub user
var ut = loginUser();
// show legend if is AU / Sponsored User
var usercountry = getCountry();





//----------------------------------------------------------------
// will call by flash
function trackpage(){

    drop_RNGuide();
    drop_RNGuide2();

    // check everytime when tracking
    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");
    }
    //alert(document.cookie);
    if (!en){
	en=usertrack();
    }

    //-------------------------
    //call ajax to get the file 
    req = false;
    dataResult = '';

    if ( window.XMLHttpRequest ) {
        try {
            req = new XMLHttpRequest();
        } catch(e) {
            req = false;
        }
    } else if ( window.ActiveXObject ) {
        try {
            req = new ActiveXObject("Msxml2.XMLHTTP");
        } catch(e) {
            try {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            } catch(e) {
                req = false;
            }
        }
    }
    if ( req ) {
        // replace space to _ in "page"
	page1=page.replace(/\s/g,"_"); //alert(page1); 
//	alert("(ajax) track =("+page1+") rid="+rid+" uid="+uid+ " en="+en);
        loc = "http://"+location.host+"/trackflash.htm?rid="+rid+"&uid="+uid+"&en="+en+"&page="+page1;
        req.open("GET", loc, false);
        req.send("");
    }

}


//----------------------------------------------------------------------------------------
// call by flash to display "Games" menu in Win only
function detectos(){
    var platform;
    if (typeof(window.navigator.platform) != 'undefined')
    {
        platform = window.navigator.platform.toLowerCase();
        if (platform.indexOf('mac') != -1){
	    // is in MAC
            return 1;
        }
    }
    return 0;
}


//---------------------------------------------------------------------------------------
// 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='';
}



//-----------------------------------------------------------------------
// call by synopsis page
function chk_ipm()
{
    url = document.location;
    url = url.toString();
//    url = url.toLowerCase();

// main page and video page need to drop mkt cookie
//    if (url.indexOf("synopsis") != -1)
//    {
        pos1 = url.indexOf("pcode=");
        pos2 = url.indexOf("cpath=");
        pos3 = url.indexOf("rsrc=");
        pos4 = url.indexOf("&", pos3);
        if ( pos1 != -1 && pos2 != -1 && pos3 != -1 )
        {
            pcode = url.substring(pos1+6 , pos2-1);
            cpath = url.substring(pos2+6, pos3-1);
            rsrc = url.substring(pos3+5, pos4);
            if ( pcode != '' && cpath != '' && rsrc != '' ) { setIPMCookie(pcode, cpath, rsrc); }
        }
//    }
}

//-----------------------------------------------------------------------
// call by chk_ipm()
function setIPMCookie(pcode, cpath, rsrc)
{
    req = false;
    dataResult = '';

    if ( window.XMLHttpRequest ) {
        try {
            req = new XMLHttpRequest();
        } catch(e) {
            req = false;
        }
    } else if ( window.ActiveXObject ) {
        try {
            req = new ActiveXObject("Msxml2.XMLHTTP");
        } catch(e) {
            try {
                req = new ActiveXObject("Microsoft.XMLHTTP");
            } catch(e) {
                req = false;
            }
        }
    }
    if ( req ) {
        req.open("GET", "http://"+location.host+"/mrkt.php?pcode="+pcode+"&cpath="+cpath+"&rsrc="+rsrc, false);
        req.send("");
        dataResult = req.responseText;
    }
    return dataResult;
}


//-----------------------------------------------------------------------
// for change default guide purpose - Not in use
/* 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("&");
        }
	// set Edition cookie
	setCookie("Edition", editionCookie, 2000);
	edt = getCookieValue('Edition');
}


//------------------------------------------------------------------------
// call by setDef() to set cookie
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";
        document.cookie = name+"="+value+"; expires=" + exp.toGMTString() + "; domain=" + domname+"; path=/";
}

function popupsz()
{
    var platform = '';
    if (typeof(window.navigator.platform) != 'undefined')
    {
        platform = window.navigator.platform.toLowerCase();
	if (platform.indexOf('mac') != -1)
	{
	    var agt=navigator.userAgent.toLowerCase();
	    var macrp = (agt.indexOf("realplayer") != -1);
	    var rpver11 = (agt.indexOf("11.") != -1);
	    var rpver10 = (agt.indexOf("10.") != -1);
	    
	    if (macrp && (rpver11||rpver10)) 
	    { 
		//alert("macrp");
		return 0;
	    }
	}
    }
    // win & mac safari
    return 1;
}


