﻿//-------------------------------------------------------------------------------
//	Dynamic Ventures, Inc.
//	BioCentury - Home
//-------------------------------------------------------------------------------

var bDropDown = false; //when the page is called from DropDown menu

var defaultText = "Search Articles";


function MM_swapImgRestore() { //v3.0
    var i, x, a = document.MM_sr;
    for (i = 0; a && i < a.length && (x = a[i]) && x.oSrc; i++)
        x.src = x.oSrc;
}

function MM_preloadImages() { //v3.0
    var d = document; if (d.images) {
        if (!d.MM_p) d.MM_p = new Array();
        var i, j = d.MM_p.length, a = MM_preloadImages.arguments; for (i = 0; i < a.length; i++)
            if (a[i].indexOf("#") != 0) { d.MM_p[j] = new Image; d.MM_p[j++].src = a[i]; } 
    }
}

function MM_findObj(n, d) { //v4.01
    var p, i, x; if (!d) d = document; if ((p = n.indexOf("?")) > 0 && parent.frames.length) {
        d = parent.frames[n.substring(p + 1)].document; n = n.substring(0, p);
    }
    if (!(x = d[n]) && d.all) x = d.all[n]; for (i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
    for (i = 0; !x && d.layers && i < d.layers.length; i++) x = MM_findObj(n, d.layers[i].document);
    if (!x && d.getElementById) x = d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
    var i, j = 0, x, a = MM_swapImage.arguments; document.MM_sr = new Array; for (i = 0; i < (a.length - 2); i += 3)
        if ((x = MM_findObj(a[i])) != null) { document.MM_sr[j++] = x; if (!x.oSrc) x.oSrc = x.src; x.src = a[i + 2]; }
}

function MM_nbGroup(event, grpName) { //v6.0
    var i, img, nbArr, args = MM_nbGroup.arguments;
    if (event == "init" && args.length > 2) {
        if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
            img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
            if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
            nbArr[nbArr.length] = img;
            for (i = 4; i < args.length - 1; i += 2) if ((img = MM_findObj(args[i])) != null) {
                if (!img.MM_up) img.MM_up = img.src;
                img.src = img.MM_dn = args[i + 1];
                nbArr[nbArr.length] = img;
            } 
        }
    } else if (event == "over") {
        document.MM_nbOver = nbArr = new Array();
        for (i = 1; i < args.length - 1; i += 3) if ((img = MM_findObj(args[i])) != null) {
            if (!img.MM_up) img.MM_up = img.src;
            img.src = (img.MM_dn && args[i + 2]) ? args[i + 2] : ((args[i + 1]) ? args[i + 1] : img.MM_up);
            nbArr[nbArr.length] = img;
        }
    } else if (event == "out") {
        for (i = 0; i < document.MM_nbOver.length; i++) {
            img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up;
        }
    } else if (event == "down") {
        nbArr = document[grpName];
        if (nbArr)
            for (i = 0; i < nbArr.length; i++) { img = nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
        document[grpName] = nbArr = new Array();
        for (i = 2; i < args.length - 1; i += 2) if ((img = MM_findObj(args[i])) != null) {
            if (!img.MM_up) img.MM_up = img.src;
            img.src = img.MM_dn = (args[i + 1]) ? args[i + 1] : img.MM_up;
            nbArr[nbArr.length] = img;
        } 
    }
}

//-------------------------------------------------------------------------------
// ChangeIFrame
// ADD by - Bela Gaspar
// Modified by Deepa for NewsCenter
//-------------------------------------------------------------------------------
function ChangeIFrame(aSection, aType, folder) {
    if (bDropDown != null && bDropDown == true) {
        bDropDown = false;
        return;
    }

    if (aType == null)
        document.getElementById('IF_' + aSection).src = "BC" + aSection + "IF.html";
    else if (folder == null)
        document.getElementById('IF_' + aSection).src = "BC" + aSection + "IF_" + aType;
    else
    // NewsCenter
        document.getElementById('IF_' + aSection).src = "../" + folder + "/BC" + aSection + "IF_" + aType;
}

function ChangeIFrameDiffSubSection(window, frame) {
    if (window != null && frame != null) {
        if (window == 'Subscribe') {
            if (frame == 'Publications' || frame == 'DataSolutions')
                document.getElementById('IF_' + window).src = "BC" + frame + "IF_3.html";
            else
                document.getElementById('IF_' + window).src = "BC" + frame + "IF.html";
        }
        else {
            if (frame == 'Publications' || frame == 'DataSolutions')
                document.getElementById('IF_' + window).src = "BC" + frame + "IF_2.html";
            else
                document.getElementById('IF_' + window).src = "BC" + frame + "IF.html";
        }
    }
}

//-------------------------------------------------------------------------------
// GetParam
// ADD by - Bela Gaspar - 11/29/2006
// Descr: return from document.location.search the asked parameter value
//-------------------------------------------------------------------------------
function GetParam(theSearchURL, theParamName) {
    var start = theSearchURL.indexOf("?" + theParamName + "=");
    if (start < 0)
        start = theSearchURL.indexOf("&" + theParamName + "=");
    if (start < 0)
        return '';
    start += theParamName.length + 2;
    var end = theSearchURL.indexOf("&", start) - 1;
    if (end < 0)
        end = theSearchURL.length;
    var result = theSearchURL.substring(start, end);
    var result = '';
    for (var i = start; i <= end; i++) {
        var c = theSearchURL.charAt(i);
        result = result + (c == '+' ? ' ' : c);
    }
    return unescape(result);
}

//-------------------------------------------------------------------------------
// ADD by - Lucian Sasu, Bela Gaspar
// Descr: open pdf file in the pop-up
//-------------------------------------------------------------------------------
function createPopUp(popNum, urlString) {
    switch (popNum) {
        case 1:
            window.open(urlString, 'popUpHelpOps', 'directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=no,width=200,height=160');
            break;
        case 2:
            window.open(urlString, 'popUpHelpDB', 'directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=no,width=200,height=210');
            break;
        case 3:
            window.open(urlString, 'popUpYear', 'directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=no,width=200,height=160');
            break;
        case 4:
            window.open(urlString, 'popUpSection', 'directories=no,location=no,menubar=no,scrollbars=no,status=no,toolbar=no,resizable=no,width=200,height=225');
            break;
        case 5:
            popUp = window.open(urlString, 'popUpContent', 'directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes');
            popUp.focus();
            break;
        case 6:
            window.open(urlString, 'helpView', 'directories=no,location=no,menubar=no,scrollbars=yes,status=no,toolbar=no,resizable=yes,width=800,height=660');
            break;
    }
}

//-------------------------------------------------------------------------------
// ADD by - Rostislav 02/28/07
// Descr: changes context of the PromoBoxes
//-------------------------------------------------------------------------------  
function ChangePromoBoxes(section, subsection) {
    var link = "SectionHandler.ashx?section=" + section + "&subsection=" + subsection;
    var div = document.getElementById('divPromoContext');
    CreateRequest(div, link, section);

}

function getHTTPObject() {
    var http = false;

    if (navigator.appName == "Microsoft Internet Explorer") {
        http = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else {
        http = new XMLHttpRequest();
    }

    return http;
}

//-------------------------------------------------------------------------------
// ADD by - Rostislav 02/28/07
// Descr: Create request (ajax) to a specified page
//-------------------------------------------------------------------------------    
function CreateRequest(control, link, section) {
    var d = new Date();
    link += "&d=" + d.getTime();
    try {
        var http = getHTTPObject();
        http.open("GET", link, true);

        http.onreadystatechange = function() {
            if (http.readyState == 4) {
                control.innerHTML = http.responseText;
                if (http.responseText == '') {
                    document.getElementById('divLeftStyle').className = 'left3';
                    document.getElementById('divRightStyle').className = 'right3';
                    document.getElementById('divPromoContext').className = 'DivHidden';
                    document.getElementById('IF_' + section).className = 'left_iframe3';
                }
                else {
                    document.getElementById('divPromoContext').className = 'DivVisible';
                    document.getElementById('divLeftStyle').className = 'left2';
                    document.getElementById('divRightStyle').className = 'right2';
                    document.getElementById('IF_' + section).className = 'left_iframe';
                }
            }
        }
        http.send(null);
    }
    catch (err) {
        //alert(err);
    }
}

function GetInnerText(object) {
    if (document.all)
        return object.innerText;
    else
        return object.textContent;
}

function SetInnerText(object, text) {
    if (document.all)
        object.innerText = text;
    else
        object.textContent = text;
}

//-------------------------------------------------------------------------------
// ADD by - Bela Gaspar
// Descr: Hide Left navigation
//-------------------------------------------------------------------------------
function HideLeftNav() {
    document.getElementById('divRightStyle').style.display = "none";
    document.getElementById('divLeftStyle').style.width = "927px";
}

//-------------------------------------------------------------------------------
// ADD by - Bela Gaspar
// Descr: Phone Validator
//
// DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
//
//-------------------------------------------------------------------------------
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s) {
    var i;
    for (i = 0; i < s.length; i++) {
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}

function stripCharsInBag(s, bag) {
    var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++) {
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone) {
    s = stripCharsInBag(strPhone, validWorldPhoneChars);
    return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function ValidateForm(PhoneID) {
    var Phone = document.getElementById(PhoneID);

    if ((Phone.value == null) || (Phone.value == "")) {
        if (PhoneID.indexOf('Fax') == -1) {
            alert("Please Enter your Phone Number")
            Phone.focus()
            return false
        }
        else
            return true;
    }
    if (checkInternationalPhone(Phone.value) == false) {
        if (PhoneID.indexOf('Fax') == -1)
            alert("Please Enter a Valid Phone Number");
        else
            alert("Please Enter a Valid Fax Number");
        //Phone.value=""
        Phone.focus()
        return false
    }
    return true
}

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;
        }
    }
}

//-------------------------------------------------------------------------------
// Descr: Archives Search box
//-------------------------------------------------------------------------------
function ClearText(inputField) {
    if (inputField.value == defaultText) {
        inputField.value = '';
        inputField.style.color = '#000';
    }
    else {
        inputField.select();
    }
}
function SetTxtColor(inputField) {
    if (inputField.value != defaultText) {
        inputField.style.color = '#000';
    }
}

/*function SetColor(inputField)
{
if (inputField)
{
alert(inputField.value);
if (inputField.value == defaultText) 
{
inputField.style.color='#b3b3b3';
} 
else if (inputField.value == '')
{
inputField.value = defaultText;
inputField.style.color='#b3b3b3';
}
else
{
inputField.style.color='#000';
alert('black');
}
}
}*/

function DispText(inputField, defaultColor) {
    if (inputField.value == '') {
        inputField.value = defaultText;
        if (defaultColor == null)
            inputField.style.color = '#b3b3b3';
        else
            inputField.style.color = "'" + defaultColor + "'";
    }
}

//-------------------------------------------------------------------------------
// Descr: Will open up bookmark option
// Used in: Publications\Articles.aspx
// Author: Bela Gaspar
// 06/22/2010
//-------------------------------------------------------------------------------
function Bookmark() {
    if (document.all)   // IE
    {
        window.external.AddFavorite(location.href, document.title);
    }
    else if (window.sidebar)  // FireFox
    {
        window.sidebar.addPanel(document.title, location.href, '');
    }
    else    // TODO: Chrome, Opera, Safari
    {
        alert('This option works with IE and Firefox only as of now. Press Ctrl+D to bookmark for other browsers.');
    }
}


//-------------------------------------------------------------------------------
// Descr: Will add/remove the image from feature story
// Used in: Home.aspx, HomeSciBx.aspx
//-------------------------------------------------------------------------------
function removeImage(firstDiv, secondDiv, imageID, summaryID) {
    var firstHeight = document.getElementById(firstDiv).clientHeight;
    var secondHeight = document.getElementById(secondDiv).clientHeight;
    if (firstHeight > secondHeight + 35)
        document.getElementById(imageID).style.display = "none";
    else {
        document.getElementById(imageID).style.display = "block";
        if (summaryID != '') {
            if (firstHeight + 40 < secondHeight)
                document.getElementById(summaryID).style.display = "none";
            else
                document.getElementById(summaryID).style.display = "block";
        }
    }
}

//-------------------------------------------------------------------------------
//Used in HomeDailyExtra.aspx
//-------------------------------------------------------------------------------
function ShowPopUp(type) {
    popUp = window.open('/BCIQ/Financings/Statistics.aspx?type=' + type, '_popup', 'status=yes,resizable=yes,toolbar=no,menubar=no,scrollbars=yes');
    popUp.focus();
}

//-------------------------------------------------------------------------------
//Used in HomeDailyExtra.aspx
//-------------------------------------------------------------------------------
function ShowChartPopUp(type) {
    popUp = window.open('/BCIQ/Financings/StatisticsChart.aspx?type=' + type, '_popup', 'width=680,height=520,status=yes,resizable=yes,toolbar=no,menubar=no,scrollbars=yes');
    popUp.focus();
}

