var RC = '\n';

// affiche/ cache un id
function toggle(img_scr, target)
{
	img = document.getElementById(img_scr);
	obj = document.getElementById(target);

	if(obj.style.display == 'none')
	{
		obj.style.display = 'block';
		img.src = 'img/collapseall.png';
	}
	else
	{
		obj.style.display = 'none';
		img.src = 'img/expandall.png';
	}
		
}

// dPrompt
function dPrompt(msg, val)
{
	return prompt(msg, val);
	
}


// dConfirm
function dConfirm(msg)
{
	return confirm(msg);
	
}


// logout
function logout()
{
	if(dConfirm("Voulez-vous vous déconnecter ?"))
		document.location.href = 'index.php?logout=1';
}


// dpopup
function dPopup(url)
{
	popupcentree(url, 650, 600, 'menubar=no,scrollbars=yes,statusbar=yes,resizable=yes');
}


// popup
function popupcentree(page, largeur, hauteur, opt)
{
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+opt);
} 


// ucfisrt
function ucfirst(str)
{
	if(str == 'undefined' || !str || str == '' || str.length == 0)return '';
	m = str.charAt(0).toUpperCase() + str.substring(1).toLowerCase();
	
	return m;
}

// strtoupper
function strtoupper(str)
{
	if(str == 'undefined' || !str || str == '' || str.length == 0)return '';
	str = str.toUpperCase();
	return str;
}

// strtolower
function strtolower(str)
{
	if(str == 'undefined' || !str || str == '' || str.length == 0)return '';
	str = str.toLowerCase();
	return str;
}

// trim
function trim(str)
{
	return str.replace(/(^\s*)|(\s*$)/g,''); 
}


// str_replace
function str_replace(a, b, str)
{
	i=0;
	
    while (i!=-1)
	{
		i = expr.indexOf(a,i);
        if (i >= 0)
		{
			expr=expr.substring(0,i)+b+expr.substring(i+a.length);
			i+=b.length;
		}
	}

	return expr;
}

function empty(str)
{
	if(str == null || str == '')
		return true;
	
	return false;
}

function $(objId)
{
	return document.getElementById(objId);
}

function getPositionLeft(This)
{
	var el = This;var pL = 0;
	while(el){pL+=el.offsetLeft;el=el.offsetParent;}
	return pL;
}


function setOpacity(zobj, opacity)
{
	//change the opacity for different browsers 
	obj = $(zobj);
	objX = obj.style;
    objX.opacity = (opacity / 100); 
    objX.MozOpacity = (opacity / 100); 
    objX.KhtmlOpacity = (opacity / 100); 
    objX.filter = "alpha(opacity=" + opacity + ")"; 
	
	
	if(opacity == 0)
		objX.visibility = 'hidden';
	else if(opacity == 1)
		objX.visibility = 'visible';
}


function opacity(id, opacStart, opacEnd, millisec) {
    //speed for each frame
    var speed = Math.round(millisec / 100);
    var timer = 0;

    //determine the direction for the blending, if start and end are the same nothing happens
    if(opacStart > opacEnd)
	{
        for(i = opacStart; i >= opacEnd; i--) 
		{
            setTimeout("setOpacity('"+id+"', '"+i+"')", (timer*speed));
            timer++;
        }
    } 
	else if(opacStart < opacEnd) 
	{
        for(i = opacStart; i <= opacEnd; i++)
        {
            setTimeout("setOpacity('"+id+"', '"+i+"')", (timer*speed));
            timer++;			
        }	
    }
}



function zoom(ID)
{
	url = 'zoom.php?ID='+ID;
	popupcentree(url, 340, 510, 'menubar=no,scrollbars=yes,statusbar=yes,resizable=yes');
}


function virtualPhoto(action)
{
	
	if(!$('virtual_photo_img'))
	{
		alert("Merci d'attendre le chargement de la page");
		return;
	}
	
	if(action)
	{	
		setOpacity('virtual_photo', 0);
		$('virtual_photo').style.visibility = 'visible';
		opacity('virtual_photo', 0, 50, 500);
				
		$('virtual_photo_content').style.visibility = 'visible';
		$('virtual_photo_img').style.visibility = 'visible';
	}
	else
	{
		opacity('virtual_photo', 50, 0, 500);
		//$('virtual_photo').style.visibility = 'hidden';
		$('virtual_photo_img').style.visibility = 'hidden';
		$('virtual_photo_content').style.visibility = 'hidden';
	}
	
}


function urlencode(uri)
{
	return encodeURI(uri);
}




function urlDelete(param)
{
	uri = window.location.search;	
	t = uri.split('&');
	nuri = '';
	for(i=0; i < t.length ;i++)
	{
		n = t[i].split('=');
		if(n != 2 && n[0] != param)
		{
			if(!empty(nuri))nuri += '&';
			nuri += t[i];
		}
	}
	return window.location.pathname+nuri;
}


// bonne email ?
function isEmail(zemail)
{
	if(zemail.indexOf("@") != "-1" &&  zemail.indexOf(".") != "-1" && zemail != "")
		return true;
	
	return false;
}


