function in_array(value,array){
    for(var i in array){
        if (array[i] == value)
            return value;
    }
    return false;
}

function insert_posting_img(url)
{
    if (!url)
        return;
    donotinsert = false;
    content = '[img]'+url+'[/img]';
    document.post.message.value += content;
}

function get_postingimg_content()
{
    content = '<form enctype="multipart/form-data" name="uimage_f" method="post" action="docmd.php?mode=avatar&op=post" target="docmd_f">';
    content += '<table style="width:500px;"><tr><td class="row1">';
    content += 'Vous pouvez ins&eacute;rer une image situ&eacute;e sur <b>Internet</b> :<BR>';
    content += 'URL : <input type ="text" size="20" name="img_url">';
    content += '<div align=center><div class="generic_button" onclick="insert_posting_img(document.uimage_f.img_url.value);close_popup(false);return false;">INS&Eacute;RER</div></div>';
    content += '</td></tr><tr><td>___________</td></tr><tr><td class="row1">';
    content += 'ou situ&eacute; sur votre <b>ordinateur</b> :<BR>';
    content += '<input type="file" name="fileinfos"><BR>';
    content += '<input type="hidden" name="upload">';
    content += '<div align=center><div class="generic_big_button" onclick="javascript:if(!document.uimage_f.fileinfos.value || isposting){return false;};var isposting=true;document.getElementById(\'waiting_s\').style.display = \'block\';document.uimage_f.submit();">TRANSF&Eacute;RER</div></div>';
    content += '<span id="waiting_s" style="display:none;"><IMG HEIGHT="15" SRC="images/icon_load.gif">Veuillez patienter pendant le transfert de votre image...</span>';
    content += '</td></tr></table>';
    content += '</form>';
    content += '<BR>';
    
    return content;
}

function get_cardsbox_content(fh_str)
{
    var nums = new Array(2,3,4,5,6,7,8,9,10,'J','Q','K','A');
    var cols = new Array('S','H','D','C');
    var content = '<BR>Choisissez les cartes (5 max.) de votre Main F&eacute;tiche :<BR>';
    var fh = fh_str.split('+');
    for (var col in cols){
        content += '<div style="display:block;width:600px;height:48px;">';
        for (var num in nums){
            var card_class = 'card'; 
            //if ( in_array(nums[num]+cols[col],fh) ){
            //    card_class = 'card_c';
            //    obj
            //}
            content += '<IMG ID="'+nums[num]+cols[col]+'" WIDTH="35" HEIGHT="48" SRC="/forums/images/smiles/'+nums[num]+cols[col]+'.gif" class="'+card_class+'" onmouseover="javascript:if(this.className!=\'card_c\'){this.className = \'card_o\';}" onmouseout="javascript:if(this.className!=\'card_c\'){this.className =\'card\';}" onclick="javascript:card_toggle(this);" ';
            
            if ( in_array(nums[num]+cols[col],fh) ){
                content += 'onload="javascript:card_toggle(this);"' 
            }
            content += '> ';
        }
        content += '</div>'; 
    }
    content += '<BR>'; 

    //content += '<input type="submit" value="OK" onclick="javascript:document.forms.f_profile.poker_fetish.value = myjoin(lh_ary);lh_ary=new Array();close_popup(false);return false;">';
    //content += '<input type="submit" value="OK" onclick="javascript:update_poker_fetish(myjoin(lh_ary));lh_ary=new Array();close_popup(false);return false;">';
    content += '<div style="display:block;height:18px;"><img src="images/icon_ok.gif" onclick="javascript:update_poker_fetish(myjoin(lh_ary));lh_ary=new Array();close_popup(false);"></div>';

    return content;
}

function update_tags(myform)
{
    var stop=0
    for (var i=0; i < myform.elements.length; i++)
    {
        if (myform.elements[i].type == 'checkbox' && myform.elements[i].checked && !stop){
            add_tag(myform.elements[i].id,1);
        }
    }
}

function update_poker_fetish(fh_str)
{
    document.forms.f_profile.poker_fetish.value = fh_str;
    var fh_span = window.document.getElementById('poker_fetish_s');
    if (!fh_span) { return; } 
    if (!fh_str) {
        //fh_span.innerHTML = '<A HREF="javascript:;">Configurer</A>';
        fh_span.innerHTML = 'Aucune configur&eacute;e';
        //fh_span.innerHTML = 'Cliquez ici';
        return;
    }
    var fh = fh_str.split('+');
    fh_span.innerHTML = '';
    var imgW = "35";
    if (fh.length > 4) { imgW="28"; } 
    for (var i in fh)
    {
        //fh_span.innerHTML += '<IMG WIDTH="35" HEIGHT="48" SRC="/forums/images/smiles/'+fh[i]+'.gif">';
        fh_span.innerHTML += '<IMG WIDTH="'+imgW+'" SRC="/forums/images/smiles/'+fh[i]+'.gif">';
    }
}

function popup_info(message,reload,rurl) {
    var msg = message + '<BR><BR><img class="clickable" src="images/icon_ok2.gif" onclick="javascript:close_popup('+reload+');">';
    print_div(msg,reload,rurl);
}

function addIframe(elt)
{
            var iFrame;
            if (!g_PopupIFrame)
                iFrame = document.createElement("IFRAME");
            else
                iFrame = g_PopupIFrame;
            iFrame.setAttribute("src", "");
            iFrame.style.position="absolute";
            iFrame.style.left =elt.offsetLeft + 'px';
            iFrame.style.top =elt.offsetTop + 'px';
            iFrame.style.width =elt.offsetWidth + 'px';
            iFrame.style.height =elt.offsetHeight + 'px';
            
            if (!g_PopupIFrame){
                document.body.appendChild(iFrame);
                g_PopupIFrame=iFrame;
            }
    
}

function delIframe()
{
    document.body.removeChild(g_PopupIFrame);
    g_PopupIFrame=null;
}

function print_div(message,reload,rurl)
{
    var obj = document;
    if (parent)
        obj = parent.document;
    
    var popup_div = obj.getElementById('popup_div');
    var popup_container = obj.getElementById('popup_container');
    var popup_content = obj.getElementById('popup_content');
    var popup_close = obj.getElementById('popup_a_close');
    
    popup_content.innerHTML = message;

    if (popup_close){
        popup_close.onclick = function(){ close_popup(reload,rurl); };
    }

    popup_div.style.visibility = 'hidden';
    popup_div.style.display = 'block';
    
    popup_container.style.height = Math.max(popup_content.offsetHeight + 10,150) +'px';
    popup_container.style.width = Math.max(popup_content.offsetWidth +10,300 ) +'px';
    popup_container.style.marginLeft = '-' + popup_container.offsetWidth / 2 + 'px'; 
    popup_content.style.marginLeft = '-' + popup_content.offsetWidth / 2 + 'px'; 
   
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
        var ieversion=new Number(RegExp.$1);
        if (ieversion>=6 && ieversion<7)
        { 
            //alert('toto');
            //else
            //    document.body.appenChild(iFrame);
            popup_div.style.zIndex = popup_div.style.zIndex+1;
            if (parent)
                parent.addIframe(popup_container);
            else
                addIframe(popup_container);
            if (parent)
                parent.scrollTo(0,0);
            else
                window.scrollTo(0,0);
        }
        else {
            popup_container.style.marginTop = '-' + popup_container.offsetHeight / 2 + 'px'; 
            popup_content.style.marginTop = '-' + (popup_content.offsetHeight / 2) + 'px';
        }
    }
    else {
        popup_container.style.marginTop = '-' + popup_container.offsetHeight / 2 + 'px'; 
        popup_content.style.marginTop = '-' + (popup_content.offsetHeight / 2) + 'px';
    }
    popup_div.style.visibility = 'visible';
    popup_content.focus();
}

function close_popup(reload_after,rurl) {
    var context = parent.document;
    if (!context)
        context = document;
    var popup = context.getElementById('popup_div');
    popup.style.display='none';
    if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)){
        var ieversion=new Number(RegExp.$1);
        if (ieversion>=6 && ieversion<7)
            if (parent)
                parent.delIframe();
            else
                delIframe();
    }
    if (window.docmd_f) {
        window.docmd_f.location.replace('wait.php');
    }
    else
    {
        document.location.replace('wait.php');
    }
    if (reload_after){
        if (rurl) {
            context.location.href = rurl; 
        }
        else {    
            
            //alert(context.location.href);
            context.location.replace(context.location.href);
            //alert(parent.location.href);
            //context.location.reload();
        }
    }
}

function get_popup(url)
{
    //window.docmd_f.location.replace(url);
    if (window.docmd_f)
        window.docmd_f.location.replace(url);
    else if (parent.docmd_f)
        parent.docmd_f.location.replace(url);
}

function form_popup(form_name, width, height, window_name) {
    if (!width) { width = '200'; }
    if (!height) { height = '200'; }
    if (!window_name) { window_name = 'wam_popup'; }
    
    var form = eval("document."+form_name);
    //var popup=window.open('wait.php',window_name,'width='+width+',height='+height+',toolbar=0,location=0,directories=0,menubar=0,scrollbars=0,resizable=1,status=0,locationbar=0');
    
    //form.target = window_name;
    form.target = "docmd_f";
    form.submit();
    //popup.focus();
}

function unset(array,index) {
    var output=[];
    for(var i in array){
        if (i!=index)
            output[i]=array[i];
    }
    return output;

}
function myjoin(array) {
    var card_str='';
    for(var i in array){
        if (card_str) {card_str = card_str+'+'}
        card_str = card_str+array[i].id;
    }
    return card_str;
}
function card_toggle(obj)
{
    if (obj.className=='card_c'){
        for(var i=0; i < lh_ary.length; i++)
            if (lh_ary[i] == obj){
                lh_ary = unset(lh_ary,i);
            }
        obj.className='card';
    }
    else {
        lh_ary.push(obj);
        if (lh_ary.length > 5) {
            var ocard = lh_ary.shift();
            if (ocard)
            {
                ocard.className='card';
            }
        }
        obj.className='card_c';
    }
}

function submitenter(myfield,e)
{
    var keycode;
    if (window.event) keycode = window.event.keyCode;
        else if (e) keycode = e.which;
            else return true;

    if (keycode == 13)
    {
        if(myfield.form.onsubmit) {
            if(myfield.form.onsubmit()) 
                myfield.form.submit();
        } else
            myfield.form.submit();
        return false;
    }
    else
        return true;
}

function h_toggle_content(id,minheight){
    var objet = document.getElementById('h_content'+id); 
    if(objet.style.display == "none" || !objet.style.display || objet.style.height == minheight+'px'){
        var hFinal      =     h_maxh[id];  //Hauteur finale (la hauteur une fois que ça aura fini de déplier !)
        var hActuel     =     minheight;        //Hauteur initiale (la hauteur dès le début !)
        
        objet.style.height = hActuel + 'px';
        objet.style.display = "block";
        objet.style.overflow = "hidden"; 
        var timer;
        var fct =        function ()
        {
                hActuel  +=       25;     //Augmente la hauteur de 10px (tu peux modifier) tous les 40ms !
                
                objet.style.height     =     hActuel      +     'px';
                
                if( hActuel > hFinal)
                {
                        objet.style.height     =    hFinal + 'px';
                        objet.style.overflow = "visible"; 
                        clearInterval(timer);   //Arrête le timer
                }
        };
        fct();

        
        timer = setInterval(fct,40);    //Toute les 40 ms
        
    }else if(objet.style.display == "block" || objet.style.height > minheight){
        var hFinal      =     minheight;  //Hauteur finale (la hauteur une fois que ça aura fini de déplier !)
        var hActuel     =     objet.offsetHeight;
        
        objet.style.overflow = "hidden"; 
        var timer;
        var fct =        function ()
        {
                hActuel  -=   25;     //Augmente la hauteur de -20px (tu peux modifier) tous les 40ms !
                if ( hActuel < hFinal)
                    hActuel = hFinal;
                objet.style.height     =     hActuel      +     'px';
                //objet.style.height     =     'auto';
                
                if( hActuel == hFinal)
                {
                        clearInterval(timer);   //Arrête le timer
                        if (hFinal == 0)
                            objet.style.display     =   'none';
                }
        };
        fct();

        
        timer = setInterval(fct,40);    //Toute les 40 ms
    }
}

function h_toggle_switch(id) {
    var element = document.getElementById(id);
    if (!element) return;
    if(element.innerHTML == "+") {
        element.innerHTML = "-"; 
    } else {
        element.innerHTML = "+"; 
    } 
}

function h_toggle_end(id) {
    var element = document.getElementById(id);
    if (!element) return;
    if (element.innerHTML && element.innerHTML != '' && element.innerHTML != '(...)' && element.innerHTML != '^^^') {
        element.parentNode.style.display = "none";
        return;
    }
    if(element.innerHTML == "(...)") {
        element.innerHTML = "^^^"; 
    } else {
        element.innerHTML = "(...)"; 
    } 
}
function h_toggle(h_id,minheight) {
    h_toggle_content(h_id,minheight);
    h_toggle_switch('h_a'+h_id);
    if (minheight != 0) {
        h_toggle_end('h_endswitch'+h_id);
        //var element = document.getElementById('h_end'+h_id);
        //if (element.style.display == 'none')
        //    element.style.display = 'block';
        //else
        //    element.style.display = 'none';
    }
}

function h_toggle_init(h_id,minheight) {
    var objet = document.getElementById('h_content'+h_id);
    var maxheight = 108;
    if (minheight == 200)
        maxheight = 200;
    if (minheight==0 || objet.offsetHeight > maxheight)
    {
        var sw = document.getElementById('h_switch'+h_id);
        if (sw) sw.style.display = 'inline';
        var content = document.getElementById('h_content'+h_id);
        content.style.overflow = "hidden";
        content.style.height = minheight+'px';
        if (minheight != 0) {
            //alert("OK");
            var end = document.getElementById('h_end'+h_id);
            if (end.style.display == 'none')
                end.style.display = 'block';
            else
                h_toggle_end('h_endswitch'+h_id);
        }
    }
}

function sig_resize(element,maxheight) {
var objet = document.getElementById(element);
    if(objet.offsetHeight > maxheight) {
        objet.style.height = maxheight+'px';
    }
}

function h_init_all(obj) {
    if (!obj) obj = document;
    for (var i=1; objet = obj.getElementById('h_content'+i); i++) {
        if (objet.style.display=="none"){
            objet.style.display = "block";
            h_maxh[i] = objet.offsetHeight;
            objet.style.display = "none";
        } else
            h_maxh[i] = objet.offsetHeight;
        h_toggle_init(i,h_minh[i]);
    }
    var max_sig_h = 150+30;
    for (var i=1; objet = obj.getElementById('sig'+i); i++) {
        if(objet.offsetHeight > max_sig_h) {
            objet.style.height = max_sig_h+'px';
        }
    }
}

// Replacement for arrayname.length property
function getarraysize(thearray) {
 for (i = 0; i < thearray.length; i++) {
 if ((thearray[i] == "undefined") || (thearray[i] == "") || (thearray[i] == null))
 return i;
 }
 return thearray.length;
}

// Replacement for arrayname.push(value) not implemented in IE until version 5.5
// Appends element to the array
function arraypush(thearray,value) {
 thearray[ getarraysize(thearray) ] = value;
}

function arraypop(thearray) {
 thearraysize = getarraysize(thearray);
 retval = thearray[thearraysize - 1];
 delete thearray[thearraysize - 1];
 return retval;
}

var h_fifo = new Array();
var q_fifo = new Array();
var h_id = 0;
var h_maxh = new Array();
var h_minh = new Array();

var lh_ary = new Array();

var g_PopupIFrame;
