
function sendRecherche()
{
	var ladate = new Date();
	try{
		new Ajax.Request('page.asp?id=465&rnd='+ladate.getTime(),
		{
			method:'get',
			onSuccess: function(transport){
				try{
					var form = document.forms['mlform'];
					var div = new Element("div",{"id":"bw_contentDiv"});
					$$('body')[0].appendChild(div);
					div.style.display="none";
					div.innerHTML = transport.responseText;
					var ID;
					if($('IdMax'))
						ID = (parseInt($('IdMax').innerHTML,10)+1).toString();
					else
						ID = "1";
					SetCookie("IDFiche",ID);
					while(ID.length<4)
					{
						ID = "0"+ID.toString();
					}
					ID = "2011MR"+ID;
					form.elements['C195'].value = ID;
					form.submit();
				}catch(any){
					alert(any||any.description);
				}
			},
			onFailure: function(){ alert('Something went wrong...') }
		});
	}
	catch(any){
		alert(any||any.description);
	}
}

function sendVente()
{
	var ladate = new Date();
	try{
		new Ajax.Request('page.asp?id=467&rnd='+ladate.getTime(),
		{
			method:'get',
			onSuccess: function(transport){
				try{
					var form = document.forms['mlform'];
					var div = new Element("div",{"id":"bw_contentDiv"});
					$$('body')[0].appendChild(div);
					div.style.display="none";
					div.innerHTML = transport.responseText;
					var ID;
					if($('IdMax'))
						ID = (parseInt($('IdMax').innerHTML,10)+1).toString();
					else
						ID = "1";
					SetCookie("IDFicheVente",ID);
					while(ID.length<4)
					{
						ID = "0"+ID.toString();
					}
					ID = "2011MV"+ID;
					form.elements['C214'].value = ID;
					form.submit();
				}catch(any){
					alert(any||any.description);
				}
			},
			onFailure: function(){ alert('Something went wrong...') }
		});
	}
	catch(any){
		alert(any||any.description);
	}
}

function loadRecherche()
{
	if(GetCookie("IDFiche")!="" && GetCookie('IDFiche')!=null)
		window.location.href = "/page.asp?id=465&IDF="+GetCookie("IDFiche");
	else
		alert("Erreur survenue, redirection recherche impossible");
}

function loadVente()
{
	if(GetCookie("IDFicheVente")!="" && GetCookie('IDFicheVente')!=null)
		window.location.href = "/page.asp?id=467&IDF="+GetCookie("IDFicheVente");
	else
		alert("Erreur survenue, redirection recherche impossible");
}

function SetCookie (name, value) 
{
	var argv=SetCookie.arguments;
	var argc=SetCookie.arguments.length;
	var expires=(argc > 2) ? argv[2] : null;
	if(expires==null)
	{
		/*
		var date_c = new Date();
		date_c.setTime(date_c.getTime()+(3600*1000));
		expires = date_c.toGMTString();
		*/
	}
	var path=(argc > 3) ? argv[3] : null;
	if(path==null)
	{
		var pathname=location.pathname;
		var myDomain=pathname.substring(0,pathname.lastIndexOf('/')) +'/';
	}
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=name+"="+escape(value)+
		((expires==null) ? "" : ("; expires="+expires))+
		((path==null) ? "" : ("; path="+path))+
		((domain==null) ? "" : ("; domain="+domain))+
		((secure==true) ? "; secure" : "");
}

function GetCookie (name) 
{
	var arg=name+"=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while (i<clen) 
	{
		var j=i+alen;
		if (document.cookie.substring(i, j)==arg)
						return getCookieVal (j);
				i=document.cookie.indexOf(" ",i)+1;
						if (i==0) break;
	}
	return null;
}

function getCookieVal(offset) 
{
	var endstr=document.cookie.indexOf (";", offset);
	if (endstr==-1)
      	endstr=document.cookie.length;
	return unescape(document.cookie.substring(offset, endstr));
}


