// Master JS file
// Updated 01-11-2010

// JavaScript Document
// Break page out of a frames-based environment
if (top.frames.length!=0) {
    if (window.location.href.replace)
        top.location.replace(self.location.href);
    else
        top.location.href=self.document.href;
}

function OpenWindow(URL) {
var MaxArguments = 4;
var ArgumentsIndex;
for(ArgumentsIndex=0;ArgumentsIndex<MaxArguments;ArgumentsIndex++) {
if(arguments.length == ArgumentsIndex) {
// then create this argument as a blank string:
arguments[ArgumentsIndex] = new String();
}
}
// URL is arguments[0]
window.open(URL, arguments[1], arguments[2], arguments[3]);
}

function open_win(url)
{
window.open("url","_blank","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=yes, resizable=yes, copyhistory=no, width=400, height=400")
}

// Focus Change

/*
function checkForSubmit()
DESCRIPTION:
Changes the focus to the Part Search Submit button when user has entered
keywords into the search box field rather than the "Buy" button on the
Part Detail page.
*/

function checkForSubmit(event, submitTheForm)
{
    var e = event || window.event;
 
    var keycode = e.charCode || e.keyCode;
 
    if(keycode == 13)
    {
        // stop propogation of this event:
        document.onkeypress = null;
        if(e.stopPropagation)
        {
            e.stopPropagation();
        }
        else if(e.cancelBubble)
        {
            e.cancelBubble = true;
        }
 
        // submit the form:
        if(submitTheForm && submitTheForm != null)
            submitTheForm.submit();

        return false;
    }
 
    return true;
}

// Part Search Link Builder

/*
function partSearchLink(keyword1,keyword2)
DESCRIPTION:
partSearchLink builds the part search query string based on the supplied keywords
*/

function partSearchLink(keyword1,keyword2)
{
    myLink = "http://www.ttieurope.com/page/search_results.html?step=buyNow&searchTerms="+keyword1+"+"+keyword2;

    window.location = myLink;
}

// Inquire Button Link Builder

/*
function partQuoteLink(partnumber,quantity)
DESCRIPTION:
partQuoteLink builds the part quote query string based on the supplied keywords and sends them to the RFQ page
*/

function partQuoteLink(partnumber,quantity)
{
    myLink = "http://www.ttieurope.com/page/quote.html?step=inquire&partNumber[1]="+partnumber+"&quantity[1]="+quantity;

    window.location = myLink;
}

/*
function showHide(theid)
DESCRIPTION:
Toggles an object's style from 'show' to 'hide' or vice versa. Both styles are controlled by the style sheet
PARAMETER(S):
theid - The CSS ID of the object to be hidden
*/

menu_status = new Array();

function showHide(theid){
    if (document.getElementById) {
    var switch_id = document.getElementById(theid);

        if(menu_status[theid] != 'show') {
           switch_id.className = 'show';
           menu_status[theid] = 'show';
        }else{
           switch_id.className = 'hide';
           menu_status[theid] = 'hide';
        }
    }
}

/*
function hideIt(theid)
DESCRIPTION:
Changes the object's style to 'hide' which is controlled by the style sheet
PARAMETER(S):
theid - The CSS ID of the object to be hidden
DEPENDENCIES:
menu_status - An array of all of the menu objects
*/

function hideIt(theid){
    if (document.getElementById) {
    var switch_id = document.getElementById(theid);

        if(menu_status[theid] != 'hide') {
           switch_id.className = 'hide';
           menu_status[theid] = 'hide';
        }
    }
}

/*
function showIt(theid)
DESCRIPTION:
Changes the object's display property to 'yes'
PARAMETER(S):
theid - The CSS ID of the object to be hidden
*/

function showIt(theid){
   var el = document.getElementById(obj);
   el.style.display = 'yes';

}

/*
function open_chart(index, w, h)
DESCRIPTION:
PARAMETER(S):
*/

function open_chart(index, w, h)
{
var img="/admin/staging/IO/8918/"+index+".gif";
var title="graph"+index;
window.open(img,title,"left=0,top=0,width=" + w + ",height=" + h + ",resizable");
}

function switchMenu(obj) {
var el = document.getElementById(obj);
if ( el.style.display != "none" ) {
   el.style.display = 'none';
}
else {
  el.style.display = '';
}
}

function hideCurrentShowNext(obj1,obj2){
var el1 = document.getElementById(obj1);
var el2 = document.getElementById(obj2);

el1.style.display = 'none';

el2.style.display = '';
}


/*
function OnChange(dropdown)
DESCRIPTION:
OnChange triggers a part search query string once a user selects an item in either the Manufacturers
or Product Types drop-down menu. It appends the value of the option that was selected to the base URL.
PARAMETER(S):
dropdown - The selected drop-down object
*/

function OnChange(dropdown)
{
  try
  {
      if (dropdown == null)
      {
          return false;
      }
      
     var myindex  = dropdown.selectedIndex;
    var baseURL = "http://www.ttieurope.com/page/search_results?step=newbrowse&";
    var browseURL = baseURL + dropdown.options[myindex].value;
    top.location.href = browseURL;
    
    return true;
  }
  catch(ex)
  {
      // an error has occurred, no action can be taken
      return false;
  }
}

/*
Function matchHeight()
DESCRIPTION:
Checks to see if the left sidebar (Green Monster) is taller than the content area,
which would cause the sidebar to overlap the footer. If so, it sets the height of the
content area to match.
*/

function matchHeight() {}


/*
function ieboxfix()
DESCRIPTION:
ieboxfix corrects a background image tiling issue in IE when using the scalable-box element;
This fix is applied to the three main filter boxes on Search Results (Manufacturers, Product Type,
and Filters).
PARAMETER(S):
div#mfr-options
div#prod-options
div#filter-options
*/

function ieboxfix(){if(!document.getElementById)return;if(/MSIE (\d+\.\d+);/.test(navigator.userAgent)){var cH=document.getElementById('content-box');var mC=document.getElementById('search-results');boxFix('prod-options');boxFix('filter-options');boxFix('mfr-options');function boxFix(thisBox){if(!document.getElementById(thisBox))return;var filterbox;filterbox=document.getElementById(thisBox);filterbox.style.width=filterbox.offsetWidth+2;filterbox.childNodes[1].style.width=filterbox.offsetWidth;if(mC.offsetWidth<filterbox.offsetWidth){mC.style.width=filterbox.offsetWidth+20+'px';cH.style.width=filterbox.offsetWidth+195+'px';}}}} 

/*
function logout()
DESCRIPTION:
logout terminates the WAS session.
This is now handled via jQuery in the JS Block include
*/

function logout(env) {

}

/*
function setPoaAcctSelector()
Used to update Pay On Acct drop-down for ezBuy
*/

function setPoaAcctSelector()
{
    try
    {
        var ezBuyAccts = document.getElementById('ezBuyAcctSelector');
        var poaAccts = document.getElementById('payOnAccountNumber');
        if(ezBuyAccts != null && poaAccts != null)
        {
            if(ezBuyAccts.value != "")
            {
                var i;
                for(i = 0; i < poaAccts.options.length; i++)
                {
                    if(poaAccts.options[i].value == ezBuyAccts.value)
                      {
                        poaAccts.options[i].selected = true;
                        break;
                    }
                }
            }
        }
    }
    catch(ex)
    {
        /* No action required */
    }
}

function MyOpenWindow(URL) {
   sURL = URL;

   sName = 'MyWindow';
   sFeatures = 'width=700,height=500,toolbar=no,menubar=no,status=yes,scrollbars=yes,resizable=yes';
   window.open(sURL, sName, sFeatures);
}

function goToQuicklink() {
   var cbo = document.getElementById("dropDwn_Quicklinks");
   var value = cbo[cbo.selectedIndex];
   if (value.value != "#") {
     window.location = value.value;
   }
}

jQuery.noConflict();
jQuery(document).ready(function(){
jQuery("#page-footer").append('<a href="#null" id="ssLink"></a>');jQuery("#ssLink").click(function()
{var terms=jQuery("#siteSearch").val();s.linkTrackVars='events,eVar9,prop5';s.linkTrackEvents='event3';s.events="event3";s.eVar9=terms;s.prop5=terms;s.tl(this,'o');});jQuery("#site-search-form").submit(function(event)
{jQuery("#ssLink").click();});
jQuery("#page-footer").append('<a href="#null" id="psLink"></a>');jQuery("#psLink").click(function()
{var terms=jQuery("#searchTerms").val();s.linkTrackVars='events,eVar2,prop1';s.linkTrackEvents='event2';s.events="event2";s.eVar2=terms;s.prop1=terms;s.tl(this,'o');});
jQuery("#product-search-form").submit(function(){jQuery("#psLink").click();});
});
