
// this function resets the yellow form inputs set by the Google toobar back to normal

function restoreStyles() {
    inputList = document.getElementsByTagName("INPUT");

    for (i = 0; i < inputList.length; i++)
        inputList[i].style.backgroundColor = "";

    selectList = document.getElementsByTagName("SELECT");

    for (i = 0; i < selectList.length; i++)
        selectList[i].style.backgroundColor = "";
}

function trim(inputString) {
    // Removes leading and trailing spaces from the passed string. Also removes
    // consecutive spaces and replaces it with one space. If something besides
    // a string is passed in (null, custom object, etc.) then return the input.

    if (typeof inputString != "string") {
        return inputString;
    }

    var retValue = inputString;
    var ch = retValue.substring(0, 1);

    while (ch == " ") {
        // Check for spaces at the beginning of the string
        retValue = retValue.substring(1, retValue.length);

        ch = retValue.substring(0, 1);
    }

    ch = retValue.substring(retValue.length - 1, retValue.length);

    while (ch == " ") {
        // Check for spaces at the end of the string
        retValue = retValue.substring(0, retValue.length - 1);

        ch = retValue.substring(retValue.length - 1, retValue.length);
    }

    while (retValue.indexOf("  ") != -1) {
        // Note that there are two spaces in the string - look for multiple spaces within the string
        retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ") + 1, retValue.length); // Again, there are two spaces in each of the strings
    }

    return retValue;                                                                                                                // Return the trimmed string back to the user
}                                                                                                                               // Ends the "trim" function

function goToUrl(selObj){
    eval("document.location.href = '" + selObj.options[selObj.selectedIndex].value + "'");
}

function open_new_window(url, height, width)
    {
    chw = window.open(url, '7050', 'resizable=no, scrollbars=yes, status=yes, height=450, width=350');

    if (chw != null)
        chw.focus();

    return false;
    }

function open_full_browser(url)
    {
    chw = window.open(url, '7051', 'resizable=yes, scrollbars=yes, status=yes');

    if (chw != null)
        chw.focus();

    return false;
    }

function submit_to_new_window(this_form)
    {
    chw = window.open('/education/university/glossary_win.php?searchterm=' + this_form.searchterm.value, '7050', 'resizable=no, scrollbars=yes, status=yes, width=500, height=550');

    if (chw != null)
        chw.focus();

    return false;
    }

function on_issue_change(index)
    {
    which_span = document.all.sel_issue[index].value;

    document.all.span_account.style.display = 'none';
    //document.all.span_account_text.style.display = 'none'; 
    document.all.span_billing.style.display = 'none';
    //document.all.span_billing_text.style.display = 'none'; 
    document.all.span_services.style.display = 'none';
    //document.all.span_services_text.style.display = 'none'; 
    document.all.user_name.style.display = 'none';
    document.all.user_email.style.display = 'none';
    document.all.user_phone.style.display = 'none';
    document.all.user_subject.style.display = 'none';
    document.all.user_comments.style.display = 'none';
    document.all.user_button.style.display = 'none';

    eval("document.all.span_" + which_span + ".style.display='inline';");
    // eval( "document.all.span_"+which_span+"_text.style.display='inline';" );
    }

function on_subtopic_change()
    {
    document.all.user_name.style.display = 'inline';

    document.all.user_email.style.display = 'inline';
    document.all.user_phone.style.display = 'inline';
    document.all.user_subject.style.display = 'inline';
    document.all.user_comments.style.display = 'inline';
    document.all.user_button.style.display = 'inline';
    }

function SetItemDisplay(item)
    {

    //if (!cookieExists( item )) {
    //   alert ("no cookie for " + item);
    //   return;
    // }

    setCookie('foo', 'bar');

    obj = document.getElementById(item);
    key = document.getElementById("x" + item);

    if (getCookie(item) != 'on')
        {
        obj.style.display = "none";

        // key.innerHTML ="[+]" ;
        key.src = "/includes/common/images/arrow.gif";
        }

    else
        {
        obj.style.display = "block";

        // key.innerHTML ="[-]";
        key.src = "/includes/common/images/arrow_dwn.gif";
        }
    }

function checkSetMenu()
    {
    SetItemDisplay('buyer');

    SetItemDisplay('supplier');
    SetItemDisplay('retailer');
    }

function saveMenuClick(itemToSave)
    { /* setCookie("menuValue",itemToSave);*/
    }

//function cookieExists(cookieName)
//   { return ( (document.cookie.indexOf(cookieName) >= 0) && (cookieValue(cookieName).length > 0) ); }

// Returns a string containing the cookies value

function setCookie(name, value)
    {
    var argv = setCookie.arguments;

    var argc = setCookie.arguments.length;
    var expires = (argc > 2) ? argv[2] : null;
    var tempcook = name + "=" + escape(value);

    if (expires)
        {
        tempcook = tempcook + ";path=/;domain=.openwebservices.com;expires=" + expires.toGMTString();
        }

    document.cookie = tempcook;
    }

function getCookie(name) {
    var cookie = " " + document.cookie;

    var search = " " + name + "=";
    var setStr = null;
    var offset = 0;
    var end = 0;

    if (cookie.length > 0)
        {
        offset = cookie.indexOf(search);

        if (offset != -1)
            {
            offset += search.length;

            end = cookie.indexOf(";", offset)

            if (end == -1)
                {
                end = cookie.length;
                } ;

            setStr = unescape(cookie.substring(offset, end));
            };
        };

    return (setStr);
}

function delCookie(name) {
    document.cookie = name + "=del;expires=Mon, 01-Jan-2000 00:00:00 GMT";
}

function region_to_onchange(this_form) {
    var intIndex;
    var intIncrement;

    intIncrement = this_form.country_to.length;

    for (intIndex = intIncrement; intIndex >= 0; intIndex--) {
        this_form.country_to.remove(intIndex);
    }

    intIncrement = 0;
    /*
    for(intIndex=0;intIndex<arrCountry.length;intIndex++)
    {
        if(arrCountryId[intIndex][0]==document.form1.region_to.value)
        {
             tempOpt=new Option(arrCountryId[intIndex][2],arrCountryId[intIndex][1]);
             document.form1.country_to.options[intIncrement++]=tempOpt;
        }
    }
    */

    tempOpt = new Option("Select", 0);
    this_form.country_to.options[intIncrement++] = tempOpt;

    for (intIndex = 0; intIndex < arrCountryId.length; intIndex++) {
        if (arrCountryId[intIndex][0] == this_form.region_to.value) {
            tempOpt = new Option(arrCountryId[intIndex][2], arrCountryId[intIndex][1]);

            this_form.country_to.options[intIncrement++] = tempOpt;
        }
    }

    if (intIncrement == 0) {
        var tempOpt = new Option("    ", 0);

        this_form.country_to.options[0] = tempOpt;
    }

    country_to_onchange(this_form);
}

function region_from_onchange(this_form) {
    var intIndex;
    var intIncrement;

    intIncrement = this_form.country_from.length;

    for (intIndex = intIncrement; intIndex >= 0; intIndex--) {
        this_form.country_from.remove(intIndex);
    }

    intIncrement = 0;

    tempOpt = new Option("Select", 0);
    this_form.country_from.options[intIncrement++] = tempOpt;

    for (intIndex = 0; intIndex < arrCountryId.length; intIndex++) {
        if (arrCountryId[intIndex][0] == this_form.region_from.value) {
            tempOpt = new Option(arrCountryId[intIndex][2], arrCountryId[intIndex][1]);

            this_form.country_from.options[intIncrement++] = tempOpt;
        }
    }

    if (intIncrement == 0) {
        var tempOpt = new Option("    ", 0);

        this_form.country_from.options[0] = tempOpt;
    }

    country_from_onchange(this_form);
}

function country_to_onchange(this_form) {
    var intIndex;
    var intIncrement;

    intIncrement = this_form.state_to.length;

    for (intIndex = intIncrement; intIndex >= 0; intIndex--) {
        this_form.state_to.remove(intIndex);
    }

    intIncrement = 0;

    for (intIndex = 0; intIndex < arrStateId.length; intIndex++) {
        if (arrStateId[intIndex][0] == this_form.country_to.value) {
            tempOpt = new Option(arrStateId[intIndex][2], arrStateId[intIndex][1]);

            this_form.state_to.options[intIncrement++] = tempOpt;
        }
    }

    if (intIncrement == 0) {
        var tempOpt = new Option("    ", 0);

        this_form.state_to.options[0] = tempOpt;
    }
}
	
function country_from_onchange(this_form) {
    var intIndex;
    var intIncrement;

    intIncrement = this_form.state_from.length;

    for (intIndex = intIncrement; intIndex >= 0; intIndex--) {
        this_form.state_from.remove(intIndex);
    }

    intIncrement = 0;

    for (intIndex = 0; intIndex < arrStateId.length; intIndex++) {
        if (arrStateId[intIndex][0] == this_form.country_from.value) {
            tempOpt = new Option(arrStateId[intIndex][2], arrStateId[intIndex][1]);

            this_form.state_from.options[intIncrement++] = tempOpt;
        }
    }

    if (intIncrement == 0) {
        var tempOpt = new Option("    ", 0);

        this_form.state_from.options[0] = tempOpt;
    }
}

function billing_country_to_onchange(this_form) {
    var intIndex;
    var intIncrement;

    intIncrement = this_form.billing_state_to.length;

    for (intIndex = intIncrement; intIndex >= 0; intIndex--) {
        this_form.billing_state_to.remove(intIndex);
    }

    intIncrement = 0;

    for (intIndex = 0; intIndex < arrStateId.length; intIndex++) {
        if (arrStateId[intIndex][0] == this_form.billing_country_to.value) {
            tempOpt = new Option(arrStateId[intIndex][2], arrStateId[intIndex][1]);

            this_form.billing_state_to.options[intIncrement++] = tempOpt;
        }
    }

    if (intIncrement == 0) {
        var tempOpt = new Option("    ", 0);

        this_form.billing_state_to.options[0] = tempOpt;
    }
}

