﻿window.onload = function () {
    startload();
}
window.onunload = function(e) { var title = getActiveStyleSheet(); createCookie("style", title, 365); }
function newstyleclick(stylec) { var oVDiv=document.getElementById("currentstyle"); oVDiv.innerHTML = 'theme: ' + stylec; setActiveStyleSheet(stylec);return false;}
function startload() 
{
    dp.SyntaxHighlighter.ClipboardSwf = 'clipboard.swf';
    dp.SyntaxHighlighter.HighlightAll('code');
    var cookie = readCookie("style"); var title = cookie ? cookie : getPreferredStyleSheet(); if (title != 'null') {newstyleclick(title);} else {newstyleclick('bamboo');}; 
    //init map
    map = new VEMap('myMap');
    //run after map is rendered
    map.onLoadMap = function()
    { 
    
        //get data from handler.   
        var s = new SiteHelpers();
        s.GetPinpoints(function(response) { 
        
            //check to make sure not null
            if (response.result != null)
            {
                var description
                //loop through response.
                for ( var i=response.result.length-1; i>=0; --i )
                {
                
                     var latitude = response.result[i].coordinates.split(",")[1];
                     var longitude = response.result[i].coordinates.split(",")[0];

                     //locations.
                     var latlong = new VELatLong(latitude,longitude);
                     var shape = new VEShape(VEShapeType.Pushpin, latlong);
                     
                     //var shape = new VEShape(VEShapeType.Pushpin, map.GetCenter());
                     shape.SetTitle(response.result[i].location);
                     description = response.result[i].iPAddress;
                     shape.SetDescription(description);
                     shape.SetCustomIcon('http://www.aprogrammersjournal.com/theme/base/images/info.png');
                     map.AddShape(shape);
                
                }
            }
            
        }); //end s.GetPinPoints

    }; 
    //render map
    map.LoadMap(new VELatLong(115,-150),1,'r',false);
    
    if (location.href.indexOf("/id/") > 0)
    {
        var frm = document.forms[0];
        frm.action = location.href; 

        //if on article page create captcha.
        Recaptcha.create("6Ld6MwEAAAAAAH8QEZ9uh9aRItPC5O_c6vZL8ldX",
                         "recaptcha_div", {
                         theme: "clean"
                         });
    }
}
function clearText(thefield){
	try {
        if (thefield.defaultValue==thefield.value)
        thefield.value = ""
     } 
    catch(err) {
    }
}
function resetText(thefield){
	try 
    {
        if (thefield.value=='')
        thefield.value = thefield.defaultValue        
     } 
    catch(err) {
    }
}
Ext.onReady(function(){
var win;
var button = Ext.get('dhref');

button.on('click', function(){
    if(!win){
        win = new Ext.Window({
            el:'cacheinfo',
            layout:'fit',
            width:400,
            height:200,
            closeAction:'hide',
            plain: true,
            resizable: false,
            draggable:false,
            
            items: new Ext.Panel({
                collapsible:false,
                width:220,
                header: false,
                border: false,
                contentEl: 'cachetext'
                })
        });
    }
    win.show(this);
});
var win2;
var button2 = Ext.get('uhref');

button2.on('click', function(){
    if(!win2){
        win2 = new Ext.Window({
            el:'mapinfo',
            layout:'fit',
            width:515,
            height:433,
            closeAction:'hide',
            plain: true,
            resizable: false,
            draggable:false,
            
            items: new Ext.Panel({
                collapsible:false,
                width:600,
                header: false,
                border: false,
                contentEl: 'myMap'
                })
        });
    }
    win2.show(this);
});
    var pt = new Ext.Panel({
        title: 'Site Options',
        collapsible:true,
        renderTo: 'container',
        width:220,
        contentEl: 'sop'
        });
    var p = new Ext.Panel({
        title: 'Community Profile',
        collapsible:true,
        renderTo: 'container',
        width:220,
        contentEl: 'cal'
    });
    var p2 = new Ext.Panel({
        title: '<a href="http://www.aprogrammersjournal.com/rss/comments/" target="_blank"><img src="http://www.aprogrammersjournal.com/Theme/Base/images/feed-icon.png" align="absmiddle" /></a>&nbsp;Latest Comments',
        collapsible:true,
        renderTo: 'container',
        width:220,
        contentEl : 'LatestComments'
    });
    var p3 = new Ext.Panel({
        title: '<a href="http://www.codeproject.com/webservices/articlerss.aspx?cat=6" target="_blank"><img src="http://www.aprogrammersjournal.com/Theme/Base/images/feed-icon.png" align="absmiddle" /></a>&nbsp;CodeProject Contributions',
        collapsible:true,
        renderTo: 'container',
        width:220,
        contentEl : 'CodeProject'
    });
    var p4 = new Ext.Panel({
        title: '<a href="http://www.di.fm/partners/xml/playlists.xml" target="_blank"><img src="http://www.aprogrammersjournal.com/Theme/Base/images/feed-icon.png" align="absmiddle" /></a>&nbsp;DI.fm',
        collapsible:true,
        renderTo: 'container',
        width:220,
        contentEl : 'difm'
    });
    var p5 = new Ext.Panel({
        title: '<a href="http://feeds.feedburner.com/neowin-main" target="_blank"><img src="http://www.aprogrammersjournal.com/Theme/Base/images/feed-icon.png" align="absmiddle" /></a>&nbsp;Neowin Headlines',
        collapsible:true,
        renderTo: 'container',
        width:220,
        contentEl : 'neowin'
    });
    var p6 = new Ext.Panel({
        title: 'Links',
        collapsible:true,
        renderTo: 'container',
        width:220,
        contentEl : 'links'
    });
//    var d = new Ext.DatePicker({
//        renderTo: 'cali',
//        width:220
//    });
});