﻿// please change the configurations as you wish.
// [begin]
// Settings for whether the item can be empty or not:
//     true: can be empty;  false: cannot be empty.
var bAllowEmpty_Nom = false;
var bAllowEmpty_Prenom = false;
var bAllowEmpty_Email = false;
var bAllowEmpty_Profession = false;
var bAllowEmpty_Company = false;
var bAllowEmpty_Pays = false;
var bAllowEmpty_Adresse = false;
var bAllowEmpty_Codepostale = false;
var bAllowEmpty_Ville = false;

// Translation of tips for empty items
var sTipEmpty = "Merci de remplir les champs marqués *!";
//var sTipEmpty_Nom = "Merci de remplir les champs marqués *!";
//var sTipEmpty_Prenom = "Merci de remplir les champs marqués *!";
var sTipEmpty_Email = "Merci de remplir les champs marqués *, ou Email valide!";
//var sTipEmpty_Profession = "Merci de remplir les champs marqués *!";
//var sTipEmpty_Company = "Merci de remplir les champs marqués *!";
//var sTipEmpty_Pays = "Merci de remplir les champs marqués *!";
//var sTipEmpty_Adresse = "Merci de remplir les champs marqués *!";
//var sTipEmpty_Codepostale = "Merci de remplir les champs marqués *!";
//var sTipEmpty_Ville = "Merci de remplir les champs marqués *!";
// [End]




var $ = function (id) {
	return "string" == typeof id ? document.getElementById(id) : id;
};

function addEventHandler(oTarget, sEventType, fnHandler) {
	if (oTarget.addEventListener) {
		oTarget.addEventListener(sEventType, fnHandler, false);
	} else if (oTarget.attachEvent) {
		oTarget.attachEvent("on" + sEventType, fnHandler);
	} else {
		oTarget["on" + sEventType] = fnHandler;
	}
};

var Class = {
  create: function() {
	return function() {
	  this.initialize.apply(this, arguments);
	}
  }
}

var Extend = function(destination, source) {
	for (var property in source) {
		destination[property] = source[property];
	}
	return destination;
}

var DateSelector = Class.create();
DateSelector.prototype = {
  initialize: function(oYear, oMonth, oDay, options) {
	this.SelYear = $(oYear);
	this.SelMonth = $(oMonth);
	this.SelDay = $(oDay);
	
	this.SetOptions(options);
	
	var dt = new Date(), iMonth = parseInt(this.options.Month), iDay = parseInt(this.options.Day), iMinYear = parseInt(this.options.MinYear), iMaxYear = parseInt(this.options.MaxYear);
	
	this.Year = parseInt(this.options.Year) || dt.getFullYear();
	this.Month = 1 <= iMonth && iMonth <= 12 ? iMonth : dt.getMonth() + 1;
	this.Day = iDay > 0 ? iDay : dt.getDate();
	this.MinYear = iMinYear && iMinYear < this.Year ? iMinYear : this.Year;
	this.MaxYear = iMaxYear && iMaxYear > this.Year ? iMaxYear : this.Year;
	this.onChange = this.options.onChange;

	this.SetSelect(this.SelYear, this.MinYear, this.MaxYear - this.MinYear + 1, this.Year - this.MinYear);

	this.SetSelect(this.SelMonth, 1, 12, this.Month - 1);

	this.SetDay();
	
	var oThis = this;

	addEventHandler(this.SelYear, "change", function(){
		oThis.Year = oThis.SelYear.value; oThis.SetDay(); oThis.onChange();
	});
	addEventHandler(this.SelMonth, "change", function(){
		oThis.Month = oThis.SelMonth.value; oThis.SetDay(); oThis.onChange();
	});
	addEventHandler(this.SelDay, "change", function(){ oThis.Day = oThis.SelDay.value; oThis.onChange(); });
  },

  SetOptions: function(options) {
	this.options = {
		Year:		0,
		Month:		0,
		Day:		0,
		MinYear:	0,
		MaxYear:	0,
		onChange:	function(){}
	};
	Extend(this.options, options || {});
  },

  SetDay: function() {
	var daysInMonth = new Date(this.Year, this.Month, 0).getDate();
	if (this.Day > daysInMonth) { this.Day = daysInMonth; };
	this.SetSelect(this.SelDay, 1, daysInMonth, this.Day - 1);
  },
  //select??
  SetSelect: function(oSelect, iStart, iLength, iIndex) {
	// option
	oSelect.options.length = iLength;
	for (var i = 0; i < iLength; i++) { oSelect.options[i].text = oSelect.options[i].value = iStart + i; }

	oSelect.selectedIndex = iIndex;
  }
};

var arrCountries = new Array( 
"Angola", "Afghanistan", "Albania", "Algeria", "Andorra", "Anguilla", "Barbuda Antigua", "Argentina", "Armenia", "Australia", 
"Austria", "Azerbaijan", "Bahamas", "Bahrain", "Bangladesh", "Barbados", "Belarus", "Belgium", "Belize", "Benin", "Bermuda Is.", 
"Bolivia", "Botswana", "Brazil", "Brunei", "Bulgaria", "Burkina-faso", "Burma", "Burundi", "Cameroon", "Canada", 
"Central African Republic", "Chad", "Chile", "China", "Colombia", "Congo", "Cook Is.", "Costa Rica", "Cuba", "Cyprus", 
"Czech Republic", "Denmark", "Djibouti", "Dominica Rep.", "Ecuador", "Egypt", "EI Salvador", "Estonia", "Ethiopia", "Fiji", 
"Finland", "France", "French Guiana", "Gabon", "Gambia", "Georgia", "Germany", "Ghana", "Gibraltar", "Greece", "Grenada", 
"Guam", "Guatemala", "Guinea", "Guyana", "Haiti", "Honduras", "Hongkong", "Hungary", "Iceland", "India", "Indonesia", "Iran", 
"Iraq", "Ireland", "Israel", "Italy", "Jamaica", "Japan", "Jordan", "Kampuchea (Cambodia )", "Kazakstan", "Kenya", "Korea", 
"Kuwait", "Kyrgyzstan", "Laos", "Latvia", "Lebanon", "Lesotho", "Liberia", "Libya", "Liechtenstein", "Lithuania", "Luxembourg", 
"Macao", "Madagascar", "Malawi", "Malaysia", "Maldives", "Mali", "Malta", "Mauritius", "Mexico", "Moldova", "Monaco", "Mongolia", 
"Montserrat Is.", "Morocco", "Mozambique", "Namibia", "Nauru", "Nepal", "Netherlands", "New Zealand", "Nicaragua", "Niger", 
"Nigeria", "North Korea", "Norway", "Oman", "Pakistan", "Panama", "Papua New Cuinea", "Paraguay", "Peru", "Philippines", 
"Poland", "French Polynesia", "Portugal", "Puerto Rico", "Qatar", "Romania", "Russia", "Saint Lueia", "Saint Vincent", 
"San Marino", "Sao Tome and Principe", "Saudi Arabia", "Senegal", "Seychelles", "Sierra Leone", "Singapore", "Slovakia", 
"Slovenia", "Solomon Is.", "Somali", "South Africa", "Spain", "Sri Lanka", "Sudan", "Suriname", "Swaziland", "Sweden", 
"Switzerland", "Syria", "Taiwan", "Tajikstan", "Tanzania", "Thailand", "Togo", "Tonga", "Trinidad and Tobago", "Tunisia", 
"Turkey", "Turkmenistan", "Uganda", "Ukraine", "United Arab Emirates", "United Kiongdom", "United States of America", 
"Uruguay", "Uzbekistan", "Venezuela", "Vietnam", "Yemen", "Yugoslavia", "Zimbabwe", "Zaire", "Zambia"  
);

function isValidEmail( email ){
	var reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;
	return reg.test( email );
}


function submitContact( formId ){
	var form = $( formId );
	var sGental, sFirstName, sLastName, sBOD, sEmail, sOccupation, sCountry, sAddr, sPostcode, sCity, sCompany;

	sGental = $( "Gental" ).value;
	sFirstName = $( "FirstName" ).value;
	sLastName = $( "LastName" ).value;
	sBOD = $( "Birthday" ).value;
	sEmail = $( "Email" ).value;
	sOccupation = $( "Occupation" ).value;;
	sCompany = $( "Company" ).value;
	sCountry = $( "Country" ).value;
	sAddr = $( "Address" ).value;
	sPostcode = $( "Postcode" ).value;
	sCity = $( "City" ).value;

	var sMsg = "";
	if( !bAllowEmpty_Nom && sFirstName == "" ){
		sMsg = sTipEmpty + "\n";
	}
	else if( !bAllowEmpty_Prenom && sLastName == "" ){
		sMsg = sTipEmpty + "\n";
	}
	else if( !bAllowEmpty_Prenom && ( sEmail == "" || !isValidEmail( sEmail ) ) ){
		sMsg += sTipEmpty_Email + "\n";
	}
	else if( !bAllowEmpty_Profession && sOccupation == "" ){
		sMsg = sTipEmpty + "\n";
	}
	else if( !bAllowEmpty_Company && sCompany == "" ){
		sMsg = sTipEmpty + "\n";
	}
	else if( !bAllowEmpty_Pays && sCountry == "" ){
		sMsg = sTipEmpty + "\n";
	}
	else if( !bAllowEmpty_Adresse && sAddr == "" ){
		sMsg = sTipEmpty + "\n";
	}
	else if( !bAllowEmpty_Codepostale && sPostcode == "" ){
		sMsg = sTipEmpty + "\n";
	}
	else if( !bAllowEmpty_Ville && sCity == "" ){
		sMsg = sTipEmpty + "\n";
	}

	if( sMsg != "" ){
		alert( sMsg );
		return false;
	}

	form.onSubmit();
	return true;
}


function numbersonly( myfield, e, dec )
{
	var key;
	var keychar;

	if( window.event ){
	   key = window.event.keyCode;
	}
	else if (e){
	   key = e.which;
	}
	else{
	   return true;
	}
	keychar = String.fromCharCode(key);

	// control keys
	if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )
	   return true;

	// numbers
	else if ((("0123456789").indexOf(keychar) > -1))
	   return true;

	// decimal point jump
	else if (dec && (keychar == "."))
	{
	   myfield.form.elements[dec].focus();
	   return false;
	}
	else
	   return false;
}

function popUp(URL) {
	day = new Date();
	id = day.getTime();
	eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=0,width=454,height=512,left = 456,top = 143');");
}
