var gl_DefaultButton = null;

document.onkeyup= KeyCheck;

function KeyCheck(e)
{
	var KeyID = (window.event) ? event.keyCode : e.keyCode;
	
	if (KeyID == 13)
	{	
		if (e)
			e.returnValue = false;
		return OnClickDefaultButton();	
	}
}

function displayPopup(url, height, width) 
{
	properties = "toolbar=0,location=0,scrollbars=1,height=" + height;
	properties = properties + ",width=" + width;
	properties = properties + ",left=0,top=0";
	popupHandle = open(url, "tipwindow", properties);
}

function SetDefaultButton(ctlFocus)
{
    gl_DefaultButton = ctlFocus;    
}

function OnClickDefaultButton()
{	
    if (gl_DefaultButton == null)
	{		
		return false;
	}
	else
	{	
		// document.getElementById(gl_DefaultButton).click();	
		return false;
	}
}


/* PROFILE AND PICTURE METHODS */

function over(strng) {
  photo.innerHTML = strng; 
  window.event.srcElement.style.color = "#FFFF00"
}


//This is the function to change text: 
function htmlChange(id, message, bg)
{ 
    d=document; 
    re=d.all?d.all[id]:getElementById(id); 
    re.innerHTML=message; 
    re.style.background = "url("+bg+")"; 
} 

function HiLite_On(id)
{
    d=document; 
    re=d.all?d.all[id]:getElementById(id); 
    re.style.borderLeft="#c0c0e5 3px solid"; 
    re.style.borderRight="#8580c5 3px solid"; 
    re.style.borderTop="#c0c0e5 3px solid"; 
    re.style.borderBottom="#8580c5 3px solid"; 
}

function HiLite_Off(id)
{
    d=document; 
    re=d.all?d.all[id]:getElementById(id); 
    re.style.borderLeft="#c0c0e5 2px solid"; 
    re.style.borderRight="#a2a0d5 2px solid"; 
    re.style.borderTop="#c0c0e5 2px solid"; 
    re.style.borderBottom="#a2a0d5 2px solid"; 
}

// Open a page in a popup window -->
function MM_openBrWindow(theURL,winName,features) 
{
    //v2.0
    window.open(theURL,winName,features);
}

function FormatDateCasual(d) {
    var d_names = new Array("Sun", "Mon", "Tue",
        "Wed", "Thr", "Fri", "Sat");

    var m_names = new Array("Jan", "Feb", "Mar",
        "Apr", "May", "Jun", "Jul", "Augt", "Sep",
        "Oct", "Nov", "Dec");

    var curr_day = d.getDay();
    var curr_date = d.getDate();
    var sup = "";
    if (curr_date == 1 || curr_date == 21 || curr_date == 31) {
        sup = "st";
    }
    else if (curr_date == 2 || curr_date == 22) {
        sup = "nd";
    }
    else if (curr_date == 3 || curr_date == 23) {
        sup = "rd";
    }
    else {
        sup = "th";
    }

    var curr_month = d.getMonth();
    var curr_year = d.getFullYear();

    return d_names[curr_day] + " " + m_names[curr_month] + " " + curr_date + sup +  " " + curr_year;
}

function LocalizeTimes() 
{   
    var timeLocal = new Date();
    var localOffset = timeLocal.getTimezoneOffset();
    
    
    // alert('LocalizeTimes, GMT offset = ' + dateObj.getTimezoneOffset());
    $telerik.$(".LocalTime").each(function() {
    var adjustedTime = new Date($telerik.$(this).text());
        adjustedTime.setMinutes(adjustedTime.getMinutes()-localOffset); //(adjstedTime.getMilliseconds + localOffset);
        $telerik.$(this).text(adjustedTime.format("h:mm tt"));
    });

    $telerik.$(".LocalDate").each(function() {
    var adjustedTime = new Date($telerik.$(this).text());
        adjustedTime.setMinutes(adjustedTime.getMinutes() - localOffset); //(adjstedTime.getMilliseconds + localOffset);
        $telerik.$(this).text(FormatDateCasual(adjustedTime));
    });   
}

function SetLocalTimeOffsetCookie(CookieName)
{
    var rightNow = new Date();
    var date1 = new Date(rightNow.getFullYear(), 0, 1, 0, 0, 0, 0);
    var temp = date1.toGMTString();
    var date2 = new Date(temp.substring(0, temp.lastIndexOf(" ") - 1));
    var hoursDiffStdTime = (date1 - date2) / (1000 * 60 * 60);
    createCookie(CookieName, hoursDiffStdTime, 0);
}

function createCookie(name, value, days) 
{
    if (days && days > 0) 
    {
        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;
}
