//validate all form actions
 function disableKeyPress(e){
     var key;
     if(window.event)
          key = window.event.keyCode;     //IE
     else
          key = e.which;     //firefox
 	 return false;
 }

 function trim(s){      	
	return s.replace(/^\s+|\s+$/g, ''); 
 } 
 
 
 function IsInteger(field) {
    var valid = "0123456789"
    var ok = "yes";
    var temp;
    for (var i=0; i<field.value.length; i++) {
        temp = "" + field.value.substring(i, i+1);
        if (valid.indexOf(temp) == "-1") ok = "no";
    }    
    return (ok != "no");
 }
 
 
 function IsValidEmail(emailStr) {
    var emailPat=/^(.+)@(.+)$/
    var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
    var validChars="\[^\\s" + specialChars + "\]"
    var quotedUser="(\"[^\"]*\")"
    var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
    var atom=validChars + '+'
    var word="(" + atom + "|" + quotedUser + ")"
    var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
    var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")

    var matchArray=emailStr.match(emailPat)
    if (matchArray==null) {
          return false;
    }

    var user=matchArray[1]
    var domain=matchArray[2]

    if (user.match(userPat)==null) {
      return false;
    }

    var IPArray=domain.match(ipDomainPat)
    if (IPArray!=null) {
          for (var i=1;i<=4;i++) {
            if (IPArray[i]>255) {
              return false;
            }
      }
      return true;
    }

    var domainArray=domain.match(domainPat);
    if (domainArray==null) {
      return false;
    }

    var atomPat=new RegExp(atom,"g");
    var domArr=domain.match(atomPat);
    var len=domArr.length;

    if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3) {
      return false;
    }

    if (len<2) {
      return false;
    }

    return true;
}
 
 
  function submitAnnuaire(){

 	    document.myForm.method="POST";
 		document.myForm.action=APP_ROOT+"annuaire-du-golf-list";
 		document.myForm.submit();

 }
 
 
 function submitNom(){
 	
 	if(document.getElementById("id_agence").value == ""){
 		return false;
 	}
 	else{
 		var id = document.getElementById("id_agence").value;
		new Ajax.Request(APP_ROOT+"mondeNomView&id="+id, {method:'get',
	         onSuccess: function(transport){
	               var response = transport.responseText;
	               document.getElementById('p36-pad-formL').innerHTML = response;                                     
	          },
	          onFailure: function(){
	               alert("System Error!");
	           }
	         }
		);
 	}
 	
 }
 
 function getNumDaysInMonth(){
 	
 	var i = 0;
 	var cur = document.getElementById("currMonth").value;
 	
 	if(document.getElementById("selectMonth").value == ""){
 		i =0;
 	}
 	else{
 		var month = document.getElementById("selectMonth").value;
 		
 		if(month =='jourjanvier'){
 			i = 1;
 		}
 		if(month =='jourfevrier'){
 			i = 2;
 		}
 		if(month =='jourmars'){
 			i = 3;
 		}
 		if(month =='jouravril'){
 			i = 4;
 		}
 		if(month =='jourmai'){
 			i = 5;
 		}
 		if(month =='jourjuin'){
 			i = 6;
 		}
 		if(month =='jourjuillet'){
 			i = 7;
 		}
 		if(month =='jouraout'){
 			i = 8;
 		}
 		if(month =='jourseptembre'){
 			i = 9;
 		}
 		if(month =='jouroctobre'){
 			i = 10;
 		}
 		if(month =='journovembre'){
 			i = 11;
 		}
 		if(month =='jourdecembre'){
 			i = 12;
 		}
 	}
 	new Ajax.Request(APP_ROOT+"competitionDayAjax&month="+i+"&cur="+cur, {method:'get',
	         onSuccess: function(transport){
	               var response = transport.responseText;
	               document.getElementById('middle_graybgForAjax').innerHTML = response;                                     
	          },
	          onFailure: function(){
	               alert("System Error!");
	           }
	         }
	);
 	
 }
 
  function submitFormAvis(){
	// for checking 
	var oErr=false;	 
	if(document.getElementById('avis').value == '')
		oErr = true;	
	for(i=0; i < 8; i++){
		if(document.getElementById('c_'+i).value == "-"){ 
			oErr = true;
			break;
		}
	}	 
	if(oErr){
		alert('D\351sol\351, tous les champs doivent \352tre renseign\351s.');
	}else{
		document.formAvis.method ="POST";
		document.formAvis.action = APP_ROOT+ "avis-deposer-" + document.getElementById('urlize_name').value + "-" + document.getElementById('id').value;
		document.formAvis.submit();	 
	}
 }
 
 function submitGolfSearch(){
	thisValue = document.getElementById("g_nom").value; 
 	if(thisValue == ""){
 		return false;
 	}else{
 		document.myForm.method = "POST";
 		document.myForm.action = APP_ROOT+"parcours-golf&g_nom=" + encodeURI(thisValue);
 		document.myForm.submit();
 	}
 }
 
 
  function submitCompetitionSearch(){
	thisValue  = document.getElementById("g_nom").value; 
	thisValue2 = document.getElementById("selectMonth").value; 
	thisValue3 = document.getElementById("selectDay").value; 
 	if(thisValue == ""){
 		return false;
 	}
 	else{
 		document.myForm.method="POST";
 		document.myForm.action = APP_ROOT+"golf-competition-liste&g_nom="+encodeURI(thisValue)+"&selectMonth="+encodeURI(thisValue2)+"&selectDay="+encodeURI(thisValue3);
 		document.myForm.submit();
 	}
 }
 
 
  function submitBoutiqueSearch(){
	var thisValue = document.getElementById("b_nom").value;
 	if(thisValue == ""){
 		return false;
 	}
 	else{
 		document.myForm.method="POST";
 		document.myForm.action = APP_ROOT+"boutique-golf-liste&b_nom=" + encodeURI(thisValue);
 		document.myForm.submit();
 	}
 }
 
 
 function submitCompetitionSelect(){
 	
 	if(document.getElementById("selectMonth").value != "none" && document.getElementById("selectDay").value != "none" ){
 		
 		document.myForm2.method="POST";
 		document.myForm2.action = APP_ROOT+"golf-competition";
 		document.myForm2.submit();
 		
 	}
 	
 	return false;
 }
 
 
 function submitFormLogin(){
	var thisObj = null;
	thisObj = document.getElementById("l_pseudo");
	if(trim(thisObj.value) == ""){
		/*alert("Nom d'utilisateur est incorrect! S'il vous pla\356t essayer \340 nouveau.");*/
		thisObj.focus();
		thisObj.select();
		return false;
	}		
	document.formLogin.method ="POST";
	document.formLogin.action = APP_ROOT+"submitLogin";
	document.formLogin.submit();	
 }
 
  function submitFormVideoLogin(){	  
	var thisObj = null;
	thisObj = document.getElementById("l_pseudo");
	if(trim(thisObj.value) == ""){		
		thisObj.focus();
		thisObj.select();
		return false;
	}		
	return true;
 }
 
function onSubmitKewegoRegistration(){
	var thisObj     = null;
	var thisObjCmpr = null;
	
	thisObj = document.getElementById("r_email");
	if(trim(thisObj.value) == "" || !IsValidEmail(thisObj.value)){
		alert("S'il vous pla\356t entrer e-mail valide!");
		thisObj.focus();
		thisObj.select();
		return false;
	}	
	
	thisObj = document.getElementById("r_pword");
	if(trim(thisObj.value) == ""){
		alert("S'il vous pla\356t entrer mot de passe valide!");
		thisObj.focus();
		thisObj.select();
		return false;
	}
	
	thisObj     = document.getElementById("r_pword");
	thisObjCmpr = document.getElementById("r_c_pword");
	if(thisObj.value != thisObjCmpr.value){ 
		alert("Les mot de passe ne correspondent pas!");
		thisObjCmpr.focus();
		thisObjCmpr.select();
		return false;
	}
	
	thisObj = document.getElementById("r_uname");
	if(trim(thisObj.value) == ""){
		alert("S'il vous pla\356t entrer le nom d'utilisateur valide!");
		thisObj.focus();
		thisObj.select();
		return false;
	}		
	
	thisObj = document.getElementById("r_country");
	if(trim(thisObj.value) == ""){
		alert("S'il vous pla\356t entrer le pays valide!");
		thisObj.focus();		
		return false;
	}	
	
	thisObj = document.getElementById("r_postal_code");
	if(trim(thisObj.value) == ""){
		alert("S'il vous pla\356t entrer le postal code valide!");
		thisObj.focus();		
		return false;
	}		
	
	thisObj     = document.getElementById("r_gender_m");
	thisObjCmpr = document.getElementById("r_gender_f");	
	if(!thisObj.checked && !thisObjCmpr.checked){
		alert("S'il vous pla\356t entrer le gender valide!");
		thisObj.focus();		
		return false;
	}
	
	thisObj = document.getElementById("r_birthday_year");
	if(trim(thisObj.value) == ""){
		alert("S'il vous pla\356t entrer le birth year valide!");
		thisObj.focus();		
		return false;
	}
	
	return true;
	 
}
  function submitFormRegistration(){
	var thisObj = null;
	var thisObjCmpr = null;
	thisObj = document.getElementById("r_nom");
	if(trim(thisObj.value) == ""){
		alert("S'il vous pla\356t entrer le nom valide!");
		thisObj.focus();
		thisObj.select();
		return false;
	}		
	thisObj = document.getElementById("r_prenom");
	if(trim(thisObj.value) == ""){
		alert("S'il vous pla\356t entrer le nom d'utilisateur valide!");
		thisObj.focus();
		thisObj.select();
		return false;
	}		
	thisObj = document.getElementById("r_index");
	if(trim(thisObj.value) == ""){
		alert("S'il vous pla\356t entrer indice valable!");
		thisObj.focus();		
		return false;
	}		
	thisObj = document.getElementById("r_pseudo");
	if(trim(thisObj.value) == ""){
		alert("S'il vous pla\356t entrer pseudo valide!");
		thisObj.focus();
		thisObj.select();
		return false;
	}	
	thisObj = document.getElementById("r_email");
	if(trim(thisObj.value) == "" || !IsValidEmail(thisObj.value)){
		alert("S'il vous pla\356t entrer e-mail valide!");
		thisObj.focus();
		thisObj.select();
		return false;
	}	
	thisObj = document.getElementById("r_email");
	thisObjCmpr = document.getElementById("r_c_email");
	if(thisObj.value != thisObjCmpr.value){ 
		alert("Les e-mails ne correspondent pas!");
		thisObjCmpr.focus();
		thisObjCmpr.select();
		return false;
	}	
	if(((trim(document.getElementById("r_c_mot_de_passe").value)!="" || 
		 trim(document.getElementById("r_mot_de_passe").value)!= "" )  && document.getElementById("editMode").value==1) 
	  || document.getElementById("editMode").value==0){
		thisObj = document.getElementById("r_mot_de_passe");
		if(trim(thisObj.value) == ""){
			alert("S'il vous pla\356t entrer le mot de passe valide!");
			thisObj.focus();
			thisObj.select();
			return false;
		}	
		thisObj = document.getElementById("r_mot_de_passe");
		thisObjCmpr = document.getElementById("r_c_mot_de_passe");
		if(thisObj.value != thisObjCmpr.value){
			alert("Les mots de passe ne correspondent pas!");
			thisObjCmpr.focus();
			thisObjCmpr.select();
			return false;
		}
  }
	document.formRegistration.method ="POST";
	document.formRegistration.action = APP_ROOT+"login";
	document.formRegistration.submit();
 }
 
 
 function submitForgotPassword(){
    var thisObj = null;
	thisObj = document.getElementById("pseudo");
	if(trim(thisObj.value) == ""){
		alert("Nom d'utilisateur est incorrect! S'il vous pla\356t essayer \340 nouveau.");
		thisObj.focus();
		thisObj.select();
		return false;
	}			
	document.formForgotPassword.method ="POST";
	document.formForgotPassword.action = APP_ROOT+"forgotPassword";
	document.formForgotPassword.submit();	 
 }

 
 /*for ajaxdrop down*/
 /*start here*/
 function makeRequest(me, oForm) {
	if(oForm == 'dept'){
		oParam = me.value+"&form="+oForm;
		document.getElementById('divDept').innerHTML = "Chargement ...";
	}else{
		oParam = me.value;
	   document.getElementById('divGolf').innerHTML = "Chargement ..."; 
	}
   if (window.XMLHttpRequest) { // Mozilla, Safari,...
	   http_request = new XMLHttpRequest();
   } else if (window.ActiveXObject) { // IE
	   http_request = new ActiveXObject("Microsoft.XMLHTTP");
   }
   //alert(oParam);
   http_request.open('GET', APP_ROOT+'ajaxDropDown&id=' + oParam, true);
   http_request.onreadystatechange = function(){
		if (http_request.readyState == 4) {
		   if (http_request.status == 200) {
			   if(oForm == 'dept')
			   	getInfosTheme(http_request);
				//alert(http_request.responseText);
			   else
			   	getInfos(http_request);
			   //alert(http_request.responseText);
		   } else {
			   alert('There was a problem with the request.');
		   }
	   }   
   }
   http_request.send(null);
}

function getInfos(req)
{	
	if(req.responseText.length > 12){
		var data = eval('(' + req.responseText + ')');	
		var gCount = data.golfs.length;
		var oElements = "";
		
		var oElements = '<select name="ddGolf" class="p34-drop-iprop" id="selectGolf">	<option value="" selected>Choisir</option>';
		
		for (var i=0;i<gCount;i++)
		{
			oElements += '<option value="'+data.golfs[i].golf.id+'">'+data.golfs[i].golf.name+'</option>';
		}
		oElements += '</select>';
		
		document.getElementById('divGolf').innerHTML = oElements;
		document.getElementById('ddLigue').disabled = "";
		
	/*	for (var i=0;i<gCount;i++){
			var x = document.createElement('option');
			x.value = data.golfs[i].golf.id;
			x.appendChild(document.createTextNode(data.golfs[i].golf.name));
			document.getElementById('selectGolf').appendChild(x);
		}*/
	}
}

function getInfosTheme(req)
{	
	if(req.responseText.length > 12){
		var data = eval('(' + req.responseText + ')');	
		var gCount = data.themes.length;
		var oElements = "";
		
		oElements =  ' <strong>D&eacute;partement</strong>&nbsp;';
		oElements += '<select name="dept">';
		oElements += '<option selected>Choisir</option>'; 
		for (var i=0;i<gCount;i++)
		{
			var oNumber = data.themes[i].theme.dept;
			oElements += '<option value="'+oNumber+'">'+oNumber+' - '+data.themes[i].theme.deptname+'</option>';
		}
		oElements += '</select>';
		document.getElementById('divDept').innerHTML = oElements;
	}else{
		oElements =  ' <strong>D&eacute;partement</strong>&nbsp;';
		oElements += '<select name="dept" disabled="true">';			
        oElements += '<option value=""></option>';
        oElements += '</select>';
		document.getElementById('divDept').innerHTML = oElements;	
	}
}
 /*end here*/

/*for menu*/
function showSubmenu(iInt){
	var oSubmenu = document.getElementById('submenu');
	if(iInt == 0)
		oSubmenu.style.display = 'block';
	else
		oSubmenu.style.display = 'none';
}

function swapImage(me, oSrc){
	me.src = oSrc;	
}
/*end menu*/

function submitSearchForm(url, inputs){		
	var newUrl = '';
	var retval = '';
	var len	= inputs.length;	
	for(i=0; i < len; i++){
		if(trim(inputs[i].value) != '' && inputs[i].value != 0 && inputs[i].value != null){
			if(retval != '') retval += '&';
			retval += inputs[i].name + '=' + inputs[i].value;	
		}		
	}	
	if(retval != '')
		retval = '&' + retval;	
	location.href = APP_ROOT+url + retval;		
	return false;
}

/*for rankings*/
function changeImage(iIndex, oType, oLimit){
	if(oType == 'black'){
		var imgFull = 'imgFull';
		var imgBlank = 'imgBlank';
		var imgHalf = 'imgHalf';
	}else{
		var imgFull = 'imgGFull';
		var imgBlank = 'imgGBlank';
		var imgHalf = 'imgGHalf';
	}
	for(i = 0; i < oLimit; i++){
		if(i <= iIndex)
			document.getElementById('star'+i).className = imgFull;
		else
			document.getElementById('star'+i).className = imgBlank;
	}
}

function retrieveStars(oVal, oType, oLimit){
	if(oType == 'black'){
		var imgFull = 'imgFull';
		var imgBlank = 'imgBlank';
		var imgHalf = 'imgHalf';
	}else{
		var imgFull = 'imgGFull';
		var imgBlank = 'imgGBlank';
		var imgHalf = 'imgGHalf';
	}

	rank = Math.round(oVal);
	intVal 	= Math.floor(oVal);
	if(rank >= oVal)
		decVal 	= rank - oVal;
	else
		decVal 	= oVal - rank;
	var ctr = 0;

	for(i = 0; i < intVal; i++){ // filled stars					
		document.getElementById('star' + ctr).className = imgFull;
		ctr++;
	}

	if(decVal > 0){ // half stars								
		document.getElementById('star' + ctr).className = imgHalf;				
		ctr++;
	}
	oLimit = oLimit - ctr;	
	for(i = 0; i < oLimit; i++){ // blank stars($ctr + $i + 1)
		document.getElementById('star' + ctr).className = imgBlank;				
		ctr++;					
	}		
}
/*end*/
