// JavaScript Document
function openSetOlfa()
{
	newwindow=window.open("set-olfa.html",'name','height=500,width=600');
	if (window.focus) {newwindow.focus()}
}

function openVideo(which)
{
	if (which=="ouverture") 
	{
		video="video1.html";
		w=853;
		h=510;
	}
	else
	{
		video="video2.html";
		w=853;
		h=510;
	}
	videowindow=window.open(video,"vid","height="+h+",width="+w);
	if (window.focus) {videowindow.focus()}
}

function checkSubmit()
{
	//we check if at least one item has been selected
	if (Trim(document.getElementById('email').value) == "" || Trim(document.getElementById('nom').value) == "" || Trim(document.getElementById('tel').value) == "" || Trim(document.getElementById('societe').value) == "" || Trim(document.getElementById('msg').value) == "" )
	{
		alert ("Veuillez renseigner tous les champs.");
	}
	else
	{
		if (!isMailValid(document.getElementById('email').value))
		{
			alert ("Veuillez entrer une adresse mail valide.");
		}
		else
		{
			document.contact.submit();
		}
	}
}


function updateDeptList(obj)
{
	//alert(obj.value);
	if (obj.value!=0) {self.location="abattants-toilettes-revendeurs.php?dept="+obj.value;}
}


//****************************************************************************************************
//			CHECKS THE VALIDITY OF AN EMAIL ADDRESS
//****************************************************************************************************
function isMailValid(e) 
{
	ok = "1234567890qwertyuiop[]asdfghjklzxcvbnm.@-_QWERTYUIOPASDFGHJKLZXCVBNM";
	
	for(i=0; i < e.length ;i++)
	{
		if(ok.indexOf(e.charAt(i))<0)
		{ 
			return (false);
		}	
	} 
	
	if (document.images)
	{
		re = /(@.*@)|(\.\.)|(^\.)|(^@)|(@$)|(\.$)|(@\.)/;
		re_two = /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;
		if (!e.match(re) && e.match(re_two)) 
		{
			return (-1);
		}
	} 
}

//****************************************************************************************************
//			TRIMMING FUNCTIONS
//****************************************************************************************************
function Trim(TRIM_VALUE)
{
	if(TRIM_VALUE.length < 1)
	{
		return"";
	}
	TRIM_VALUE = RTrim(TRIM_VALUE);
	TRIM_VALUE = LTrim(TRIM_VALUE);
	if(TRIM_VALUE=="")
	{
		return "";
	}
	else
	{
		return TRIM_VALUE;
	}
}

function RTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	var v_length = VALUE.length;
	var strTemp = "";
	if(v_length < 0)
	{
		return"";
	}
	var iTemp = v_length -1;
	
	while(iTemp > -1)
	{
		if(VALUE.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = VALUE.substring(0,iTemp +1);
			break;
		}
		iTemp = iTemp-1;
	}
	return strTemp;
}

function LTrim(VALUE)
{
	var w_space = String.fromCharCode(32);
	if(v_length < 1)
	{
		return"";
	}
	var v_length = VALUE.length;
	var strTemp = "";
	
	var iTemp = 0;
	
	while(iTemp < v_length)
	{
		if(VALUE.charAt(iTemp) == w_space)
		{
		}
		else
		{
			strTemp = VALUE.substring(iTemp,v_length);
			break;
		}
		iTemp = iTemp + 1;
	}
	return strTemp;
}

