// JavaScript Document
var timer;
var scrollImages = new Array();
var counter = 0;
var speed = 2000;
var qty;

function initScroll(img)	{

	/*test images*/
	var arLen=img.length;
	qty=(img.length-1);
	for ( var i=0, len=arLen; i<len; ++i ){

		scrollImages[i] = new Image();
		scrollImages[i].src = img[i];

	}

	timer = setInterval("startScrolling()", speed);
}

function startScrolling()	{

document.getElementById('imgDefilant').src = scrollImages[++counter].src;

	if(counter == qty)
		counter = -1;
}

function DisplayDiv(count)
{
	alert(count);
	if(count <= 9){
	document.getElementById('scoreBoard').style.display="block";
	}else{
		 document.getElementById('scoreBoard2').style.display="block";
	}
}

//function for partners_mosaique.php to validate and submit the form
function validateForm(){
	//count nb of checked - checkboxes
	var w = document.getElementsByTagName('input');
	var c = 0;
	for(var i = 0; i < w.length; i++){
		if(w[i].type=='checkbox'){
	    	if (w[i].checked == true){
	    		c=c+1;
			}
	  	}
	}
  	//if at least one box is checked
	if (c>=1) {
		document.form.submit();
		document.form.reset();
	}else{
		return false;
	}
}

/**fonction  global pour valider une formulaiew**/

function processFormData() {

	var tagInput  = document.getElementsByTagName('input');
	var tagSelect = document.getElementsByTagName('select');
	var message   = '';
	var reg 	  = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	var errMail	  = false;
   
	/** check all input type**/
	
	for(var i=0;i<tagInput.length;i++){
		
		switch(tagInput[i].type){
			/*case 'radio':
				if(tagInput[i].checked != true){
					message =  'Please choose in all compulsory field (*)';
				}
			break;*/
			case 'text':
					
				if(tagInput[i].value == ''){
					message = 'Please fill in all compulsory field (*)';
				 }
				 if (tagInput[i].name == 'txtEmail' && tagInput[i].value != ''){
				 	
				 	if(reg.test(tagInput[i].value)==false){
				 		message += "Email is invalid \n";
				 	errMail = true;
				 	}
				 	
				 }
				  if (tagInput[i].name == 'txtCnfEmail' && tagInput[i].value != ''){
				 	
				 	if(reg.test(tagInput[i].value)==false){
				 		message += "Confirmation Email is invalid \n";
				 		errMail = true;
				 	}
				 	
				 }
				 
				 if (tagInput[i].name == 'txtNadults' && tagInput[i].value != ''){
				 	
				 	if(!IsNumeric(tagInput[i].value)){
				 		message += "Please insert numeric values for number of adults \n";
				 	}
				 	
				 }
				 
				  if (tagInput[i].name == 'txtNnights' && tagInput[i].value != ''){
				 	
				 	if(!IsNumeric(tagInput[i].value)){
				 		message += "Please insert numeric values for number of nights \n";
				 	}
				 	
				 }
				 
				   if (tagInput[i].name == 'txtNteens' && tagInput[i].value != ''){
				 	
				 	if(!IsNumeric(tagInput[i].value)){
				 		message += "Please insert numeric values for number of teenagers \n";
				 	}
				 	
				 }
				
				 
				  if (tagInput[i].name == 'txtNchildren' && tagInput[i].value != ''){
				 	
				 	if(!IsNumeric(tagInput[i].value)){
				 		message += "Please insert numeric values for number of children \n";
				 	}
				 	
				 }
				 
				  if (tagInput[i].name == 'txtPhone' && tagInput[i].value != ''){
				 	
				 	if(!IsNumeric(tagInput[i].value)){
				 		message += "Please insert numeric values for telephone number \n";
				 	}
				 	
				 }
				 
				 if (tagInput[i].name == 'txtDtime' && tagInput[i].value != ''){
				 	
				 	if(IsValidTime(tagInput[i].value) != ''){
				 		message += "Please insert a valid format time for departure (HH:MM) \n";
				 	}
				 	
				 }
				  if (tagInput[i].name == 'txtAtime' && tagInput[i].value != ''){
				 	
				 	if(IsValidTime(tagInput[i].value) != ''){
				 		message += "Please insert a valid format time for arrival (HH:MM) \n";
				 	}
				 	
				 }
				 
			break;
		}
	}
	
	
	
	if(errMail == false){
		if(document.getElementById('txtEmail').value != document.getElementById('txtCnfEmail').value){
			message += "The confirmation mail does not match your email \n";
		}
	}
	
	if(message != ''){
		alert(message);
		return false;
	}else{
		return true;
		document.form.reset();
	}

		
}


function IsNumeric(sText)

{
   var ValidChars = "0123456789.";
   var IsNumber=true;
   var Char;

 
   for (i = 0; i < sText.length && IsNumber == true; i++) 
      { 
      Char = sText.charAt(i); 
      if (ValidChars.indexOf(Char) == -1) 
         {
         IsNumber = false;
         }
      }
   return IsNumber;
   
   }

   
   
function IsValidTime(timeStr) {
// Checks if time is in HH:MM:SS AM/PM format.
// The seconds and AM/PM are optional.

var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))?(\s?(AM|am|PM|pm))?$/;
var message ='';
var matchArray = timeStr.match(timePat);
if (matchArray == null) {

message += "Time is not in a valid format \n";
return false;
}
hour = matchArray[1];
minute = matchArray[2];
second = matchArray[4];
ampm = matchArray[6];

if (second=="") { second = null; }
if (ampm=="") { ampm = null }

if (hour < 0  || hour > 23) {
//alert("Hour must be between 1 and 12. (or 0 and 23 for military time)");
message += "Hour must be between 1 and 12. (or 0 and 23 for military time \n";

}
/*if (hour <= 12 && ampm == null) {
if (confirm("Please indicate which time format you are using.  OK = Standard Time, CANCEL = Military Time")) {
alert("You must specify AM or PM.");
return false;
   }
}*/
/*if  (hour > 12 && ampm != null) {
alert("You can't specify AM or PM for military time.");
return false;
}*/
if (minute<0 || minute > 59) {
message += "Minute must be between 0 and 59. \n";

}
if (second != null && (second < 0 || second > 59)) {
message +=  "Second must be between 0 and 59. \n";

}
return message;
}