function popupon(layername,URL)
	{
	popupimg.name = URL;
	popupimg.src='http://media.pontivy.fr/3/' + URL +'.jpg';
	valtop=document.body.scrollTop;
	valheight=Math.abs(document.body.clientWidth/2-760/2+35);
	if(valtop<166){valtop=166;}
	document.getElementById(layername).style.visibility = "visible";
	document.getElementById(layername).style.top=valtop+14;	
	document.getElementById(layername).style.left=valheight;
	document.getElementById(layername).focus();
	}

function popupoff(layername)
	{
	layername.style.height=0;
	layername.style.width=0;
	layername.style.visibility = "hidden";
	}

function LTrim(str) 
		{
            var whitespace = new String(" "); 
            var s = new String(str); 
            if (whitespace.indexOf(s.charAt(0)) != -1) 
			{
            	var j=0, i = s.length; 
				while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
	        		j++; 
             		s = s.substring(j, i);
         	}
			return s;
 		};


function RTrim(str) 
	{
           var whitespace = new String(" ");   
           var s = new String(str); 
           if (whitespace.indexOf(s.charAt(s.length-1)) != -1)
		{
        	var i = s.length - 1;
           	while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
           		i--; 
           	s = s.substring(0, i+1);
            }
            return s;
	};
function Trim(str) 
	{
	return RTrim(LTrim(str));      
	};

function docsearch()

	{
	if(document.forms['frmsearch'].valsearch.value.length>2)

		{
		document.forms['dosearch'].rb.value='search-' + document.forms['frmsearch'].valsearch.value;
		document.forms['dosearch'].submit();
		return false;

		}

	else

		{

		return false;	

		}
	}

function _TestIsDate1(obj)
   {
	var object_value=obj.value;
    //Returns true if value is a eurodate format or is NULL
    //otherwise returns false	

    if (object_value.length == 0)
        return true;

	isplit = object_value.indexOf('-');

	if (isplit == -1 || isplit == object_value.length)
		return false;

	sYear = object_value.substring(0, isplit);
	monthSplit = isplit + 1;

	isplit = object_value.indexOf('-', monthSplit);

		if (isplit == -1 ||  (isplit + 1 )  == object_value.length)
		return false;

	    sMonth = object_value.substring((sYear.length + 1), isplit);
	   	
	isplit = object_value.indexOf(' ');
	sDay = object_value.substring(8,isplit+1);

	if (!checkinteger(sMonth)) //check month
		return false;
	else
	if (!checkrange(sMonth, 1, 12)) // check month
	return false;
	else
	if (!checkinteger(sYear)) //check year
		return false;
	else
	if (!checkrange(sYear, 0, null)) //check year
		return false;
	else
	if (!checkinteger(sDay)) //check day
		return false;
	else
	if (!checkday(sYear, sMonth, sDay)) //check day
		return false;
	else
		return true;
    }
	
function checkday(checkYear, checkMonth, checkDay)
    {

	maxDay = 31;

	if (checkMonth == 4 || checkMonth == 6 ||
			checkMonth == 9 || checkMonth == 11)
		maxDay = 30;
	else
	if (checkMonth == 2)
	{
		if (checkYear % 4 > 0)
			maxDay =28;
		else
		if (checkYear % 100 == 0 && checkYear % 400 > 0)
			maxDay = 28;
		else
			maxDay = 29;
	}

	return checkrange(checkDay, 1, maxDay); //check day
    }

function checkinteger(object_value)
    {
    //Returns true if value is a number or is NULL
    //otherwise returns false	

    if (object_value.length == 0)
        return true;

    //Returns true if value is an integer defined as
    //   having an optional leading + or -.
    //   otherwise containing only the characters 0-9.
	var decimal_format = ".";
	var check_char;

    //The first character can be + -  blank or a digit.
	check_char = object_value.indexOf(decimal_format)
    //Was it a decimal?
   if (check_char < 1)
	return checknumber(object_value);
    else
	return false;
    }

function numberrange(object_value, min_value, max_value)
    {
    // check minimum
    if (min_value != null)
	{
        if (object_value < min_value)
		return false;
}

    // check maximum
    if (max_value != null)
	{
	if (object_value > max_value)
		return false;
	}
	
    //All tests passed, so...
    return true;
    }

function checknumber(object_value)
    {
    //Returns true if value is a number or is NULL
    //otherwise returns false	

    if (object_value.length == 0)
        return true;

    //Returns true if value is a number defined as
    //   having an optional leading + or -.
    //   having at most 1 decimal point.
    //   otherwise containing only the characters 0-9.
	var start_format = " .+-0123456789";
	var number_format = " .0123456789";
	var check_char;
	var decimal = false;
	var trailing_blank = false;
	var digits = false;

    //The first character can be + - .  blank or a digit.
	check_char = start_format.indexOf(object_value.charAt(0))
    //Was it a decimal?
	if (check_char == 1)
	    decimal = true;
	else if (check_char < 1)
		return false;
        
	//Remaining characters can be only . or a digit, but only one decimal.
	for (var i = 1; i < object_value.length; i++)
	{
		check_char = number_format.indexOf(object_value.charAt(i))
		if (check_char < 0)
			return false;
		else if (check_char == 1)
		{
			if (decimal)		// Second decimal.
				return false;
			else
				decimal = true;
		}
		else if (check_char == 0)
		{
			if (decimal || digits)	
				trailing_blank = true;
        // ignore leading blanks

		}
	        else if (trailing_blank)
			return false;
		else
			digits = true;
	}	
    //All tests passed, so...
    return true
   }
	
function checkrange(object_value, min_value, max_value)
    {
    //if value is in range then return true else return false

    if (object_value.length == 0)
        return true;


    if (!checknumber(object_value))
	{
	return false;
	}
    else
	{
	return (numberrange((eval(object_value)), min_value, max_value));
	}
	
    //All tests passed, so...
    return true;
    }

function check_email(object_value)
{
	var s = object_value;
	var ok = 1;
	if ((s.length < 7)){
		ok = 0;
	}
	var at = s.indexOf('@');
	if (at < 1){
		ok = 0;
	}
	if (at != s.lastIndexOf('@')){
		ok = 0;
	}
	if ((s.lastIndexOf('.') < (at+2)) || (s.lastIndexOf('.') > (s.length-3)) || (s.lastIndexOf('.') < (s.length-6))){
		ok = 0;
	}
	if ((s.indexOf(',') != -1) || 	
		(s.indexOf(' ') != -1) || 
		(s.indexOf(';') != -1) ||
		(s.indexOf('\\') != -1) ||
		(s.indexOf(':') != -1) ||
		(s.indexOf('?') != -1) || 
		(s.indexOf('	') != -1) || 
		(s.indexOf('"') != -1) || 
		(s.indexOf("'") != -1) || 
		(s.indexOf('[') != -1) || 
		(s.indexOf(']') != -1) ||
		(s.indexOf('`') != -1) ||
		(s.indexOf('!') != -1) ||
		(s.indexOf('#') != -1) ||
		(s.indexOf('$') != -1) ||
		(s.indexOf('%') != -1) ||
		(s.indexOf('^') != -1) ||
		(s.indexOf('&') != -1) ||
		(s.indexOf('*') != -1) ||
		(s.indexOf('(') != -1) ||
		(s.indexOf(')') != -1) ||
		(s.indexOf('=') != -1) ||
		(s.indexOf('+') != -1) ||
		(s.indexOf('}') != -1) ||
		(s.indexOf('{') != -1) ||
		(s.indexOf('|') != -1) ||
		(s.indexOf('<') != -1) ||
		(s.indexOf('>') != -1)  )
	
		{
		ok = 0;
	}
	
	if (ok == 1){
	return true;}
	else
	{
	return false;}
}
	
