function update_calendar(id,day,month,year)
{
	new Ajax.Updater( 'calendar', '/fashion/fashion_weeks_shows_calendar_update.php?id='+id+'&d='+day+'&m='+month+'&y='+year );
}

function update_showrooms_calendar(id,type,day,month,year)
{
	new Ajax.Updater( 'calendar', '/fashion/fashion_weeks_showrooms_calendar_update.php?id='+id+'&t='+type+'&d='+day+'&m='+month+'&y='+year );
}

function update_selection(type,fw)
{
	new Ajax.Updater( 'selection', '/fashion/fashion_weeks_selection_update.php?t='+type+"&f="+fw);
}

function cancel_selection(type,fw)
{
	/*
	new Ajax.Request( '/fashion/fashion_weeks_selection_cancel.php',{
					method:'get',
					parameters:'t='+type+'&f='+fw,
					onSuccess:function(){document.location.reload();}
					});
	*/
	var all = getMyCookiesId(type+"_name");
	
	for (i=0;i<all.length;i++)
	{
		id = all[i];
		var val_fw = getMyCookie(type+"_fw["+id+"]");
		if (val_fw==fw)
		{
			setMyCookie(type+"_fw["+id+"]",-1,0);
			setMyCookie(type+"_name["+id+"]",-1,0);
		}
	}
	
	if (all.length>0) document.location.reload();
}

function create_checkbox(name,img_id,id)
{
	var val = getMyCookie(name);
	if (val=='')
		document.write("<a href=\"javascript:swap_checkbox('"+name+"','"+img_id+"','"+id+"');\"><img id=\""+img_id+"\" src=\"/img/dotunselected.png\" border=\"0\" /></a>");
	else
		document.write("<a href=\"javascript:swap_checkbox('"+name+"','"+img_id+"','"+id+"');\"><img id=\""+img_id+"\" src=\"/img/dotselected.png\" border=\"0\" /></a>");
}

function swap_checkbox(name,img_id,id)
{
	var img = document.getElementById(img_id);
	var img_src = img.src;

	if (img_src.indexOf('dotunselected.png')!=-1)
	{
		img.src='/img/dotselected.png';
		setMyCookie(name,id,7);
	}
	else
	{
		img.src='/img/dotunselected.png';
		setMyCookie(name,-1,0);
	}
}

function create_checkbox2(type,id,fw,name)
{
	var img_id = type+"_"+id;
	var val_fw = getMyCookie(type+"_fw["+id+"]");
	var val_name = getMyCookie(type+"_name["+id+"]");
	
	if ((val_name!='')&&(val_fw==fw))
		document.write("<a href=\"javascript:swap_checkbox2('"+type+"','"+id+"','"+fw+"','"+name+"');\"><img id=\""+img_id+"\" src=\"/img/dotselected.png\" border=\"0\" /></a>");
	else
		document.write("<a href=\"javascript:swap_checkbox2('"+type+"','"+id+"','"+fw+"','"+name+"');\"><img id=\""+img_id+"\" src=\"/img/dotunselected.png\" border=\"0\" /></a>");
}

function swap_checkbox2(type,id,fw,name)
{
	var img_id = type+"_"+id;
	var img = document.getElementById(img_id);
	var img_src = img.src;

	if (img_src.indexOf('/img/dotunselected.png')!=-1)
	{
		img.src='/img/dotselected.png';
		setMyCookie(type+"_fw["+id+"]",fw,7);
		setMyCookie(type+"_name["+id+"]",name,7);
	}
	else
	{
		img.src='/img/dotunselected.png';
		setMyCookie(type+"_fw["+id+"]",-1,0);
		setMyCookie(type+"_name["+id+"]",-1,0);
	}
	
	update_selection(type,fw);
}


function setMyCookie(nom,valeur,jours)
{
	var expDate = new Date();
	expDate.setTime(expDate.getTime() + (jours * 24 * 3600 * 1000));
	document.cookie = nom + "=" + escape(valeur) + ";expires=" + expDate.toGMTString() + ";path=/fashion/";
}

function getMyCookie(nom) 
{
	deb = document.cookie.indexOf(nom + "=");
	if (deb >= 0) 
	{
		deb += nom.length + 1;
		fin = document.cookie.indexOf(";",deb);
		if (fin < 0) fin = document.cookie.length;
		return unescape(document.cookie.substring(deb,fin));
	}
	return ""
}

function getMyCookiesId(nom)
{
	var res = new Array();
	var fin = 0;
	while ( (deb = document.cookie.indexOf(nom + "[", fin) ) >= 0) 
	{
		deb += nom.length + 1;
		fin = document.cookie.indexOf("]",deb);
		if (fin < 0) fin = document.cookie.length;
		id = unescape(document.cookie.substring(deb,fin));
		res.push(id);
		fin = document.cookie.indexOf(";",fin);
	}
	return res;
}