﻿/**
 *	Live Nation EU - Javascript Tools
 *
 *	@date		2007-07-11
 *	@author		Michael Giuliano
 *	@copyright	Live Nation (Music) UK
 */


/**
 *  Loader function
 *  Add a function to window.onload event
 */
function addLoadEvent(func, args) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = function() {
            func(args);
        }
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func(args);
        }
    }
}


/**
 *  Open link in a _blank window if rel is set to "external"
 */
function externalLinks() {
    if (!document.getElementsByTagName) return;
    var anchors = document.getElementsByTagName("a");
    for (var i=0; i<anchors.length; i++) {
        var anchor = anchors[i];
        if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external") {
            anchor.target = "_blank";
        }
    }
    anchors = document.getElementsByTagName("area");
    if (anchors){
        for (var i=0; i<anchors.length; i++) {
            var anchor = anchors[i];
            if (anchor.getAttribute("href"))
                anchor.target = "_blank";
        }
    }
}


/**
 *  Crop the Package description text area
 *
 *  Crops to 143px if Buy Button is present
 *  Crops to 222px otherwise
 */
function cropPackageText() {
    var el = $("eventPackageDescription");
    var elHeight = Element.getHeight(el);
    var btn = $("buyButton");
    var more = $("more_info");
    if (btn == null) {
        if (elHeight > '210') {
            el.style.height = "210px";
            more.style.display = 'block';
        }
    } else {
        if (elHeight > '130') {
            el.style.height = "130px";
            more.style.display = 'block';
        }
    }
}


/**
 *  Sets Focus
 */
function setFocus(id) {
    id.focus();
}


/**
 *  Check if the keypress is the "enter" key
 */
function checkEnter(e) {
    var characterCode;
    if(e && e.which) { //if which property of event object is supported (NN4)
        e = e;
        characterCode = e.which; //character code is contained in NN4's which property
    } else {
        e = event;
        characterCode = e.keyCode; //character code is contained in IE's keyCode property
    }
    if(characterCode == 13) {
        return true;
    } else {
        return false;
    }
}


/**
 *  Check pressed key
 */
function checkKey(e) {
    if(checkEnter(e)) {
        return checkSearchString();
    } else {
        return true;
    }
}


/**
 *  Check whether the Search String is not null
 */
function checkSearchString() {
    var ssObj = $("enterSearchTerms");
    if (ssObj.value != "") {
        gotosearch(ssObj);
    } else {
        alert("Search box can not be empty.");
        setFocus(ssObj);
    }
    return false;
}

 
/**
 *  Triggers the search button
 */
function gotosearch(o){
    var value = o.value;
    o.value = "Searching ...";
    location.href = "http://www.livenation.se/search/intermediateSearch/searchstring/" + value;
}