
var champs = {
        'transaction_3':2,
        'prix_11':1,
        'annee_10':1,
        'km_12':1,
        'energie_42':1,
        'body_5':2,
        'titre_4':2,
        'cache_31':1
    };

var required = {
        'prenom_1':1,
        'nom_2':1,
        'adresse_30':1,
        'zip_21':1,
        'commune_6':1,
        'phone1_17':1,
        'pays_8':1,
        'email1_18':1
    };


var controle = {
    'password':1
};


function displayBloc (bloc2see,bloc2hide) {
    var b2see = document.getElementById("display"+bloc2see);
    var b2hide = document.getElementById("display"+bloc2hide);
    b2see.style.display="block";
    b2hide.style.display="none";
}

var vus = new Object;

function voirCodes (code,un) {
    var lcd;
    if (un) {
        lcd = document.getElementById(code);
    } else {
        lcd = document.getElementById("c"+code);
    }
    if (vus[code] && vus[code]==1 ) {
        lcd.style.display="none";
        vus[code]='';
    } else {
        lcd.style.display="block";
        vus[code]=1;
    }
}



function visuel () {

    var vl = document.getElementById('visuel');
    var bloquer = "no";
    for ( p in champs) {
        if ( document.getElementById(p) ) {
            if ( document.getElementById(p).value  ) {
                  var vv = document.getElementById(p).value;
                  if (p == "body_5") {
                    vv = vv.replace(/(\r\n|\r|\n)/g,"<br>\n");
                  }
                  document.getElementById('v'+p).innerHTML = vv;
                  if ( document.getElementById('t'+p) ) {
                    document.getElementById('t'+p).style.display="block";
                  }
                  document.getElementById('verif').style.display="block";
                  document.getElementById('v'+p).style.border="";
                  document.getElementById('v'+p).style.background="white";
            } else {
                if (  champs[p] == 2 ) {
                    bloquer = "yes";
                    document.getElementById('v'+p).innerHTML = " &nbsp;  - &nbsp; ";
                    document.getElementById('v'+p).style.background="yellow";
                    document.getElementById('v'+p).style.border="1px solid red";
                    document.getElementById('verif').style.display="none";
                }
            }
        }
        if ( p == "cache_31") {
            var nc = document.getElementsByName(p);
            for ( i=0;  i < nc.length; i++) {
                if ( nc[i].checked ) {
                    document.getElementById('v'+p).innerHTML = cache[nc[i].value];
                }
            }
        }
    }
    if ( bloquer == "yes" ) {
        document.getElementById('verif').style.display="none";
    }
    vl.style.display="block";
    document.getElementById('tabannonce').style.display="none";
}


function modifier (action) {
        if (action && action == 1) {
            document.getElementById('pbut').style.display="none";
            document.getElementById('psub').style.display="block";
            document.getElementById('psub').style.border="2px solid red";
        }
        document.getElementById('visuel').style.display="none";
        document.getElementById('tabannonce').style.display="block";
}

function afficheur (datas,dom) {
    var adresse;
    var debut = datas.reverse().join('');
    if (dom && dom[0]) {
        adresse  = '<a class="lien02" href="mailto:'+ debut + "&#64;" + dom.reverse().join('')   +'">' + debut + "&#64;" + dom.join('')  + '</a>';
    } else {
        adresse = debut ;
    }
    document.write(adresse);
}

function afficher (datas) {
    var satad = datas.reverse().join('');
    document.write(satad);
}

function ouvrirPopup (pFichier, pTitre, pLargeur, pHauteur) {
    var urlwhois = "http://whoiswho.canada.lannonce.com";
    var posX = (screen.width / 2) - (pLargeur / 2);
    var posY = (screen.height / 2) - (pHauteur / 2);
    window.open(urlwhois+pFichier,pTitre,"width = " + pLargeur + ", height = " + pHauteur + ", left = " + posX + ", top = " + posY + ", resizable = 0");
}

function revoir () {
    for (p in  champs ) {
        var tt = document.getElementById("v"+p);
        if ( tt && tt.innerHTML ) {
            document.getElementById("t"+p).style.display="block";
        }
    }
}

function grabArea (area,areatitle) {
    var areagrabbed = document.getElementById('areagrabbed');
    areagrabbed.innerHTML = document.getElementById(area).innerHTML;
    document.getElementById(areatitle).style.background="yellow";
}

function redalert (erreur,ou) {
    for (e in required) {
        if (erreur[e] == 1) {
            var raidir = document.getElementById(e);
            raidir.style.border="3px inset red";
            raidir.style.background="yellow";
            //alert(e);
            if ( msgerr['msg_'+e]  ) {
                raidmsg=document.getElementById('msg_'+e);
                raidmsg.style.border="2px solid red";
                raidmsg.style.background="yellow";
                raidmsg.style.fontWeight="bold";
                raidmsg.innerHTML=msgerr['msg_'+e];
            }
        }
    }
    if ( erreur['password'] ) {
        var raidir = document.getElementById('password');
        raidir.style.border="3px inset red";
        raidir.style.background="yellow";
        if ( msgerr['password']  ) {
            raidmsg=document.getElementById('msg'+ msgerr['password']);
                whereDisplay = document.getElementById(ou);
                whereDisplay.style.border="2px solid red";
                whereDisplay.style.background="yellow";
                whereDisplay.style.fontWeight="bold";
                whereDisplay.innerHTML = raidmsg.innerHTML; 
        }
    }

}

function deconnect () {
    var mycookie = GetCookie('estoc');
    if (mycookie) {
        var domain = document.location.host;
        DeleteCookie('estoc');
    }
}

var $pas={
    display: function (todisplay) {
        for ( var i =0; i < todisplay.length ; i++) {
            if ($( todisplay[i])) {
                if ( $( todisplay[i]).style.display=='block' ) {
                    $( todisplay[i]).style.display='none';
                } else {
                    $( todisplay[i]).style.display='block';
                }
            }
        }
        return false;
    },
    plus:function () {
        return false;
    },
    popup:function () {
        return false;
    }
}


// "Internal" function to return the decoded value of a cookie

function getCookieVal (offset) {
  var endstr = document.cookie.indexOf (";", offset);
  if (endstr == -1)
    endstr = document.cookie.length;
  return unescape(document.cookie.substring(offset, endstr));
}
//
//  Function to correct for 2.x Mac date bug.  Call this function to
//  fix a date object prior to passing it to SetCookie.
//  IMPORTANT:  This function should only be called *once* for
//  any given date object!  See example at the end of this document.
//
function FixCookieDate (date) {
  var base = new Date(0);
  var skew = base.getTime(); // dawn of (Unix) time - should be 0
  if (skew > 0)  // Except on the Mac - ahead of its time
    date.setTime (date.getTime() - skew);
}
//
//  Function to return the value of the cookie specified by "name".
//    name - String object containing the cookie name.
//    returns - String object containing the cookie value, or null if
//      the cookie does not exist.
//
function GetCookie (name) {
  var arg = name + "=";
  var alen = arg.length;
  var clen = document.cookie.length;
  var i = 0;
  while (i < clen) {
    var j = i + alen;
    if (document.cookie.substring(i, j) == arg)
      return getCookieVal (j);
	i = document.cookie.indexOf(" ", i) + 1;
    if (i == 0) break; 
  }
  return null;
}
//
//  Function to create or update a cookie.
//    name - String object containing the cookie name.
//    value - String object containing the cookie value.  May contain
//      any valid string characters.
//    [expires] - Date object containing the expiration data of the cookie.  If
//      omitted or null, expires the cookie at the end of the current session.
//    [path] - String object indicating the path for which the cookie is valid.
//      If omitted or null, uses the path of the calling document.
//    [domain] - String object indicating the domain for which the cookie is
//      valid. If omitted or null, uses the domain of the calling document.
//    [secure] - Boolean (true/false) value indicating whether cookie transmission
//      requires a secure channel (HTTPS).  
//
//  The first two parameters are required.  The others, if supplied, must
//  be passed in the order listed above.  To omit an unused optional field,
//  use null as a place holder.  For example, to call SetCookie using name,
//  value and path, you would code:
//
//      SetCookie ("myCookieName", "myCookieValue", null, "/");
//
//  Note that trailing omitted parameters do not require a placeholder.
//
//  To set a secure cookie for path "/myPath", that expires after the
//  current session, you might code:
//
//      SetCookie (myCookieVar, cookieValueVar, null, "/myPath", null, true);
//
function SetCookie (name,value,expires,path,domain,secure) {
  document.cookie = name + "=" + escape (value) +
    ((expires) ? "; expires=" + expires.toGMTString() : "") +
    ((path) ? "; path=" + path : "") +
    ((domain) ? "; domain=" + domain : "") +
    ((secure) ? "; secure" : "");
}

//  Function to delete a cookie. (Sets expiration date to start of epoch)
//    name -   String object containing the cookie name
//    path -   String object containing the path of the cookie to delete.  This MUST
//             be the same as the path used to create the cookie, or null/omitted if
//             no path was specified when creating the cookie.
//    domain - String object containing the domain of the cookie to delete.  This MUST
//             be the same as the domain used to create the cookie, or null/omitted if
//             no domain was specified when creating the cookie.
//
function DeleteCookie (name,path,domain) {
  if (GetCookie(name)) {
    document.cookie = name + "=" +
      ((path) ? ";path=" + path : "") +
      ((domain) ? ";domain=" + domain : "") + 
      ";expires=Thu, 01-Jan-70 00:00:01 GMT";
  }
}


function visible () {
    var tc = document.getElementById('tabcontact');
    if ( user['nom']  ) {
        tc.style.display="none";
    } else {
        tc.style.display="block";
        tc.style.border="1px solid black";
    }
    var ta = document.getElementById('tabannonce');
    if ( user['nom'] ) {
        ta.style.display="block";
    } else {
        ta.style.display="none";
    }
    for (p in errors) {
        var dc = document.getElementById(p);
        if (p == "errare") {
            if (errors[p] == "no") {
                dc.innerHTML = document.getElementById('msg'+12).innerHTML;
                dc.style.color="yellow";
                dc.style.background="red";
            }
        } else {
            dc.style.border="1px solid red";
        }
    }
}


