/*
	****************************************************
	Script Java pour la validation des abonnement PaySec

	Version: 1.00 du 26/12/2008
	Copyright: www.pronostic-hippique.com
	Maintained by:	S.C. CVRS Consulting SRL
					Timisoara - Romania
					Phone:  +40 356-104.318
					Mobile: +40 720-653.789
	****************************************************
*/

var PS_MessageWait = "<center><br><br><img src=\"paysec/lib/images/loading1.gif\" width=\"50\" height=\"50\"><br>Chargement, veuillez patienter ...<br><br></center>";

function doNothing(){
	alert('doNothing function called!');
}

// **************************
// *** Trim sur theString ***
// **************************
function PS_TrimString(theStringToTrim){
	txtStringToTrim = new String(theStringToTrim);
	while (txtStringToTrim.substring(0,1) == ' '){
		txtStringToTrim = txtStringToTrim.substring(1, txtStringToTrim.length);
	}
	while (txtStringToTrim.substring(txtStringToTrim.length-1, txtStringToTrim.length) == ' '){
		txtStringToTrim = txtStringToTrim.substring(0,txtStringToTrim.length-1);
	}
	return txtStringToTrim;
}

// *******************************
// *** Fonctions Ouverture POP ***
// *******************************
function PS_OpenPop(filepopname,namepopwin){
	window.open(filepopname,namepopwin,"menubar=yes,toolbar=no,scrollbars=yes,status=yes,width=500,height=400,top=0,left=0");
}
function PS_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 PS_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=no,status=yes,width="+popxsize+",height="+popysize+",top="+popwintoppos+",left="+popwinleftpos+"");
}

// ******************************************************
// *** Afficher le contenu HTML, réduire les messages ***
// ******************************************************
function doSwitchToHTMLContent(){
	document.getElementById('TBox_ContentHTML').style.display = 'block';
	document.getElementById('TBox_MessagesHTML').style.display = 'none';
}

function doVerifySubscriptionForm(TBox_ContentHTML,TBox_MessagesHTML){
	var TLibVar_PSSubsciptionLength	= new String();
	var TLibVar_PSSubsciptionTypePay= new String();
	var TLibVar_PSUserFName			= new String();
	var TLibVar_PSUserLName			= new String();
	var TLibVar_PSUserMail			= new String();
	var TLibVar_PSUserLog			= new String();
	var TLibVar_PSUserPassword		= new String();
	var TLibVar_PSUserCPassword		= new String();
	var TLibVar_POSTValues			= new String();

	for (i=0;i<document.getElementsByName('paysec_subscriptionlength').length;i++){
		if (document.getElementsByName('paysec_subscriptionlength')[i].checked){
			TLibVar_PSSubsciptionLength	= document.getElementsByName('paysec_subscriptionlength')[i].value;
			break;
		}
	}
	for (i=0;i<document.getElementsByName('paysec_methodepay').length;i++){
		if (document.getElementsByName('paysec_methodepay')[i].checked){
			TLibVar_PSSubsciptionTypePay = document.getElementsByName('paysec_methodepay')[i].value;
			break;
		}
	}

	TLibVar_PSUserFName		= PS_TrimString(document.getElementById('paysec_userfname').value);
	TLibVar_PSUserLName		= PS_TrimString(document.getElementById('paysec_userlname').value);
	TLibVar_PSUserMail		= PS_TrimString(document.getElementById('paysec_usermail').value);
	TLibVar_PSUserLog		= PS_TrimString(document.getElementById('paysec_userlog').value);
	TLibVar_PSUserPassword	= PS_TrimString(document.getElementById('paysec_userpass').value);

	TLibVar_POSTValues = 'BoxToInclude=doDisplayMessageRegister';
	TLibVar_POSTValues+= '&action=doVerifySubscription';
	TLibVar_POSTValues+= '&PS_Length='+escape(TLibVar_PSSubsciptionLength);
	TLibVar_POSTValues+= '&PS_PayType='+escape(TLibVar_PSSubsciptionTypePay);
	TLibVar_POSTValues+= '&PS_FName='+escape(TLibVar_PSUserFName);
	TLibVar_POSTValues+= '&PS_LName='+escape(TLibVar_PSUserLName);
	TLibVar_POSTValues+= '&PS_Mail='+encodeURIComponent(TLibVar_PSUserMail);
	TLibVar_POSTValues+= '&PS_Login='+escape(TLibVar_PSUserLog);
	TLibVar_POSTValues+= '&PS_Password='+escape(TLibVar_PSUserPassword);

	if (!document.getElementsByName('ph_abocgv')[0].checked){
		alert('L\'abonnement à nos services ne peut se faire qu\'en acceptant nos conditions générales.\nPour cela, veuillez cocher la case correspondante!');
	}else{
		// *** Scroller la fenêtre en haut ***
		scroll(0,0);
		// *** Cacher le formulaire d'abonnement ***
		document.getElementById(TBox_ContentHTML).style.display = 'none';
		// *** Développer les messages ou le résumé ***
		document.getElementById(TBox_MessagesHTML).style.display = 'block';
		// *** Afficher le message d'attente ***
		document.getElementById(TBox_MessagesHTML).innerHTML = PS_MessageWait;
		// *** Appel ajax - màj contenu ***
		PSecAjaxQueryURL('POST','paysec/lib/include/PaySec_ContentNewUserAccount.php',TLibVar_POSTValues,TBox_MessagesHTML);
	}
}
