

function check_pass(field1, field2, result, message) {
    if (document.getElementById(field1).value != document.getElementById(field2).value && document.getElementById(field1).value != "" && document.getElementById(field2).value != "")
	document.getElementById(result).innerHTML = "<font color='#bb0000'>" + message + "</font>";
    else
	document.getElementById(result).innerHTML = "";
    //setTimeout("check_pass('" + field1 + "', '" + field2 + "', '" + result + "', \"" + message + "\");", 600);
}

function getCookie( check_name ) {
        // first we'll split this cookie up into name/value pairs
        // note: document.cookie only returns name=value, not the other components
        var a_all_cookies = document.cookie.split( ';' );
        var a_temp_cookie = '';
        var cookie_name = '';
        var cookie_value = '';
        var b_cookie_found = false; // set boolean t/f default f
        
        for ( i = 0; i < a_all_cookies.length; i++ )
                {
                        // now we'll split apart each name=value pair
                        a_temp_cookie = a_all_cookies[i].split( '=' );
                        
                        
                        // and trim left/right whitespace while we're at it
                        cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
                        
                        // if the extracted name matches passed check_name
                        if ( cookie_name == check_name )
                                {
                                        b_cookie_found = true;
                                        // we need to handle case where cookie has no value but exists (no = sign, that is):
                                        if ( a_temp_cookie.length > 1 )
                                                {
                                                        cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
                                                }
                                        // note that in cases where cookie is initialized but no value, null is returned
                                        return cookie_value;
                                        break;
                                }
                        a_temp_cookie = null;
                        cookie_name = '';
                }
        if ( !b_cookie_found )
                {
                        return null;
                }
}

function ajax(url)
{ 
        var xhr;
        var res;
        try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
        catch (e) 
        {
                try {   xhr = new ActiveXObject('Microsoft.XMLHTTP');    }
                catch (e2) 
                {
                        try {  xhr = new XMLHttpRequest();     }
                        catch (e3) {  xhr = false;   }
                }
        }
        
        xhr.onreadystatechange  = function()
                { 
                        if(xhr.readyState  == 4)
                                {
                                        if(xhr.status  == 200) {
                                                res = xhr.responseText;
                                        }
                                }
                }; 
        
        xhr.open("GET", url,  false); 
        xhr.send(null);
        return res;
}

function getPageAsync(url, div)
{ 
        var xhr;
        var res;
	//alert(url);
        try {  xhr = new ActiveXObject('Msxml2.XMLHTTP');   }
        catch (e) 
        {
                try {   xhr = new ActiveXObject('Microsoft.XMLHTTP');    }
                catch (e2) 
                {
                        try {  xhr = new XMLHttpRequest();     }
                        catch (e3) {  xhr = false;   }
                }
        }
        
        xhr.onreadystatechange  = function()
                { 
                        if(xhr.readyState  == 4)
                                {
                                        if(xhr.status  == 200) {
					    //alert(xhr.responseText);
					    document.getElementById(div).innerHTML = xhr.responseText;
                                        }
                                }
                }; 
        
        xhr.open("GET", url, true); 
        xhr.send(null);
}

function getLastInsert(id, n) {
        return ajax("/UploadControler/last" + id + "/" + n);
}

function getLastInsertId(id, n) {
        return ajax("/UploadControler/last" + id + "Id/" + n);
}

function setImg(id, n) {
        img = getLastInsert(id, n);
        document.getElementById(id  + "" + n).innerHTML = "<img src='" + img + "' />";
        imgId = getLastInsertId(id, n);
        document.getElementById(id  + "" + n).innerHTML += "<input type='hidden' name='" + id + "Id" + n + "' value='" + imgId + "' />";
	//alert(document.getElementById(id  + "" + n).innerHTML);
}

function browse(id) {
        document[id].browse();
}

function showAlertBox(mess) {
	document.getElementById("alertBox").innerHTML = "<a href='javascript:hideAlertBox()'>fermer</a>" + mess;
	document.getElementById("alertBox").style.visibility = "visible";
	document.getElementById("alertBox").style.top = (window.pageYOffset + 200) + "px";
}

function hideAlertBox() {
    document.getElementById("alertBox").style.visibility = "hidden";
}

function addAsFriend(id) {
	$.get("/membre/addFriend/" + id, function (data) {
		showAlertBox("<br /><h4>Message bien envoyé. Vous serez prévenu dès que votre demande sera acceptée ou refusée.</h4>");
	});
}

function lostPassword() {
	content = "<table>";
	content += "<tr><td>Entrez votre login : <input style='border:1px solid #999;' type='text' id='lostPasswordLogin' /></td>";
	content += "<td align='center'><input style='background-color:#CCCBCB; border:1px solid #27819B; color:#27819B; text-transform:uppercase; margin:0 0 0 5px; font-size:10px; cursor:pointer; font-weight:bold;' type='submit' onclick='sendLostPasswordReq($(\"#lostPasswordLogin\")[0].value)' value='envoyer' /></td></tr>";
	content += "</table>";
	showAlertBox(content);
}

function sendLostPasswordReq(login) {
	$.get("/membre/sendPasswordByMail/" + login, function (data) {
		if (data == "1")
			showAlertBox("<br /><h4>Un email a été envoyé a l'addresse donnée lors de la création de compte.</h4>");
		else
			showAlertBox("<br /><p>Un problème interne est survenu. Veuillez réessayer ultérieurement.</p>");
	});
}

function chapterMove() {
	var from = null;
	var to = null;
	var fromName;
	var toName;

	this.setChap = function(id, name) {
		if (from == null) {
			from = id;
			fromName = name;
		}
		else {
			to = id;
			toName = name;
		}
		disp();
	}

	this.cancel = function() {
		to = null;
		from = null;
		disp();
	}

	this.send = function() {
		location.href="/admin/moveArticles/" + to + "/" + from;
	}

	var disp = function() {
		content = "<table>";
		if (from != null)
			content += "<tr><td>depuis: " + fromName + "</td></tr>";
		if (to != null)
			content += "<tr><td>vers: " + toName + "</td></tr>";
		if (from && to)
			content += "<tr><td style='font-size:10px;' align='right' onclick='mover.send()'>déplacer</td></tr>";
		content += "<tr><td style='font-size:10px;' align='right' onclick='mover.cancel()'>annuler</td></tr>";
		content += "</table>";
		showAlertBox(content);
	}
}

