/* newWindow
-----------------------------------------------------------------------------*/
function newWindow(mypage, myname, w, h, scroll){
    var winl = (screen.width-w)/2;
    var wint = (screen.height-h)/2;
    var settings ='height='+h+',';
    settings +='width='+w+',';
    settings +='top='+wint+',';
    settings +='left='+winl+',';
    settings +='scrollbars='+scroll+',';
    settings +='resizable=no';
    win=window.open(mypage,myname,settings);
    if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}
/* changeToMail
-----------------------------------------------------------------------------*/
var mails=new Array();
mails[0] = "exam"+"ple@"+"examp"+"le."+"com";
mails[1] = "";

function changeToMail(id,i,title){
    if (!title) title="Envoyez un e-mail!";
    if (document.getElementById(id)) {
        document.getElementById(id).innerHTML = "<a href='" + "mai" + "lto:" + mails[i] + "' title='" + title + "'>" + mails[i] + "</a>";
    }
}
/* addLoadEvent
-----------------------------------------------------------------------------*/
function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}
/* Events
-----------------------------------------------------------------------------*/
function doOnBlur(obj, nSel, text) {
    switch (nSel) {
        case 1:
            if (obj.value.replace(/ /g,'') == ''){
                $(obj).animate({"opacity": 0}, 200);
                setTimeout(function(){obj.value = text; obj.className = "normal";}, 200);
                $(obj).animate({"opacity": 1}, 200);
            }
            break;
    }
}
function doOnFocus(obj,nSel, text) {
    switch (nSel) {
        case 1:
            if (obj.value == text){
                //obj.value = "";
                $(obj).animate({"opacity": 0}, 200);
                setTimeout(function(){obj.value = ""; obj.className = "over";}, 200);
                $(obj).animate({"opacity": 1}, 200);
            }
            break;
    }
}
/* Thumbs
-----------------------------------------------------------------------------*/
function changeThumb(idImg, idImg_Src, idImg_Top, idImg_Left, idHref, idHref_Link){
    setTimeout(function(){
        $('#'+idImg).attr('src',idImg_Src);
        $('#'+idImg).css('margin-top',idImg_Top+'px');
        $('#'+idImg).css('margin-left',idImg_Left+'px');}
        ,400);

    $('#'+idHref).attr('href',idHref_Link);
    $('#'+idImg).fadeOut(400);
    $('#'+idImg).fadeIn(500);
}
function AjaxExecutePost(strFunction, strArgs, strReturnFunction){
	$.post("ajax.php", {strFunction: strFunction, strArgs: unescape(strArgs)}, function(data){
	  eval(strReturnFunction + "(data);");
	});
}


function doLoginMonCompte(){
	var strParm = "'"+escape($("#m_loginEmail").val())+"'";
		strParm += ",'"+escape($("#m_loginPwd").val())+"'";

		AjaxExecutePost("loginUser", escape(strParm), "afterLogin");
}

function afterLogin(strRes){
	if (strRes == 'ERROR')
		alert('Utilisateur ou mot de passe invalide.');
	else{
		eval ("objRES="+strRes+";");
		$("#p_logedInName").html(objRES.client_firstname+" "+objRES.client_lastname);

        /*
		  $("#m_loginEmail").animate({"opacity":0}, 200);
		  $("#m_loginPwd").animate({"opacity": 0}, 200);

		$("#mon-compte").fadeOut("100", function (){
			$("#mon-compte2").fadeIn();
			});
        */
        $("#p_logedInName").html(objRES.client_firstname+" "+objRES.client_lastname);
		$("#panier-notlogged").fadeOut("100", function (){
            $("#panier-logged").fadeIn();
        });

	}
}


function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}

function eraseCookie(name) {
	createCookie(name,"",-1);
}

