Null reference error in javascript function
<p>İ want to use this code but when the page opens, I get a null reference error.  When I open the page a second time, this error doesn't occur.</p>

<p>I understand when the site caches, this error doesn't occur.  The error comes from tb_show function. </p>

<p>My code:</p>

<pre><code>&lt;script type="text/javascript"&gt;

    function writeCookie(CookieAdi) {
        var dtGun = 1
        var strValue = "1"
        if (dtGun == null || dtGun == "") dtGun = 365;
        var d = new Date();
        d.setTime(d.getTime() + (dtGun * 24 * 60 * 60 * 1000));
        var zt = "; expires=" + d.toGMTString();
        document.cookie = CookieAdi + "=" + strValue + zt + "; path=/";
    }

    function readCookie(cookieadi) {
        var c = document.cookie;
        if (c.indexOf(cookieadi) != -1) {
            s1 = c.indexOf("=", c.indexOf(cookieadi)) + 1;
            s2 = c.indexOf(";", s1);
            if (s2 == -1) s2 = c.length;
            strValue = c.substring(s1, s2);
            return strValue;
        } 
    }

    writeCookie('OnerFacebook');

    if (readCookie('OnerFacebook') != 1) {
            tb_show('', 'http://www.mobilyala.com/OnerFacebook/?KeepThis=true&amp;TB_iframe=true&amp;height=500&amp;width=300&amp;modal=true', '');
    }

&lt;/script&gt;
</code></pre>

<p>What should I do for it?</p>
