//VALIDATION FUNCTIONS
function myvalid()
{
    var text="";
    for(var i=0;i<tab.length;i++)
    {

        var element=document.form.elements[tab[i][0]];
		var result=eval(tab[i][2])(element);
        if(result!="")
        {
            if(tab[i][3])
            var mess=tab[i][3];
            else mess=result;
            text=text+"The field \""+tab[i][1]+"\" "+mess+"\n"; 
        }
    }

    if(text == "")
    {
		return true;		
    }else
    {
        alert(text);
		return false;
    } 
}


function validSubmit()
{
    if(myvalid())
    {
        document.form.submit();
    }
}


function stringValid(obj)
{
    if(obj.value.length == 0 || obj.value=="")
    {
        return "is mandatory";
    }
    else
    {
        
        return "";
    }
}

function stringValid2(obj)
{
    /*********************************** contrôle si la chaine est vide et si elle contient un pointvirgule *********************************************/
     
    if(obj.value.length == 0 || obj.value == "" )
    {
        return "is mandatory";
    }
    else
    {
        if( obj.value.indexOf(";") >= 0 )
	    return ("contains ';' ");
        else
	    return "";
    }
  /******************************************************************************************************************************************************/
}




function phoneValid(obj)
{
    if(obj.value.length < 10 || obj.value=="")
    {
        return "must contain at least 10 numbers";
    }
    else
    {
        return "";
    }
}

function loginValid(obj)
{
    if(obj.value.length < 6 || obj.value=="")
    {
        return "must contain at least 6 caracters";
    }
    else
    {
        return "";
    }
}

function emailValid(obj)
{
  var result = "is not a valid email and must contain one '@' and one '.' like 'name@domain.com'";
  var theStr = new String(obj.value)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+2) && (theStr.length > pindex+2))
	result = "";
  }
  return result;
}

function selectValid(obj)
{
    if(obj.options[obj.selectedIndex].value != 0)
    {
		return "";
    }
    else
    {
        return "must be selected";        
    }
}

function stateValid(obj)
{
	var country=document.form.country_id.options[document.form.country_id.selectedIndex].value;
    if(obj.options[obj.selectedIndex].value != 0 && country != 232 && country != 40)
    {
		return "cannot be selected for '"+document.form.country_id.options[document.form.country_id.selectedIndex].text+"'";
    }
    else if(obj.options[obj.selectedIndex].value == 0 && (country == 232 || country == 40))
    {
		return "must be selected for Canada and United States";
    }
    {
        return "";        
    }
}

function stateOldValid(obj)
{
	var country=document.form.country.options[document.form.country.selectedIndex].value;
    if(obj.options[obj.selectedIndex].value != 0 && country != 232 && country != 40)
    {
		return "cannot be selected for '"+document.form.country.options[document.form.country.selectedIndex].text+"'";
    }
    else if(obj.options[obj.selectedIndex].value == 0 && (country == 232 || country == 40))
    {
		return "must be selected for Canada and United States";
    }
    {
        return "";        
    }
}

function Chercheptvi (obj) {

    if( obj.value.indexOf(";") >= 0 )
        return ("contains ';' ");
    else
        return "";
}



function stateSelection()
{
}
