var prima=0;// some  general  variable
var tipo=0;//general  variable
var dateExists=true;
var curForm="";



//validate  an input  field
function isVuoto(obj){
 fill=''
 
   // se l'oggetto  esiste
	if(document.forms[curForm].elements[obj]){
	   // se è vuto
	   if(document.forms[curForm].elements[obj].value!='')fill=document.forms[curForm].elements[obj].value
	}
	else fill=true
   return fill

}

//validatea  combo Box   field
function checkCombo(obj){
      valore=""; 
	  if(document.forms[curForm].elements[obj].selectedIndex!=-1){
       index=document.forms[curForm].elements[obj].selectedIndex
	   valore=document.forms[curForm].elements[obj].options[index].value
	  }
  
	  return valore

}
//   validate a radio button  fileds
function checkRadio(obj){
  radio_choice = false;
  butVal=''
  for (counter = 0; counter < document.forms[curForm].elements[obj].length; counter++){
        if (document.forms[curForm].elements[obj][counter].checked){
		     radio_choice = true; 
			 butVal=counter
	    }
  }
  return radio_choice;butVal;
} 

function ceckDate(obj){
dateExists=true
 var monthLength = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
 curData=document.forms[curForm].elements[obj].value
 arrData=curData.split('-');
 day=arrData[0];
 month=arrData[1];
 year=arrData[2]
 maxYear=2100;
 minYear=1900;
    if(arrData.length!=3)
	    dateExists = false;
    if (year/4 == parseInt(year/4))
		monthLength[1] = 29;
	if (day > monthLength[month-1])
		dateExists = false;
	if (month >12 || month<1)
		dateExists = false;
	if (year >maxYear || year<minYear)
	   dateExists = false;
	return dateExists;


}

 
function ckDate(value,obj){
  if(!veriDate(value,obj)){
      alert('Wrong data or Data format\nData must be  dd-mm-yyyy')
  }
}






function veriDate(valore,obj){
  dateExists=true
  var monthLength = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
  var re = new RegExp ('/', 'gi') ;
  curData = valore.replace(re, '-') ;
  if(obj)obj.value=curData;
  arrData=curData.split('-');
  day=arrData[0];
  month=arrData[1];
  year=arrData[2]
  maxYear=2100;
  minYear=1900;
  if(arrData.length!=3)
     dateExists = false;
  if (year/4 == parseInt(year/4))
     monthLength[1] = 29;
  if (day > monthLength[month-1])
	 dateExists = false;
  if (month >12 || month<1)
	 dateExists = false;
  if (year >maxYear || year<minYear)
	dateExists = false;
	return dateExists;
}

//verifico  se il valore dell'oggetto e un numero
function isNumber(obj){
  fill=''
   if(document.forms[curForm].elements[obj]){
     fill=document.forms[curForm].elements[obj].value;
	 if(isNaN(fill)&& fill!=''){fill=''}
	 else fill=true
   }
  else fill=true
  return fill
}

//  cechk  e-mail

function checkEmail(obj) {
  fill=''
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(curform.elements[obj].value)){
    return fill=true
  }
  return fill
}

// 
function  validatePhoneNumber(obj){

  fill=true
  var stripped = curform.elements[obj].value.replace(/[\(\)\.\-\ ]/g, '');
  //strip out acceptable non-numeric characters
  if (isNaN(stripped) || stripped=='') {
	   
	   return fill=''
  } 
  return fill
}




function getValue(obj){
  return document.forms[curForm].elements[obj].value;
}

function setDefault(obj) {
    document.forms[curForm].elements[obj].selectedIndex=0
}

function setIndex(obj,Indice) {
   document.forms[curForm].elements[obj].selectedIndex=Indice
}

function getIndex(obj) {
   document.forms[curForm].elements[obj].selectedIndex
}




//clear  the   old  option  in  the  select  list
function removeOption(obj) {

    while (obj.length > 0) {
        obj.remove(0);
    }
	
}
// add option to a list
function insertOption(obj,a,b) {
  var y=document.createElement('option');
  y.text=b
  y.value=a
  try  {
      obj.add(y,null); // standards compliant
  }
  catch(ex) {
    obj.add(y); // IE only
  }
}

function populateComboBox(dataList){
   for(i=0;i<dataList.length;i++){
      insertOption(objCombo,dataList[i].a,dataList[i].b)
   }
}
 

function validazioneCampiForm(formObj,tipo){
	clearContainer('messaggi');
    hideContainer('messaggi')
    formObject = document.getElementById(formObj);
	curForm=formObj;   
	conObj.setForm(formObject); 
	postData="remote=1&tipo="+tipo;
	sUrl = serverPath+"includes/functions/ma_ajax_smile_helper.inc.php";
	updateContainer('messaggi')
    mode='formValidation';	
	return false;
}


function showContainer(obj){
  DomObj.setStyle(obj, 'display', 'block'); 
}

function hideContainer(obj){
  DomObj.setStyle(obj, 'display', 'none'); 
}
