var locked=0 ;
function SearchValidate(need_submit)
{
 var no_error=1;
 if (locked>0)
 {
	 no_error=0;
 }
 else
 {
	 if ( (document.searchForm.q.value=="") && ( (document.searchForm.catfilter.selectedIndex == 0) || (document.searchForm.catfilter.options[document.searchForm.catfilter.selectedIndex].value == "") ) )
	 {
		 no_error=0;
		 document.searchForm.q.focus();
	 }
	 else
	 {
		 locked++;
		 if (need_submit==1) document.searchForm.submit() ;
	 }

 }
 return (no_error==1);
}


function padlength(what){
	var output=(what.toString().length==1)? "0"+what : what;
	return output;
}

function AffHorloge(){
	serverdate.setSeconds(serverdate.getSeconds()+1)
	var timestring=padlength(serverdate.getHours())+":"+padlength(serverdate.getMinutes())+":"+padlength(serverdate.getSeconds());
	document.getElementById("horloge").innerHTML=timestring;
}

function InitHorloge(h) {
   document.write("<div id='horloge' style='display:inline;'>"+h+"</div>");
	setInterval("AffHorloge()", 1000);
}

function HideInfo0() {
    $("layerblack0").hide();
    $("_INFO0").hide();
}
function ShowInfo0(){
	$('layerblack0').show();
	Center( '_INFO0' );
	$('_INFO0').show();
}

function HideInfo() {
    $("layerblack").hide();
    $("_INFO").hide();
}
function ShowInfo(){
	$('layerblack').show();
	Center( '_INFO' );
	$('_INFO').show();
}
function ShowError(){
	$('layerblack').show();
	Center( '_IERROR' );
	$('_IERROR').show();
}
function HideError(){
    $("layerblack").hide();
    $("_IERROR").hide();
}
function HideIndicator(){
	$('indicator').hide() ;	
}
function ShowIndicator() {
	Center('indicator') ;
	$('indicator').show();
}


function HideInfo2() {
    $("layerblack2").hide();
    $("_INFO2").hide();
}
function ShowInfo2(){
	$('layerblack2').show();
	Center( '_INFO2' );
	$('_INFO2').show();
}

function getWindowWidth( who) {
	return ($(who).innerWidth || document.documentElement.clientWidth || document.body.clientWidth || 0);
}
function getWindowHeight( who ){
	return ($(who).innerHeight || document.documentElement.clientHeight || document.body.clientHeight || 0);
}
function getDocumentWidth(who){
	return Math.min(document.body.scrollWidth,getWindowWidth(who));
}
function getDocumentHeight(who){
	return Math.max(document.body.scrollHeight,getWindowHeight(who));
}

function Center( who ){
	var dimensions = $(who).getDimensions();
	Position.prepare();
	var offset_left = (Position.deltaX + Math.floor((getWindowWidth(who) - dimensions.width) / 2));
	var offset_top = (Position.deltaY + ((getWindowHeight(who) > dimensions.height) ? Math.floor((getWindowHeight(who) - dimensions.height) / 2) : 0));
	$(who).setStyle({
	top: ((dimensions.height <= getDocumentHeight(who)) ? ((offset_top != null && offset_top > 0) ? offset_top : '10') + 'px' : 10),
	left: ((dimensions.width <= getDocumentWidth(who)) ? ((offset_left != null && offset_left > 0) ? offset_left : '10') + 'px' : 10)
	});
}

function NoAutomaticSubmit(){
	return false ;	
}
function SendContactMessage(){
	ShowIndicator();
	$('errormessage').hide();
	new Ajax.Updater( 'errormessage',
						  'includes/ajax/sendmessage.php',
						  {
							onComplete:HideIndicator,
						  	method:"post", 
							evalScripts:true,
							parameters:Form.serialize('ajmessageboard')
							}
						 );
}
function Contact( l, user, t ){
	ShowIndicator();
	new Ajax.Updater( '_INFODIV',
	  'includes/ajax/sendmessage.php',
	  {onComplete:ShowInfo, 
		method:"post", 
		evalScripts:true,
		parameters:{lang:l, user_id:user, title:t}
		}
	 );	
}
function ContactMessagerie( l, user, t, mess ){
	ShowIndicator();
	new Ajax.Updater( '_INFODIV',
	  'includes/ajax/sendmessage.php',
	  {onComplete:ShowInfo, 
		method:"post", 
		evalScripts:true,
		parameters:{lang:l, user_id:user, title:t, fromid:mess}
		}
	 );	
}
function SendQuestion(){
	ShowIndicator();
	$('errormessage').hide();
	new Ajax.Updater( 'errormessage',
						  'includes/ajax/board.php',
						  {
							onComplete:HideIndicator,
						  	method:"post", 
							evalScripts:true,
							parameters:Form.serialize('ajmessageboard')
							}
						 );
}
function PoserQuestion( l, id ){
	ShowIndicator();
	new Ajax.Updater( '_INFODIV',
	  'includes/ajax/board.php',
	  {onComplete:ShowInfo, 
		method:"post", 
		evalScripts:true,
		parameters:{lang:l, auction:id }
		}
	 );	
}
function PoserQuestionItem( l, id ){
	ShowIndicator();
	new Ajax.Updater( '_INFODIV',
	  'includes/ajax/board.php',
	  {onComplete:ShowInfo, 
		method:"post", 
		evalScripts:true,
		parameters:{lang:l, auction:id, fromitem:id }
		}
	 );	
}
function RepondreQuestion( l, id ){
	ShowIndicator();
	new Ajax.Updater( '_INFODIV',
	  'includes/ajax/board.php',
	  {onComplete:ShowInfo, 
		method:"post", 
		evalScripts:true,
		parameters:{lang:l, board_id:id }
		}
	 );	
}
function ReloadQR( l, auc, idboard, r ){
	if ( $('_QR') ){
		new Ajax.Updater( '_QR',
		  'includes/ajax/board.php',
		  { 
			method:"post", 
			evalScripts:true,
			parameters:{lang:l, action:'reload', fromitem:auc, board:idboard, qr:r }
			}
		 );	
	}
}
function AddFavoriteSeller( l, user){
	ShowIndicator();
	new Ajax.Updater( '_INFODIV',
	  'includes/ajax/favorite_seller_add.php',
	  {onComplete:ShowInfo, 
		method:"post", 
		evalScripts:true,
		parameters:{lang:l, id_seller:user}
		}
	 );	
}
function HideFavoriteSeller( id ){	
	var code = "favoriteseller_"+ id ;
	var base = code ;
	var j = 0 ;
	if ($('favsellericon')) $('favsellericon').show();
	if ($(code)) 
		$(code).hide();
	code = code + '_' + j;
	while ($(code)) {
		$(code).hide();
		j = j + 1 ;
		code = base + '_' + j;
	}
		
}