var $browserName = navigator.appName;
var isNS4 = (document.layers) ? 1 : 0;
var isIE4 = (document.all) ? 1 : 0;
var isW3C = (document.getElementById && !document.all) ? 1 : 0;

function trim(str) {     // Supprime les espaces en début et en fin de chaine        
    return str.replace(/^\s+/, '').replace(/\s+$/, '');
}

function ltrim(str) {
    return str.replace(/^\s+/, '');
}

function getCalculatedProperty(objName, property) {

    // ***** W3C Compatible DOM (NN6, Mozilla 16, etc.) *****

    if (isW3C) {
        docObj = document.getElementById(objName);
		
        if (property == "visibility") {
	    cssp = docObj.style.visibility;
	    return (cssp == "") ? "inherit" : cssp;
	}

	if (property == "clip") {
	    cssp = docObj.style.clip;

	    if (cssp == "") {
		cssStr = "rect(0px "; 
		cssStr += getCalculatedProperty(objName, "width") + " ";
		cssStr += getCalculatedProperty(objName, "height") 
+ " ";
		cssStr += "0px)";
		return cssStr;
	    }
	    return cssp;
	}

	if (property == "zIndex") {
	    cssp = docObj.style.zIndex;
	    return (cssp == "") ? "inherit" : cssp;
	}

	cssp = document.defaultView.getComputedStyle
(docObj, "").getPropertyValue(property);

	return (cssp == "") ? "unknown" : cssp;
    }

    // ***** Netscape Navigator 4+ DOM *****

    if (isNS4) {
	docObj = document.layers[objName];

	if (property == "visibility") {
	    cssp = docObj.visibility;
	    return (cssp == "hide") ? "hidden" : (cssp 
== "show") ? "visible" : "inherit";
	}

	if (property == "clip") {
	    cssStr = "rect(" + docObj.clip.top + "px ";
	    cssStr += docObj.clip.right + "px ";
	    cssStr += docObj.clip.bottom + "px ";
	    cssStr += docObj.clip.left + "px)";
	    return cssStr;
	}

	if ((property == "width") || (property == "height")) {
	    return eval("docObj.clip." + property) + "px";
	}

	if (property == "top") property = "pageY";
	if (property == "left") property = "pageX";

	cssp = eval("docObj." + property);

	if (property != "zIndex") cssp += "px";

	return cssp;
    }

    // ***** Internet Explorer 4+ DOM *****

    if (isIE4) {
	if (property == "width") return eval(objName + ".offsetWidth") 
+ "px";

	if (property == "height") return eval(objName 
+ ".offsetHeight") + "px";

	if (property == "clip") {
	    cssp = eval(objName + ".style.clip");

	    if (cssp == "") {
		cssStr = "rect(0px ";
		cssStr += getCalculatedProperty(objName, "width") + " ";
		cssStr += getCalculatedProperty(objName, "height") 
+ " ";
		cssStr += "0px)";
		return cssStr;
	    }
	    return cssp;
	}

	if (property == "top") return eval(objName + ".offsetTop") 
+ 'px';

	if (property == "left") return eval(objName + ".offsetLeft") 
+ 'px';

        // Else, use 'currentStyle' to find the rest

	return eval(objName + ".currentStyle." + property);
    }
}

function getImgHeight()
{
	//document.getElementById("fiche_top_body_bg").style.height=getCalculatedProperty("fiche_top_title", "height");	
}

function mySpaceHeights()
{
	/*
	// hauteur du div gauche de espace perso
	var $leftH = parseInt(getCalculatedProperty("my_space_left", "height"));
	// hauteur du div droit
	var $rightH = parseInt(getCalculatedProperty("my_space_right", "height"));

	if ($leftH < $rightH)
	{
		document.getElementById("my_space_left").style.height = $rightH+"px";
	}
	else if ($leftH > $rightH)
	{
		document.getElementById("my_space_left").style.height = "auto";
	}*/
}

function swapArrow($id)
{
	//alert($id);
	var $otherElem;
	var $button = document.getElementById('connect_register_button'); 
	var $arrow = document.createElement('img');
	$arrow.src = 'Images/arrow.png';
	$arrow.width = 15;
	$arrow.height = 12; 
	if ($id == 'connect')
	{
		$otherElem = 'register'; 
	}
	else if ($id == 'register')
	{
		$otherElem = 'connect';
	}
	var $td1 = document.getElementById($id+"_img");
	var $td2 = document.getElementById($otherElem+"_img");
	deleteChildNodes($td2);
	if ($td1.childNodes.length == 0) $td1.appendChild($arrow); 
	document.getElementById($id).style.fontWeight= 'bold';
	document.getElementById($otherElem).style.fontWeight= 'normal';
	//alert(document.getElementById($id).firstChild.nodeValue);
	$button.name = $id + '_button';
	
}

function swap2() {
	document.getElementById('zone_error_mail').focus();
	document.getElementById('zone_error_mail').style.backgroundColor = "#FFE871";
}
function swap3() {
	//document.getElementById('zone_error_mail').focus();
	document.getElementById('zone_error_mail').style.backgroundColor = "white";
}


function swapTabColor($bloc,$idParent,$child, $total, $iter)
{
	var $parent = $($idParent);
	var $i = 0;
	var $child = $parent.firstDescendant();
	for(var i=0; ( ($child.readAttribute('id') != "finSuggestedDocs") && i<$total && ($child != undefined) ); i++){
		$child.writeAttribute('class','');
		if(i%2 == 0) //C'est une petite division inter-onglets
		{
			$child.addClassName('petiteDiv');
			if(i == ($iter - 1))//C'est un front montant
			{
				if(i != 0) $child.addClassName('frontMontant');
				else $child.addClassName('premier');
			}
			else if(i == ($iter + 1))//C'est un front descendant
			{
				if(i != $total-1) $child.addClassName('frontDescendant');
				else $child.addClassName('dernier');
			}
			else//C'est une division vide
			{
				//On la vide
				$child.addClassName('ongletVide');
			}
		}
		else //c'est un onglet
		{
			$child.addClassName('onglet');
			if(i == $iter) //C'est l'onglet selectionné
			{
				$child.addClassName('ongletSelect');
			}
			else //C'est un onglet vide
			{
				$child.addClassName('ongletVide');
			}
		}
		$child = $child.next();
	}

	var $content = document.getElementById("tabs_content");
	for ($i=0; $i<$content.childNodes.length; $i++)
	{
		if ($content.childNodes[$i].nodeName != "#text")
		{
			if ($content.childNodes[$i].style.display == "block") $content.childNodes[$i].style.display = "none";
		}
	}
	document.getElementById($bloc).style.display = "block";
}

var timer;
var pas = 3;

function moveLayer(content,container,sens)  // fct simulant une scrollbar
{
	objet = document.getElementById(content); 
  if(parseInt(objet.style.top) + (pas*sens) > 0)  // vérif scroll vers le haut
  {
		clearTimeout(timer);
	}  
	// vérif scroll vers le bas
	else if(parseInt(objet.style.top) + (pas*sens) < -(objet.offsetHeight-document.getElementById(container).offsetHeight)) 
	{
		clearTimeout(timer); 
	}
  else 
  {
    objet.style.top = (parseInt(objet.style.top) + (pas*sens)) + "px";
	}
	timer = setTimeout("moveLayer('" + content+ "','" + container + "'," + sens + ");", 30);
}

function displayBlock($id,$spanId)
{
	var $leftH = parseInt(getCalculatedProperty("my_space_left", "height")); 
	var $rightH = parseInt(getCalculatedProperty("my_space_right", "height")); 
	var $div = document.getElementById($id);
	var $divH; // hauteur du div review en display "none"
	var $span = document.getElementById($spanId);
	if ($div.style.display == 'none')
	{
		$div.style.display = '';
		//$span.innerHTML = '<img src="Images/en/button_evaluate_on.gif">';
		//$span.style.color ='#A5DDFB';
		//$divH = parseInt(getCalculatedProperty($id, "height")); 
	}
	else if ($div.style.display == '')
	{
		$div.style.display = 'none';
		//$span.innerHTML = '<img src="Images/en/button_evaluate_off.gif">';
		//$span.style.color ='#F53298';
		//mySpaceHeights();
	}
}
function displayBlocks($id,$spanId)
{
	var $leftH = parseInt(getCalculatedProperty("my_space_left", "height")); 
	var $rightH = parseInt(getCalculatedProperty("my_space_right", "height")); 
	var $div = document.getElementById($id);
	var $divH; // hauteur du div review en display "none"
	var $span = document.getElementById($spanId);
	if ($div.style.display == 'none')
	{
		$div.style.display = 'block';
		$span.innerHTML = '<img src="Images/en/button_evaluate_on.gif" style="margin-top:6px">';
		$span.style.color ='#A5DDFB';
		$divH = parseInt(getCalculatedProperty($id, "height")); 
	}
	else if ($div.style.display == 'block')
	{
		$div.style.display = 'none';
		$span.innerHTML = '<img src="Images/en/button_evaluate_off.gif" style="margin-top:6px" ></span>';
		$span.style.color ='#F53298';
		mySpaceHeights();
	}
}

/* menus déroulants ------------------------------------------------- */

var old_menu;
var delai;

function showMenuCategoriesNav(src,show_menu) {
	if (show_menu == true) 
	{
		window.clearTimeout(delai);
		if (old_menu != null) 
		{
			close_menu(src);
		}
		//var smenu=src.firstChild.nextSibling.nextSibling;
		var smenu = document.getElementById(src);
		smenu.style.display='block';
	} 
	else
	{ 
		// old_menu=src;
		old_menu = document.getElementById(src);
		delai = window.setTimeout("close_menu('"+src+"')",400);
	}
}

function close_menu(src) 
{
	//old_menu.firstChild.nextSibling.nextSibling.style.display='none';
	old_menu.style.display='none';
	old_menu = null;
}

var x_cart, y_cart;
var old_menu_cart = document.getElementById('cart_detail');
var delai_cart;


function FindPos(AObject)
{
    var posX = 0, posY = 0;
    
    do
    {
        posX += AObject.offsetLeft;
        posY += AObject.offsetTop;
        AObject = AObject.offsetParent;
    }
    while( AObject != null );

    var pos = [];
    pos['X'] = posX;
    pos['Y'] = posY;
    
    return pos;
}


function showCartDetail(art_id,type) {
	if(type !=0) type=1;	
	if(type==0)
	{
		$requete = creerRequete();
		$browser = navigator.appName;
		var $url = "Tools/ajax-updateCartDetail.php?art_id="+art_id;
		$requete.open("GET", $url, true);
		$requete.onreadystatechange = showCartDetail;//(true);
	  	//loadXML();
		$requete.send(null);
	}
	else
	{
		if ($requete.readyState == 4)
		{
			if ($requete.status == 200)
			{
				var decalageGauche = FindPos(document.getElementById('left_cart'));
				if( navigator.appName == "Microsoft Internet Explorer"){
					$('cart_detail').setStyle({
						/*top: (y_cart-12+document.documentElement.scrollTop)+"px",
						left: (decalageGauche['X']+180)+"px"*/
					});
				}
				else{
					$('cart_detail').setStyle({
						top:y_cart-12+"px",
						left: decalageGauche['X']+180+"px"
					});
				}
				
				var smenu = document.getElementById('cart_detail');
								
				var $xml = $requete.responseXML;
				var $doc = $xml.getElementsByTagName("document");

				iddoc = $doc[0].getAttribute('id');
				prixdoc = $doc[0].childNodes[1].firstChild.nodeValue;
				titredoc = $doc[0].childNodes[0].firstChild.nodeValue;

				//Remplissage de la division
				$('cart_detail_title').replace('<span id="cart_detail_title">'+titredoc+'</span>');
				$('cart_detail_price').replace('<span id="cart_detail_price" style=\"margin:0;padding:0\">'+prixdoc+'</span>');
				$('cart_detail_remove_link').writeAttribute('href','javascript:removeDocFromCart('+iddoc+',\'left\');');
			}
		}
	}
}

function showCartDetailsuite(show_menu) {
	src='cart_detail';
	if(show_menu !=true && show_menu !=false) show_menu=true;
	if (show_menu == true) 
	{
		window.clearTimeout(delai_cart);
		if (old_menu_cart != null) 
		{
			close_menu_cart(src);
		}
		var smenu = document.getElementById(src);
		smenu.style.display='block';
	} 
	else
	{ 
		old_menu_cart = document.getElementById(src);
		delai_cart = window.setTimeout("close_menu_cart('"+src+"')",400);
	}
}

function close_menu_cart()
{
	//old_menu.firstChild.nextSibling.nextSibling.style.display='none';
	old_menu_cart.style.display='none';
	old_menu_cart = null;
}

function position(e) {
	if (navigator.appName.substring(0,3) == "Net") {
		x_cart = e.pageX;
		y_cart = e.pageY;
	}
	else {
		x_cart = event.x+document.body.scrollLeft;
		y_cart = event.y+document.body.scrollTop;
	}
}

	
/* ------------------------------------------------------------------------------ */
var $lastId;

function getLastId()
{
	var $div = document.getElementById('links');
	var $lastSpan = $div.lastChild;
	var $tab = new Array();
	if (navigator.appName == 'Microsoft Internet Explorer')
	{
		$lastId = $lastSpan.getAttribute('id');
	}
	else 
	{
		$lastId = $lastSpan.previousSibling.getAttribute('id');
	}	
	$tab = $lastId.split("_");
	$lastId = $tab[1];
	//alert($lastId);
}

var $repeatFct;
var $slider;
var $idLink;

function showLinks($spanId,$catId,$idLink,type)
{ 
	$idLink = parseInt($idLink);
	var $div = document.getElementById('links'); 
	if ($div.childNodes)
		{
			for (var $i=0; $i<$div.childNodes.length; $i++)
			{
				if ($div.childNodes[$i].nodeName == "SPAN")
				{
					var $child = $div.childNodes[$i]; 
					$child.style.display = "none";
					for (var $j=0; $j<$child.childNodes.length; $j++)
					{
						if ($child.childNodes[$j].nodeName == "A" || $child.childNodes[$j].nodeName == "SPAN")
						{
							$child.childNodes[$j].style.fontWeight = "normal";
						}
					}
				}
			}
		}	

	if ($idLink == 3 && $spanId == 'prevPage')
	{
		//alert($spanId);
		for (var $i=$idLink; $i >= (parseInt($idLink)-2); $i--)
		{
			if ($i >= 1) document.getElementById("pg_"+$i).style.display = "inline";
		}		
	}
	else 
	{
		for (var $i=$idLink; $i >= (parseInt($idLink)-2); $i--)
		{
			if ($i >= 1) document.getElementById("pg_"+$i).style.display = "inline";
		}	
		for (var $i=$idLink; $i <= (parseInt($idLink)+2); $i++)
		{ 
			if ($i <= $lastId) document.getElementById("pg_"+$i).style.display = "inline";
		} 
	}
	if (navigator.appName == 'Microsoft Internet Explorer') document.getElementById("pg_"+$idLink).firstChild.style.fontWeight = "bold";
	else document.getElementById("pg_"+$idLink).firstChild.nextSibling.style.fontWeight = "bold";


   
	if (($idLink - 2) > 1)
	{
		
 		var $prev = document.createElement("SPAN");
		var $prevSpan = document.getElementById('prevPage');
		$prevSpan.onmouseover = function() {showLinks('prevPage',$catId,(parseInt($idLink)-parseInt(1)),1)};
		$prev.style.display = "inline";	
		$div.insertBefore($prev,document.getElementById("pg_"+($idLink-2)));
	}
	if (($lastId - $idLink) > 2)
	{
		var $next = document.createElement("SPAN");
		var $nextId = (parseInt($idLink) + parseInt(1));
		var $nextSpan = document.getElementById('nextPage');
		$nextSpan.onmouseover = function() {showLinks('nextPage',$catId,(parseInt($idLink)+parseInt(1)),1)};
		$next.style.display = "inline";
		$div.insertBefore($next,document.getElementById("pg_"+($idLink+3)));
		
	}
	if ($spanId != '') 
	{
		var $page = 0;
		
		if ($spanId == 'nextPage') $page = parseInt($idLink) + parseInt(1);
		else if ($spanId == 'prevPage') $page = parseInt($idLink) - parseInt(1); 
		if ($page > $lastId || ($lastId - $page < 2) || ($idLink == 3 && $spanId == 'prevPage')) clearTimeout($repeatFct);
		else $repeatFct = setTimeout("showLinks('" + $spanId + "'," + $catId + "," + $page +",1)",550);
	}
	if(type == 1){
		$slider.setValue($idLink);
	}
}

function formatNumber($number,$n)
{
	var $numberString = String($number);
	var $tab = new Array(); 
	$tab = $numberString.split('.');
	if ($tab.length > 1)    // présence d'une décimale
	{
		if ($tab[1].length < $n)
		{	
			$numberString+='0';
		}
	}
	else 
	{
		$numberString+='.00';
	}
	return $numberString;
}

function simpleTruncateString($string,$charsNb)
{
	var $truncated = '';
	if ($string.length > $charsNb)
	{
		$truncated = $string.substring(0,$charsNb)+' ...';
	}	
	else $truncated = $string;
	return $truncated;
} 
function truncateString($string,$charsNb)
{
	var $truncated = new Array();
	if ($string.length > $charsNb)
	{
		if ($string.charAt($charsNb) == ' ')
		{
			$truncated[0] = $string.substring(0,$charsNb)+' ...';
			$truncated[1] = $string.substring($charsNb+1);			
		}
		else if ($string.charAt($charsNb) != ' ')
		{
			var $left;
			var $right;
			for (var $i=$charsNb; $i>=0; $i--)
			{
				if ($string.substr($i,1) == ' ')
				{
					$left = $i;
					break;
				}
			}
			for (var $i=$charsNb; $i<$string.length; $i++)
			{
				if ($string.substr($i,1) == ' ')
				{
					$right = $i;
					break;
				}
			}
			if (($right-$charsNb) < ($charsNb-$left))
			{
				$truncated[0] = $string.substring(0,$right)+' ...';
				$truncated[1] = $string.substring($right+1);					
			}
			else
			{
				$truncated[0] = $string.substring(0,$left)+' ...';
				$truncated[1] = $string.substring($left+1);					
			}
		}

	}
	else $truncated[0] = $string;
	return $truncated;
}
function submitForm($form)
{
	//var $test = document.forms[$form].elements['email'].value;
	//alert($test);
	document.forms[$form].submit();
}
function showPicForm()
{
	var $disp = document.getElementById('pop_photo_profil'); 
    var $fond = document.getElementById('profil_table');
 //   var $fond = document.getElementById('main');
	var Obj2 = document.getElementById('container');
	var flash_publish = document.getElementById('flash_anim_publish');
	
	if ($disp.style.display == 'none'){
		$disp.style.display = 'block';
	}
	
	if(flash_publish){
		flash_publish.style.display = 'none';
	}
	
	if(Obj2){
	    with( Obj2.style){
			opacity=0.1;
			filter='alpha(opacity=8)';
			   $fond.style.display = 'none';
	    }
	}

}

	
function fermer_photo(){
	var $disp = document.getElementById('pop_photo_profil'); 
    var $fond = document.getElementById('profil_table');
	var Obj2 = document.getElementById('container');
	var flash_publish = document.getElementById('flash_anim_publish');
	
	if ($disp.style.display == 'block')
	{
		$disp.style.display = 'none';
	}
	
	if(flash_publish){
		flash_publish.style.display = 'block';
	}
   
	if(Obj2){
		with( Obj2.style){
			opacity=1;
			filter='opacity(alpha=100)';
			$fond.style.display = 'block';
        }
	}
}
function showBlock($idContainer,$idBlock)
{
	var $container = document.getElementById($idContainer);
	$length = $container.childNodes.length;
	var $childNode;
	for (var $i=0; $i<$length; $i++)
	{
		$childNode = $container.childNodes[$i]
		if ($childNode.nodeType == 1)
		{
			if ($childNode.getAttribute('id') == $idBlock) $childNode.style.display = 'block';
			else
			{
				if ($childNode.style.display == 'block') $childNode.style.display = 'none';
			}
		}
	}
	document.getElementById('my_space_left').style.height = "auto";
	mySpaceHeights();
}

function noFileFound()
{
	alert($msg);
}
function showList($id,$bool)
{
	var $list = document.getElementById($id);
	if ($bool) $list.style.display = 'block';
	else if (!$bool && $list.style.display == 'block') $list.style.display = 'none';
}
function enableButton($checkbox,$idButton)
{
	var $button = document.getElementById($idButton);
	var $state = $checkbox.checked;
	if ($state) $button.disabled = false;
	else $button.disabled = true;
}
function countChars($textArea,$inputDest)
{
	var $length = $textArea.value.length;
	var $dest = document.getElementById($inputDest); 
	$dest.value = $length;
}
/*
function limite(textarea, max)
{
    if(textarea.value.length >= max)
    {
        textarea.value = textarea.value.substring(0,max);
    }
    var reste = max - textarea.value.length;
    var affichage_reste =  reste +‘ caractères restants’;
    document.getElementById(‘max_desc’).innerHTML = affichage_reste;
}
*/
function checkRegForm($idForm)
{
	var $form = document.getElementById($idForm);
	$email = $form.email_reg.value;
	$pass = $form.pw_reg.value;
	$bool = true;
	var $td_email = document.getElementById('email_reg');
	var $td_pw = document.getElementById('pw_reg');
	if (!checkMail($email))
	{
		$bool = false;
		
		$td_email.style.color = "red";		
	}
	else if (checkMail($email))
	{
		if ($td_email.style.color == "red") $td_email.style.color = "black";
	}
	if (trim($pass) == "")
	{
		$bool = false;	
		$td_pw.style.color = "red";		
	}
	else if (trim($pass) != "")
	{
		if ($td_pw.style.color == "red") $td_pw.style.color = "black";
	}
	if ($bool) document.forms[$idForm].submit();
}
function checkMail(mail){
	var expr = /^[a-zA-Z][a-zA-Z0-9]+([_\-\.]?[a-zA-Z0-9]+){1,3}@[a-zA-Z0-9]+(\.[a-zA-Z]{2,4})?\.([a-zA-Z]{2,4})$/g; // *=0 à n; ?=0 ou 1
	return validation(mail,expr);
}

function checkFormContact($idForm)
{
	$form = document.getElementById($idForm);
	$name = $form.nom.value;
	$email = $form.Email.value;
	$subject = $form.Sujet.value;
	$message = $form.Message.value;
	
	 $td_nom =  document.getElementById('td_nom');
	 $td_email =  document.getElementById('td_email');
	 $td_sujet =  document.getElementById('td_sujet');
	 $td_message =  document.getElementById('td_message');
	
	$bool = true;
	
	if($name == '')
	{
		$bool = false;
		$td_nom.style.color = "red";
	}
	else
	{
		$td_nom.style.color = "#403D3D";
	}
	
	if (!checkMail($email))
	{
		$bool = false;
		$td_email.style.color = "red";		
	}
	else
	{
		$td_email.style.color = "#403D3D";
	}
	
	if($subject  == '')
	{
		$bool = false;
		$td_sujet.style.color = "red";	
	}
	else
	{
		$td_sujet.style.color = "#403D3D";	
	}
	if($message == '')
	{
		$bool = false;
		$td_message.style.color = "red";	
	}
	else
	{
		$td_message.style.color = "#403D3D";
	}
	
	return $bool;
}

function checkFormPersonal($idForm)
{

	$form = document.getElementById($idForm);
	$name = $form.name.value;
	$firstname = $form.firstname.value;
	$address = $form.address.value;
	$zip = $form.zip.value;
	$city = $form.city.value;
	
	$lab_name =  document.getElementById('label_name');
	$lab_firstname =  document.getElementById('label_firstname');
	$lab_address =  document.getElementById('label_address');
	$lab_zip =  document.getElementById('label_zip');
	$lab_city =  document.getElementById('label_city');

	$bool = true;
	
	if($name == '')
	{
		$bool = false;
		$lab_name.style.color = "red";
	}
	else
	{
		$lab_name.style.color = "#403D3D";
	}
	
	if($firstname == '')
	{
		$bool = false;
		$lab_firstname.style.color = "red";
	}
	else
	{
		$lab_firstname.style.color = "#403D3D";
	}
	
	
	if($address == '')
	{
		$bool = false;
		$lab_address.style.color = "red";
	}
	else
	{
		$lab_address.style.color = "#403D3D";
	}
	
	if($zip == '')
	{
		$bool = false;
		$lab_zip.style.color = "red";
	}
	else
	{
		$lab_zip.style.color = "#403D3D";
	}
	
	if($city == '')
	{
		$bool = false;
		$lab_city.style.color = "red";
	}
	else
	{
		$lab_city.style.color = "#403D3D";
	}
	
	
	return $bool;
}


function validation(string,expr){
	var ch=string.match(expr);     // renvoie un tableau contenant les résultats 
	if (ch!=null) return true
	else return false
}
function checkDocUploadForm($form)
{
	//var $table = document.getElementById('table_files');
	var $nbDocs = document.getElementById('nbDocs').value;
	var $categ;
	var $subcat;
	var $title;
	var $descr;
	var $content;
	var $metaDescr;
	var $type;
	var $nbPages;
	var $level;
	var $color = "red";
	var $normalColor = "#403D3D";
	var $bool = true;
	var $localBool= true;
	var $onglets = new Array();
	for ($i=0; $i<$nbDocs; $i++)
	{
		$localBool = true;

		$categ = document.getElementById('category_'+$i);
		if ($categ.options[$categ.selectedIndex].value == 0)
		{
			document.getElementById('td_category_'+$i).style.color = $color;
			$bool = false;
			$localBool = false;
		}
		else if ($categ.options[$categ.selectedIndex].value != 0)
		{
			document.getElementById('td_category_'+$i).style.color = "#000000";
		}
		$subcat = document.getElementById('other_cat_'+$i);
		if ($subcat.options[$subcat.selectedIndex].value == 0)
		{
			document.getElementById('td_subcat_'+$i).style.color = $color;
			$bool = false;
			$localBool = false;
		}
		else if ($subcat.options[$subcat.selectedIndex].value != 0)
		{
			document.getElementById('td_subcat_'+$i).style.color = "#000000";
		}
		$title = document.getElementById('title_'+$i);
		if (trim($title.value) == "")
		{
			document.getElementById('td_title_'+$i).style.color = $color;
			$bool = false;
			$localBool = false;
		}
		else if (trim($title.value) != "")
		{
			document.getElementById('td_title_'+$i).style.color = "#000000";
		}
		$descr = document.getElementById('art_description_'+$i);
		if ($descr.value.length < 180)
		{
			document.getElementById('td_art_description_'+$i).style.color = $color;
			$bool = false;
			$localBool = false;
		}
		else if ($descr.value.length >= 180)
		{
			document.getElementById('td_art_description_'+$i).style.color = '#000000';
		}
		$content = document.getElementById('index_'+$i);
		if (trim($content.value) == "")
		{
			document.getElementById('td_index_'+$i).style.color = $color;
			$bool = false;
			$localBool = false;
		}
		else if (trim($content.value) != "")
		{
			document.getElementById('td_index_'+$i).style.color = '#000000';
		}
		$metaDescr = document.getElementById('description_meta_'+$i);
		if (trim($metaDescr.value) == "")
		{
			document.getElementById('td_description_meta_'+$i).style.color = $color;
			$bool = false;
			$localBool = false;
		}
		else if (trim($metaDescr.value) != "")
		{
			document.getElementById('td_description_meta_'+$i).style.color = '#000000';
		}		
		$type = document.getElementById('type_'+$i);
		if ($type.options[$type.selectedIndex].value == -1)
		{
			document.getElementById('td_type_'+$i).style.color = $color;
			$bool = false;
			$localBool = false;
		}
		else if ($type.options[$type.selectedIndex].value > -1)
		{
			document.getElementById('td_type_'+$i).style.color = '#000000';
		}
		$nbPages = document.getElementById('nbpages_'+$i);
		if (trim($nbPages.value) == "" || (trim($nbPages.value) != "" && isNaN($nbPages.value)) )
		{
			document.getElementById('td_nbpages_'+$i).style.color = $color;
			$bool = false;
			$localBool = false;
		}
		else if (trim($nbPages.value) != "" && !isNaN($nbPages.value))
		{
			document.getElementById('td_nbpages_'+$i).style.color = '#000000';
		}		
		$level = document.getElementById('level_'+$i);
		if ($level.options[$level.selectedIndex].value == 0)
		{
			document.getElementById('td_level_'+$i).style.color = $color;
			$bool = false;
			$localBool = false;
		}
		else if ($level.options[$level.selectedIndex].value != 0) document.getElementById('td_level_'+$i).style.color = "#000000"; 	
		
		
		if( !$localBool ) document.getElementById('onglet'+$i).style.color = $color;
		else document.getElementById('onglet'+$i).style.color = $normalColor;
	}

	if ($bool) document.forms[$form].submit();
}



function checkFormDescript($form)
{
	var $bool = true;
	var $color = "red";
	$categ = document.getElementById('category');
	if ($categ.options[$categ.selectedIndex].value == 0)
	{
			document.getElementById('td_category').style.color = $color;
			$bool = false;
	}
	else 
	{	
		document.getElementById('td_category').style.color = "#000000";
	}
	
	$subcat = document.getElementById('other_cat');
	if ($subcat.options[$subcat.selectedIndex].value == 0)
		{
			document.getElementById('td_subcat').style.color = $color;
			$bool = false;
		}
		else 
		{
			document.getElementById('td_subcat').style.color = "#000000";
		}
		$title = document.getElementById('title');
		if (trim($title.value) == "")
		{
			document.getElementById('td_title').style.color = $color;
			$bool = false;
		}
		else
		{
			document.getElementById('td_title').style.color = "#000000";
		}
		$descr = document.getElementById('art_description');
		if ($descr.value.length < 180)
		{
			document.getElementById('td_art_description').style.color = $color;
			$bool = false;
		}
		else
		{
			document.getElementById('td_art_description').style.color = '#000000';
		}
		
		$content = document.getElementById('index');
		if (trim($content.value) == "")
		{
			document.getElementById('td_index').style.color = $color;
			$bool = false;
		}
		else
		{
			document.getElementById('td_index').style.color = '#000000';
		}
		$metaDescr = document.getElementById('description_meta');
		if (trim($metaDescr.value) == "")
		{
			document.getElementById('td_description_meta').style.color = $color;
			$bool = false;
		}
		else
		{
			document.getElementById('td_description_meta').style.color = '#000000';
		}		
		$type = document.getElementById('type');
		if ($type.options[$type.selectedIndex].value == -1)
		{
			document.getElementById('td_type').style.color = $color;
			$bool = false;
		}
		else
		{
			document.getElementById('td_type').style.color = '#000000';
		}
		$nbPages = document.getElementById('nbpages');
		if (trim($nbPages.value) == "" || (trim($nbPages.value) != "" && isNaN($nbPages.value)) )
		{
			document.getElementById('td_nbpages').style.color = $color;
			$bool = false;
			$localBool = false;
		}
		else
		{
			document.getElementById('td_nbpages').style.color = '#000000';
		}		
		$level = document.getElementById('level');
		if ($level.options[$level.selectedIndex].value == 0)
		{
			document.getElementById('td_level').style.color = $color;
			$bool = false;
			
		}
		else 
		{
			document.getElementById('td_level').style.color = "#000000"; 	
		}
	
	if ($bool) document.forms[$form].submit();


}

function print_r(obj) {
  win_print_r = window.open('about:blank', 'win_print_r');
  win_print_r.document.write('<html><body>');
  r_print_r(obj, win_print_r);
  win_print_r.document.write('</body></html>');
 }

 function r_print_r(theObj, win_print_r) {
  if(theObj.constructor == Array ||
   theObj.constructor == Object){
   if (win_print_r == null)
    win_print_r = window.open('about:blank', 'win_print_r');
   }
   for(var p in theObj){
    if(theObj[p].constructor == Array||
     theObj[p].constructor == Object){
     win_print_r.document.write("<li>["+p+"] =>"+typeof(theObj)+"</li>");
     win_print_r.document.write("<ul>")
     r_print_r(theObj[p], win_print_r);
     win_print_r.document.write("</ul>")
    } else {
     win_print_r.document.write("<li>["+p+"] =>"+theObj[p]+"</li>");
    }
   }
  win_print_r.document.write("</ul>")
 }



/* FONCTION POUR AJOUT DE DOC */
function toggleCat(id, value){
	if(value=='0'){
		$('id_sub_categories_').descendants()[0].update('<option value="0" id="opt_cat_0">-</option>');
	}else{
		//var arr=$('id_sub_categories_').descendants();
		//alert(arr.join());
		$('other_cat').update(document.getElementById(id+value).innerHTML);
		//$('id_sub_categories_').firstDescendant().update(document.getElementById(id+value).innerHTML);
		//$('id_sub_categories_').firstDescendant().update(document.getElementById(id+value).innerHTML);
		//print_r(f);//.update(document.getElementById(id+value).innerHTML);
		//$('id_sub_categories_')..update(document.getElementById(id+value).innerHTML);
	}
}

function toggleTable(id){
	//Changer la couleur de fond des onglets concernés
	var les_onglets = document.getElementById('onglets_docs').getElementsByTagName('span');
		for(var i=0; i<les_onglets.length; i++){
			les_onglets[i].style.backgroundColor = "white";
	}
	document.getElementById('onglet'+id).style.backgroundColor="#e5f3f9";
	
	//Effacer tout le contenu + afficher la bonne dis
	var les_contenus = document.getElementById('contenu_onglets').getElementsByTagName('div');
		for(var i=0; i<les_contenus.length; i++){
			les_contenus[i].style.display="none";
	}
	document.getElementById('table_files'+id).style.display="block";
}

function cutFilename(nom){
	return 
}

/* Fonctions pour ajouter/supprimer des champs de formulaire pour la promotion d'oodoc */
function addChamp(){
	//var lastEnfant = $('lien_ajout_promo').remove();
	var longueurDiv = $('cases_email').childElements().length;
	if(longueurDiv < 11)
		$('cases_email').insert('<div id="email'+longueurDiv+'"><input class="input_promotion" type="text" name="email'+longueurDiv+'" /><img src="Images/cross.png" alt="" width="16" height="16" onClick="suppChamp($(this).ancestors()[0].readAttribute(\'id\'));" style="vertical-align:middle;" /></div>');
	$('cases_email').insert(lastEnfant);
}
function suppChamp(id){
	$(id).remove();
	var enfants = $('cases_email').childElements();
	for(var i=0; i<enfants.length-1; i++){
		enfants[i].writeAttribute('id','email'+i);
		enfants[i].firstChild.writeAttribute('name','email'+i);
	}
}
function verif_emailS(){
	//Vérification de l'e-mail
	atom   = '[-a-z0-9!#$%&\'*+\\/=?^_`{|}~]';   // caracteres autorisés avant l'arobase
	domain = '([a-z0-9]([-a-z0-9]*[a-z0-9]+)?)'; // caracteres autorisés apres l'arobase (nom de domaine)
	var regex = '^' + atom + '+' +   // Une ou plusieurs fois les caracteres autorisés avant l'arobase
	'(\.' + atom + '+)*' +         // Suivis par zéro point ou plus séparés par des caracteres autorisés avant l'arobase
	'@' +                           // Suivis d'un arobase
	'(' + domain + '{1,63}\.)+' +  // Suivis par 1 a 63 caracteres autorisés pour le nom de domaine séparés par des points
	domain + '{2,63}$';          // Suivi de 2 a 63 caracteres autorisés pour le nom de domaine
	regex = new RegExp( regex, "g" );
	
	var retour = true;
	var formElems = $('form_promo').getInputs('text');
	for(var i=0; i<formElems.length; i++){
		formElems[i].setStyle({
						border: ''
						});
		if( formElems[i].getValue() == "" ){
			formElems[i].setStyle({
							border: '1px solid red'
							});
			retour = false;
		}
		if( formElems[i].readAttribute('name').match(new RegExp( "^(email)[0-9]+$", "g" )) ){
			var contenu = formElems[i].getValue();
			formElems[i].setStyle({
							border: ''
							});
			if(contenu.match(regex)){
			}else{
				formElems[i].setStyle({
								border: '1px solid red'
								});
				retour = false;
			}			
		}
	}
	return retour;
}
