function toggleEd(id) {
	$('ed_img_'+id).toggle();
	$('ed_txt_'+id).toggle();
}

function openPopup(page,nom,option) {
	window.open(page,nom,option);
}
    
function showPage(page, lang, sub) {
	
	if (sub == undefined) sub = '';
	
	var opt  = {
	    method: 'post',
	    postBody: 'lang='+lang,
	    onSuccess: function(t) {
			var data = t.responseText;
			var pg = (sub != '') ? "section_"+page+"_"+sub: "section_"+page;
			$(pg).toggle();
			$(pg).update(data);
	    }
	}
	new Ajax.Request('/pages/'+page+'.php?sub='+sub, opt);
}

//enlève un élément de la linkedlist
function removeFromList(linkTable, id) {

	$(linkTable+'_list_item'+id).remove();
	
	var children 	= $(linkTable+'_list').childElements();
	var list 		= '';
	for (var i = 1; i < children.length; i++) {
		list += children[i].id.replace(linkTable+'_list_item', '');
	}

	$(linkTable).value = list;
}

//enlève un élément de la linkedlist et le supprimer de la db
function deleteFromList(linkTable, targettable, aid, bid) {

	var opt  = {
	    method: 'post',
	    postBody: 'linkTable='+linkTable+'&targettable='+targettable+'&aid='+aid+'&bid='+bid,
	    // Handle successful response
	    onSuccess: function(t) {
			var vars = t.responseText.split('-');
			var linkTable	= vars[0];
			var aid 		= vars[1];
			
			$(linkTable+'_list_item'+aid).remove();
			try {
				$(linkTable+'_list_itemb'+id).remove();
			} catch (e) {}
			var children 	= $(linkTable+'_list').childElements();
			var list 		= '';
			for (var i = 1; i < children.length; i++) {
				list += children[i].id.replace(linkTable+'_list_item', '');
			}

			$(linkTable).value = list;
	    }
	}
	new Ajax.Request('a_removelinkeditem.php', opt);

}

function switchTab(name, tabNum, tabCount, cName) {
	
	if (cName == undefined) cName = name;
	for (var i = 0; i < tabCount; i++) {
		$(name+'Tab'+i).className = cName+"TabUn";
		$(name+i).hide();
	}

	$(name+'Tab'+tabNum).className = cName+"TabSe";
	$(name+tabNum).show();	
}


function switchFrame(name, tabNum, tabCount, cName) {
	
	if (cName == undefined) cName = name;
	for (var i = 0; i < tabCount; i++) {
		var cl = 'fframeTabUn';
		
		if (i == 0) {
			cl = 'fframerightTabUn';
		}
		if (i == tabCount -1) {
			cl = 'fframeleftTabUn';
		}
		
		$(name+'Tab'+i).className = cl;
		$(name+i).hide();
	}

	$(name+'Tab'+tabNum).className = cName+"TabSe";
	$(name+tabNum).show();	
}


function deleteItem(table, linktable, id) {
	var opt  = {
	    method: 'post',
	    postBody: 'linkTable='+linktable+'&table='+table+'&id='+id,
	    // Handle successful response
	    onSuccess: function(t) {
			var vars = t.responseText.split('-');
			var linkTable	= vars[0];
			var id 			= vars[1];
			
			try {
				$(linkTable+'_list_item'+id).remove();
			} catch (e) {}

			try {
				$(linkTable+'_list_itemb'+id).remove();
			} catch (e) {}

			var children 	= $(linkTable+'_list').childElements();
			var list 		= '';
			for (var i = 0; i < children.length; i++) {
				list += children[i].id.replace(linkTable+'_list_item', '');
			}

			$(linkTable).value = list;
	    }
	}
	new Ajax.Request('a_removeitem.php', opt);	
}

function addLinkedItem(id, bid, table, linkTable, targetTable, title) {
	if ($(linkTable+'_list_item'+id) == undefined) {
		var children  = $(linkTable+'_list').childElements();
		var child 	  = children[children.length-1];

		var color = (child.getStyle('background-color') == "rgb(241, 241, 241)") ? '#fcfcfc' : '#f1f1f1';

		var edit	= '<a onclick="return confirmEdit();" href="index.php?page=edittable&table='+targetTable+'&action=edit&id='+id+'"><img src="../skin/images/admin/edit.png" alt="" title="Editer" /></a>';
		var rem		= '<a onclick="return confirmRemove();" href="javascript:removeFromList(\''+linkTable+'\', '+id+');"><img src="../skin/images/admin/delete.png" alt="" title="Supprimer le lien" /></a>';
		var del		= '<a onclick="return confirmDelete();" href="javascript:deleteFromList(\''+linkTable+'\', \''+targetTable+'\', '+id+', '+bid+');"><img src="../skin/images/admin/delete.png" alt="" title="Supprimer" /></a>';

		var row = '<div id="'+linkTable+'_list_item'+id+'" style="background:'+color+';" onmouseover="table_highlight(\''+linkTable+'_list_item'+id+'\')" onmouseout="table_restor(\''+linkTable+'_list_item'+id+'\', \''+color+'\')">\
				<table>\
					<tr>\
						<td class="col1">'+id+'</td>\
						<td class="col2">'+title+'</td>\
						<td class="col3">'+edit+rem+del+'</td>\
					</tr>\
				</table>\
			</div>';
		$(linkTable+'_list').insert({bottom: row});
		
		var children 	= $(linkTable+'_list').childElements();
		var list 		= '';
		for (var i = 1; i < children.length; i++) {
			list += children[i].id.replace(linkTable+'_list_item', '')+",";
		}

		$(linkTable).value = list;
	}
	switchTab('panel'+linkTable,0,3, 'fframe');
}

function confirmDelete() {
	if (confirm("Etes-vous sûr de vouloir supprimer cet  élément?"))
		return true ;
	else
		return false ;
}

function confirmRemove() {
	if (confirm("Etes-vous sûr de vouloir détacher cet objet de la list?"))
		return true ;
	else
		return false ;
}

function confirmEdit() {
	if (confirm("Attention! Etes-vous sûr de vouloir éditer cet élément et perdre les données en cours?"))
		return true ;
	else
		return false ;
}

function selectPict(img, id) {
	$('delete').value = img;
	
	for(var i = 0; i < imgNum; i++) {
		$('img_'+i).setStyle({border:'2px solid #ebebeb', opacity:1});		
	}
	$('img_'+id).setStyle({border:'2px solid #007ce5', opacity:0.5});
}

var winW;
var winH;

if (parseInt(navigator.appVersion)>3) {
 if (navigator.appName=="Netscape") {
  winW = window.innerWidth;
  winH = window.innerHeight;
 }
 if (navigator.appName.indexOf("Microsoft")!=-1) {
  if (document.body != null) {
	
	winW = document.body.offsetWidth;
  	winH = document.body.offsetHeight;	
}
	

 }
}

























// JavaScript Document
var general_serverUrl 		= 'http://www.magasin-cnac.org/nodo';
var general_menuTogglers	= new Array;
var general_menuTogglersS	= new Array;
var global					= this;

var newsHidden				= false;
var listHidden				= true;
var backgroundHidden		= false;
var windowsShown			= true;
var openedMenu				= -1;

var cC						= new Array();

function restorBackground()
{
	if (backgroundHidden)
	{
		document.body.style.background 	= 'rgb(232,233,235)';
		$('content').style.background 	= 'rgb(232,233,235)';
		$('content').style.cursor 		= 'crosshair';
		document.body.style.cursor 		= 'crosshair';
		backgroundHidden = false;
	}
}

function maskBackground()
{
	if (!backgroundHidden)
	{
		document.body.style.background 	= 'rgb(232,233,235)';
		$('content').style.background 	= 'rgb(232,233,235)';
		document.body.style.cursor 		= 'auto';
		backgroundHidden = true;
	}
}



function rowHighlight(tr, color) {
	$(tr).style.background = color;
}

function rowRestor(tr) {
	$(tr).style.background = "";
}

function table_highlight(tr)
{
	$(tr).style.background = "#cae3ed";
}

function table_restor(tr,color)
{
	$(tr).style.background = color;
}


function stripPx (input)
{
	return input.substring(0,input.length-2); 
}

function hideList()
{
	if (!listHidden)
	{
		$('mainmenu_news').className 	= 'mainmenu_newsShow';
		$('mainmenu').className 		= 'mainmenuHide'; 
		$('rightmenu').className		= 'rightmenuHide';
		//change les listes
		for (i = 0; i<listMenu; i++)
		{
			$('list_'+i+'_0').className = 'lettersHide';
			$('list_'+i+'_1').className = 'letterlineHide';
			$('list_'+i+'_2').className = 'listHide';
		}
		
		listHidden = true;
		general_menuTogglers = Array();
		
		restorMenus();
	}
}


function hideNews()
{
	if (!newsHidden)
	{
		$('news_0_0').className = 'lettersNewsHide';
		$('news_0_1').className = 'letterlineNewsHide';
		$('news_img').src 		= 'uploads/news_nb_thumb.jpg';
		$('news_1_0').className = 'lettersNewsHide';
		$('news_1_1').className = 'letterlineNewsHide';
		$('news_1_2').className = 'newsartistsHide';
		$('news_2_0').className = 'lettersNewsHide';
		$('news_2_1').className = 'letterlineNewsHide';
		$('news_2_2').className = 'newscontentHide';
		
		/*boucle des artistes*/
		for (var i = 0; i<arList; i++)
		{
			$('newArtist_'+i).className = 'artistHide';
		}
		newsHidden = true;
	}
}

function showList()
{
	hideWindows();
	if (listHidden)
	{
		$('mainmenu_news').className 	= 'mainmenu_newsHide';
		$('mainmenu').className 		= 'mainmenuShow'; 
		$('rightmenu').className		= 'rightmenuShow';
		//change les listes
		for (i = 0; i<listMenu; i++)
		{
			$('list_'+i+'_0').className = 'lettersShow';
			$('list_'+i+'_1').className = 'letterlineShow';
			$('list_'+i+'_2').className = 'listShow';
		}
		
		listHidden = false;
	}
}

function showNews()
{
	hideWindows();
	if (newsHidden)
	{
		$('news_0_0').className = 'lettersNewsShow';
		$('news_0_1').className = 'letterlineNewsShow';
		$('news_img').src 		= 'uploads/news_thumb.jpg';
		$('news_1_0').className = 'lettersNewsShow';
		$('news_1_1').className = 'letterlineNewsShow';
		$('news_1_2').className = 'newsartistsShow';
		$('news_2_0').className = 'lettersNewsShow';
		$('news_2_1').className = 'letterlineNewsShow';
		$('news_2_2').className = 'newscontentShow';
		
		/*boucle des artistes*/
		for (var i = 0; i<arList; i++)
		{
			$('newArtist_'+i).className = 'artistShow';
		}
		
		newsHidden = false;
	}	
}


function restorMenus()
{
		for (i = 0; i<mainMenu.length; i++)
		{
			if (mainMenu[i] != '' )	$('item_'+mainMenu[i]).className = '';
			general_menuTogglers[mainMenu[i]] = false;
			general_menuTogglersS[mainMenu[i]] = false;
		}
		
		for (i = 0; i<listMenuData.length; i++)
		{
			if (listMenuData[i] != '')
			{
				//alert($('item_'+listMenuData[i]).className.indexOf('_hover'));
				if ($('item_'+listMenuData[i]).className != 'txt_hv')
				{
					general_menuTogglers[listMenuData[i]] = false;
					general_menuTogglersS[listMenuData[i]] = false;
					if ($('item_'+listMenuData[i]+'_m') != null) $('item_'+listMenuData[i]+'_m').remove();
					if ($('item_'+listMenuData[i]).className.indexOf('_hover') > 0)
					{
						$('item_'+listMenuData[i]).className = $('item_'+listMenuData[i]).className.replace('_hover', '_hv');
					}
					else
					{
						$('item_'+listMenuData[i]).className = $('item_'+listMenuData[i]).className+'_hv';
						$('item_'+listMenuData[i]).className = $('item_'+listMenuData[i]).className.replace('_hv_hv', '_hv');
					}
				}
			}
		}
}

function restorMenusB()
{
		for (i = 0; i<mainMenu.length; i++)
		{
			if (global.general_menuTogglersS[mainMenu[i]] != true)
			{
				if (mainMenu[i] != '' )	$('item_'+mainMenu[i]).className = '';
				global.general_menuTogglers[mainMenu[i]] = false;
			}
		}
		
		for (i = 0; i<listMenuData.length; i++)
		{
			if (listMenuData[i] != '')
			{
				//alert($('item_'+listMenuData[i]).className.indexOf('_hover'));
				
				if ($('item_'+listMenuData[i]).className != 'txt_hv' && global.general_menuTogglersS[listMenuData[i]] != true)
				{
					global.general_menuTogglers[listMenuData[i]] = false;
					if ($('item_'+listMenuData[i]+'_m') != null) $('item_'+listMenuData[i]+'_m').remove();
					if ($('item_'+listMenuData[i]).className.indexOf('_hover') > 0)
					{
						$('item_'+listMenuData[i]).className = $('item_'+listMenuData[i]).className.replace('_hover', '_hv');
					}
					else
					{
						$('item_'+listMenuData[i]).className = $('item_'+listMenuData[i]).className+'_hv';
						$('item_'+listMenuData[i]).className = $('item_'+listMenuData[i]).className.replace('_hv_hv', '_hv');
					}
				}
			}
		}
}

function hideChildren(id)
{
	restorMenusB();
}

function showChildren(id)
{
	
	$('item_'+menusPrev[id].root).className = menusPrev[id].rstyle;
	for (var i = 0; i < menusPrev[id].list.length; i++)
	{
		$('item_'+menusPrev[id].list[i]).className = menusPrev[id].style;
	}
	/*
	var opt = {
		method: 'post',
		postBody: 'id='+id+'&tohide='+openedMenu,
	
		// Handle successful response
		onSuccess: function(t) {
			
			restorMenusB();
			//alert(global.openedMenu);
			var params 	= t.responseText.split('#');
			var toopen 	= params[3];
			var action	= params[4];
			var eth		= params[5];
			var hidelist= params[6].split(',');
			var hasChild= params[7];
			var hie		= params[0].split(',');
			var fid		= params[1];
			params		= params[2].split(',');
			try
			{
				if (fid != 'n')
				{
				
					if (hidelist.length  > 2 && openedMenu != "non")
					{
						for (var i = 0; i < hidelist.length-1; i++)
						{
							var cur		= hidelist[i].split('-');
							//global.general_menuTogglers[cur[0]] = false;
							$('item_'+cur[0]).className = $('item_'+cur[0]).className+"_hv";
						}
					}
				
				
					if ($('item_'+global.openedMenu+'_m') != null) $('item_'+global.openedMenu+'_m').remove();
					//if (global.openedMenu != -1) global.general_menuTogglers[global.openedMenu] = false;
	
					global.openedMenu = eth;
				}
			
				for (var i = 0; i < params.length-1; i++)
				{
					var children = params[i].split('-');
					$('item_'+children[0]).className = children[1];
				}
			}
			catch(e)
			{
			}
		}
	};

	new Ajax.Request(general_serverUrl+'/ajax/menuClick.php?hide=false', opt);*/
}

function menuAction(id)
{
	//pour afficher
	var opt = {
		method: 'post',
		postBody: 'id='+id+'&tohide='+openedMenu,
	
		// Handle successful response
		onSuccess: function(t) {
			
			hideNews();
			showList();
			
			restorMenus();
			//alert(global.openedMenu);
	
			var params 	= t.responseText.split('#');
			var toopen 	= params[3];
			var action	= params[4];
			var eth		= params[5];
			var hidelist= params[6].split(',');
			var hasChild= params[7];
			var parent  = params[8];
			var hie		= params[0].split(',');
			var fid		= params[1];
			params		= params[2].split(',');
			try
			{
				if (fid != 'n')
				{
					/*désactive le sous menu ouvert*/
					/*if (hidelist.length  > 2 && openedMenu != "non")
					{
						for (var i = 0; i < hidelist.length-1; i++)
						{
							var cur		= hidelist[i].split('-');
							global.general_menuTogglers[cur[0]] = false;
							$('item_'+cur[0]).className = $('item_'+cur[0]).className+'_hv';
						}
					}*/
				
					/*enlève la flèche de l'ancien sous menu*/
					if ($('item_'+global.openedMenu+'_m') != null) $('item_'+global.openedMenu+'_m').remove();
					if (global.openedMenu != -1)
						global.general_menuTogglers[global.openedMenu] = false;
						global.general_menuTogglersS[global.openedMenu] = false;
	
					global.openedMenu = eth;
				}
				
	
				/* flèche*/

				if (fid != 'n' && hasChild > 0) 
				{
					if ($('item_'+fid+'_m') == null) new Insertion.After('item_'+fid, '<div id="item_'+fid+'_m">&nbsp;&lt;</div>');
				}
		
				/*active la hiérarchie*/
				if (parent != -1) {
					for (var i = 0; i < hie.length-1; i++)
					{
						if (global.general_menuTogglers[hie[i]] == undefined)
						{
							global.general_menuTogglers[hie[i]] = true;
							global.general_menuTogglersS[hie[i]] = true;
						}
						else if (global.general_menuTogglers[hie[i]] == false)
						{
							global.general_menuTogglers[hie[i]] = true;
							global.general_menuTogglersS[hie[i]] = true;
						}
					}
				}
				
				/*enfants*/
				if (parent != -1) {
					for (var i = 0; i < params.length-1; i++)
					{
						var children = params[i].split('-');
						if ($('item_'+children[0]) != null) {
							$('item_'+children[0]).className = children[1];
							global.general_menuTogglersS[children[0]] = true;
						}
					}
				}
			}
			catch(e)
			{
				alert('a'+e);
			}
			if (toopen != 'non') doAction(action, id, toopen);
		}
	};
	
	//pour cacher
	var opt2 = {
		method: 'post',
		postBody: 'id='+id,
	
		// Handle successful response
		onSuccess: function(t) {
			hideNews();
			showList();

			var params 	= t.responseText.split('#');
			var toopen 	= params[1];
			var action	= params[2];
			var list 	= params[0].split(',');
	
			/*active la hiérarchie*/
			if (list.length  > 2)
			{
				for (var i = 0; i < list.length-1; i++)
				{
					var cur		= list[i].split('-');
					if (i != 0 || cur[0] <= 10)
					{
						$('item_'+cur[0]).className = $('item_'+cur[0]).className+"_hv";
						global.general_menuTogglersS[cur[0]] = false;
					}
					if ($('item_'+cur[0]+'_m') != null) $('item_'+cur[0]+'_m').remove();
					global.general_menuTogglers[cur[0]] = false;
					
					
				}
			}
			
			/*ouvrir*/
			if (toopen != 'non')
			{
					doAction(action, id, toopen);
			}
		}
	};
	
	if (general_menuTogglers[id] == false || general_menuTogglers[id] == undefined)
	{
		new Ajax.Request(general_serverUrl+'/ajax/menuClick.php?hide=false', opt);
	}
	else
	{
		new Ajax.Request(general_serverUrl+'/ajax/menuClick.php?hide=true', opt2);
	}
}

function doAction(action, id, type)
{
	if (action == '')
	{
		//textes (type C)
		if (type == 1) showWindowSet(Array({name:'text',type:1,width:596,height:556,left:256,top:144,content:general_serverUrl+'/ajax/getText.php?id='+id+'&lang='+curLang,onlytext:false,scrollable:true,printable:true}));

		//listes (type D)
		if (type == 2) showWindowSet(Array({name:'list',type:2,width:419,height:472,left:200,top:23,content:general_serverUrl+'/ajax/getList.php?id='+id+'&lang='+curLang,onlytext:true,scrollable:true,printable:false}));

		//listes (type B)
		if (type == 3) showWindowSet(Array({name:'typeb1',type:3,width:422,height:533,left:7,top:23,content:general_serverUrl+'/ajax/getimages.php?id='+id+'&lang='+curLang,onlytext:true,scrollable:false,printable:false},
										   {name:'typeb2',type:3,width:497,height:628,left:475,top:50,content:general_serverUrl+'/ajax/getText.php?id='+id+'&lang='+curLang,onlytext:false,scrollable:true,printable:true},
										   {name:'typeb3',type:3,width:261,height:136,left:132,top:562,content:general_serverUrl+'/ajax/getfiles.php?id='+id+'&lang='+curLang,onlytext:true,scrollable:true,printable:false}
										   ));
	}
	else
	{
		eval (action);
	}
}

function openEditor(el)
{
	var haut=(screen.height-480)/2;
	var Gauche=(screen.width-640)/2;
	fencent=window.open('../ajax/textedit.php?id='+el, 'Edit text', "top="+haut+",left="+Gauche+",width="+640+",height="+480);
}

function switchGal(a,b,c,img)
{
	$('gpic').src = img;
	var final  = (a == '') ? '' : a;
	final      = (b == '') ? final : final+', <i>'+b+'</i>';
	final      = (c == '') ? final : final+', '+c;
	
	$('gdesc').innerHTML = final; 
}

function tags_add()
{
	for (i=0; i<$('tag_container').options.length; i++)
	{
  		if ($('tag_container').options[i].selected )
		{
			$('taginocc').options[$('taginocc').options.length] = new Option($('tag_container').options[i].text, $('tag_container').options[i].value);
  		}
	}

	for (i = $('tag_container').length - 1; i>=0; i--)
	{
    	if ($('tag_container').options[i].selected)
		{
			$('tag_container').remove(i);
    	}
  	}
}

function tags_del()
{
	for (i=0; i<$('taginocc').options.length; i++)
	{
  		if ($('taginocc').options[i].selected )
		{
			$('tag_container').options[$('tag_container').options.length] = new Option($('taginocc').options[i].text, $('taginocc').options[i].value);
  		}
	}

	for (i = $('taginocc').length - 1; i>=0; i--)
	{
    	if ($('taginocc').options[i].selected)
		{
			$('taginocc').remove(i);
    	}
  	}
}

function textifyTags()
{
	$('artists').value = '';
	for (i = $('taginocc').length - 1; i>=0; i--)
	{
		$('artists').value =   $('taginocc').options[i].value + "," + $('artists').value;
	}
	$('artists').value = $('artists').value.substr(0, $('artists').value.length-1);
}

function listArtist(id, myDate)
{
	var opt = {
		method: 'get',
		onSuccess: function(t){
			var content 	= t.responseText;
			var num			= content.split('###')[0];
	
			//complex parsing
			if (myDate == undefined) myDate = false;
			
			title1 = (myDate) ? content.split('###')[5] : content.split('###')[1];
			title1 = (content.split('###')[7] == '1' || content.split('###')[7] == '3') ? content.split('###')[5]+' - '+content.split('###')[6] : title1;
			title2 = content.split('###')[3];
			head = content.split('###')[4];
			content = '<p class="ssNormal" style="margin-top:0px;"><b>'+title1+'</b></p><h1>'+title2+'</h1><h2>'+head+'</h2><div class="ssHr"></div><br/><div class="ssTxt">'+content.split('###')[2]+'</div>';
			
			$('window-art3_contentS').innerHTML = '<div class="ssNormal" id="print"><b><a href="javascript:window.print();">Imprimer</a></b></div>'+content;
			$('printArea').innerHTML = content;
		}
	};
	new Ajax.Request(general_serverUrl+'/ajax/getText.php?id='+id+'&lang='+curLang+'&num=1', opt);

	var opt = {
		method: 'get',
		onSuccess: function(t){
			var content 	= t.responseText;
			var num			= content.split('###')[0];
	

			cont	= content.split('###');
			if (cont[1] == 'img')
			{
				first	= cont[2].split('---');
				if(cont[2] != '')
				{
					content = '<table><tr><td><div id="gdesc">'+first[0]+', <i>'+first[1]+'</i>, '+first[2]+'</div></td></tr><tr><td valign="top" style="height:423px; width:368px"><img id="gpic" src="'+first[3]+'" alt="" /></td></tr><tr><td>';
					for (j = 2; j<cont.length-1; j++)
					{
						im = cont[j].split('---');
						content += '<a href="javascript:switchGal(\''+im[0]+'\',\''+im[1]+'\',\''+im[2]+'\',\''+im[3]+'\');"><img src="'+im[4]+'" alt="" /></a>&nbsp;';
				
					}
					content += '</td></td></table>';
				}
				else
				{
					content = '';
				}
			}
			$('window-art1_contentS').innerHTML = content;
		}
	};
	new Ajax.Request(general_serverUrl+'/ajax/getimages.php?id='+id+'&lang='+curLang+'&num=1', opt);
	
	var opt = {
		method: 'get',
		onSuccess: function(t){
			var content 	= t.responseText;
			var num			= content.split('###')[0];
	
			cont	= content.split('###');
			content = cont[1];
			
			$('window-art4_contentS').innerHTML = content;
		}
	};
	new Ajax.Request(general_serverUrl+'/ajax/getfiles.php?id='+id+'&lang='+curLang+'&num=1', opt);
}

var BrowserDetect = {
	init: function () {
		this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
		this.version = this.searchVersion(navigator.userAgent)
			|| this.searchVersion(navigator.appVersion)
			|| "an unknown version";
		this.OS = this.searchString(this.dataOS) || "an unknown OS";
	},
	searchString: function (data) {
		for (var i=0;i<data.length;i++)	{
			var dataString = data[i].string;
			var dataProp = data[i].prop;
			this.versionSearchString = data[i].versionSearch || data[i].identity;
			if (dataString) {
				if (dataString.indexOf(data[i].subString) != -1)
					return data[i].identity;
			}
			else if (dataProp)
				return data[i].identity;
		}
	},
	searchVersion: function (dataString) {
		var index = dataString.indexOf(this.versionSearchString);
		if (index == -1) return;
		return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
	},
	dataBrowser: [
		{ 	string: navigator.userAgent,
			subString: "OmniWeb",
			versionSearch: "OmniWeb/",
			identity: "OmniWeb"
		},
		{
			string: navigator.vendor,
			subString: "Apple",
			identity: "Safari"
		},
		{
			prop: window.opera,
			identity: "Opera"
		},
		{
			string: navigator.vendor,
			subString: "iCab",
			identity: "iCab"
		},
		{
			string: navigator.vendor,
			subString: "KDE",
			identity: "Konqueror"
		},
		{
			string: navigator.userAgent,
			subString: "Firefox",
			identity: "Firefox"
		},
		{
			string: navigator.vendor,
			subString: "Camino",
			identity: "Camino"
		},
		{		// for newer Netscapes (6+)
			string: navigator.userAgent,
			subString: "Netscape",
			identity: "Netscape"
		},
		{
			string: navigator.userAgent,
			subString: "MSIE",
			identity: "Explorer",
			versionSearch: "MSIE"
		},
		{
			string: navigator.userAgent,
			subString: "Gecko",
			identity: "Mozilla",
			versionSearch: "rv"
		},
		{ 		// for older Netscapes (4-)
			string: navigator.userAgent,
			subString: "Mozilla",
			identity: "Netscape",
			versionSearch: "Mozilla"
		}
	],
	dataOS : [
		{
			string: navigator.platform,
			subString: "Win",
			identity: "Windows"
		},
		{
			string: navigator.platform,
			subString: "Mac",
			identity: "Mac"
		},
		{
			string: navigator.platform,
			subString: "Linux",
			identity: "Linux"
		}
	]

};
BrowserDetect.init();

/*-----------------------------------------------------------
    Toggles element's display value
    Input: any number of element id's
    Output: none 
    ---------------------------------------------------------*/
function toggleDisp() {
    for (var i=0;i<arguments.length;i++){
        var d = $(arguments[i]);
        if (d.style.display == 'none')
            d.style.display = 'block';
        else
            d.style.display = 'none';
    }
}

/*-----------------------------------------------------------
    Toggles tabs - Closes any open tabs, and then opens current tab
    Input:     1.The number of the current tab
                    2.The number of tabs
                    3.(optional)The number of the tab to leave open
                    4.(optional)Pass in true or false whether or not to animate the open/close of the tabs
    Output: none 
    ---------------------------------------------------------*/
function toggleTab(num,numelems,opennum,animate) {
    if ($('tabContent'+num).style.display == 'none'){
        for (var i=1;i<=numelems;i++){
            if ((opennum == null) || (opennum != i)){
                var temph = 'tabHeader'+i;
                var h = $(temph);
                if (!h){
                    var h = $('tabHeaderActive');
                    h.id = temph;
                }
                var tempc = 'tabContent'+i;
                var c = $(tempc);
                if(c.style.display != 'none'){
                    if (animate || typeof animate == 'undefined')
                        Effect.toggle(tempc,'blind',{duration:0.2, queue:{scope:'menus', limit: 3}});
                    else
                        toggleDisp(tempc);
                }
            }
        }
        var h = $('tabHeader'+num);
        if (h)
            h.id = 'tabHeaderActive';
        h.blur();
        var c = $('tabContent'+num);
        c.style.marginTop = '2px';
        if (animate || typeof animate == 'undefined'){
            Effect.toggle('tabContent'+num,'blind',{duration:0.2, queue:{scope:'menus', position:'end', limit: 3}});
        }else{
            toggleDisp('tabContent'+num);
        }
    }
}

function add_tag(iid) {
	var haut=(screen.height-25)/2;
	var Gauche=(screen.width-170)/2;
	fencent=window.open('ajax/tags.php?iid='+iid+'&id=taginocc', 'Edit text', "top="+haut+",left="+Gauche+",width="+170+",height="+25);
}
 
function remove_tag() {
	for (i = $('taginocc').length - 1; i>=0; i--) {
    	if ($('taginocc').options[i].selected) {
			$('taginocc').remove(i);
    	}
  	}
}

function textifyTags() {
	$('tags').value = '';
	for (i = $('taginocc').length - 1; i>=0; i--) {
		$('tags').value =   $('taginocc').options[i].value + "," + $('tags').value;
	}
	$('tags').value = $('tags').value.substr(0, $('tags').value.length-1);
}

function add_theme(iid) {
	var haut=(screen.height-25)/2;
	var Gauche=(screen.width-170)/2;
	fencent=window.open('ajax/themes.php?iid='+iid+'&id=themeinocc', 'Edit text', "top="+haut+",left="+Gauche+",width="+170+",height="+25);
}
 
function remove_theme() {
	for (i = $('themeinocc').length - 1; i>=0; i--) {
    	if ($('themeinocc').options[i].selected) {
			$('themeinocc').remove(i);
    	}
  	}
}

function textifyTheme() {
	$('theme').value = '';
	for (i = $('themeinocc').length - 1; i>=0; i--) {
		$('theme').value =   $('themeinocc').options[i].value + "," + $('theme').value;
	}
	$('theme').value = $('theme').value.substr(0, $('theme').value.length-1);
}



function fileSelOver(id) {
	$(id).toggleClassName('fileOver');
	$('i'+id).src = $('i'+id).src.replace(/.png/g, '_over.png');
}

function fileSelOut(id) {
	$(id).toggleClassName('fileOver');
	$('i'+id).src = $('i'+id).src.replace(/_over.png/g, '.png');
}

function fileSelSelOver(id) {
	$(id).toggleClassName('fileOver');
	$(id).toggleClassName('fileSel');
	$('i'+id).src = $('i'+id).src.replace(/_sel.png/g, '_over.png');
}

function fileSelSelOut(id) {
	$(id).toggleClassName('fileOver');
	$(id).toggleClassName('fileSel');
	$('i'+id).src = $('i'+id).src.replace(/_over.png/g, '_sel.png');
}
