// Use the stats system Versie 1.3, 21 mei 2001

var inputVal = "Code postal";
var inputVal2 = " Mot recherché ou numéro d'annonce";
var inputVal3 = " Mot recherché ou numéro d'annonce";
var inputVal4 = "Collez ici le code HTML fourni par l'hébergeur de votre vidéo (lecteur exportable ou embed)";
var hintValuePriceMin = "Prix min";
var hintValuePriceMax = "Prix max";

loc = escape(document.location.href);
ref = escape(document.referrer);

var image = '<img width=1 height=1 border=0 hspace=0 vspace=0 src="img/spacer.gif">';
var tcimage='<img width=1 height=1 border=0 hspace=0 vspace=0 src="img/spacer.gif">';

// Controleer browser versie (getObj)
var ns4=(document.layers);
var ie4=(document.all && !document.getElementById);
var ie5=(document.all && document.getElementById);
var ns6=(!document.all && document.getElementById);

String.prototype.trim = function() {
    a = this.replace(/^\s+/, '');
    return a.replace(/\s+$/, '');
};

function s_form() {
    return confirm("Weet u zeker dat u dit bod wilt verwijderen?");
}

function trash(imgpath, owner, bidder, ad, bid, from_url){
    var user_id = getCookie ('user_id') || 0;
    if ( ( owner == user_id || bidder == user_id ) && bid )
    return '<form action="/del_bid.php" method=post onSubmit="javascript:return s_form()">' +
    '<input type=hidden name=adId value="'+ ad + '">' +
    '<input type=hidden name=bi_id value="' + bid + '">' +
    '<input type=hidden name=from_url value="' + from_url + '">' +
    '<input ' + 'type="image" ' +
    'src="'+imgpath+'btn_trashcan.gif" ' +
    'border="0" ' +
    'alt="Verwijder dit bod" ' +
    'align="right">' +
    '</form>';
    return '&#160;';
}

function gotFlash ()
{
    var plugin = (navigator.mimeTypes && navigator.mimeTypes["application/x-shockwave-flash"]) ? navigator.mimeTypes["application/x-shockwave-flash"].enabledPlugin : 0 ;
    if (plugin)
    {
        var words = navigator.plugins["Shockwave Flash"].description.split (" ") ;
        var len = words.length ;
        for (var walk = 0 ; walk < len ; ++walk)
        {
            if (isNaN (parseInt (words[walk])))
            continue ;
            return words[walk] >= 6 ;
        }

        return false  ;
    }
    else if (navigator.userAgent && navigator.userAgent.indexOf ("MSIE") >= 0 && (navigator.appVersion.indexOf ("Win") != -1))
    {
        document.write ("<SCR" + "IPT LANGUAGE=\"VBScript\">") ; //FS hide this from IE4.5 Mac by splitting the tag
        document.write ('on error resume next \n') ;
        document.write ("gotFlashNow = (IsObject (CreateObject (\"ShockwaveFlash.ShockwaveFlash.\" & 6)))\n") ;
        document.write ("<\/SCR" + "IPT>") ;

        return gotFlashNow;
    }

    return false ;
}

function getClientWidth() {
    return (navigator.userAgent.indexOf("MSIE") > 0) ? document.body.clientWidth : window.innerWidth;
}

//Omniture track
function track_exit(name) {
    track_omniture_obj(true, name, 'e');
}
function track_custom(name) {
    track_omniture_obj(true, name, 'o');
}
function track_download(name) {
    track_omniture_obj(true, name, 'd');
}

function track_omniture(name, type) {
    var s_exit=s_gi(s_account);
    s_exit.tl(type,name);
}

function track_omniture_obj(obj, name, type) {
    var s_exit=s_gi(s_account);
    s_exit.tl(obj,type,name);
}

function getObj(id){
    var tmp_obj;
    // Netscape 4
    if(ns4) {tmp_obj = document.layers[id];}
    // Explorer 4
    else if(ie4){tmp_obj = document.all[id];}
    // W3C - Explorer 5+ and Netscape 6+
    else if(ie5 || ns6){tmp_obj = document.getElementById(id);}
    return(tmp_obj);
}

function gotoAd(url){document.location.href=url;}
function gotoUrl(url){document.location.href=url;}

/* create tmp cookie function, no good ones available at this point */

function Set_Cookie( name, value, expires, path, domain, secure )
{
    // set time, it's in milliseconds
    var today = new Date();
    today.setTime( today.getTime() );
    if ( expires )
    {
        expires = expires * 1000 * 60 * 60 * 24;
    }
    var expires_date = new Date( today.getTime() + (expires) );

    document.cookie = name + "=" +escape( value ) +
    ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
    ( ( path ) ? ";path=" + path : "" ) +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ( ( secure ) ? ";secure" : "" );
}


function getCookie(name) { // use: getCookie("name");
    return Get_Cookie(name);
}


function Get_Cookie( name ) {
    index = document.cookie.indexOf(name + "=");
    if (index == -1) return null;
    index = document.cookie.indexOf("=", index) + 1; // first character
    endstr = document.cookie.indexOf(";", index);
    if (endstr == -1) endstr = document.cookie.length; // last character
    return unescape(document.cookie.substring(index, endstr));
}

function Delete_Cookie( name, path, domain ) {
    if ( Get_Cookie( name ) ) document.cookie = name + "=" +
    ( ( path ) ? ";path=" + path : "") +
    ( ( domain ) ? ";domain=" + domain : "" ) +
    ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}
/* end tmp cookie functions */

// New functionality
function makeHint(element, text) {
    if (!element._defaultText) {
        element._defaultText = text;
        if (element.maxLength > -1) {
            element._maxLength = element.maxLength;
            element.maxLength = 9999;
        }

        element.onfocus = function () {
            if (this.value == this._defaultText) {
                this.value = "";
            }
            if (typeof this._maxLength != 'undefined') {
                this.maxLength = this._maxLength;
            }
            this.style.color = "#000"; //better do this within css, and swapping classNames
        }
        element.onblur = function () {
            this.value.trim();
            if (this.value == "") {
                if (typeof this._maxLength != 'undefined') {
                    this.maxLength = 9999;
                }
                this.value = element._defaultText;
                this.style.color = "#999";
            }
        }
        element.onblur();//first time around call it
    }
}

function resize(element, tag) {
    var temp = document.createElement(tag);
    temp.style.display = 'block';
    var txt = element.innerHTML;
    element.innerHTML = "";
    element.appendChild(temp);
    var width = temp.offsetWidth;
    temp.style.display = 'inline';
    temp.innerHTML = txt;
    if (temp.offsetWidth > width) {
        var txtArray = txt.split(/&nbsp;/);
        element.title = temp.innerText || temp.textContent;//txt.replace('&nbsp;', ' ');
        var pre = txtArray[0];
        var post = txtArray[1]||'';
        while (pre.length > 0 && temp.offsetWidth > width) {
            pre = pre.substr(0, pre.length-1);
            temp.innerHTML = pre + '\u2026&nbsp;'+post;
        }
        var txt = temp.innerHTML;
    }
    element.innerHTML = txt;
    //a.style.display='block';
}

/* unobtrusive style input filter on numeric and comma */
function makeInputFilter(element) {
    element.onkeydown = function (e) {
        e = (e) ? e : event;
        var keyCode = (e.charCode) ? e.charCode : ((e.keyCode) ? e.keyCode : ((e.which) ? e.which : 0));
        return ((keyCode >= 48 && keyCode <= 57 && !(e.shiftKey || e.altKey)) || (keyCode >= 96 && keyCode <= 105) || keyCode == 188 || keyCode == 46 || (keyCode <= 40  && keyCode != 32));
    }
}

function validateSearch(form) {
	
    //form.titleSearch.focus();
    if (form.titleSearch.value == "" || (form.titleSearch._defaultText && form.titleSearch.value == form.titleSearch._defaultText)) {
        alert("Veuillez renseigner le(s) mot(s) recherché(s).");
        form.titleSearch.focus();
        return false;
    }
    if (form.titleSearch.value.trim().length<2) {
        alert('Vous avez donné un mot d\'un seul lettre. minimum 2 lettres.');
        form.titleSearch.focus();
        return false;
    }

    return true;
}

function Reformat(tempAmountFormat) {
    if (tempAmountFormat!='') {
        return(replace(tempAmountFormat, '.', ''));
    }
    return '';
}

function Recalculate(tempAmount) {
    if (!isNaN(tempAmount.replace(',', '')) && tempAmount!='') {
        tempAmount=tempAmount.replace('.', ',');
        commaPosition = tempAmount.lastIndexOf(",");
        if (commaPosition == -1) {
            amountFull = tempAmount;
            amountCents = '';
        }
        else {
            amountFull = tempAmount.substring(0, commaPosition);
            amountCents = tempAmount.substring(commaPosition+1, commaPosition+3);
            amountCents = amountCents+'00';
            if (parseInt(amountCents) == 0) {amountCents = '';}
        }
        amountFull = amountFull.replace(',', '');
        amountFull = amountFull-0;
        amountFull = currencyFormat(amountFull);
        if (amountCents > 0) {
            tempAmountNew = amountFull+','+amountCents.substring(0,2);
        }
        else {
            tempAmountNew = amountFull;
        }
        return tempAmountNew;
    }

    return '';
}
function currencyFormat(number) {
    number = '' + number;
    if (number.length > 3) {
        var mod = number.length%3;
        var output = (mod > 0 ? (number.substring(0,mod)) : '');
        for (i=0 ; i < Math.floor(number.length/3) ; i++) {
            if ((mod  == 0) && (i  == 0)) {
                output+= number.substring(mod+3*i,mod+3*i+3);
            } else {
                output+= '' + number.substring(mod+3*i,mod+3*i+3);
                //output+= '.' + number.substring(mod+3*i,mod+3*i+3);
            }
        }
        return (output);
    }

    return number;
}
