﻿function $(param) {
    if (typeof (param) == 'undefined' || !param) {
        return null;
    }
    else if (typeof (param.tagName) == 'undefined' || !param.tagName) {
        if (document.all)
            el = document.getElementById(param) ? document.getElementById(param) : document.all[param];
        else
            el = document.getElementById(param);

        if (el)
            return el;
        else
            return null;
    }
    else if (param.tagName) {
        return param;
    }
    else {
        return null;
    }
}

function getQuerystring(key, default_) {
    if (default_ == null) default_ = "";
    key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
    var qs = regex.exec(window.location.href);
    if (qs == null)
        return default_;
    else
        return qs[1];
}

var DivObj = "";
function ShowOverlay() {
    var pageSize = this.getPageSize();
    var bgObj = document.createElement("div");
    DivObj = bgObj;
    bgObj.setAttribute('id', 'bgDiv');
    bgObj.style.position = "absolute";
    bgObj.style.top = "0";
    bgObj.style.background = "#000000";
    bgObj.style.filter = "progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=65";
    bgObj.style.opacity = "0.5";
    bgObj.style.left = "0";
    bgObj.style.width = pageSize[0] + "px";
    bgObj.style.height = pageSize[1] + "px";
    bgObj.style.zIndex = "9999";
    document.body.appendChild(bgObj);

}

function HideOverlay() {
    document.body.removeChild(DivObj);
}

function getPageSize() {
    var xScroll, yScroll;
    if (window.innerHeight && window.scrollMaxY) {
        xScroll = window.innerWidth + window.scrollMaxX;
        yScroll = window.innerHeight + window.scrollMaxY;
    } else if (document.body.scrollHeight > document.body.offsetHeight) { // all but Explorer Mac
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    } else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }
    var windowWidth, windowHeight;
    if (self.innerHeight) {	// all except Explorer
        if (document.documentElement.clientWidth) {
            windowWidth = document.documentElement.clientWidth;
        } else {
            windowWidth = self.innerWidth;
        }
        windowHeight = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
        windowWidth = document.documentElement.clientWidth;
        windowHeight = document.documentElement.clientHeight;
    } else if (document.body) { // other Explorers
        windowWidth = document.body.clientWidth;
        windowHeight = document.body.clientHeight;
    }

    // for small pages with total height less then height of the viewport
    if (yScroll < windowHeight) {
        pageHeight = windowHeight;
    } else {
        pageHeight = yScroll;
    }

    // for small pages with total width less then width of the viewport
    if (xScroll < windowWidth) {
        pageWidth = xScroll;
    } else {
        pageWidth = windowWidth;
    }
    return [pageWidth, pageHeight];
}

var DisDiv = "";
function DisplayPopup(parent, divId) {
    ShowOverlay()
    var DivObj = $(divId);
    DivObj.style.display = 'block';
    DivObj.style.visibility = 'visible';
    DivObj.style.position = "absolute";
    DivObj.style.zIndex = "20001";
    if (parent != "" && parent != 0) {
        var placement = findPos(parent);
        DivObj.style.left = placement[0] - 170 + "px";
        DivObj.style.top = placement[1] - 20 + "px";
    } else {
        DivObj.style.left = "50%"; //Math.round((document.documentElement.clientHeight / 2) - (DivObj.style.height / 2) + document.documentElement.scrollTop) + 'px';
        DivObj.style.top = "50%"; //Math.round((document.documentElement.clientWidth / 2) - (DivObj.style.width / 2)) + "px";
        DivObj.style.marginLeft = "-270px";
        DivObj.style.marginTop = -190 + document.documentElement.scrollTop + "px";
    }

}
function findPos(obj) {
    var curleft = curtop = 0;
    if (obj.offsetParent) {
        curleft = obj.offsetLeft
        curtop = obj.offsetTop
        while (obj = obj.offsetParent) {
            curleft += obj.offsetLeft
            curtop += obj.offsetTop
        }
    }
    return [curleft, curtop];
}

function HidePopup(divId) {
    $(divId).style.display = 'none';
    HideOverlay()
}

function CloseFilePopup(divId) {
    HidePopup(divId)
    DisplayPopup(0, 'MnPopup')
}

function onEnterpress(e, func) {
    var KeyPress;
    if (e && e.which) {
        e = e
        KeyPress = e.which
    } else {
        e = event
        KeyPress = e.keyCode
    }
    if (KeyPress == 13) {
        func()
        return false
    } else {
        return true
    }
}

function ClearMsg(DivID) {
    var Div = $(DivID)
    Div.className = '';
    Div.innerHTML = '';

}
function ShowMessage(DivID, Msg) {
    var Div = $(DivID)
    Div.className = 'Divmessage';
    Div.innerHTML = Msg;
    setTimeout('ClearMsg(\'' + DivID + '\')', 5000)
}



function OpenIdUserValidate() {
    if ($('txtUserNameOpen').value.length == 0) {
        ShowMessage('ErrMsg', 'Please enter your Name!');
        return false;
    }
    if ($('txtEmailOpen').value.length == 0) {
        ShowMessage('ErrMsg', 'Please enter your Email!');
        return false;
    }
    var patemail = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
    var result = $('txtEmailOpen').value.match(patemail)
    if (result == null) {
        ShowMessage('ErrMsg', 'Please enter valid E-Mail!');
        return false;
    }
    SaveInfo()
}
function SaveInfo() {
    var Url = 'SaveOpenIdValues.ashx?UN=' + $('txtUserNameOpen').value + '&EM=' + $('txtEmailOpen').value + '&Iden=' + $('hdnValue').value;
    MakeAjaxRequest(Url, LoadResult, true)
}
function LoadResult(response) {
    var Content = response.responseXML.documentElement.getElementsByTagName('Result');
    var Result = Content[0].getAttribute('R');
    if (Result.length == 4) {
        HidePopup('EmailPopup');
        window.location = "Index.aspx";
        $('hdnValue').value = "";
    }
}

function ShowPresenterInfo(parent, name, businessName, designation, presbiography) {
    var position = this.findPos(parent);
    var itemele = document.getElementById('divContactWindow');    
    itemele.style.top = position[1] + 15 - 50 + "px";
    itemele.style.left = position[0] + 120 + "px";
    itemele.style.display = "block";
    //alert(presbiography.toString().replace("~", "'"));

    $('popName').innerHTML = name;
    if (designation == "") {
        $('popDesignation').innerHTML = "N/A";
    }
    else {
        $('popDesignation').innerHTML = designation;
    }
    if (businessName == "") {
        $('popBusiness').innerHTML = "N/A";
    }
    else {
        $('popBusiness').innerHTML = businessName;
    }
    if (presbiography == "") {
        $('popBiography').innerHTML = "N/A";
    }
    else {
        $('popBiography').innerHTML = presbiography.toString().replace(/[~\r]+/g, "'").replace(/[#]+/g, "<br>");
        ;
    }
}

function ClosePopUp() {
    $('divContactWindow').style.display = "none";
}


function ShowPresenterInfoNEW(parent, PresenterID) {

    var position = this.findPos(parent);
    var itemele = document.getElementById('divContactWindow');
    itemele.style.top = position[1] + 15 - 200 + "px";
    itemele.style.left = position[0] + 120 + "px";
    itemele.style.display = "block";
    var Url = 'GetPresenterInfo.ashx?PresenterID=' + PresenterID;
    MakeAjaxRequest(Url, ReceivedPresenterInfo, true)

}

function ReceivedPresenterInfo(response) {

    var PresenterInfo = response.responseXML.documentElement.getElementsByTagName('Presenter');
//    $('popName').innerHTML = PresenterInfo[0].childNodes[0].firstChild.nodeValue.replace(/['\r]+/g, "'");
//    $('popDesignation').innerHTML = PresenterInfo[0].childNodes[1].firstChild.nodeValue.replace(/['\r]+/g, "'");
//    $('popBusiness').innerHTML = PresenterInfo[0].childNodes[2].firstChild.nodeValue.replace(/['\r]+/g, "'");
//    $('popBiography').innerHTML = PresenterInfo[0].childNodes[3].firstChild.nodeValue.replace(/['\r]+/g, "'");

    $('popName').innerHTML = PresenterInfo[0].childNodes[0].firstChild.nodeValue.replace(/['\r]+/g, "'");
    $('popDesignation').innerHTML = PresenterInfo[0].childNodes[4].firstChild.nodeValue.replace(/['\r]+/g, "'");
    $('popBiography').innerHTML = PresenterInfo[0].childNodes[3].firstChild.nodeValue.replace(/['\r]+/g, "'");
    if (PresenterInfo[0].childNodes[5].firstChild.nodeValue == "~") {
        $('NominationImg').style.display = "none";
    }
    else {
        $('NominationImg').style.display = "block";
        $('NominationImg').src = PresenterInfo[0].childNodes[5].firstChild.nodeValue;
    }
}



