﻿function hov(loc,cls)
{
	if(loc.className)
		loc.className=cls;
}

function CheckForEnter(myfield, evt, butonId)
{
    var keycode;

    if (window.event)
        keycode = window.event.keyCode;
    else if (evt)
        keycode = evt.which;
    else
        return true;

    if (keycode == 13)
    {
       document.getElementById(butonId).click();
       return false;
    }
    else
       return true;
}

function IsEnter(myfield, evt)
{
    var keycode;

    if (window.event)
        keycode = window.event.keyCode;
    else if (evt)
        keycode = evt.which;
    else
        return false;

    if (keycode == 13)
    {
       return true;
    }
    else
       return false;
}

function FillInDate()
{
    var date = new Date();
    document.getElementById('dateLabel').innerText = date.toDateString();
}

function TestUrl(url)
{
    window.open(url, '_blank');
}

function FixUrl(url)
{
    if (url.indexOf("http") != 0)
        url = "http://" + url;
        
    return url;
}

function SetCaretAtEnd(obj)
{
    obj.focus();
    
    if (obj.createTextRange)
    {
        var range = obj.createTextRange();
        range.collapse(false);
        range.select();
    }
    else if (obj.setSelectionRange)
    {
        obj.focus();
        var length = obj.value.length;
        obj.setSelectionRange(length, length);
    }
}

function SetCaretAtStart(obj)
{
    if (obj.createTextRange)
    {
        var range = obj.createTextRange();
        range.collapse(true);
        range.select();
    }
    else if (obj.setSelectionRange)
    {
        obj.focus();
        obj.setSelectionRange(0, 0);
    }
}

function UpdateVoteUI(arg, context)
{
    var questionTd = document.getElementById(context);
    questionTd.innerHTML = arg;
    questionTd.className = "results";
   
    if (document.getElementById('affinityFrame'))
    {
        document.getElementById('affinityFrame').src = "affinity.aspx";
        affinityFrame.document.location.reload();
    }
}

function UpdateRatingUI(arg, context)
{
    var ratingAnchor = document.getElementById(context);
    ratingAnchor.className = "mocklinkHilight";
    ratingAnchor.innerText = "rating saved!";
}

function UpdateAddFavUI(arg, context)
{
    var ratingAnchor = document.getElementById(context);
    ratingAnchor.className = "mocklinkHilight";
    ratingAnchor.innerText = "added to favorites!";
}

function ReloadUI(arg, context)
{
    window.location.reload();
}
