﻿function HideDiv(strDiv, strQuery)
{
    document.getElementById(strDiv).style.display = "none";
    document.getElementById(strDiv).childNodes[0][1].value = decodeURIComponent(strQuery);
}

function ToggleDiv(strDiv) {
    oCustomDiv = document.getElementById(strDiv);
    if (oCustomDiv.style.display == "block") {
        oCustomDiv.style.display = "none";
    }
    else
        oCustomDiv.style.display = "block";
}

    
function EmbedVideo(strLink, strVidID, strSize)
{
    var oDiv = document.getElementById(strLink);
    if (strSize == "BIG") {
        oDiv.innerHTML = "<object width=\"400\" height=\"250\"><param name=\"movie\" value=\"http://www.youtube-nocookie.com/v/" + strVidID + "&hl=en&fs=1&rel=0&color1=0x234900&color2=0x4e9e00\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube-nocookie.com/v/" + strVidID + "&hl=en&fs=1&rel=0&color1=0x234900&color2=0x4e9e00\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"400\" height=\"250\"></embed></object>";
        oDiv.style.width = "400px";
        oDiv.style.height = "250px";
        document.getElementById(strLink + "Complete").style.height = "260px";
    }
    else if (strSize == "SMALL")
        oDiv.innerHTML = "<object width=\"134\" height=\"100\"><param name=\"movie\" value=\"http://www.youtube-nocookie.com/v/" + strVidID + "&hl=en&fs=1&rel=0&color1=0x234900&color2=0x4e9e00\"></param><param name=\"allowFullScreen\" value=\"true\"></param><param name=\"allowscriptaccess\" value=\"always\"></param><embed src=\"http://www.youtube-nocookie.com/v/" + strVidID + "&hl=en&fs=1&rel=0&color1=0x234900&color2=0x4e9e00\" type=\"application/x-shockwave-flash\" allowscriptaccess=\"always\" allowfullscreen=\"true\" width=\"134\" height=\"100\"></embed></object>";
}

function UpdateChCounter(textarea, idCounter)
{
    var oCounter = document.getElementById(idCounter);
    var oButton = document.getElementById("Update");
    var iLength = textarea.value.length;
    
    if (140-iLength < 0)
    {
        oCounter.style.color = "red";
        oButton.disabled = true;
    }
    else
    {
        oCounter.style.color = "gray";
        oButton.disabled = false;
    }
    oCounter.innerHTML = (140-iLength).toString();
}

function Tooltip(value, tipID)
{
    oTip = document.getElementById(tipID);
    
    if (oTip.innerHTML == "")
        oTip.innerHTML = value + " tweets - click to drill in";
    else
        oTip.innerHTML = "";
}

function LoadContent(iPage, maxID) 
{
    document.getElementById("MoreButton").innerHTML = "<img style='border: none' src='/img/wait.gif'>";
    var strUrl = "/moretweets.aspx?page=" + iPage.toString();
    if (maxID != "")
        strUrl += "&max_id=" + maxID;
   $("#TweetHtml" + iPage.toString()).load(strUrl);
}

function LoadDirPeople(iIndex, strQuery) 
{
    document.getElementById("MoreDirButton").innerHTML = "<img style='border: none' src='/img/wait.gif'>";
    var strUrl = "/morepeople.aspx?dindex=" + iIndex.toString();
    if (strQuery != null && strQuery != "")
        strUrl += "&query=" + strQuery;
   $("#DirHtml" + iIndex.toString()).load(strUrl);
}

function LoadSugPeople(iIndex, strQuery) 
{
    document.getElementById("MoreSugButton").innerHTML = "<img style='border: none' src='/img/wait.gif'>";
    var strUrl = "/morepeople.aspx?sindex=" + iIndex.toString();
    if (strQuery != null && strQuery != "")
        strUrl += "&query=" + strQuery;
   $("#SugHtml" + iIndex.toString()).load(strUrl);
}

function LoadResultPeople(iIndex, strQuery) 
{
    document.getElementById("MoreResultButton").innerHTML = "<img style='border: none' src='/img/wait.gif'>";
    var strUrl = "/morepeople.aspx?index=" + iIndex.toString();
    if (strQuery != null && strQuery != "")
        strUrl += "&query=" + encodeURIComponent(strQuery);
   $("#ResultHtml" + iIndex.toString()).load(strUrl);
}

function DropCookie()
{
    var date = new Date();
    var ms = date.getTime();
    ms = ms + 300000; // add 5 minutes
    date.setTime(ms);
    strDateExpiration = date.toUTCString();
    document.cookie = "url=" + window.location.href + "; expires=" + strDateExpiration;
}

// global
var clckTimeOut = null; 
var map=null;
var g_strLatLong = null;

function loadScript() {
    var script = document.createElement("script");
    script.type = "text/javascript";
    if (window.location.host.indexOf("crowdeye.com") >= 0)
        script.src = "http://maps.google.com/maps?file=api&v=2&key=ABQIAAAADvZj5I_09Ek-PPrMA6WbmhRL06r-09Tp00g2ue7ZpTgFCEWAahQKWEbyC2TjWjQDdSRorVKnSV8xZQ&async=2&callback=loadMap";
    else
        script.src = "http://maps.google.com/maps?file=api&v=2&key=ABQIAAAADvZj5I_09Ek-PPrMA6WbmhR75HMjITR22zc7VXwpyaZqcbFQFBQdVPUDJhMFL6PNkZ9zlFZ8FLV81Q&async=2&callback=loadMap";
    document.body.appendChild(script);
}

function UnloadMap() {
    document.getElementById("MapControls").style.display = "none";
    if (map != null)
    {
        document.getElementById("latlongmap").value = "";
        GUnload();
    }
}

function ShowMap(strLatLong, strCity) {
    if (strCity == null || strCity == "")
        g_strLatLong = strLatLong;
    else
        g_strLatLong = null;
    loadScript();
}

function loadMap() {
    if (document.getElementById("map_canvas")) {
        document.getElementById("MapControls").style.display = "block";
        if (GBrowserIsCompatible()) {
            map = new GMap2(document.getElementById("map_canvas"));
            if (g_strLatLong != null && g_strLatLong != "") {
                strLatLong = decodeURIComponent(g_strLatLong);
                map.setCenter(GLatLng.fromUrlValue(strLatLong), 8);
            }
            else
                map.setCenter(new GLatLng(39.504041, -96.328125), 2);
            map.setUIToDefault();

            if (g_strLatLong != null && g_strLatLong != "")
                AddPointToMap(map, GLatLng.fromUrlValue(strLatLong));

            GEvent.addListener(map, 'dblclick', MapDblClick); // Add a click listener
            GEvent.addListener(map, 'click', MapClick); // Add a click listener
        }
        else {
            document.getElementById("map_canvas").innerHTML = "<h1>Browser not compatible with Google Maps. Sorry...</h1>";
        }
    }
} 

function MapClick(ol, latlon)
{
    clckTimeOut = window.setTimeout(function(){MapSingleClick(ol,latlon)},500);
}

function MapDblClick(ol,latlon) 
{ 
	window.clearTimeout(clckTimeOut);
	clckTimeOut = null;
} 

function MapSingleClick(ol, latlon) 
{
    if (clckTimeOut)
    {
        map.clearOverlays();
        AddPointToMap(map, latlon); 
    }    
    window.clearTimeout(clckTimeOut); 
    clckTimeOut = null; 
} 

function AddPointToMap(map, point)
{
    map.addOverlay(new GMarker(point)); 
	document.getElementById("latlongmap").value = point.toUrlValue();
}

function SelectACity(strLatLong) 
{
    document.getElementById("latlongcity").value = strLatLong;
    document.CityForm.submit();
}

function ShowLinks(strDiv)
{
    oLink = document.getElementById(strDiv).style.display = "none"; 
    oCustomDiv = document.getElementById(strDiv + "s");
    oCustomDiv.style.display = "block";
}
