/* 	Fonctions JavaScript pour le site - Pronostic-ICI-Turf
	******************************************************
	Version: 1.00 du 10/08/2008
	Copyright: www.pronostic-ici-turf.fr
	Maintained by:	S.C. CVRS Consulting SRL
					Timisoara - Romania
					Phone:  +40 356-104.318
					Mobile: +40 720-653.789
*/

// ******************************************
// *** Déclaration des variables globales ***
// ******************************************
var CVOMVar_TimeNow			= Math.round(Math.random()*1000000000);
var CVOMVar_MessageWait		= "<center><br><br><div class=\"BoxWait\"><img src=\"lib/images/loading1.gif\" width=\"50\" height=\"50\"><br>Chargement, veuillez patienter ...</div><br><br></center>";

// ***********************************
// *** Scroller la fenêtre en haut ***
// ***********************************
function CVOM_ScrollToTop(){
	document.body.scrollTop = 0;
}

// ****************************
// *** Trim sur theStringCT ***
// ****************************
function CVOM_TrimString(theStringCVOM){
	txtStringCVOM = new String(theStringCVOM);
	while (txtStringCVOM.substring(0,1) == ' '){
		txtStringCVOM = txtStringCVOM.substring(1, txtStringCVOM.length);
	}
	while (txtStringCVOM.substring(txtStringCVOM.length-1, txtStringCVOM.length) == ' '){
		txtStringCVOM = txtStringCVOM.substring(0,txtStringCVOM.length-1);
	}
	return txtStringCVOM;
}

// *******************************
// *** Fonctions Ouverture POP ***
// *******************************
function CVOM_OpenPop(filepopname,namepopwin){
	window.open(filepopname,namepopwin,"menubar=yes,toolbar=no,scrollbars=yes,status=yes,width=500,height=400,top=0,left=0");
}
function CVOM_OpenPopXY(filepopname,namepopwin,popxsize,popysize){
	window.open(filepopname,namepopwin,"menubar=no,toolbar=no,scrollbars=no,status=yes,width="+popxsize+",height="+popysize+",top=0,left=0");
}
function CVOM_OpenPopCenter(filepopname,namepopwin,popxsize,popysize){
	var popwinleftpos = Math.round((screen.width-popxsize)/2);
	var popwintoppos  = Math.round((screen.height-popysize)/2);
	window.open(filepopname,namepopwin,"menubar=no,toolbar=no,scrollbars=yes,status=yes,width="+popxsize+",height="+popysize+",top="+popwintoppos+",left="+popwinleftpos+"");
}

// *****************************************
// *** Aller sur une page id_doc+options ***
// *****************************************
function CVOM_GoWebDirect(call_doc){
	document.location = call_doc;
}

// ***************************
// *** Retour History.Back ***
// ***************************
function CVOM_GoBack(){
	history.back();
}

// ********************************************
// *** Gestion du changement du contenu dans***
// *** une boîte pointé par TLib_BoxName	***
// ********************************************
function doLoadContentBox(TLibVar_BoxName,TLibVar_ScriptName,TLibVar_ScriptOptions){
	// *** Développer la TBox si elle n'est pas dévéloppée ***
	if (document.getElementById(TLibVar_BoxName).style.display == "none")
	    document.getElementById(TLibVar_BoxName).style.display = "block";
	// *** Insérer le message d'attente ***
    document.getElementById(TLibVar_BoxName).innerHTML = CVOMVar_MessageWait;
	// *** Appel ajax - màj contenu ***
	CVRSAjaxQueryURL('POST',TLibVar_ScriptName,TLibVar_ScriptOptions,TLibVar_BoxName);
}

// ***************************************
// *** Afficher d'autres résultats PMU ***
// ***************************************
function CVRS_ChangeResDisplay(theForm){
	CVOM_GoWebDirect('arrive-rapports-quinte-pmu-'+theForm.value+'.htm');
	return true;
}

// ****************************************
// *** Filtrer les numéros de téléphone ***
// ****************************************
function doCheckWriteTelFormatSimple(theStringCVOM){
	var re = /\d{10}/;
	var TLibVar_TrueTelFormat = re.exec(theStringCVOM);
	if (!TLibVar_TrueTelFormat || theStringCVOM.length>10)
		return false;
	else
		return true;
}

// ***********************************
// *** Filtrer les adresses e-mail ***
// ***********************************
function doCheckValidMail(theStringCVOM){
	var TLibVarFilter=/^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
	if (TLibVarFilter.test(theStringCVOM))
		return true;
	else
		return false;
}

// *****************************************************
// *** Accepter uniquement les caractères Numériques ***
// *****************************************************
function FilterValueToNum(theStringCVOM){
	return theStringCVOM.replace(/[^0-9]/g,"");
}

// ***************************************************
// *** Accepter uniquement les champs de type Prix ***
// ***************************************************
function FilterValueToPrice(theStringCVOM){
	theStringCVOM = theStringCVOM.replace(/[^0-9.]/g,"");
	if (isNaN(parseFloat(theStringCVOM))){
	    theStringCVOM = "0";
	}
	return theStringCVOM;
}
function FilterValueToPriceZeroIfEmpty(theStringCVOM){
	theStringCVOM = theStringCVOM.replace(/[^0-9.]/g,"");
	if (isNaN(parseFloat(theStringCVOM))){
	    theStringCVOM = "0";
	}
	return theStringCVOM;
}
function FilterValueToPriceZeroIfEmptyPN(theStringCVOM){
	theStringCVOM = theStringCVOM.replace(/[^0-9.\-]/g,"");
	if (isNaN(parseFloat(theStringCVOM))){
	    theStringCVOM = "0";
	}
	return theStringCVOM;
}

// ****************************************************
// *** Accepter uniquement les champs de type Float ***
// *** Exemple: -100 +100 etc.                      ***
// ****************************************************
function FilterValueToPricePN(theStringCVOM){
	return theStringCVOM.replace(/[^0-9.\-]/g,"");
}

// ***********************************************
// *** Accepter uniquement les caracères Alpha ***
// ***********************************************
function FilterValueToAlpha(theStringCVOM){
	return theStringCVOM.replace(/[^a-zéàçèôê' ]/gi,"");
}

// ******************************************
// *** Transformer la touche Enter en Tab ***
// ******************************************
function autoTab(input,len, e) {
	var isNN = (navigator.appName.indexOf("Netscape")!=-1);
	var keyCode = (isNN) ? e.which : e.keyCode;
	var filter = (isNN) ? [0,8,9,13] : [0,8,9,13,16,17,18,37,38,39,40,46];

	if((input.value.length >= len && !containsElement(filter,keyCode)) ||
		(keyCode == 13 && input.value.length > 0)) {
		input.value = input.value.slice(0, len);
		input.form[(getIndex(input)+1) % input.form.length].focus();
	}

	function containsElement(arr, ele) {
		var found = false, index = 0;
		while(!found && index < arr.length){
			if(arr[index] == ele)
				found = true;
			else
				index++;
		}
		return found;
	}

	function getIndex(input) {
		var index = -1, i = 0, found = false;
		while (i < input.form.length && index == -1){
			if (input.form[i] == input)
				index = i;
			else
				i++;
		}
		return index;
	}
	return true;
}
