// Cheesecom common functions

//Fonction Trim -> enlève les blanc surnuméraires en début et fin de chaine de caractères
String.prototype.trim = function ()
{
	var reg = new RegExp("^\\s*");
	var reg2 = new RegExp("\\s*$");
	return this.replace(reg, "").replace(reg2, "");
}

//Fonction d'ouverture d'une popup
function PopUp(winHeight,winWidth,theURL,winName)
{
	var features = "scrollbars=no,resizable=yes,width=" + winWidth + ",height=" + winHeight + ",top=" + (screen.height/2-winHeight/2) + ",left=" + (screen.width/2-winWidth/2);
	window.open(theURL,winName,features);
}

//Fonction de fermeture d'une popup
function ClosePopup()
{
	window.close();
}

//Fonction qui ferme une popup et rafraichi la page qui avait appelé la popup
function CloseAndRefresh()
{
	//rafraichi la page qui a ouvert le popup
	window.opener.location.reload();
	
	//ferme le popup après une demi-seconde.
	setTimeout("ClosePopup()",500);
}

//Fonction qui ferme la popup et fait naviguer la fenêtre ouvrante vers le paramètre
function CloseAndGoTo(param)
{
	//Change la page en cours dans la fenêtre ouvrante
	window.opener.location.href=param;
	
	//ferme le popup après une demi-seconde.
	setTimeout("ClosePopup()",500);
}

//Fonction qui sert à ouvrir une image agrandie après avoir cliqué sur sa copie réduite
function openwin(folder,image,imgheight,imgwidth,title) {
	/*if (format=="1")
	{
		height = "500";
		width = "375";
	}
	else
	{
		height = "375";
		width = "500";
	}*/
	
	w=open('','agrandissement','scrollbars=no,resizable=no,width='+imgwidth+',height='+imgheight+',top='+(screen.height/2-Math.floor(parseInt(imgheight)/2))+',left='+(screen.width/2-Math.floor(parseInt(imgwidth)/2)));
	w.document.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\r\n");
	w.document.write("<html xmlns=\"http://www.w3.org/1999/xhtml\">\r\n");
	w.document.write("<head>\r\n");
	w.document.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\r\n");
	w.document.write("<title>"+title+"</title>\r\n");
	w.document.write("<style type=\"text/css\">\r\n");
	w.document.write("<!--\r\n");
	w.document.write("body {\r\n");
	w.document.write("margin:0px;\r\n");
	w.document.write("padding:0px;\r\n");
	w.document.write("}\r\n");
	w.document.write("-->\r\n");
	w.document.write("</style>\r\n");
	w.document.write("</head>\r\n");
	w.document.write("<body>\r\n");
	w.document.write("<div style=\"width:"+imgwidth+"px; height:"+imgheight+"px\"><img src=\"/images/"+folder+"/big/"+image+"\" alt=\"agrandissement\" width=\""+imgwidth+"\" height=\""+imgheight+"\" border=\"0\" /></div>\r\n");
	w.document.write("</body>\r\n");
	w.document.write("</html>\r\n");
	w.document.close();
}

//Fonction de changement d'image on rollover
function SwapImage(imageid,newimage) {
	x=MM_findObj(imageid);
	x.src=newimage;
}

//Fonction de changement d'image on rollover et changement de taille
function SwapImageChangeSize(imageid,newimage,newheight,newwidth) {
	SwapImage(imageid,newimage);
	x.height=newheight;
	x.width=newwidth;
}

//Fonction de changement d'image on rollover et changement de taille ainsi que de place
function SwapImageChangeSizeAndPos(imageid,newimage,newheight,newwidth,newx,newy) {
	SwapImageChangeSize(imageid,newimage,newheight,newwidth);
	x.style.left=newx+"px";
	x.style.top=newy+"px";
}

function ChangeLinkText(p,c1,c2){
	p.oldtext = p.innerHTML;
	p.innerHTML = "> " + p.innerHTML;
	if(c1!=null){
		var eltClass = cssClass(p);
		if(!eltClass.exists(c1))
		{
			eltClass = cssClass(p.parentNode);
		}
		eltClass.replace(c1,c2);
	}
}

function RestoreLinkText(p,c1,c2){
	p.innerHTML = p.oldtext;
	var eltClass = cssClass(p.parentNode);
	if(c1!=null){
		var eltClass = cssClass(p);
		if(!eltClass.exists(c1))
		{
			eltClass = cssClass(p.parentNode);
		}
		eltClass.replace(c1,c2);
	}
}

//fonction d'affichage d'un sous-menu
function ShowMenu(newmenu,previousmenu){

	document.getElementById(newmenu).style.display="";
	document.getElementById(previousmenu).style.display="none";
}

//Fonctions de gestion du slideshow
var imgindex = 0;
function NextImage(imageid) {
	if(imgindex==pictures.length-1)
	{
		imgindex=0;	
	}
	else
	{
		imgindex++;	
	}
	document.getElementById('content').style.width="";
	document.getElementById('content').style.heigth="";
	x=MM_findObj(imageid);
	x.src=images[imgindex].src;
	x.width = images[imgindex].width;
	x.height = images[imgindex].height;
	if(x.width>480)
	{
		document.getElementById('content').style.width=x.width+"px";	
	}
	//document.write("test :" + document.getElementById('content').style.height);
}
function PrevImage(imageid) {
	if(imgindex==0)
	{
		imgindex=pictures.length-1;	
	}
	else
	{
		imgindex--;	
	}
	document.getElementById('content').style.width="";
	document.getElementById('content').style.height="";
	x=MM_findObj(imageid);
	x.src=images[imgindex].src;
	x.width = images[imgindex].width;
	x.height = images[imgindex].height;
	if(x.width>480)
	{
		document.getElementById('content').style.width=x.width+"px";	
	}
}
images = new Array();
function PreloadSlide(folderpath)
{
	for (i=0;i<pictures.length;i++)
	{
		images[i] = new Image();
		images[i].src = pictures[i];
	}
}