function submitpayment(optionform,itemform,itemname){
	selected=0;
    for (counter = 0; counter < optionform.length; counter++)
    {
     if (optionform[counter].checked)
	 {
     selected=counter;
     }
	}

	  if (selected > 1)
	  {
		   if (selected == 2)
		   {
			itemname=itemname.replace("X","1");
   
		   }
		   else if (selected == 3)
		   {
			 itemname=itemname.replace("X","2") + 's';
		   }
		   else if (selected == 4)
		   {
			   itemname=itemname.replace("X","4") + 's';
		   }
		   else if (selected == 5)
		   {
			   itemname=itemname.replace("X","10") + 's';
		   }
	  itemform.value=itemname;   
	  document.forms['formP'].action = 'https://www.sandbox.paypal.com/cgi-bin/webscr'; 
	  }
	  else
	  {
	  document.forms['formP'].action = 'paymentstep1.php'; 
	  }
      document.forms['formP'].submit(); 

}
function setmailasread(num){
	  document.getElementById('image'+num).className = 'open';
	  document.getElementById('mail1'+num).className = 'nobold';
	  document.getElementById('mail2'+num).className = 'nobold';
	  document.getElementById('mail3'+num).className = 'nobold';
	  return true;
}
function setevalasread(num){
	  document.getElementById('eval1'+num).className = 'nobold';
	  document.getElementById('eval2'+num).className = 'nobold';
	  document.getElementById('eval3'+num).className = 'nobold';
	  document.getElementById('eval4'+num).className = 'nobold';
	  document.getElementById('eval5'+num).className = 'nobold';
	  return true;
}
function stopUpload(){
      document.getElementById('f1_upload_process').style.visibility = 'hidden'; 
	  document.getElementById('f1_upload_error').style.visibility = 'visible'; 
	  document.getElementById('upload_target').style.height = '106px';
      return true;   
}

function startUpload(){
	  document.form1.flag.value='suivant';
	  document.getElementById('f1_upload_error').style.visibility = 'hidden'; 
      document.getElementById('f1_upload_process').style.visibility = 'visible';
	  document.form1.submit();
      return true;
}
function getFormAsString(formName) {
    // on choppe les valeurs du form
    formElements = document.forms[formName].elements;
    
    // on construit l'url
    returnString = "";
    for (var i = 0; i < formElements.length; i++ ) {
		 if (formElements[i].type == 'checkbox' || formElements[i].type == 'radio' ) {
			 if (formElements[i].checked == true) {
				  returnString += escape(formElements[i].name) + "=" + escape(formElements[i].value) + "&";
             			 }
					
		 }
		 else
		 {
		  returnString += escape(formElements[i].name) + "=" + escape(formElements[i].value) + "&";
		 }
    }
    
    // on retourne l'url
    
	return returnString; 
	
}

function makesql(numechange,page,action) {
        var httpRequest = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
		    
            httpRequest = new XMLHttpRequest();
            if (httpRequest.overrideMimeType) {
                httpRequest.overrideMimeType('text/html');
                // Voir la note ci-dessous à propos de cette ligne
            }
        }
        else if (window.ActiveXObject) { // IE
            try {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e) {
                try {
                    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (e) {}
            }
        }

        if (!httpRequest) {
            alert('Browser error, please use a new version, this function use AJAX');
            return false;
        }
        httpRequest.onreadystatechange = function() { alertContents(httpRequest,action,numechange); };
        httpRequest.open('POST','http://www.xchange.be/exchange'+action+'.php?ID='+numechange, true);
		httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        sendstr=getFormAsString('form4');
		
		httpRequest.send(sendstr + 'flag=suivant');
    }
 function alertContents(httpRequest,action,numechange) {
        if (httpRequest.readyState == 4) {
            if (httpRequest.status == 200) {
			    str=httpRequest.responseText;
				//alert(str);
                if(str.indexOf("OKMEN") >-1){
				
				if (action == 'start' || action == 'accept')
				{
					form1.affichage.value='0';
					
				}
				
				else
				{
					 form1.affichage.value='2';
				}
				
				form1.submit();
				}
				else
				{
				 if (document.getElementById)
	             {
		         x = document.getElementById('errormsg');
		         x.innerHTML = str;
	             }
	             else if (document.all)
	             {
		         x = document.all['errormsg'];
		         x.innerHTML = str;
	             }
	             else if (document.layers)
	             {
		          x = document.layers['errormsg'];
		          x.document.open();
		          x.document.write(str);
		          x.document.close();
	             }

				 //document.location='http://www.xchange.be?page_id='+page+'&ID='+numechange; 
				}
            } else {
                alert('Site unavailable, please try again later');
            }
        }

    }
function makesqlINS(action,pageok,pageko) {
        var httpRequest = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
		    
            httpRequest = new XMLHttpRequest();
            if (httpRequest.overrideMimeType) {
                httpRequest.overrideMimeType('text/html');
                // Voir la note ci-dessous à propos de cette ligne
            }
        }
        else if (window.ActiveXObject) { // IE
            try {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e) {
                try {
                    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (e) {}
            }
        }

        if (!httpRequest) {
            alert('Browser error, please use a new version, this function use AJAX');
            return false;
        }
        httpRequest.onreadystatechange = function() { alertContents2(httpRequest,pageok,pageko); };
        httpRequest.open('POST','http://www.xchange.be/'+action, true);
		httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        sendstr=getFormAsString('form1');
		httpRequest.send(sendstr + 'flag=suivant');
    }
function alertContents2(httpRequest,pageok,pageko) {
        if (httpRequest.readyState == 4) {
            if (httpRequest.status == 200) {
			    str=httpRequest.responseText;
				fab=httpRequest.responseText;
                if(str.indexOf("OKMEN") >-1){
				tmp= new Array ();
				tmp[1]=1;
				tmp=str.split('OKMEN');
				//alert (fab);
				document.location='http://www.xchange.be?page_id='+pageok+'&ID='+tmp[1]+'&oid='+tmp[1]; 
				}
				else
				{
				 form1.b1.disabled=false;
				 tab=str.substr(str.length-1,1);
				 
				 errormsg='errormsg'+tab;
				 if (document.getElementById)
	             {
		         x = document.getElementById(errormsg);
		         x.innerHTML = str.substr(0,str.length-1);
	             }
	             else if (document.all)
	             {
		         x = document.all[errormsg];
		         x.innerHTML = str.substr(0,str.length-1);
	             }
	             else if (document.layers)
	             {
		          x = document.layers[errormsg];
		          x.document.open();
		          x.document.write(str.substr(0,str.length-1));
		          x.document.close();
	             }
				 if (tab != 'e')
				 {
                 $('#usual1 div').idTabs('tab'+tab);
				 }
				 else
				 {
				  location.href='http://www.xchange.be/index.php?page_id='+pageko+ '#up'
				 }
				}
            } else {
                alert('Site unavailable, please try again later');
            }
        }

    }
function makesqllistcompatible(param,action) {
        var httpRequest = false;

        if (window.XMLHttpRequest) { // Mozilla, Safari,...
		    
            httpRequest = new XMLHttpRequest();
            if (httpRequest.overrideMimeType) {
                httpRequest.overrideMimeType('text/html');
                // Voir la note ci-dessous à propos de cette ligne
            }
        }
        else if (window.ActiveXObject) { // IE
            try {
                httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
            }
            catch (e) {
                try {
                    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
                }
                catch (e) {}
            }
        }

        if (!httpRequest) {
            alert('Browser error, please use a new version, this function use AJAX');
            return false;
        }
        httpRequest.onreadystatechange = function() { alertContentsC(httpRequest); };
        httpRequest.open('POST','http://www.xchange.be/exchange'+action+'.php?'+param, true);
		httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		httpRequest.send('flag=suivant');
    }
 function alertContentsC(httpRequest) {
        if (httpRequest.readyState == 4) {
            if (httpRequest.status == 200) {
			     str=httpRequest.responseText;
				 if (document.getElementById)
	             {
		         x = document.getElementById('listcompatible');
		         x.innerHTML = str;
	             }
	             else if (document.all)
	             {
		         x = document.all['listcompatible'];
		         x.innerHTML = str;
	             }
	             else if (document.layers)
	             {
		          x = document.layers['listcompatible'];
		          x.document.open();
		          x.document.write(str);
		          x.document.close();
	             }

				 //document.location='http://www.xchange.be?page_id='+page+'&ID='+numechange; 
				
            } else {
                alert('Site unavailable, please try again later');
            }
        }

    }
function extractlist(selectCtrl,hiddenform) { //pour les liste dans les formulaire de recherche
var i, j;
var prompt;
var valchamp;
var valchamp3="";
// empty existing items
for (i = 0; i <= selectCtrl.options.length-1; i++) {
if (selectCtrl.options[i].selected == true){
 //selectCtrl.options[i].selected = true
 //valchamp=sprintf("%02d", selectCtrl.options[i].value);
 valchamp3=valchamp3+sprintf('%4d',selectCtrl.options[i].value);
 valchamp3=valchamp3+selectCtrl.options[i].value;
}
}
if (valchamp3==""){valchamp3="XXXX";}
hiddenform.value=valchamp3; 

//}
}

var NUM_CENTYEAR = 30;
// is time input control required by default
var BUL_TIMECOMPONENT = false;
// are year scrolling buttons required by default
var BUL_YEARSCROLL = true;

var calendars = [];
var RE_NUM = /^\-?\d+$/;

function calendar1(obj_target) {

	// assigning methods
	this.gen_date = cal_gen_date1;
	this.gen_time = cal_gen_time1;
	this.gen_tsmp = cal_gen_tsmp1;
	this.prs_date = cal_prs_date1;
	this.prs_time = cal_prs_time1;
	this.prs_tsmp = cal_prs_tsmp1;
	this.popup    = cal_popup1;

	// validate input parameters
	if (!obj_target)
		return cal_error("Error calling the calendar: no target control specified");
	if (obj_target.value == null)
		return cal_error("Error calling the calendar: parameter specified is not valid target control");
	this.target = obj_target;
	this.time_comp = BUL_TIMECOMPONENT;
	this.year_scroll = BUL_YEARSCROLL;
	
	// register in global collections
	this.id = calendars.length;
	calendars[this.id] = this;
}

function cal_popup1 (str_datetime) {
	if (str_datetime) {
		this.dt_current = this.prs_tsmp(str_datetime);
	}
	else {
		this.dt_current = this.prs_tsmp(this.target.value);
		this.dt_selected = this.dt_current;
	}
	if (!this.dt_current) return;

	var obj_calwindow = window.open(
		'calendar.html?datetime=' + this.dt_current.valueOf()+ '&id=' + this.id,
		'Calendar', 'width=240,height='+(this.time_comp ? 215 : 190)+
		',status=no,resizable=no,top=200,left=200,dependent=yes,alwaysRaised=yes'
	);
	obj_calwindow.opener = window;
	obj_calwindow.focus();
}

// timestamp generating function
function cal_gen_tsmp1 (dt_datetime) {
	return(this.gen_date(dt_datetime) + ' ' + this.gen_time(dt_datetime));
}

// date generating function
function cal_gen_date1 (dt_datetime) {
	return (
		(dt_datetime.getDate() < 10 ? '0' : '') + dt_datetime.getDate() + "-"
		+ (dt_datetime.getMonth() < 9 ? '0' : '') + (dt_datetime.getMonth() + 1) + "-"
		+ dt_datetime.getFullYear()
	);
}
// time generating function
function cal_gen_time1 (dt_datetime) {
	return (
		(dt_datetime.getHours() < 10 ? '0' : '') + dt_datetime.getHours() + ":"
		+ (dt_datetime.getMinutes() < 10 ? '0' : '') + (dt_datetime.getMinutes()) + ":"
		+ (dt_datetime.getSeconds() < 10 ? '0' : '') + (dt_datetime.getSeconds())
	);
}

// timestamp parsing function
function cal_prs_tsmp1 (str_datetime) {
	// if no parameter specified return current timestamp
	if (!str_datetime)
		return (new Date());

	// if positive integer treat as milliseconds from epoch
	if (RE_NUM.exec(str_datetime))
		return new Date(str_datetime);
		
	// else treat as date in string format
	var arr_datetime = str_datetime.split(' ');
	return this.prs_time(arr_datetime[1], this.prs_date(arr_datetime[0]));
}

// date parsing function
function cal_prs_date1 (str_date) {

	var arr_date = str_date.split('-');

	if (arr_date.length != 3) return cal_error ("Invalid date format: '" + str_date + "'.\nFormat accepted is dd-mm-yyyy.");
	if (!arr_date[0]) return cal_error ("Invalid date format: '" + str_date + "'.\nNo day of month value can be found.");
	if (!RE_NUM.exec(arr_date[0])) return cal_error ("Invalid day of month value: '" + arr_date[0] + "'.\nAllowed values are unsigned integers.");
	if (!arr_date[1]) return cal_error ("Invalid date format: '" + str_date + "'.\nNo month value can be found.");
	if (!RE_NUM.exec(arr_date[1])) return cal_error ("Invalid month value: '" + arr_date[1] + "'.\nAllowed values are unsigned integers.");
	if (!arr_date[2]) return cal_error ("Invalid date format: '" + str_date + "'.\nNo year value can be found.");
	if (!RE_NUM.exec(arr_date[2])) return cal_error ("Invalid year value: '" + arr_date[2] + "'.\nAllowed values are unsigned integers.");

	var dt_date = new Date();
	dt_date.setDate(1);

	if (arr_date[1] < 1 || arr_date[1] > 12) return cal_error ("Invalid month value: '" + arr_date[1] + "'.\nAllowed range is 01-12.");
	dt_date.setMonth(arr_date[1]-1);
	 
	if (arr_date[2] < 100) arr_date[2] = Number(arr_date[2]) + (arr_date[2] < NUM_CENTYEAR ? 2000 : 1900);
	dt_date.setFullYear(arr_date[2]);

	var dt_numdays = new Date(arr_date[2], arr_date[1], 0);
	dt_date.setDate(arr_date[0]);
	if (dt_date.getMonth() != (arr_date[1]-1)) return cal_error ("Invalid day of month value: '" + arr_date[0] + "'.\nAllowed range is 01-"+dt_numdays.getDate()+".");

	return (dt_date)
}

// time parsing function
function cal_prs_time1 (str_time, dt_date) {

	if (!dt_date) return null;
	var arr_time = String(str_time ? str_time : '').split(':');

	if (!arr_time[0]) dt_date.setHours(0);
	else if (RE_NUM.exec(arr_time[0]))
		if (arr_time[0] < 24) dt_date.setHours(arr_time[0]);
		else return cal_error ("Invalid hours value: '" + arr_time[0] + "'.\nAllowed range is 00-23.");
	else return cal_error ("Invalid hours value: '" + arr_time[0] + "'.\nAllowed values are unsigned integers.");
	
	if (!arr_time[1]) dt_date.setMinutes(0);
	else if (RE_NUM.exec(arr_time[1]))
		if (arr_time[1] < 60) dt_date.setMinutes(arr_time[1]);
		else return cal_error ("Invalid minutes value: '" + arr_time[1] + "'.\nAllowed range is 00-59.");
	else return cal_error ("Invalid minutes value: '" + arr_time[1] + "'.\nAllowed values are unsigned integers.");

	if (!arr_time[2]) dt_date.setSeconds(0);
	else if (RE_NUM.exec(arr_time[2]))
		if (arr_time[2] < 60) dt_date.setSeconds(arr_time[2]);
		else return cal_error ("Invalid seconds value: '" + arr_time[2] + "'.\nAllowed range is 00-59.");
	else return cal_error ("Invalid seconds value: '" + arr_time[2] + "'.\nAllowed values are unsigned integers.");

	dt_date.setMilliseconds(0);
	return dt_date;
}

function cal_error (str_message) {
	alert (str_message);
	return null;
}
