﻿
var Session = {
        playerId:function(){
            var pId = parseInt(getCookie("playerId")); 
            if (isNaN(pId)) 
                pId= 0            
            return pId;
         }
        ,renew: function()
            {
                if (Session.playerId() != 0){
                    $.get("/ws/security/renew.aspx?sess=" + sess + "&playerId=" + Session.playerId(), 
                            function(data)
                            {var pSess = $(data).find("security[sess]").attr("sess"); if (pSess != undefined) updateSess(pSess);}) ;    
                }
            } 
    }

function IsNullOrEmpty(value)
{
    return (value == null || value == '') ;
}

///////////////////////////////////////////////////////////////////

function PageLoader()
{
    this.functions = new Array() ;    
} 

PageLoader.prototype.addOnLoadScript= function(functionCallText) {
    this.functions[this.functions.length] = functionCallText ;
}

PageLoader.prototype.insertOnLoadScript= function(index, functionCallText) {

    var l = this.functions.length ;
    for(var i = index; i<l-index ; ++i)
    {        
        this.functions[i+1] = this.functions[i];    
    }
    this.functions[index] = functionCallText ;
    
}


PageLoader.prototype.executeOnLoadScripts = function() {
    for (var i=0; i< this.functions.length ; ++i)
    {   
        try{
            eval(this.functions[i]);
        }
        catch(e)
        {
            //alert(e.message) ;
        }
        
    }
}

var pageLoader = new PageLoader() ;

// Detect Browser
var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},

	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.userAgent,
			subString: "Chrome",
			identity: "Chrome"
		},
		
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};

BrowserDetect.init();


function isBrowserSupported()
{
    var isSupported = false ; 
    switch (BrowserDetect.browser)
    {
        case "Explorer":
            if (BrowserDetect.version >= 6) 
            {
                isSupported = true ;
            }
            break;
        case "Firefox":
            if (BrowserDetect.version >= 1.5) 
            {
                isSupported = true ;        
            }
            break;      
        case "Opera":
            if (BrowserDetect.version >= 9) 
            {
                isSupported = true ;        
            }
            break;        
              
        case "Netscape":        
            if (BrowserDetect.version >= 7) 
            {
                isSupported = true ;                
            }
            break;        
        case "Safari":
            if (BrowserDetect.version >= 2) 
            {
                isSupported = true ;                
            }
            break;        
        case "Chrome":
            isSupported = true ;                
            break;            
        case "Mozilla":
            break;        
        default:
            break

    }
    return isSupported ;
}
    if (window.location.href.indexOf("/page.aspx?faqSection=Support&faqName=SupportedBrowsers") <=0 && !isBrowserSupported())
    {
        window.location.replace("/page.aspx?faqSection=Support&faqName=SupportedBrowsers") ;
    }


    function param()
    {
        this.array = new Array(1);
        this.array[0] = '' ;
        this.setValue = function(v) { this.array[0] = v; }
        this.getValue = function()  { return this.array[0]; }
    }
   
    function init(theme)
    {
        if (jQuery.facebox != null && jQuery.facebox.settings != null){
            jQuery.facebox.settings.closeImage = '/App_Themes/' + theme + '/images/d6.gif' ;
            jQuery.facebox.settings.loadingImage = '/images/loadingAnim.gif' ;            
        }
        if ($.growl != null){
            //$.growl.settings.dockTemplate = '<div id=\"growlDock\"></div>';
            //$.growl.settings.dockCss = "";
            //$.growl.settings.noticeCss = 'position:relative';
            //$.growl.settings.noticeTemplate = '<div ><span>%title%</span><p>%message%</p></div>';            
        }

    
        pageLoader.addOnLoadScript('loadPageHistory();') ;
        pageLoader.addOnLoadScript('checkDynamicContent();') ;                
        pageLoader.addOnLoadScript('initHistoryListener();') ;        
        pageLoader.executeOnLoadScripts() ;
    }
    
    
    var plCol;
    
    function preLoad()
    {
        try
        {
            var base = 2000;
            var interval = 250; var t = 0;
            plCol = document.getElementsByTagName("img");
            for(var i =0;i<plCol.length;i++)
                if ((plCol[i].getAttribute("_src")!="")&&(plCol[i].getAttribute("_src")!=null))
                {
                    window.setTimeout( "pl(" + i.toString() + ");", (base + (t * interval))); t++;
                }
                }
        catch (e)
        {
            //nothing
        }
    }
    
    function pl(i)
    {
        try
        {
            plCol[i].src = assetBroker + plCol[i].getAttribute("_src") + "?p=p";
            plCol[i].removeAttribute("_src");
        }
        catch (e)
        {
            //nothing
        }
    }
            
    function goBack(){

        window.history.back();
        return false ;
    }    

    function loadXML(data)
    {
        var xmlDoc = null ;
        if (data == null || data =='')
            return null;
        // code for IE
        try{
            if (window.ActiveXObject)
            {
                xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
                xmlDoc.async = false;
                xmlDoc.loadXML(data);
            }
            // code for Mozilla, Firefox, Opera, etc.
            else {
              var parser=new DOMParser();
              xmlDoc = parser.parseFromString(data,"text/xml");

            }
        }
        catch(e)
        {
            return null;
        }
        return xmlDoc ;
    }
    
    function hasCookie(name)
    {
        var cookieName = name + "=";
        return (document.cookie.indexOf(cookieName)>-1);
    }

    // Allows getting single value cookies and multi value cookies
    function getCookie(name,subName){
        var value = getCookieValue(document.cookie,name,";");
        if(subName)
        {            
            value = getCookieValue(value,subName,"&");
        }
        return value;
    }
    
    function getCookieValue(allCookie,name,sep)
    {
        var cookieName = name + "="; // identify the cookie name and include the seperator
        var cookieValue = "";
        if(document.cookie.length > 0)
        {
            startIndex = allCookie.indexOf(cookieName); 
            if(startIndex != -1) 
            {
                startIndex += cookieName.length;
                endIndex = allCookie.indexOf(sep, startIndex);
                if(endIndex == -1)
                { 
                    endIndex = allCookie.length; 
                }
                cookieValue=unescape(allCookie.substring(startIndex, endIndex)); 
            }

        }
        return cookieValue; // show value of cookie
    }
    
    function setCookie(nameValue)
    {
        //expect a nameValue of the form "name=value"
        var expiry;
        //if expiry value is ommitted, creates a browser session cookie
        document.cookie = nameValue + "; path=/; expires=" + ((expiry) ? expiry.toGMTString() : '');
        return true;
    }
    
    function clearCookie ( cookie_name )
    {
  
      var cookie_date = new Date ( );  // current date & time
      cookie_date.setTime ( cookie_date.getTime() - 1 );
      document.cookie = cookie_name += "=; expires=" + cookie_date.toGMTString();
    }
    
    function checkDynamicContent()
    {
    
        var o = document.getElementById('lnkAccessAccount');
        if (o)
        {
            o.style.display = (getCookie('playerId').length > 0) ? 'block' : 'none';
        }

        var o = document.getElementById('lnkRegisterNow');
        if (o)
        {
            o.style.display = (getCookie('playerId').length > 0) ? 'none' : 'block';
        }
       
        var o = document.getElementById("txtSearchText")
        var showBackToSearchResults = false;
        if (o)
        {
            if (o.value != "")
            {
                showBackToSearchResults = true;
            }
        }
        
        if (showBackToSearchResults)
        {
            var o = document.getElementById("backToList");
            
            if (o)
            {
                o.style.display = "block";
            }
        }
        
       getPageContentSection(1, "dynamicNews");
       getPageContentSection(1, "dynamicPlayerNews");
       getPageContentSection(3, "dynamicWinners");
       getPageContentSection(3, "dynamicWinnersHowToPlay");
       getPageContentSection(8, "dynamicLatestTrivia");
       
       getPageContentSection(9, "dynamicFACTOID");
       getPageContentSection(10, "dynamicLatestMembers");

       getPageContentSection(11, "dynamicPlayingNowFree");
       getPageContentSection(12, "dynamicPlayingNowCash");
              
       //loadHomePageFlashObject("Default", "homeDefaultScript");
       
    }

    function redirect(url){
        window.location.replace(url);
        return false ;
    }  
    
    function runReplaceText()
    {
        replaceText('h2', document.getElementsByTagName('h2'));
        replaceTextWithRollover('a', document.getElementsByTagName('a'));
        
    }
    
    function IntegerCommaFormatted(amount)
    {
	    var delimiter = ","; // replace comma if desired
	    var i = parseInt(amount);
	    if(isNaN(i)) { return ''; }
	    var minus = '';
	    if(i < 0) { minus = '-'; }
	    i = Math.abs(i);
	    var n = new String(i);
	    var a = [];
	    while(n.length > 3)
	    {
		    var nn = n.substr(n.length-3);
		    a.unshift(nn);
		    n = n.substr(0,n.length-3);
	    }
	    if(n.length > 0) { a.unshift(n); }
	    n = a.join(delimiter);
	    amount = n;
	    amount = minus + amount;
	    return amount;
    }

    
    function replaceText(tag, x)
    {
        var replace = document.createElement('img');
        for (var i=0;i<x.length;i++)
        {
            var y = replace.cloneNode(true);
            
            y.src = '/CC/gdi/' + tag + '.aspx?text=' + escape(x[i].firstChild.nodeValue);
            
            y.alt = x[i].firstChild.nodeValue;
            x[i].replaceChild(y,x[i].firstChild);
        }
    }

    function replaceTextWithRollover(tag, x)
    {
        var replace = document.createElement('img');
        for (var i=0;i<x.length;i++)
        {
            var suffix = '.aspx?text=' + escape(x[i].firstChild.nodeValue);

            var test = new Image();
            test.src = '/CC/gdi/' + tag + '_On' + suffix; //preloads rolover image

            var y = replace.cloneNode(true);
            y.src = '/CC/gdi/' + tag + suffix;
            y.onsrc = test.src;
            y.offsrc = '/CC/gdi/' + tag + suffix;
            
            x[i].onmouseover = rollOver;
            x[i].onmouseout = rollOut;
            
            y.alt = x[i].firstChild.nodeValue;
            x[i].replaceChild(y,x[i].firstChild);
        }
    }

    function rollOver()
    {
        var theEvent = window.event || arguments[0];
        
        var srcElm = sourceElement(theEvent) ;
        srcElm.src = srcElm.onsrc ;
        
       //event.srcElement.src = event.srcElement.onsrc ;        

        
    }

    function rollOut()
    {
        var theEvent = window.event || arguments[0];
        
        var srcElm = sourceElement(theEvent) ;
        srcElm.src = srcElm.offsrc ;    
        //event.srcElement.src = event.srcElement.offsrc;
    }
    
    function sourceElement(e)
    {
     
        if (document.all)
            return e.srcElement ;    
        else
            return e.target ;            
    }
    

    function isValidEmail (email)
    {
	    var format = /^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/ ;
	    return(format.test(email)); 
    } 
    
    function updateCheckboxList(source, listName)
    {
        // if source is null then reset the list
        var value ;
        if (source == null)
            value = false ;
        else
            value = source.checked ;
            
        var chkSelected = document.getElementsByName(listName) ;            
            
        for (i=0 ; i<chkSelected.length; ++ i)
            chkSelected[i].checked = value ;
            
        return false ;
    }
    
    function replacePage(Url)
    {
        window.location.replace(Url) ;
        return false ;
    }
    
    
    function getHttpRequestObject()
    {
        var httpRequest ;        
        
        try{
            if (!window.XMLHttpRequest)
                httpRequest = new ActiveXObject("Microsoft.XMLHTTP") ;
            else
                httpRequest = new XMLHttpRequest() ;
        }
        catch(e) {
            return null ;
        }            
        return httpRequest ;
    
    }
        
    function isNumeric(TextBox,strType) 
    // check for valid numeric strings 
    { 
        var retVal = true ;
        if (strType="Decimal") 
        { 
            var strValidChars = "0123456789."; 
        } 
        else if (strType="Integer") 
        { 
            var strValidChars = "0123456789"; 
        } 
        var strString; 
        var strChar; 
        strString = TextBox.value; 

        for (i = 0; i < strString.length; i++) 
        { 
            strChar = strString.charAt(i); 
            if (strValidChars.indexOf(strChar) == -1) 
            { 
                TextBox.value = TextBox.value.substring(0, i) ; 
                TextBox.value.length = i ;
                retVal = false ; 
            }
        } 
        return retVal ;
    } 
    
    function justNumbers(e)
    {
        var keynum ;
        var keychar ;
        var numcheck;
        
        /*
        if(window.event) // IE
        {
            keynum = e.keyCode ;
        }
        else if(e.which) // Netscape/Firefox/Opera
        {        
            keynum = e.which ;
        }
        */
        
        if(e.which) // Netscape/Firefox/Opera
        {
            keynum = e.which ;
        }
        else if (window.event) // IE
        {        
            keynum = e.keyCode ;            
        }        
        
        
        if (keynum ==null || keynum  == 'undefined')
            return true;
        
        if (keynum == 13) return true; 
        if (keynum == 8) return true;  
        
       
                
        
        keychar = String.fromCharCode(keynum) ;
        numcheck = /\d/  ;
        return (numcheck.test(keychar) || keychar == '.'|| keynum == 8) ;
    }


      function openCalendar(url)
      {
        var popupWindow = null;
        var settings='width=900,height=585,location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=no,resizable=yes,dependent=no';
        popupWindow = window.open(url, '_blank', settings);
        popupWindow.focus();
        return false ;
      }
      
      function openHelpWindow(url, width, height, windowName)
      {
        var popupWindow = null;
        var settings='width='+ width + ',height=' + height+ ',location=no,directories=no,menubar=no,toolbar=no,status=no,scrollbars=yes,resizable=yes,dependent=no';
        popupWindow = window.open(url, windowName, settings);
        popupWindow.focus();
        return false ;
      } 
    
    function clearDropdown(oDropdown)
    {
        if (!oDropdown ) return false ;
        
        var l = oDropdown.options.length ;

        for (var i=l ; i>=0;--i)
        {
            oDropdown.remove(i) ;
        }
        return true ;
    }
    
    function addItemToDropdown(oDropdown, text, value)
    {
        if (!oDropdown ) return false ;
        var oOption = document.createElement("OPTION") ;
        oDropdown.options.add(oOption) ;        
        oOption.text = text ;
        oOption.value = value ;

    }
    
    
    
        
    //////////////////////////////////////////////////////////////////////////////
    // This is a dropdown class to handle client side manipulation of html dropdowns
    
    function DropDown(id)
    {
        this.id = id ;
        this.control = document.getElementById(id) ; 
        return this; 
    }
    
    DropDown.prototype.clear = function()
    {
            if (!this.control) return false ;
            
            var l = this.control.options.length ;

            for (var i=l ; i>=0;--i)
            {
                this.control.remove(i) ;
            }
            return true ;        
    }
    
        
    DropDown.prototype.add =  function (text, value) 
    {
            if (!this.control) return false ;
            var oOption = document.createElement("OPTION") ;
            this.control.options.add(oOption) ;        
            oOption.text = text ;
            oOption.value = value ;        
    }

    DropDown.prototype.remove =  function (index) 
    {
           this.control.remove(i) ;        
    }
    
    DropDown.prototype.find =  function (value) 
    {
        if (!this.control) return false ;            
        var foundItem = null ;
        var l = this.control.options.length ;

        for (var i=0 ; i<l; ++i)
        {
            if (this.control.options[i].value == value) {
                foundItem = this.control.options[i]
                break ;
            }
        }
        
        return foundItem ;
        
    }
    
    DropDown.prototype.setValue = function (value) 
    {
        if (!this.control) return false ;            
        
        //var foundItem = this.find(value) ;
        
        //if( foundItem != null)
        this.control.value = value ;
            

        
    }
    //////////////////////////////////////////////////////////////////////////////  
        
    
    function loadPageHistory()
    {
    
        var historyLoaded = ajx_onHistoryLoad();               
        
    }
    
    function findFaqNavNode(pageName)
    {
            //find navigation node
        var menu = document.getElementById("nav");
        
        var navLis = menu.getElementsByTagName("LI");
        
        for(var i=0;i<navLis.length;i++)
        {
            var li = navLis[i];
            
            if (li.getAttribute("faqName") == pageName)
            {
                if (li.getElementsByTagName("A").length > 0)
                var link = li.getElementsByTagName("A")[0];
                break;
            }
        }
        return li;
    }
    
    //////////////////////////////////////////
    //             FLASH EXTERNAL           //
    //////////////////////////////////////////
                
    
    function updateMyGames() {
        
        try {
            if (SWFMovie("flashMyGames") != null)
                SWFMovie("flashMyGames")._refresh(true);
        } catch (e) {
            //cannot refresh my games;
            return false;
        }
        return true;
    }

    function updateGameList() {

        try {
            if (SWFMovie("flashGameList") != null)
                SWFMovie("flashGameList")._refresh(true);
        } catch (e) {
            //cannot refresh game list;
            return false;
        }
        try {
            if (SWFMovie("flashFavorites") != null)
                SWFMovie("flashFavorites")._refresh(true);
        } catch (e) {
            //cannot refresh favorites;
            return false;
        }
        return updateMyGames();
    }
    
    function getSess()
    {
        sess = getCookie("sess");
        return ((sess.length > 0) ? sess : "") ;
    }
    
    function updateSess(pSess) {

        if (pSess != "")
        {
            sess = pSess;
            setCookie("sess=" + pSess);
        }
        
        try {
            if (SWFMovie("flashArena") != null)
                SWFMovie("flashArena")._sess(pSess);
        } catch (e) {
            //cannot update session;
            return false;
        }
        try {
            if (SWFMovie("flashCcalendar") != null)        
                SWFMovie("flashCalendar")._sess(pSess);
        } catch (e) {
            //cannot update session;
            return false;
        }
        try {
            if (SWFMovie("flashMyGames") != null)
                SWFMovie("flashMyGames")._sess(pSess);
        } catch (e) {
            //cannot update session;
            return false;
        }
        return updateGameList();
    }
    
    function SWFMovie(movieName){
        if (navigator.appName.indexOf("Microsoft") != -1) {
            return window[movieName];
        }
        else {
            return document[movieName];
        }
    }
    
    function jsChangeDivHeight(divId, height)
    {
       // alert("divId = " + divId +", height = " + height);
        var o = document.getElementById(divId);
        if (o != null)
        {
            o.style.height = height.toString() + "px";
            o.style.minHeight = height.toString() + "px";
            o.style.maxHeight = height.toString() + "px";
        }
        return true;
    }    
    
//     function configureSiteContent(locationId,siteId,vr,locationName,flashvars,controlBox,wipe,overlay)
//     {
//        var so = configureContent(locationId,vr,locationName,flashvars,controlBox,wipe,overlay);
//        so.addVariable('siteId',siteId);
//        return so;
//     }
//     
//     function configureCampaignContent(locationId,campCode,vr,controlBox,wipe,overlay)
//     {
//        var so = configureContent(locationId,vr,controlBox,wipe,overlay);
//        so.addVariable('campCode',campCode);
//        return so;
//     }
     
     function configAdvert(locationId,locationName,flashvars,controlBox,wipe,overlay)
     {
        if(controlBox == null) controlBox = false;
        if(wipe == null) wipe = false;
        if(overlay == null) overlay = "";
        
        flashvars.locationId = locationId;
        flashvars.controlBox = ((controlBox) ? "1" : "");
        if (wipe) flashvars.transitionType = "wipe";
        if (overlay.length > 0) flashvars.overlay = overlay;
        
        var params =    {   quality: "high",
                            wmode: "transparent", 
                            salign: "TL", 
                            bgcolor: "#FFFFFF"};
                            
        var attributes = {  id: "flash"+locationName,  
                            name: "flash"+locationName};
        
        swfobject.embedSWF("/flash/advert.swf", locationName, "1000", "1000", "8.0.0", "expressInstall.swf", flashvars, params, attributes);
        
     }
    
    
    function FAQSearch_On_KeyPress(e)
    {
        
    	var key = window.event ? window.event.keyCode : e.which;
    	if (key == 13)
    	{
    	    if (this.getFAQSearchResult)
    	    {
    	        getFAQSearchResult();
    	        return false;    
            }

//            if(document.forms['frmFAQSearch'] != null)
//            {
//                document.forms['frmFAQSearch'].submit() ;
//            }
    	}
	    return true;
    }       
    

    function getElementsByClassName(oElm, strTagName, strClassName){
        var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
        
	    var arrReturnElements = new Array();
	    strClassName = strClassName.replace(/\-/g, "\\-");
	    var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	    var oElement;
	    for(var i=0; i<arrElements.length; i++){
	        oElement = arrElements[i];
	        if(oRegExp.test(oElement.className)){
	            arrReturnElements.push(oElement);
	        }
	    }
	    return (arrReturnElements) ;
	}

    function showCallout(e)
    {   
        var calloutBox = document.getElementById("calloutBox") ;
               
        if (calloutBox == null) return;
        
        var calloutBoxText = document.getElementById("calloutBoxText") ;
        
        if (calloutBoxText == null) return; 
        var source = e.srcElement;
        var text = source.getAttribute("tip") ;
        if (text == null)
            return;
            
        var position = findPos(source) ;
        
        var left = position[0];
        var top = position[1];
        

        calloutBoxText.innerHTML = text ;  
              
        left = left + source.offsetWidth - 5 ;
        
        // dirty hack to get the actual size of the callout box before display.
        calloutBox.style.display = "block" ;
        calloutBox.style.visibility = "hidden" ;        
                
        top = top - (calloutBox.offsetHeight - 5);
        
        calloutBox.style.left = left + "px";
        calloutBox.style.top = top + "px";
        
        // clean up the dirty hack to get the actual size of the callout box before display.        
        calloutBox.style.display = "none" ; 
        calloutBox.style.visibility = "visible" ;
                
        fadeIn("calloutBox", 3) ;
    }
    
    function findPos(obj) {
	    var curleft = curtop = 0;
	    if (obj.offsetParent) {
		    do {
			    curleft += obj.offsetLeft;
			    curtop += obj.offsetTop;
		    } while (obj = obj.offsetParent);
	    }
	    return [curleft,curtop];
    }

    
    function hideCallout()
    {        
        var calloutBox = document.getElementById("calloutBox") ;
        if (calloutBox == null) return;

        calloutBox.style.display = 'none' ;

    }
        

function fadeIn(objectName, speedFactor)
{
    for( var i = 0 ; i <= 100 ; i++ )
    {
        setTimeout( 'setOpacity("' + objectName + '",' + (i / 10) + ')' , speedFactor * i );            
    }
}

function fadeOut(objectName, speedFactor)
{
     for( var i = 0 ; i <= 100 ; i++ ) {
        setTimeout( 'setOpacity("' + objectName + '",' + (10 - i / 10) + ')' , speedFactor * i );
    }
}

function setOpacity(objectName, value) {
 var object = document.getElementById(objectName);
 object.style.opacity = value / 10;
 object.style.filter = 'alpha(opacity=' + value * 10 + ')';
 object.style.display = (value <= 0) ? "none" : "block";

}

function replace(text, expr, val) {
    while(expr.test(text)) {
      text = text.replace(expr, val);
    }
    return text;
};

var popupDialog = {
    ok: 1
    , cancel: 2
    , ok_fnc: null
    , cancel_fnc: null
    , templateForm: '\
            <div class="div%size%">\
                <div class="grayBoxH">%title%</div>\
                <div class="grayBoxC" style="display:block;">\
                %body%\
                %controls%\
                </div>\
                <div class="grayBoxF"></div>\
              </div>'
    , showForm: function(title, body, size, controlMask, ok_fn, cancel_fn) {

        if (ok_fn != null && ok_fn != undefined)
            popupDialog.ok_fnc = ok_fn;
        if (cancel_fn != null && cancel_fn != undefined)
            popupDialog.cancel_fnc = cancel_fn;

        var controls = '<ul class="feed">';
        if ((controlMask & popupDialog.ok) != 0) controls += '<li class="feedLink"><a href="javascript:void(0);" onclick="javascript:popupDialog.close(\'ok\');return(false);" class="feedLink">OK &#187;</a></li>';
        if ((controlMask & popupDialog.cancel) != 0) controls += '<li class="feedLink"><a href="javascript:void(0);" onclick="javascript:popupDialog.close(\'cancel\');return(false);" class="feedLink">Cancel &#187;</a></li>';
        controlMask += '</ul>';

        var html = replace(popupDialog.templateForm, /%title%/, title);
        html = replace(html, /%body%/, body);
        html = replace(html, /%controls%/, controls);
        html = replace(html, /%size%/, size);
        //$(document).trigger("close.facebox");
        $.facebox(html);
    }
    , close: function(action) {
        $(document).trigger("close.facebox");
        switch (action) {
            case 'ok':
                popupDialog.ok_fnc();
                break;
            case 'cancel':
                popupDialog.cancel_fnc();
                break;
            default:
                break;
        }
        return false;
    }

}

function socialCall(value, instanceUid) {
    getGameResult(instanceUid);
}