/**
 * @author kevox
 */
var thisHost = window.location.host;
// this routine will queue initialisation routines
// and should be used instead of <body onload=...
//
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

function altTextAsTitles() {
// assigns value of image alt text as title text for Firefox
    if(document.images) {
        var images = document.getElementsByTagName('img');
        for(var i = 0; i < images.length; i++) {
            if(images[i].alt) {
                images[i].title = images[i].alt;
            }
        }
    }
}

function openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
  return false;
}

function popUp(url) {
            window.open(url, 'title', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=400,height=600,left = 100,top = 100');
            }
            

function tabNavInit() {
    var tabs = document.getElementById('tabNavInner');
    var listElements = tabs.getElementsByTagName('li');
    if(listElements) {
        for (var i = 0; i < listElements.length; i ++) {
            if(listElements[i].id.indexOf('select') == -1) {
                // this is not a selected element, so
                // assign mouseover / mouseout functions
                listElements[i].onmouseover = tabOver;
                listElements[i].onmouseout = tabOut;
            }
        }
    }
}

function tabOut() {
    var thisAnchor = this.getElementsByTagName('a');
    this.style.backgroundImage = 'url(/homepage/images/tabRight.gif)';
    thisAnchor[0].style.color = '#333367';
    thisAnchor[0].style.backgroundImage = 'url(/homepage/images/tabLeft.gif)';
    //this.className = '';
}
function tabOver() {
    var thisAnchor = this.getElementsByTagName('a');
    this.style.backgroundImage = 'url(/homepage/images/tabSelectedRight.gif)';
    thisAnchor[0].style.color = '#ffffff';
    thisAnchor[0].style.backgroundImage = 'url(/homepage/images/tabSelectedLeft.gif)';
    //this.className = 'over';
}

// again for the login tabs

function tabLoginInit() {
    var tabs = document.getElementById('tabLoginInner');
    var listElements = tabs.getElementsByTagName('li');
    if(listElements) {
        for (var i = 0; i < listElements.length; i ++) {
            if(listElements[i].className.indexOf('select') == -1) {
                // this is not a selected element, so
                // assign mouseover / mouseout functions
                listElements[i].onmouseover = loginTabOver;
                listElements[i].onmouseout = loginTabOut;
            }
        }
    }
    // find the two login links
    var buyerLoginLink = document.getElementById('buyerLink');
    var sellerLoginLink = document.getElementById('sellerLink');
    // find their parent <li> elements
    var buyerLoginListItem = buyerLoginLink.parentNode;
    var sellerLoginListItem = sellerLoginLink.parentNode;
    if(buyerLoginListItem) {
        buyerLoginListItem.onclick = buyerScript;
    }
    if(sellerLoginListItem) {
        sellerLoginListItem.onclick = sellerScript;
    }
    var loginForm = document.getElementById('loginForm');
    loginForm.action = 'https://'+thisHost+'/login.do';
    loginForm.userName.focus ();
}
function flashInit() {
    var flashLink = document.getElementById('flashDemo');
    if(flashLink) {
        flashLink.href = '';
        flashLink.target = '';
        flashLink.onclick = launchFlash;
    }
}
function launchFlash() {
     openBrWindow('/process.html','','width=780,height=540');
     return false;
}


function loginTabOut() {
    var thisAnchor = this.getElementsByTagName('a');
    this.style.backgroundImage = 'url(/homepage/images/login/tabRight.gif)';
    thisAnchor[0].style.color = '#333367';
    thisAnchor[0].style.backgroundImage = 'url(/homepage/images/login/tabLeft.gif)';
    //this.className = '';
}
function loginTabOver() {
    var thisAnchor = this.getElementsByTagName('a');
    this.style.backgroundImage = 'url(/homepage/images/login/tabSelectedRight.gif)';
    thisAnchor[0].style.color = '#ffffff';
    thisAnchor[0].style.backgroundImage = 'url(/homepage/images/login/tabSelectedLeft.gif)';
    //this.className = 'over';
}
function buyerScript() {
    // set tabs to appropriate states
    var thisAnchor = document.getElementById('buyerLink');
    var thatAnchor = document.getElementById ('sellerLink');
    var thisListItem = thisAnchor.parentNode;
    var thatListItem = thatAnchor.parentNode;
    thatListItem.style.backgroundImage = 'url(/homepage/images/login/tabRight.gif)';
    thatAnchor.style.color = '#333367';
    thatAnchor.style.backgroundImage = 'url(/homepage/images/login/tabLeft.gif)';    
    thisListItem.style.backgroundImage = 'url(/homepage/images/login/tabSelectedRight.gif)';
    thisAnchor.style.color = '#ffffff';
    thisAnchor.style.backgroundImage = 'url(/homepage/images/login/tabSelectedLeft.gif)';
    thatListItem.className = '';
    thisListItem.className = 'selectedTab';
    thisListItem.onmouseover = '';
    thisListItem.onmouseout = '';
    thatListItem.onmouseover = loginTabOver;
    thatListItem.onmouseout = loginTabOut;
    // set form action to appropriate action
    var loginForm = document.getElementById('loginForm');
    loginForm.action = 'https://'+thisHost+'/login.do';
    loginForm.userName.focus ();
    return false;
}
function sellerScript() {
    // set tabs to the appropriate states
    var thisAnchor = document.getElementById('sellerLink');
    var thatAnchor = document.getElementById ('buyerLink');
    var thisListItem = thisAnchor.parentNode;
    var thatListItem = thatAnchor.parentNode;
    thatListItem.style.backgroundImage = 'url(/homepage/images/login/tabRight.gif)';
    thatAnchor.style.color = '#333367';
    thatAnchor.style.backgroundImage = 'url(/homepage/images/login/tabLeft.gif)';    
    thisListItem.style.backgroundImage = 'url(/homepage/images/login/tabSelectedRight.gif)';
    thisAnchor.style.color = '#ffffff';
    thisAnchor.style.backgroundImage = 'url(/homepage/images/login/tabSelectedLeft.gif)';
    thatListItem.className = '';
    thisListItem.className = 'selectedTab';
    thisListItem.onmouseover = '';
    thisListItem.onmouseout = '';
    thatListItem.onmouseover = loginTabOver;
    thatListItem.onmouseout = loginTabOut;
    // set form action to appropriate action
    var loginForm = document.getElementById('loginForm');
    loginForm.action = 'https://'+thisHost+'/autosalvage/login.do';
    loginForm.userName.focus();
    return false;
}


// login init script without focus on user field for customer registration screens

function tabLoginInitWithoutFocus() {
    var tabs = document.getElementById('tabLoginInner');
    var listElements = tabs.getElementsByTagName('li');
    if(listElements) {
        for (var i = 0; i < listElements.length; i ++) {
            if(listElements[i].className.indexOf('select') == -1) {
                // this is not a selected element, so
                // assign mouseover / mouseout functions
                listElements[i].onmouseover = loginTabOver;
                listElements[i].onmouseout = loginTabOut;
            }
        }
    }
    // find the two login links
    var buyerLoginLink = document.getElementById('buyerLink');
    var sellerLoginLink = document.getElementById('sellerLink');
    // find their parent <li> elements
    var buyerLoginListItem = buyerLoginLink.parentNode;
    var sellerLoginListItem = sellerLoginLink.parentNode;
    if(buyerLoginListItem) {
        buyerLoginListItem.onclick = buyerScript;
    }
    if(sellerLoginListItem) {
        sellerLoginListItem.onclick = sellerScript;
    }
    var loginForm = document.getElementById('loginForm');
    loginForm.action = 'https://'+thisHost+'/login.do';
}

