  //////////////////////////////////////////
 // MyBizznet team work copyright © 2008 //
//////////////////////////////////////////

// Application name: AA Matech Website
// Version: 1
// Last update : 11/04/2008
// Author:  Mathieu Caille
// Team: MyBizznet core team [All rights reserved]
// Email:   mathieu.caille@mybizznet.com
// MyBizznet All the tools for my business
// website http://www.mybizznet.com
/////////////////////////////////////////////////////////////////////////////////////

////// This JavaScript Document must work with Prototype FrameWork
////// Greate thank to the Prototype Core Team 
////// Website http://www.prototypejs.org
////// Don't Forget to Donate money if you use this framework
////// Copyright (c) 2005-2008 Sam Stephenson (http://www.prototypejs.org) 

////// This JavaScript Document must work with Script.aculo.us
////// Greate thank to the Script.aculo.us Core Team 
////// Website http://script.aculo.us
////// Don't Forget to Donate money if you use this framework
////// Copyright (c) 2005-2008 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)

/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////


sfHover = function() {
	var sfEls = document.getElementById("menu").getElementsByTagName("LI");
	for (var i=0; i<sfEls.length; i++) {
		sfEls[i].onmouseover=function() {
			this.className+=" sfhover";
		}
		sfEls[i].onmouseout=function() {
			this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
		}
	}
}
if (window.attachEvent) window.attachEvent("onload", sfHover);




// Autocomplete of search input

function AutocompSearch() {
	new Ajax.Autocompleter('productsearch' , 'suggest' , 'request/getproducts.php' ,
						      { 
							  method: 'post',
							  paramName: 'search'});
							}
Event.observe(window, 'load', AutocompSearch);

// Clear defaut value of search input

function ClearSearchField(thefield){

if (thefield.defaultValue==thefield.value)

thefield.value = ""

}

/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////

// Result of search

function ViewSearchResult() {
	new Ajax.Updater('welcome' , 'request/search_result.php' , { parameters: { VALUE: $F('productsearch')}});
	new Effect.Fade ('stock48');	
	}
	
	
/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
// Contact form overlay windows


function OverlayContact() {
	Lightview.show({
	evalScripts:true,
	  href: 'request/contact_us.php',
	  rel: 'ajax',
	  title: '<h1><img src="img/butSearch.gif" alt="" align="absmiddle" /> Matech - Contactez-nous </h1>',
	  options: {
		evalScripts:true,
	    autosize: true,
		ajax: {
		  onComplete: function(){
		    // once the request is complete we observe the submit button
			$('contact_form').observe('submit', submitAjaxForm);
		  } 
	    }
	  }
	});
};

// Submit contact form

function submitAjaxForm(event) {
  // block default form submit
  event.stop();
  new Ajax.Request('request/send_mail.php',
				{
				parameters: $('contact_form').serialize()});
  Lightview.show({
    href: 'request/confirm_mail.php',
    rel: 'ajax',
    options: {
      title: 'Thank you',
	  menubar: false,
	  topclose: true,
	  autosize: true,
      ajax: {
        parameters: Form.serialize('contact_form') // the parameters from the form
      }
    }
  });
}


/////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////
// Overlay Edit company contents

function OverlayEditCompany() {
	Lightview.show({
	  href: 'request/admin/edit_company.php',
	  rel: 'ajax',
	  title: 
	  '<h1><img src="img/icones/22x22/actions/edit-copy.png" alt="" align="absmiddle" />  Edition contenu </h1>',
	  options: {
	    width:650,
		height:350,
		ajax: {
		evalScripts:true,
		parameters:{ID: $F('company_number')} ,
		  onComplete: function(){
		    // once the request is complete we observe the submit button
			$('edit_company').observe('submit', submitUpdateCompanyForm);
		  } 
	    }
	  }
	});
};

// Submit company contents

function submitUpdateCompanyForm(event) {
  // block default form submit
  event.stop();
  new Ajax.Request('request/update_company.php',
				{
				evalScripts:true,
				parameters: $('edit_company').serialize(),
				onComplete: function(requester) {
				new Ajax.Updater('contents', 'contents/company.php', {parameters: {ID: $F('company_number')}});
  						}
				});

  Lightview.show({
    href: 'request/admin/confirmation/update.php',
    rel: 'ajax',
    options: {
      title: 'Mise à jour effectuee',
	  menubar: false,
	  topclose: true,
	  autosize: true
    }
  });
}

// Add news to front page 

function AddNews() {
	new Ajax.Updater( 'contents', '../request/form_add_news.php',
					{
					 evalScripts:true
					 });
	new Effect.Fade ('stock48');
	new Effect.Appear ('contents');
};


function SaveNews() {
	new Ajax.Request('../request/save_news.php',
	{
	parameters: $('add_news').serialize(),
	onComplete: function(requester) {	
	new Effect.Fade ('contents');
	new Ajax.Updater('news', '../contents/news.php');
	}
						});}

// Update news to front page 

function ViewUpdateNews() {
	new Ajax.Updater( 'contents', '../request/form_update_news.php',					 
					 {
						 evalScripts:true,
						 parameters:{ID: $F('ID_NEWS')}
					 });
						 new Effect.Fade ('stock48');
						 new Effect.Appear ('contents');
	};


// Save update news 


function UpdateNews() {
	new Ajax.Request('../request/save_update_news.php',
	{
	parameters: $('update_news').serialize(),
	onSuccess: function(transport) {
	new Ajax.Updater('news' , '../contents/news.php');	
	}
						});}
	

// Delete news to front page 

function ViewDeleteNews() {
	new Ajax.Updater( 'contents', '../request/admin/delete_news.php',					 
					 {
						 evalScripts:true,
						 parameters:{ID: $F('ID_NEWS')}
					 });
						 new Effect.Fade ('stock48');
						 new Effect.Appear ('contents');
	};
	
// Submit Delete news function 

function SubmitDeleteNews() {
  new Ajax.Request('../request/delete_news.php',
				{
				evalScripts:true,
				parameters: $('delete_news').serialize(),
				onComplete: function(requester) {
				new Ajax.Updater('news', '../contents/news.php');
				new Effect.Fade ('contents');
  						}
				});
}

// View add doc to news

function AddDocNews() {
	new Ajax.Updater( 'contents', '../request/form_add_docnews.php',
					{
					 evalScripts:true,
					 parameters:{ID: $F('ID_NEWS')}
					 });
	new Effect.Fade ('stock48');
	new Effect.Appear ('contents');
};

// Save news doc

/* function SaveDocNews() {
	new Ajax.Request('../request/save_news_doc.php',
	{
	parameters: $('add_docnews').serialize(),
	onSuccess: function(transport) {
	new Ajax.Updater('news' , '../contents/news.php');	
	}
					});}
*/