﻿//Script for SEO
var _sf_startpt = (new Date()).getTime();
      
function isNumberKey(event, obj) {
    var keyCode = event.keyCode;
    if (keyCode == 0)
        keyCode = event.which;
    

    if ((keyCode >= 49 && keyCode <= 57) || keyCode == 46 || keyCode == 13) {
        return true;
    }
    else if ((keyCode >= 97 && keyCode <= 122) || (keyCode >= 65 && keyCode <= 90) || keyCode == 32) {
        return false;
        if (keyCode == 46) {
            var text;

            text = obj.value.toString();

            if (text.toString().indexOf(".") != -1) {
                return false;
            }
        }
    }
    else {
        return GetDefault(event);
    }
    return true;
}

    function isCharacter(event, obj) {
    var keyCode = event.keyCode;
    if (keyCode == 0)
        keyCode = event.which;
    

    if ((keyCode >= 49 && keyCode <= 57) ) {
        return false;
    }
    else if ((keyCode >= 97 && keyCode <= 122) || (keyCode >= 65 && keyCode <= 90) || keyCode == 32 || keyCode == 46 || keyCode == 13) {
        return true;
        if (keyCode == 46) {
            var text;

            text = obj.value.toString();

            if (text.toString().indexOf(".") != -1) {
                return false;
            }
        }
    }
    else {
        return GetDefault(event);
    }
    return true;
}

function url_validate(userUrl)
{

    var regUrl = /^(((ht|f){1}(tp:[/][/]){1})|((www.){1}))[-a-zA-Z0-9@:%_\+.~#?&//=]+$/;
    if(regUrl.test(userUrl) == false)
    {
        document.getElementById("status").innerHTML = "Website URL is not valid yet.";
    }
    else
    {
        document.getElementById("status").innerHTML = "You have entered a valid website URL!";
    }
}


function ValidateImageExt() {

    var Upload_Image = document.getElementById('<%= imgAttch.ClientID %>');
    var myfile = Upload_Image.value;
    if (myfile.indexOf("jpg") > 0 || myfile.indexOf("gif") > 0 || myfile.indexOf("bmp") > 0 || myfile.indexOf("png") > 0 || myfile.indexOf("tiff") > 0) {
        return true;
    }
    else {
        return false;
    }

}

 //Page Load
$(document).ready(function () {

    //Gets the anchor and assign the click event
    $("a[id*='aTopicViewAll']").click(function () {

        //Show the topic link
        if ($("li[TopicLink='Y']").length > 0) {
            $("li[TopicLink='Y']").slideDown();
            $("li[TopicLink='Y']").attr('TopicLink', 'N');
            $("a[id*='aTopicViewAll']").html('Show 10 Topics');
        }
        else {
            $("li[TopicLink='N']").slideUp();
            $("li[TopicLink='N']").attr('TopicLink', 'Y');
            $("a[id*='aTopicViewAll']").html('View All');
        }
    });

    //Assign color
    AssignColor();
    //Assign random tweet
    AssignRandomTweet();    
});

//Assign color to the box
function AssignColor() {
    $("img[ImgResult='Y']").each(function () {
        $(this).width($(this).attr("Result") * 2);
    });
}

//Declare to keep the counter
// 6 is static because there are 21 options & index starts from 0 so 7-1 = 6
var timer = Math.floor(Math.random() * 6);
//Assign random tweet
function AssignRandomTweet() {

//Vivek Kundra - http://twitter.com/vivekkundra
//Aneesh Chopra - http://twitter.com/askaneesh
//Andrea Di Maio - http://twitter.com/AndreaDiMaio
//White House - http://twitter.com/whitehouse
//Shawn McCarthy - http://twitter.com/Shawn_McCarthy
//Linda Cureton - http://twitter.com/curetonl
//NASA - http://twitter.com/nasa

//@Microsoft_Gov - http://twitter.com/microsoft_gov
//Dr. Mark Drapeau - http://twitter.com/cheeky_geeky
//Alec J Ross - http://twitter.com/alecjross
//NextGov - http://twitter.com/nextgov
//GCN - http://twitter.com/govcomputernews
//Chris Dorobek - http://twitter.com/cdorobek
//Alex Howard - http://twitter.com/digiphile

//Joe Trippi - http://twitter.com/joetrippi
//GovTwit - http://twitter.com/govtwit
//Nick Hoover - http://twitter.com/iweeknick
//Patrick Thibodeau - http://twitter.com/DCgov
//GovLoop - http://twitter.com/govloop
//FedScoop - http://twitter.com/fedscoop

//var list1 = [ "vivekkundra"
//            , "askaneesh"
//            , "AndreaDiMaio"
//            , "whitehouse"
//            , "Shawn_McCarthy"
//            , "curetonl"
//            , "nasa" ] ;

//var list2 = [ "microsoft_gov"
//            , "cheeky_geeky" 
//            , "alecjross" 
//            , "nextgov" 
//            , "govcomputernews" 
//            , "cdorobek" 
//            , "digiphile" ];

//var list3 = [ "joetrippi"
//            , "govtwit" 
//            , "iweeknick" 
//            , "DCgov" 
//            , "govloop" 
//            , "fedscoop" ];


//    var list1Val = list1[Math.floor(Math.random()*list1.length)] 
//    var list2Val = list2[Math.floor(Math.random()*list2.length)] 
//    var list3Val = list3[Math.floor(Math.random()*list3.length)] 

    var list = [ "vivekkundra"
            , "askaneesh"
            , "AndreaDiMaio"
            , "whitehouse"
            , "Shawn_McCarthy"
            , "curetonl"
            , "nasa" 
            , "microsoft_gov"
            , "cheeky_geeky" 
            , "alecjross" 
            , "nextgov" 
            , "govcomputernews" 
            , "cdorobek" 
            , "digiphile" 
            , "joetrippi"
            , "govtwit" 
            , "iweeknick" 
            , "DCgov" 
            , "govloop" 
            , "fedscoop"
            , "vivekkundra" 
             ];// Repeated from top to show him because we wanted to have a 21 number array            
             
    var indexer = ((timer + 1) * 3);        
    ShowTweet( "tweet1" , list[indexer - 3] );
    ShowTweet( "tweet2" , list[indexer - 2] );
    ShowTweet( "tweet3" , list[indexer - 1] );

//    //Refresh every 60 seconds
//    timer = timer + 1;
//    if( timer > 6 )
//    {
//        timer = 0;
//    }
//    setTimeout("AssignRandomTweet();" , 60000);
}

function ShowTweet(_div , _account)
{
    $("#"+ _div).html("");
    $("#"+ _div).tweet({
        join_text: "auto",
        username: _account,
        avatar_size: 48,
        count: 1,
//        auto_join_text_default: "we said,",
//        auto_join_text_ed: "we",
//        auto_join_text_ing: "we were",
//        auto_join_text_reply: "we replied",
//        auto_join_text_url: "we were checking out",
    auto_join_text_default: "",
        auto_join_text_ed: "",
        auto_join_text_ing: "",
        auto_join_text_reply: "",
        auto_join_text_url: "",
        loading_text: "Loading tweets..."
    });
}

