function getElementsByClassName(classname, node) {
    if (!node) node = document.getElementsByTagName("body")[0];
    var a = [];
    var re = new RegExp('\\b' + classname + '\\b');
    var els = node.getElementsByTagName("*");
    for (var i = 0, j = els.length; i < j; i++)

        if (re.test(els[i].className)) a.push(els[i]);
    return a;
}

function getPos(elm) {
    for (var zx = zy = 0; elm != null; zx += elm.offsetLeft, zy += elm.offsetTop, elm = elm.offsetParent);
    return { x: zx, y: zy }
}

function getPageWidth() {
    return window.innerWidth != null ? window.innerWidth : document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth : document.body != null ? document.body.clientWidth : null;
}

function popupDialog(pageUrl, cName, cValue) {
    //Check for cookie - if yes do not popup dialog
    //NOTE the title parm will not work without the width parm
    if (popOrNot(cName, cValue)) { 
	    SP.UI.ModalDialog.showModalDialog({ 
            url: pageUrl, 
            title: ' ',
            width: 700, 
            height: 527,                                
            showClose: true,  
            allowMaximize: false,
            dialogReturnValueCallback: CloseAlertDialog
        });

        $('.ms-dlgTitle').css('background','#ffffff');
        $('.ms-dlgCloseBtn .s4-clust').css('width','91px');
        $('.ms-dlgCloseBtn .s4-clust .ms-dlgCloseBtnImg').removeAttr('style');
        $('.ms-dlgCloseBtn .s4-clust .ms-dlgCloseBtnImg').attr('src', '/Style%20Library/PSEcom/Images/closeAlert.png');
    }
}

function CloseAlertDialog(dialogResult, returnValue) { 
} 

function popOrNot(cName, cValue)
{
//Check for cookie - if not there add it and return true to popup dialog
var cexpires = "";
if (document.cookie.length == 0)
    {
        document.cookie = cName + "=" + cValue + cexpires + "; path=/";
        return true;
    }
var cStart = document.cookie.indexOf(cName + "=");
if (cStart == -1)
    {
        document.cookie = cName + "=" + cValue + cexpires + "; path=/";
        return true;
    }
return false;
}

