﻿// Dom Work
function NewWindow(mypage,myname,w,h,scroll)
{    
    var win = null;
    LeftPosition = (screen.width) ? (screen.width-w)/2 : 0;    
    TopPosition = (screen.height) ? (screen.height-h)/2 : 0;    
    settings='height='+h+',width='+w+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',resizable';
    win = window.open(mypage,myname,settings);    
    if(win.window.focus){win.window.focus();}  
}

function Cover(bottom, top, ignoreSize) {
    var location = Sys.UI.DomElement.getLocation(bottom);
    top.style.position = 'absolute';
    top.style.top = location.y + 'px';
    top.style.left = location.x + 'px';
    if (!ignoreSize) {
        top.style.height = bottom.offsetHeight + 'px';
        top.style.width = bottom.offsetWidth + 'px';
    }
}

// Bookmarklet
function bookmarksite(title, url){
    if (document.all)
        window.external.AddFavorite(url, title);
    else if (window.sidebar)
        window.sidebar.addPanel(title, url, "")
}

// Cookie settings
function getCookie(c_name)
{
    if (document.cookie.length > 0)
    {
        c_start = document.cookie.indexOf(c_name + "=");
        if (c_start != -1)
        { 
            c_start = c_start + c_name.length + 1 ;
            c_end = document.cookie.indexOf(";", c_start);
            if (c_end == -1) 
                c_end = document.cookie.length;
            
            return unescape(document.cookie.substring(c_start,c_end));
        } 
    }
    return "";
}    

function setCookie(c_name, c_value, c_days)
{
	if (c_days) {
		var date = new Date();
    	date.setTime(date.getTime() + (c_days*24*60*60*1000));
	    var expires = "; expires=" + date.toGMTString();
    } else {
        var expires = "";
    }

    document.cookie = c_name + "=" + escape(c_value) + expires + "; path=/";
}    

function eraseCookie(c_name) {
	createCookie(c_name, "", -1);
}

function showBranch(branch) {
    var objBranch = document.getElementById(branch);
	
    if (objBranch != null) {
	    if(objBranch.style.display == 'block')
		    objBranch.style.display = 'none';
	    else 
		    objBranch.style.display = 'block';
    }
}

function clickButton(e, buttonid){
    var evt = e ? e : window.event;
    var bt = document.getElementById(buttonid);

    if (bt){
        if (evt.keyCode == 13){
            bt.click();
            return false;
        }
    }
}

function checkArticlesUserCookie()
{
    if (document.getElementById('divInsiderOn') != null && document.getElementById('divInsiderOff') != null) {
        var ArticlesUserId = getCookie('ArticlesUserId');

        if (ArticlesUserId != null && ArticlesUserId != "")
            document.getElementById('divInsiderOn').style.display = 'block';
        else 
            document.getElementById('divInsiderOff').style.display = 'block';
    }
}
