// JScript source code
/*=== SPECIFIC TO THIS STORE ===*/
var agt=navigator.userAgent.toLowerCase();
var is_opera = (agt.indexOf("opera") != -1);
var is_safari = (agt.indexOf("safari") != -1);
if(is_safari) {
    var isAppleWebKit = (agt.indexOf('applewebkit') != -1);
    var appleWebKitVersion = ( (isAppleWebKit) ? parseFloat( agt.substring( agt.indexOf('applewebkit/') + 12) ) : -1 );
    var safari_vminor = parseFloat( agt.substring( agt.lastIndexOf('safari/') + 7 ) );
    var safari_vmajor = parseInt(safari_vminor);
}
/*=== SPECIFIC TO THIS STORE ===*/


function addEvent(object, type, handler){
/*
    Add any event handler to the browser, such as an onload function.
    Stable and cross-browser safe.
        object = where to attach event; >window< almost every time, though not necessarily
        type = what kind of handler to add, eg: "load"
        handler = the code (anonymous function) that will be called when event is fired.
*/
	if (object.addEventListener)
		object.addEventListener(type, handler, false);
	else if (object.attachEvent)
		object.attachEvent(['on',type].join(''),handler);
	else
		object[['on',type].join('')] = handler;
}

function findElement(item) {
/*
    Find any element by ID in a version 4+ browser.
    Returns the element.
*/
    return document.getElementById ? document.getElementById(item) : document.all[item];
}

function findElementInTags(thetag,boolstr,coll) {
/*
    Find one element in a set of tags using any attribute (not just id)
        thetag = what tag collection to use, such as 'IMG'
        boolstr = what test to give each tag, for example "className.indexOf('name') > -1"
        coll = what collection to start with, instead of >document<.getElementsByTagName
    Returns first item found.
*/
    if(coll)
        var tagColl = coll.getElementsByTagName(thetag);
    else
        var tagColl = document.getElementsByTagName(thetag);
    var theEl = false;
    for(i=0;i<tagColl.length;i++) {;
        if(eval("tagColl[i]." + boolstr)) {
            theEl = tagColl[i];
            break;
        }
    }
    return theEl;
}

function findElementsInTags(thetag,boolstr,coll) {
/*
    Find ALL elements in a set of tags using any attribute (not just id)
        thetag = what tag collection to use, such as 'IMG'
        boolstr = what test to give each tag, for example "className.indexOf('name') > -1"
        coll = what collection to start with, instead of >document<.getElementsByTagName
    Returns array of all items found.
*/
    if(coll)
        var tagColl = coll.getElementsByTagName(thetag);
    else
        var tagColl = document.getElementsByTagName(thetag);
    var elArray = new Array();
    for(i=0;i<tagColl.length;i++) {;
        if(eval("tagColl[i]." + boolstr)) {
            elArray[elArray.length] = tagColl[i];
        }
    }
    if(elArray.length == 0) elArray = false;
    return elArray;
}

function limitChars(str, lim, ml, mltext) {
/*
    Limits a string to [lim] character length.  Optional "more" link.
        str = string to modify
        lim = string length limit
        ml = more link (false if no, some url if true)
        mltext = more link text (false if no, some text if true)
*/
		if(!str) return str;
		
    var newstr = '';
    for(var i=0; i<lim; i++) {
        newstr += str.charAt(i);
    }
    if(str.length > lim)
        newstr += "... ";

    if(ml && mltext){
        mltext = replace(mltext,'>','&gt;');
        mltext = replace(mltext,'<','&lt;');
        newstr += '<span class="more"><a href="' + ml + '">' + mltext + '</a></span>';
    }
    return newstr;
}

function replace(string,text,by) {
/*
    Replaces text in a string.
        string = string to manipulate
        text = char or string to find
        by = char or string to substitute in
*/
    var strLength = string.length, txtLength = text.length;
    if ((strLength == 0) || (txtLength == 0)) return string;

    var i = string.indexOf(text);
    if ((!i) && (text != string.substring(0,txtLength))) return string;
    if (i == -1) return string;

    var newstr = string.substring(0,i) + by;

    if (i+txtLength < strLength)
        newstr += replace(string.substring(i+txtLength,strLength),text,by);

    return newstr;
}

function remove(s, t) {
/*
    Remove all occurrences of a token in a string
        s  string to be processed
        t  token to be removed
    Returns new string
*/
  i = s.indexOf(t);
  r = "";
  if (i == -1) return s;
  r += s.substring(0,i) + remove(s.substring(i + t.length), t);
  return r;
}