    var username;
    var page = 1;
    var hide = "0";
    var mouseX = 0;
    var mouseY = 0;
    var searchDef = "Type Search Term & Press Enter";
    var search = searchDef;
    var screen_name;
    var arrTags = Array();
    var arrPtags = Array();    
    var orderby = "followerorder desc";

    $(document).ready(function() {

        if (document.getElementById("tz")) {
            document.getElementById("tz").value = GetTimeZone();
        }
        if (document.getElementById("dispName")) {
            document.getElementById("dispNameShow").innerHTML = document.getElementById("dispName").innerHTML;
        }

        if (document.getElementById("topTags")) {
            topTagsGet();
        }
    });

    function disabledcheck(obj) {
        var ret = false;
        if ($(obj).hasClass("disabled")) {
            ret = true;
        }
        return ret;
    }

function kloutShow()
{
    var idlist = "";
    $(".user").each(function() {
        if (idlist.length > 0) {
            idlist += ",";
        }
        idlist += $(this).attr("id");
    });
    Processing(true);
    $.ajax({
        url: "klout.aspx?code=" + escape(code) + "&codeplus=" + escape(codeplus) + "&idlist=" + escape(idlist) + "&screen_name=" + escape(username),
        type: 'GET',
        success: function(response) {
            var klout = eval("(" + response + ")");
            if (klout.users) {
                for(var ctr = 0;ctr < klout.users.length; ctr++)
                {
                    $("#klout_" + klout.users[ctr].twitter_screen_name).html("Klout Score: " + klout.users[ctr].kscore + "<br/>");
                }
            }
        },
        complete: function() {
                Processing(false);
       }         
    });
}



function topTagsGet() {
    $.ajax({
        url: "toptags.aspx",
        type: 'GET',
        success: function(response) {
            $("#topTags").html(response);
        }
    });

}    

function tagListLoad()
{
    $.ajax({
        url:"tags.aspx?code="+escape(code)+"&codeplus="+escape(codeplus)+ "&screen_name=" + escape(username), 
        type: 'GET', 
        success: function(response) {
            var tagList = response;
            if(tagList)
            {
                arrTags = tagList.split(",");
            }
        }
    });
} 

function pTagListLoad()
{
    $.ajax({
        url:"tags.aspx?ptags=true&code="+escape(code)+"&codeplus="+escape(codeplus)+"&screen_name=" + username, 
        type: 'GET', 
        success: function(response) {
            var pTagList = response;
            if(pTagList)
            {
                arrPtags = pTagList.split(",");
            }
        }
    });
} 

    
function autocStart(v){ 
   var a=[];

   if(arrTags)
   {
       for(var i=0;i<arrTags.length;i++) {
         a.push({id:i, value:arrTags[i], info:"", extra:"" });
       }
   }

   return a;
}

function autocpStart(v){ 
   var a=[];

   if(arrPtags)
   {
       for(var i=0;i<arrPtags.length;i++) {
         a.push({id:i, value:arrPtags[i], info:"", extra:"" });
       }
   }

   return a;
}


function autocPrint(obj){ 
    $('#' + obj.id + '_lookup').html('ID: '+obj.id+'<br>VALUE: '+obj.value+'<br>EXTRA: '+obj.extra); 
}


function Processing(prcsOn) {
    if(prcsOn)
    {
        $.blockUI({ message: "<p>Please Wait... </p><p><img src='images/wait.gif' alt='' /></p><p><a href='javascript:void(0)' onclick='$.unblockUI();'>Cancel</a></p>" });
    }
    else {
        $.unblockUI(); 
    }

}
   
    function optionsToggle(obj)
    {
        if(obj.innerHTML == "+options")
        {
            obj.innerHTML = "-options";
            document.getElementById("addlOptions").style.display = "block";
        }
        else
        {
            obj.innerHTML = "+options";
            document.getElementById("addlOptions").style.display = "none";
        }
    }
    
    function blacklistToggle(obj)
    {
        
        if(obj.checked)
        {
            createCookie("blacklist","1",365);
        }
        else
        {
            eraseCookie("blacklist");
        }
        
        document.forms[0].submit();
    
    }
    
    function preview_tweets(link)
    {
        link += '&code='+code+'&codeplus='+codeplus+'&ocode='+ocode+'&username='+username;
        document.getElementById("frmPrev").setAttribute("src",link);
        TagToTip('spnPrev',STICKY, true, CLICKCLOSE, false, CLOSEBTN, true, OFFSETX,-400,OFFSETY,-200);
    }
    

    function selectOrderBy(lnk) {

        orderby = document.getElementById("selOrderBy").options[document.getElementById("selOrderBy").selectedIndex].value;
        if (document.getElementById('search')) {
            document.getElementById('search').value = '';
        }
        refreshPage('followers', 1, '0');
    }
    

    function refreshPage(action, currPage, hideWhat)
    {
        username = escape(document.getElementById("username").value);
        ocode = escape(document.getElementById("ocode").value);
        page = currPage;
        if(hideWhat) {
           hide=hideWhat;
       }
        Processing(true);
        setTimeout('refreshPageDelay("'+ action + '",'+ currPage+',"' + hide + '")',1000);
    }
    function refreshPageDelay(action, currPage, hide)
    {
        var search = "";
        var tz = "0";

        if(document.getElementById("search"))
        {
            search = document.getElementById("search").value;
            if(search == searchDef)
            {
                search = "";
            }
        }
        
        if(document.getElementById("tz"))
        {
            tz = document.getElementById("tz").value;
        }
        var url = 'twitter.aspx?code='+code+'&codeplus='+codeplus+'&ocode='+ocode+'&page='+currPage+'&action='+action+'&username='+username+"&hide=" + hide + "&search=" + search + "&tz=" + tz + "&orderby=" + orderby;

        $.ajax({
            url: url,
            type: 'GET',
            success: function(response) {
                if (action == "login") {
                    if (codeplus.length == 0 && response.length > 0 & response.indexOf("invalid") < 0) {
                        codeplus = response;
                    }
                    refreshPageDelay("followers", 1, 0);
                }
                else {
                    document.getElementById("divMain").innerHTML = response;
                    if (response.length == 0) {
                        document.getElementById("divMain").innerHTML = "An unknown error occurred.  Please click on the <strong>Everyone</strong> menu item to continue.";
                    }
                    Processing(false);
                }
                if (search == "") {
                    search = searchDef;
                }
                if (document.getElementById("search")) {
                    document.getElementById("search").value = search;
                }

            },
            error: function(xhr, status, error) {
                var response = "";
                if (xhr.responseText) {
                    response = xhr.responseText;
                }
                document.getElementById("divMain").innerHTML = response;
                if (response.length == 0) {
                    document.getElementById("divMain").innerHTML = "An unknown error occurred.  Please click on the <strong>Everyone</strong> menu item to continue.";
                }
                Processing(false);
            },
            complete: function() {
                if (action != "login") {
                    Processing(false);
                }
                else {
                    tagListLoad();
                    pTagListLoad();
                }
            }

        });
        if (document.getElementById("divMain").innerHTML.length == 0) {
            document.getElementById("divMain").innerHTML = "An unknown error occurred.  Please click on the <strong>Everyone</strong> menu item to continue.";
        }


    }
    
    function bulkAction()
    {
        var follow = 0;
        var unfollow = 0;
        var sFollow = "";
        var sUnfollow = "";
        $('.bulkCheck').each(function(index) {
            if ($(this).attr('checked')) {
                var args = $(this).attr('value').split("_");
                if (args.length == 3) {
                    if (args[1] == "follow") {
                        follow++;
                    }
                    if (args[1] == "leave") {
                        unfollow++;
                    }
                }
            }
        });
        if(follow == 1)
        {
            sFollow = "1 person";
        }
        else
        {
            sFollow = follow + " people";
        }
        if (unfollow == 1) {
            sUnfollow = "1 person";
        }
        else {
            sUnfollow = unfollow + " people";
        }
        
        //if(confirm("Click 'OK' to Follow " + sFollow + " and Unfollow " + sUnfollow + ".\nSuccess or Failure will be reported below each account."))
        if(confirm("Click 'OK' to Follow " + sFollow + ".\nSuccess or Failure will be reported below each account."))                
        {
            $('.bulkCheck').each(function(index) {
                if ($(this).attr('checked')) {
                    var args = $(this).attr('value').split("_");
                    if (args.length == 3) {
                        action(args[2], args[1]);
                    }
                }
            });
        }
    }


    function action(id, command) {

        if(command.id)
        {
            var cmd_id = command.id;
            if (cmd_id.indexOf("chk_email_") == 0)
            {
                if(command.checked)
                {
                    command = "email_out~1";
                }
                else
                {
                    command = "email_out~0";                
                }
            }
            if (cmd_id.indexOf("chk_phone_") == 0) {
                if (command.checked) {
                    command = "phone_out~1";
                }
                else {
                    command = "phone_out~0";
                }
            }
            if (cmd_id.indexOf("chk_skype_") == 0) {
                if (command.checked) {
                    command = "skype_out~1";
                }
                else {
                    command = "skype_out~0";
                }
            }
        }
        if(command == "ding")
        {
            if(!confirm("Are you sure you want to ding this person?\n\nThis action cannot be reversed."))
            {
                return false;
            }
        }
        if (command == "hide") 
        {
            if (!confirm("Are you sure you want to hide this Follower?\n\nThis action cannot be undone.")) 
            {
                return false;
            }
        }
    
        Processing(true);
        setTimeout('actionDelay("' + id + '","'+command+'")', 500);
    }
    
    function actionDelay(id, action) {
        var url = 'twitter.aspx?code=' + code + '&codeplus=' + codeplus + '&ocode='+ocode+'&action='+action+'&id=' + id + '&username=' + username;
        $.ajax({
            url: url,
            type: 'GET',
            success: function(response) {
                if (response.indexOf("Error Response") >= 0) {
                    document.getElementById("div_" + id + "_msg").innerHTML = "<span style='color:red'>Error</span>";
                }
                else {
                    switch (action) {
                        case "follow":
                            document.getElementById("div_" + id + "_msg").innerHTML = "<span style='color:green'>Following</span>";
                            $("#chk_" + id).hide();
                            $("#follow_" + id).hide();
                            $("#unfollow_" + id).show();
                            break;
                        case "leave":
                            document.getElementById("div_" + id + "_msg").innerHTML = "<span style='color:green'>No longer Following</span>";
                            $("#chk_" + id).show();
                            $("#follow_" + id).show();
                            $("#unfollow_" + id).hide();
                            break;
                        case "block":
                            document.getElementById("div_" + id + "_msg").innerHTML = "<span style='color:green'>Blocked</span>";
                            $("#bl_" + id).hide();
                            $("#unbl_" + id).show();
                            break;
                        case "report":
                            document.getElementById("div_" + id + "_msg").innerHTML = "<span style='color:green'>Blocked and Reported</span>";
                            break;
                        case "hide":
                            document.getElementById("div_" + id + "_msg").innerHTML = "<span style='color:green'>Hidden</span>";
                            break;
                        case "unblock":
                            document.getElementById("div_" + id + "_msg").innerHTML = "<span style='color:green'>Unblocked</span>";
                            $("#bl_" + id).show();
                            $("#unbl_" + id).hide();
                            break;
                        case "ding":
                            if (response == "1") {
                                if (document.getElementById("ding_" + id)) {
                                    document.getElementById("ding_" + id).innerHTML = parseInt(document.getElementById("ding_" + id).innerHTML) + 1;
                                }
                            }
                            if (response == "2") {
                                alert("You want to ding them twice?\n\nWow! They must be REALLY bad.\n\nSorry, but you can only ding them once.");
                            }
                            break;
                        default:
                            document.getElementById("div_" + id + "_msg").innerHTML = "<span style='color:green'>" + response + "</span>";
                            break;

                    }
                }
            },
            error: function(xhr, status, error) {
                document.getElementById("div_" + id + "_msg").innerHTML = "<span style='color:red'>Error</span>";
            },
            complete: function() {
                Processing(false);
            }

        });
    }

    function limitText(limitField, limitNum) {
        if (limitField.value.length > limitNum) {
            limitField.value = limitField.value.substring(0, limitNum);
        }
    }    
    
    function dataUpdate(id) {
        Processing(true);
        setTimeout('dataUpdateDelay("' + id + '")', 500);
    }
    function dataUpdateDelay(id) {
        var tags = document.getElementById('tagsTxt_' + id).value;
        var ptags = document.getElementById('ptagsTxt_' + id).value;
        var notes = document.getElementById('noteTxt_' + id).value;                
        var url = 'twitter.aspx?code=' + code + '&codeplus=' + codeplus + '&ocode=' + ocode + '&action=dataupdate&id=' + id + '&tags=' + escape(tags) + '&ptags=' + escape(ptags) + '&notes=' + escape(notes) + '&username=' + username;
        $.ajax({
            url: url,
            type: 'GET',
            success: function(response) {
                if (response.indexOf("Error Response") >= 0) {
                    document.getElementById("div_" + id + "_msg").innerHTML = "<span style='color:red'>Error</a></span>";
                }
                else {
                    var tagRet = response.split("|");
                    if(tagRet.length == 2)
                    {
                        document.getElementById('tagsTxt_' + id).value = tagRet[0];
                        document.getElementById('ptagsTxt_' + id).value = tagRet[1];                        
                    }
                    document.getElementById("div_" + id + "_msg").innerHTML = "<span style='color:green'>Saved</span>";
                }
                tagListLoad();
                pTagListLoad();
            },
            error: function(xhr, status, error) {
                document.getElementById("div_" + id + "_msg").innerHTML = "Error";
            },
            complete: function() {
                Processing(false);
            }

        });
    }
    
    function tags(id)
    {
        Processing(true);
        setTimeout('tagsDelay("'+ id + '")',500);
    }
    function tagsDelay(id)
    {
        var tags = document.getElementById('tagsTxt_' + id).value;
        var url = 'twitter.aspx?code='+code+'&codeplus='+codeplus+'&ocode='+ocode+'&action=tags&id=' + id + '&tags=' + escape(tags) + '&username=' + username; 
        $.ajax({
            url:url, 
            type: 'GET', 
            success: function(response) {
                if(response.indexOf("Error Response") >= 0)
                {
                   document.getElementById("div_" + id + "_msg").innerHTML = "<span style='color:red'>Error</a></span>"; 
                }
                else
                {
                    document.getElementById('tagsTxt_' + id).value = response;
                    document.getElementById("div_" + id + "_msg").innerHTML = "<span style='color:green'>Saved</span>";
                }
                tagListLoad();
                pTagListLoad();
            }, 
            error: function(xhr, status, error) {
                document.getElementById("div_" + id + "_msg").innerHTML = "Error"; 
            },
            complete: function() {
                Processing(false);
            } 
                        
        });         
    }
    
    function pTags(id)
    {
        Processing(true);
        setTimeout('pTagsDelay("'+ id + '")',500);
    }
    function pTagsDelay(id)
    {
        var tags = document.getElementById('ptagsTxt_' + id).value;
        var url = 'twitter.aspx?code='+code+'&codeplus='+codeplus+'&ocode='+ocode+'&action=ptags&id=' + id + '&ptags=' + escape(tags) + '&username=' + username; 
        $.ajax({
            url:url, 
            type: 'GET', 
            success: function(response) {
                if(response.indexOf("Error Response") >= 0)
                {
                   document.getElementById("div_" + id + "_msg").innerHTML = "<span style='color:red'>Error</a></span>"; 
                }
                else
                {
                    document.getElementById('ptagsTxt_' + id).value = response;
                    document.getElementById("div_" + id + "_msg").innerHTML = "<span style='color:green'>Saved</span>";
                }
                tagListLoad();
                pTagListLoad();
            }, 
            error: function(xhr, status, error) {
                document.getElementById("div_" + id + "_msg").innerHTML = "Error"; 
            },
            complete: function() {
                Processing(false);
            } 
                        
        });         
    }

    function stats(screen_name)
    {
            Processing(true);
            setTimeout('statsDelay("'+ screen_name + '")',500);
    }

    function statsDelay(screen_name)
    {
        var url = 'twitter.aspx?code='+code+'&codeplus='+codeplus+'&action=stats&id=' + screen_name + '&username=' + username; 
        $.ajax({
            url:url, 
            type: 'GET', 
            success: function(response) {
                if(response.indexOf("Followers") >= 0)
                {
                    document.getElementById("stats_" + screen_name).innerHTML = response;
                }
            }, 
            error: function(xhr, status, error) {
                document.getElementById("div_" + id + "_msg").innerHTML = "Error"; 
            },
            complete: function() {
                Processing(false);
            } 
            
        });         
    } 

    function updateStatus(status)
    {
            Processing(true);
            setTimeout('statusDelay("'+ escape(status) + '")',500);
    }

    function statusDelay(status)
    {
        var url = 'twitter.aspx?code='+code+'&codeplus='+codeplus+'&action=status&status=' + status + '&username=' + username;
        $.ajax({
            url:url, 
            type: 'POST', 
            success: function(response) {
                document.getElementById("status").value = "";
                refreshPage('temptweet',1,'0');
            }, 
            error: function(xhr, status, error) {
               document.getElementById("divMain").innerHTML = response; 
            },
            complete: function() {
                Processing(false);
            } 
            
        });         
    } 

  function StatusUpdate()
    {
        var status = DOM("status");
        var statusLen = DOM("statusLen");
        statusLen.innerHTML = 140 - status.value.length;
    }
    function DOM(id)
    {
        var obj = null;
        
        if(document.getElementById(id))
        {
           obj = document.getElementById(id);
        }

        return obj;
    }

   
var _rulesAdded = false;

function ShowWindow()
{
	$$('modalWindow').style.display = $$('modalBackground').style.display = 'block';

	// special < IE7 -only processing for windowed elements, like select	
	if (window.XMLHttpRequest == null)
	{
		var type = $$('hideType').value;
		
		if (type == 'iframe')
			$$('modalIframe').style.display = 'block';
		if (type == 'replace')
			ReplaceSelectsWithSpans();
	}

	// call once to center everything
	OnWindowResize();
	
	if (window.attachEvent)
		window.attachEvent('onresize', OnWindowResize);
	else if (window.addEventListener)
		window.addEventListener('resize', OnWindowResize, false);
	else
		window.onresize = OnWindowResize;
	
	// we won't bother with using javascript in CSS to take care
	//   keeping the window centered
	if (document.all)
		document.documentElement.onscroll = OnWindowResize;
}

function OnWindowResize()
{
	// we only need to move the dialog based on scroll position if
	//   we're using a browser that doesn't support position: fixed, like < IE 7
	var left = window.XMLHttpRequest == null ? document.documentElement.scrollLeft : 0;
	var top = window.XMLHttpRequest == null ? document.documentElement.scrollTop : 0;
	var div = $$('modalWindow');
	
	div.style.left = Math.max((left + (GetWindowWidth() - div.offsetWidth) / 2), 0) + 'px';
	div.style.top = Math.max((top + (GetWindowHeight() - div.offsetHeight) / 2), 0) + 'px';
}

function HideWindow()
{
	$$('modalWindow').style.display = $$('modalBackground').style.display = 'none';
	
	// special IE-only processing for windowed elements, like select	
	if (document.all)
	{
		var type = $$('hideType').value;
		
		if (type == 'iframe')
			$$('modalIframe').style.display = 'none';
		if (type == 'replace')
			RemoveSelectSpans();
	}
	
	if (window.detachEvent)
		window.detachEvent('onresize', OnWindowResize);
	else if (window.removeEventListener)
		window.removeEventListener('resize', OnWindowResize, false);
	else
		window.onresize = null;
}

/* These functions deal with IE's retardedness in not allowing divs to 
 * cover select elements by replacing the select elements with spans. */

function RemoveSelectSpans()
{
    var selects;
    if(document.getElementsByTagName('select'))
    {
	    selects = document.getElementsByTagName('select');
	}
	
	for (var i = 0; i < selects.length; i++)
	{
		var select = selects[i];
		
		if (select.clientWidth == 0 || select.clientHeight == 0 || 
			select.nextSibling == null || select.nextSibling.className != 'selectReplacement')
		{
			continue;
		}
			
		select.parentNode.removeChild(select.nextSibling);
		select.style.display = select.cachedDisplay;
	}
}

function ReplaceSelectsWithSpans()
{
	var selects 
	
	if(document.getElementsByTagName('select'))
	{
	    selects = document.getElementsByTagName('select');
	}
	
	for (var i = 0; i < selects.length; i++)
	{
		var select = selects[i];
		
		if (select.clientWidth == 0 || select.clientHeight == 0 || 
			select.nextSibling == null || select.nextSibling.className == 'selectReplacement')
		{
			continue;
		}
			
		var span = document.createElement('span');
		
		// this would be "- 3", but for that appears to shift the block that contains the span 
		//   one pixel down; instead we tolerate the span being 1px shorter than the select
		span.style.height = (select.clientHeight - 4) + 'px';
		span.style.width = (select.clientWidth - 6) + 'px';
		span.style.display = 'inline-block';
		span.style.border = '1px solid rgb(200, 210, 230)';
		span.style.padding = '1px 0 0 4px';
		span.style.fontFamily = 'Arial';
		span.style.fontSize = 'smaller';
		span.style.position = 'relative';
		span.style.top = '1px';
		span.className = 'selectReplacement';
		
		span.innerHTML = select.options[select.selectedIndex].innerHTML + 
			'<img src="custom_drop.gif" alt="drop down" style="position: absolute; right: 1px; top: 1px;" />';
		
		select.cachedDisplay = select.style.display;
		select.style.display = 'none';
		select.parentNode.insertBefore(span, select.nextSibling);
	}
}

/* The following two functions are not used, but have been kept here because 
 *   they might be useful; one must use this method to programmatically add
 *   javascript-valued CSS values (using element.style.div = expresssion(...)
 *   does not work).  These are only useful for IE.
 */

function AddStyleRules()
{
	if (_rulesAdded)
		return;
		
	_rulesAdded = true;

	var stylesheet = document.styleSheets[document.styleSheets.length - 1];
	
	if (!document.all)
	{
		InsertCssRule(stylesheet, '#modalBackground', 'position: fixed; height: 100%; width: 100%; left: 0; top: 0;');		
		InsertCssRule(stylesheet, '#modalWindow', 'position: fixed; left: 0; top: 0;');		
	}
	else
	{
		InsertCssRule(stylesheet, '#modalBackground', 
			'position: absolute; ' +
			'left: expression(ignoreMe = document.documentElement.scrollLeft + "px"); ' +
			'top: expression(ignoreMe = document.documentElement.scrollTop + "px");' +
			'width: expression(document.documentElement.clientWidth + "px"); ' +
			'height: expression(document.documentElement.clientHeight + "px");');

		InsertCssRule(stylesheet, '#modalWindow', 
			'position: absolute; ' +
			'left: expression(ignoreMe = document.documentElement.scrollLeft + "px"); ' +
			'top: expression(ignoreMe = document.documentElement.scrollTop + "px");');

	}
}

function InsertCssRule(stylesheet, selector, rule)
{
	if (stylesheet.addRule)
	{
		stylesheet.addRule(selector, rule, stylesheet.rules.length);
		return stylesheet.rules.length - 1;
	}
	else
	{
		stylesheet.insertRule(selector + ' {' + rule + '}', stylesheet.cssRules.length);
		return stylesheet.cssRules.length - 1;
	}
}



/* utiltiy functions */

function GetWindowWidth()
{
	var width =
		document.documentElement && document.documentElement.clientWidth ||
		document.body && document.body.clientWidth ||
		document.body && document.body.parentNode && document.body.parentNode.clientWidth ||
		0;
		
	return width;
}

function GetWindowHeight()
{
    var height =
		document.documentElement && document.documentElement.clientHeight ||
		document.body && document.body.clientHeight ||
  		document.body && document.body.parentNode && document.body.parentNode.clientHeight ||
  		0;
  		
  	return height;
}

function $$(id)
{
	return document.getElementById(id);
}


function checkEnter(e){ 
    var characterCode 

    if(e && e.which){ 
        e = e;
        characterCode = e.which;
    }
    else{
        e = event;
        characterCode = e.keyCode;
    }

    if(characterCode == 13){ 
        refreshPage('login',1,'0'); 
        return false 
    }
    else{
        return true 
    }

}

function checkBulkToggle(obj)
{
    if(obj.innerHTML == "Select All")
    {
        $('.bulkCheck').attr('checked', 'checked');
        obj.innerHTML = "Deselect All";
    }
    else
    {
        $('.bulkCheck').removeAttr('checked');
        obj.innerHTML = "Select All";
    }
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

function TinyUrlCreate()
{
    var status = DOM("status").value;

    if(status.indexOf("http") >= 0)
    {
        var start = status.indexOf("http");
        var finish = status.indexOf(" ",start);
        if(finish < 0)
        {
           finish = status.length;
        }
        var in_url = status.substr(start, finish - start);
        var url = 'temptweet.aspx'; 
        $.ajax({
            url:url,
            data: {url_in: in_url },
            type: 'POST', 
            success: function(response){
            if(response != "Error")
            {
                DOM("status").value = status.replace(in_url,transport.responseText);
            }
            else
            {
                alert("The TinyUrl process failed.");
            }
        },
        error: function(transport){alert("The TinyUrl process failed.");
        }
        }); 
    }
}

/* GetTimeZone returns the client's UTC time zone offset. */
function GetTimeZone(){
	var tzostring;
	// tzo will be the return value.
	var tzo = "";
	var tzoarr
	//create a new date object, and use it to get the UTC Timezone Offset.
	var d = new Date();

	/* getTimezoneOffset returns the number of minutes
	   difference between Greenwich Mean Time (UTC Time) and the client's time.
		 Divide the result by 60 to get the hours offset. */
	tzostring = (d.getTimezoneOffset()/60).toString();
	
	/* For some reason, the getTimeZoneOffset gives a negative number where
	   there should be a positive, and vice-versa. So, if the result contains a negative(-) sign, 
		 prefix the return value with a plus(+) and vice versa. */
	if (tzostring.indexOf("-") > -1){
		tzostring = tzostring.replace("-", "");
		tzo += "+";
	}
	else {
		tzo += "-";
	}

/* Next, search for a decimal point. If one exists, use split() 
	   to create an array of values on each side of the decimal point. */
	if (tzostring.indexOf(".") > 0){
		// split tzostring into an array.
		tzoarr = tzostring.split(".");
		
		/* append tzo[0] (everything to the left of the decimal point)
		   to tzo. PadWithZero will pad if neccesary. */
		tzo += PadWithZero(tzoarr[0]);
		
		/* Convert tzoarr[1] (everything to the right of the decimal point)
		   from base 10 to base 60 (e.g., from 5.75, the 75 would become 45). 
			 This is necessary because the timezoneOffset value for Kathmandu would be -5.75,
			 which has to be converted to +0545 to be valid as an RFC-822 timezone offset. */
		if (parseInt(tzoarr[1]) == 5){
			tzo += "30";
		}
		else if(parseInt(tzoarr[1]) == 75){
			tzo += "45";
		}
		else if(parseInt(tzoarr[1]) == 25){
			tzo += "15";
		}
	}
	else {
		// If no decimal points, just append tzostring to tzo, and tack on 2 zeros at the end
		tzo += PadWithZero(tzostring) + "00";
	}
	return tzo;
}

/* PadWithZero returns "0" + val if the number 
   is less than 10 and greater than -1.
	 Parameter: any integer. */
function PadWithZero(val){
	val = parseInt(val)
	if (val < 10 && val > -1){
		return "0" + val;
	}
	return val;
}