function deleteconfirm(msg, urladress) {
	if (window.confirm(msg)) {
		location.href=urladress;
	}
}

function textCounter(field, countfield, maxlimit) {
if (field.value.length > maxlimit) // if too long...trim it!
field.value = field.value.substring(0, maxlimit);
// otherwise, update 'characters left' counter
else 
countfield.value = maxlimit - field.value.length;
}

function getId(element_id){
	element_id = element_id.split("-");
	element_id = element_id[element_id.length-1];
	if (!element_id) { element_id = 0; }
	
	return element_id;	
}

function liste_province(form_id, champ_pays_nom, champ_province_nom, selected){
		
	var id_pays = $("#"+form_id+" select[name='"+champ_pays_nom+"']").val();
	 
	var json_url = "proprietes_script.php?task=liste_province&id_pays=" + encodeURIComponent(id_pays);
	$.getJSON(json_url,function(data){
		$("#"+form_id+" select[name='"+champ_province_nom+"']").empty(); //clear states selections
		
		if(data==""){
			$("#"+form_id+" select[name='"+champ_province_nom+"']").append("<option value=\"0\">-- Aucune province --</option>");
		}
		else{
			for(i=0; i<data.code.length; i++){
				if(selected != '' && data.code[i] == selected){
					$("#"+form_id+" select[name='"+champ_province_nom+"']").append("<option value=\"" + data.code[i]  + "\" selected=\"selected\">" + data.nom[i]  + "</option>");
				}else{
					$("#"+form_id+" select[name='"+champ_province_nom+"']").append("<option value=\"" + data.code[i]  + "\">" + data.nom[i]  + "</option>");	
				}
				
			}
		}
		
	   
	});
   return false;
}


function clear_form(form, id_aussi){
	$(':input','#' + form) 
   .not(':button, :submit, :reset, :hidden, :radio, :checkbox') 
   .val('');
   $(':input','#' + form) 
   .removeAttr('checked') 
   .removeAttr('selected');
   if(id_aussi == 1){
	   $("#"+form+" input[name='id']").val('');
   }
   if ($("#"+form+" select[name='id_pays']").length != 0) {
	   $("#"+form+" select[name='id_pays']").val('1');
   }
   if ($('#id_province').length != 0) {
		liste_province(form, 'id_pays', 'id_province', 10);
   }
}
function get_sector_url(langue){
	if(langue=='e'){
		document.location.href = '/property-for-sale-municipalities-' + $('#lesecteur option:selected').text() + '/' + $('#lesecteur option:selected').val() + '.html';	
	}else{
		document.location.href = '/maison-a-vendre-municipalite-' + $('#lesecteur option:selected').text() + '/' + $('#lesecteur option:selected').val() + '.html';	
	}
	
}

function roundNumber(rnum, rlength) { // Arguments: number to round, number of decimal places
  var newnumber = Math.round(rnum*Math.pow(10,rlength))/Math.pow(10,rlength);
  return newnumber; // Output the result
}
function IsNumeric(sText)
{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }



