window.addEvent('domready', function(){

	$('mode_search').addEvent('submit', function(e) {
		new Event(e).stop();
		
		document.location.href = 'http://www.vetement-en-ligne.com/Recherche-Mode/' + URLEncode( ucwords(noaccent( $('searchinput').value.toLowerCase()) ) );
	});
	
	if ( $('mode_search2') ) {
		$('mode_search2').addEvent('submit', function(e) {
			new Event(e).stop();
			
			document.location.href = 'http://www.vetement-en-ligne.com/Recherche-Mode/' + URLEncode( ucwords(noaccent( $('searchinput2').value.toLowerCase()) ) );
		});
	}
});

function URLEncode (clearString) {
  var output = '';
  var x = 0;
  clearString = clearString.toString();
  var regex = /(^[a-zA-Z0-9_.]*)/;
  while (x < clearString.length) {
    var match = regex.exec(clearString.substr(x));
    if (match != null && match.length > 1 && match[1] != '') {
    	output += match[1];
      x += match[1].length;
    } else {
      if (clearString[x] == ' ')
        output += '+';
      else {
        var charCode = clearString.charCodeAt(x);
        var hexVal = charCode.toString(16);
        output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
      }
      x++;
    }
  }
  return output;
}
function noaccent(chaine) {
	temp = chaine.replace(/[àâä]/gi,"a")
	temp = temp.replace(/[éèêë]/gi,"e")
	temp = temp.replace(/[îï]/gi,"i")
	temp = temp.replace(/[ôö]/gi,"o")
	temp = temp.replace(/[ùûü]/gi,"u")
	return temp
}
function ucwords( str ) {
    // http://kevin.vanzonneveld.net
    // +   original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
    // +   improved by: _argos
    // +   bugfixed by: Onno Marsman
    // *     example 1: ucwords('kevin van zonneveld');
    // *     returns 1: 'Kevin Van Zonneveld'
    // *     example 2: ucwords('HELLO WORLD');
    // *     returns 2: 'HELLO WORLD'
 
    return (str+'').replace(/^(.)|\s(.)/g, function ( $1 ) { return $1.toUpperCase ( ); } );
}