﻿
function strip(str, len) {
    str += '';
    if (str.indexOf('px') == -1) return str;
    if (str.length > len)
        str = str.substring(0, len);
    return str;
}

// ======

// valid for Iframe1 - @@@AGL generalize passing param Iframe id

function resizeIframe(height) {
    height = parseInt(height);
    height += 100;
    $('iframe#Iframe1').attr('height', height);
}

var pages = new Array();

function newid() {
    var aObj = document.getElementById('Menu').getElementsByTagName('a');
    var ii2 = '';
    var count = 0;
    var bodyId = '';
    var href = '';
    
    for (i = 0; i < aObj.length; i++) {
        ii2 = aObj[i].getAttribute("className");
        ii2 = ii2.replace('oct', '');
        // this comes first, all else conditions derive from this one
        if (ii2.indexOf('001') > -1) {
            aObj[i].setAttribute("className", ii2);
            pages.push(aObj[i]);
        }
//        else {
//            // test other pages and set pages[i] accordingly
//            href = aObj[i].href;
//            ii2 = pages[count].getAttribute("className");
//            ii2 = 'oct ' + ii2;
//            pages[count].setAttribute("className", ii2);
        //        }

    }

//    for (i = 0; i < pages.length; i++) {
//        alert(pages[i].toString());
//        var ii3 = pages[i].getAttribute("className");
//        alert(ii3)
//    }

    if (thispage.indexOf('products') > -1) {
        bodyId = 'page1'; // for the #page1 row-bot see style.css
        count = 0;
    }
    else
        if (thispage.indexOf('products') > -1) {
            bodyId = "page2";
            count = 1;
        }
        else
            if (thispage.indexOf('support') > -1) {
                bodyId = "page3";
                count = 2;
            }
            else
                if (thispage.indexOf('about') > -1) {
                    bodyId = "page4";
                    count = 3;
                }
                else
                    if (thispage.indexOf('contact') > -1) {
                        bodyId = "page5";
                        count = 4;
                    }
                    else {
                        // non direct links (those in submenus)
                        if (thispage.indexOf('hoppi') > -1 || thispage.indexOf('topsear') > -1) {
                            count = 1;
                        }
                    }


                    ii2 = pages[count].getAttribute("className");
                    ii2 = 'oct ' + ii2;
                    pages[count].setAttribute("className", ii2);
}
 
        




function body_onkeydown() {
    if (event.keyCode == 13 || event.keyCode == 27) {
        var _defaultButtonName = "cancelButton";
        var frm = document.forms[0];
        if (frm && document.all(_defaultButtonName)) {
            document.all(_defaultButtonName).click();
        }
    }
}


function gtlWithClick(which) {
    createCookie('langGNO', lang, 660);
    if (which == 0) document.location.href = "index.aspx";
}


function cookieTime() {
    try {

        if (lang != null && lang != '') {
            createCookie("langGNO", lang, -1) // destroy
            createCookie("langGNO", lang, 20);
        }
    }
    catch (err) { }
}


// ======

function createCookie(name, value, days) {
    var expires = "";
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days * 84400 * 1000)); // 1/1000 of seconds
        expires = "; expires=" + date.toGMTString();
    }

    document.cookie = name + "=" + value + expires + "; path=/";
}

// ======

function gotoLanguage(which) // @@@AGL which is not used, just to align same behavior
{
    var dropdownIndex = document.getElementById('ddlLang').selectedIndex;
    var dropdownValue = document.getElementById('ddlLang')[dropdownIndex].value;
    lang = dropdownValue;
    createCookie('langGNO', lang, 660);
}

// ======

function RemoveClassName(objElement, strClass) {
    if (objElement.className) {
        var arrList = objElement.className.split(' ');
        var strClassUpper = strClass.toUpperCase();
        for (var i = 0; i < arrList.length; i++) // find all instances and remove them
        {
            if (arrList[i].toUpperCase() == strClassUpper) // if class found
            {
                arrList.splice(i, 1); // remove array item
                i--; // decrement loop counter as we have adjusted the array's contents
            }
        }
        objElement.className = arrList.join(' '); // assign modified class name attribute
    }
    // if there was no class, then there is nothing to remove
}

// ======

function AddClassName(objElement, strClass, blnMayAlreadyExist) {
    if (objElement.className) {
        var arrList = objElement.className.split(' ');
        /*
        if (blnMayAlreadyExist) // the new class name may already exist in list
        {
        var strClassUpper = strClass.toUpperCase();
        for (var i = 0; i < arrList.length; i++) // find all instances and remove them
        {
        if ( arrList[i].toUpperCase() == strClassUpper )
        {
        arrList.splice(i, 1);
        i--; // decrement loop counter as we have adjusted the array's contents
        }
        }
        }
        */
        arrList[arrList.length] = strClass; // add the new class to end of list
        objElement.className = arrList.join(' ');
    }
    else {
        alert('too bad');
    }
}

// ======

function HasClassName(objElement, strClass) {
    if (objElement.className) {
        var arrList = objElement.className.split(' '); // the classes are space separated list, so first get the list
        var strClassUpper = strClass.toUpperCase(); // get uppercase class for comparison purposes
        for (var i = 0; i < arrList.length; i++) // find all instances and remove them
        {
            if (arrList[i].toUpperCase() == strClassUpper) {
                return true; // found
            }
        }
    }
    return false;
}

