
function SetFocus(TargetFormName) {
  var target = 0;
  if (TargetFormName != "") {
    for (i=0; i<document.forms.length; i++) {
      if (document.forms[i].name == TargetFormName) {
        target = i;
        break;
      }
    }
  }

  var TargetForm = document.forms[target];
    
  for (i=0; i<TargetForm.length; i++) {
    if ( (TargetForm.elements[i].type != "image") && (TargetForm.elements[i].type != "hidden") && (TargetForm.elements[i].type != "reset") && (TargetForm.elements[i].type != "submit") ) {
      TargetForm.elements[i].focus();

      if ( (TargetForm.elements[i].type == "text") || (TargetForm.elements[i].type == "password") ) {
        TargetForm.elements[i].select();
      }

      break;
    }
  }
}

function RemoveFormatString(TargetElement, FormatString) {
  if (TargetElement.value == FormatString) {
    TargetElement.value = "";
  }

  TargetElement.select();
}

function CheckDateRange(from, to) {
  if (Date.parse(from.value) <= Date.parse(to.value)) {
    return true;
  } else {
    return false;
  }
}

function IsValidDate(DateToCheck, FormatString) {
  var strDateToCheck;
  var strDateToCheckArray;
  var strFormatArray;
  var strFormatString;
  var strDay;
  var strMonth;
  var strYear;
  var intday;
  var intMonth;
  var intYear;
  var intDateSeparatorIdx = -1;
  var intFormatSeparatorIdx = -1;
  var strSeparatorArray = new Array("-"," ","/",".");
  var strMonthArray = new Array("jan","feb","mar","apr","may","jun","jul","aug","sep","oct","nov","dec");
  var intDaysArray = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);

  strDateToCheck = DateToCheck.toLowerCase();
  strFormatString = FormatString.toLowerCase();
  
  if (strDateToCheck.length != strFormatString.length) {
    return false;
  }

  for (i=0; i<strSeparatorArray.length; i++) {
    if (strFormatString.indexOf(strSeparatorArray[i]) != -1) {
      intFormatSeparatorIdx = i;
      break;
    }
  }

  for (i=0; i<strSeparatorArray.length; i++) {
    if (strDateToCheck.indexOf(strSeparatorArray[i]) != -1) {
      intDateSeparatorIdx = i;
      break;
    }
  }

  if (intDateSeparatorIdx != intFormatSeparatorIdx) {
    return false;
  }

  if (intDateSeparatorIdx != -1) {
    strFormatArray = strFormatString.split(strSeparatorArray[intFormatSeparatorIdx]);
    if (strFormatArray.length != 3) {
      return false;
    }

    strDateToCheckArray = strDateToCheck.split(strSeparatorArray[intDateSeparatorIdx]);
    if (strDateToCheckArray.length != 3) {
      return false;
    }

    for (i=0; i<strFormatArray.length; i++) {
      if (strFormatArray[i] == 'mm' || strFormatArray[i] == 'mmm') {
        strMonth = strDateToCheckArray[i];
      }

      if (strFormatArray[i] == 'dd') {
        strDay = strDateToCheckArray[i];
      }

      if (strFormatArray[i] == 'yyyy') {
        strYear = strDateToCheckArray[i];
      }
    }
  } else {
    if (FormatString.length > 7) {
      if (strFormatString.indexOf('mmm') == -1) {
        strMonth = strDateToCheck.substring(strFormatString.indexOf('mm'), 2);
      } else {
        strMonth = strDateToCheck.substring(strFormatString.indexOf('mmm'), 3);
      }

      strDay = strDateToCheck.substring(strFormatString.indexOf('dd'), 2);
      strYear = strDateToCheck.substring(strFormatString.indexOf('yyyy'), 2);
    } else {
      return false;
    }
  }

  if (strYear.length != 4) {
    return false;
  }

  intday = parseInt(strDay, 10);
  if (isNaN(intday)) {
    return false;
  }
  if (intday < 1) {
    return false;
  }

  intMonth = parseInt(strMonth, 10);
  if (isNaN(intMonth)) {
    for (i=0; i<strMonthArray.length; i++) {
      if (strMonth == strMonthArray[i]) {
        intMonth = i+1;
        break;
      }
    }
    if (isNaN(intMonth)) {
      return false;
    }
  }
  if (intMonth > 12 || intMonth < 1) {
    return false;
  }

  intYear = parseInt(strYear, 10);
  if (isNaN(intYear)) {
    return false;
  }
  if (IsLeapYear(intYear) == true) {
    intDaysArray[1] = 29;
  }

  if (intday > intDaysArray[intMonth - 1]) {
    return false;
  }
  
  return true;
}

function IsLeapYear(intYear) {
  if (intYear % 100 == 0) {
    if (intYear % 400 == 0) {
      return true;
    }
  } else {
    if ((intYear % 4) == 0) {
      return true;
    }
  }

  return false;
}

function rowOverEffect(object) {
  if (object.className == 'moduleRow') object.className = 'moduleRowOver';
}

function rowOutEffect(object) {
  if (object.className == 'moduleRowOver') object.className = 'moduleRow';
}

function popupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width=450,height=280,screenX=150,screenY=150,top=150,left=150')
}

function setProductWishList() {
	document.getElementById('wishlist_x').value='wishlist';
	document.cart_quantity.submit();
}

function setOpWishList(param) {
	if(param == 'add') {
		document.getElementById('hdn_op_wshlst').value='add_prod_x';
		document.wishlist_form.submit();
	} else if(param == 'del') {
		document.getElementById('hdn_op_wshlst').value='delete_prod_x';
		document.wishlist_form.submit();
	}
}

// check cgv - order confirmation
function checkConfirmDevisDemande() {
	if(!document.getElementById('conditions').checked) {
		alert("Pour confirmer votre demande de devis la case conditions générales de vente doit étre cochée !");
		return false;
	} else {
		return true;
	}
	return true;
}

// check quotation demand form
function checkQuotationRequestForm() {
	var _lname = trim(document.getElementById('lname').value);
	//var _address = trim(document.getElementById('address').value);
	var _zipCode = trim(document.getElementById('zipCode').value);
	var _city = trim(document.getElementById('city').value);
	var _tel = trim(document.getElementById('tel').value);
	var _email = trim(document.getElementById('email').value);
	var _comment = trim(document.getElementById('comment').value);
	if(_lname=='' || _zipCode=='' || _city=='' || _tel=='' || _email=='' || _comment=='') {
		alert("Veuillez remplir tous les champs obligatoire !");
		return false;
	} else if(!checkPhoneNumber(_tel)) {
		alert("Veuillez saisir un numéro de téléphone valide !");
		return false;
	} else if(echeck(_email)==false) {
	      alert('Adresse email invalide !');
	      return false;
	} else if(_lname.length < 2) {
		alert("Le nom doit comporter au minimum 2 lettres !");
		return false;
	} else if(_zipCode.length < 5) {
		alert("Le code postal doit comporter au minimum 5 caractères !");
		return false;
	} else if(_city.length < 2) {
		alert("La ville doit comporter au minimum 2 lettres !");
		return false;
	} else if(!document.getElementById('newsletterChoice_yes').checked && !document.getElementById('newsletterChoice_non').checked) {
		alert("Veuillez spécifier votre choix à propos de nos prochaines offres !");
		return false;
	} else if(!document.getElementById('conditions').checked) {
		alert('Pour confirmer votre demande de devis la case conditions générales d\'utilisation doit étre cochée !')
		return false;
	} else {
	//_imgListAry.length
		return true;
	}
}

function echeck(str) {
	var at="@"
	var dot="."
	var lat=str.indexOf(at)
	var lstr=str.length
	var ldot=str.indexOf(dot)
	if (str.indexOf(at)==-1){
	   //alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr){
	   //alert("Invalid E-mail ID")
	   return false
	}

	if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr){
		//alert("Invalid E-mail ID")
		return false
	}

	 if (str.indexOf(at,(lat+1))!=-1){
		//alert("Invalid E-mail ID")
		return false
	 }

	 if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot){
		//alert("Invalid E-mail ID")
		return false
	 }

	 if (str.indexOf(dot,(lat+2))==-1){
		//alert("Invalid E-mail ID")
		return false
	 }
	
	 if (str.indexOf(" ")!=-1){
		//alert("Invalid E-mail ID")
		return false
	 }

	 return true					
}

// function check phone numbre
	function checkPhoneNumber(_phn) {
		switch(_phn) {
			case "0": return false; break;
			case "00": return false; break;
			case "000": return false; break;
			case "0000": return false; break;
			case "00000": return false; break;
			case "000000": return false; break;
			case "0000000": return false; break;
			case "00000000": return false; break;
			case "000000000": return false; break;
			case "0000000000": return false; break;
			default: return true;
		}
	}
//

// bandeau adv
/*var imgPath = new Array;
var SiClickGoTo = new Array;
var version = navigator.appVersion.substring(0,1);
var _imageCount = 0;
function setIntiValues(_imgList) {
	if (version >= 3) {
		_imgListAry = _imgList.split(",");
		_imageCount=_imgListAry.length;
		for(var j=0; j<_imgListAry.length; j++) {
			i = new Image;
			i.src = _imgListAry[j];
			SiClickGoTo[j] = "";
			imgPath[j] = i.src;
		}
	}
}*/

/*var version = navigator.appVersion.substring(0,1);
var imgPath = new Array;
function StartAnim(_imgList, _animBloc) {
	a = 0;
	var SiClickGoTo = new Array;
	_imgListUniq = _imgList.split("|");
	for(var k=0; k<_imgListUniq.length; k++) {
		var _imageCount = 0;
		if (version >= 3) {
			_imgListAry = _imgListUniq[k].split(",");
			_imageCount=_imgListAry.length;
			for(var j=0; j<_imgListAry.length; j++) {
				i = new Image;
				i.src = _imgListAry[j];
				SiClickGoTo[j] = "";
				imgPath[j] = i.src;
			}
		}

		if (version >= 3) {
			document.getElementById(_animBloc).innerHTML += '<A HREF="#" onClick="ImgDest();return(false)">SALAM<IMG SRC="images/monimage.jpg" BORDER=0 ALT=Menu NAME=defil id="defil'+k+'"></A>';
			defilimg(a, _imageCount, imgPath, k);
		}
	} // end for(var k=0; k<_imgListUniq.length; k++)
}
/*function ImgDest() {
	document.location.href = SiClickGoTo[a-1];
}*/


/*function defilimg(a, _imageCount, imgPath, k) {
	if (a == _imageCount) {
		a = 0;
	}
	if (version >= 3) {
		//document.defil.src = imgPath[a];
		document.getElementById('defil'+k).src = imgPath[a];
		a++;
		tempo3 = setTimeout("defilimg("+a+", "+_imageCount+", '"+imgPath+"', "+k+")",2000);
	}
}*/

var imgPath = new Array;
function bndClass(_imgList, _animBloc, idBloc, pos) {
	this.version = navigator.appVersion.substring(0,1);
	this.SiClickGoTo = new Array;
	this._imageCount = 0;
	this.a = 0;
	this.getAnim = function() {
		_imgListAry = _imgList.split(",");
		this._imageCount=_imgListAry.length;
		/*for(var j=0; j<_imgListAry.length; j++) {
			i = new Image;
			i.src = _imgListAry[j];
			this.SiClickGoTo[j] = "";
			imgPath[j] = _imgListAry[j]; //i.src;
		}*/
		defilimg(this.a, this._imageCount, _imgList, idBloc, pos);

	}
}

function StartAnim(_imgList, _animBloc, pos) {
	_imgListAryPipe = _imgList.split("|");
	for(var j=0; j<_imgListAryPipe.length; j++) {
		document.getElementById(_animBloc).innerHTML += '<div id="defil_'+pos+'_'+j+'"></div>';
		var obj = new bndClass(_imgListAryPipe[j], _animBloc, j, pos);
		obj.getAnim();
	}
}

function defilimg(a, _imageCount, _imgList, idBloc, pos) {
	imgPath = _imgList.split(",");
	if (a == _imageCount) {
		a = 0;
	}
	var _htmlOutput = '';
	_imgTypes = imgPath[a].split("::");
	if(_imgTypes[0] == '2') {
		_animParts = _imgTypes[1].split("_@_");
		_htmlOutput = '<div>';
		_htmlOutput += '<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,29,0" width="'+_animParts[1]+'" height="'+_animParts[2]+'">';
		_htmlOutput += '<param name="movie" value="images/bnd/'+_animParts[0]+'" />';
		_htmlOutput += '<param name="quality" value="high" />';
		_htmlOutput += '<embed src="images/bnd/'+_animParts[0]+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="'+_animParts[1]+'" height="'+_animParts[2]+'"></embed>';
		_htmlOutput += '</object>';
		_htmlOutput += '<div style="clear: both;"></div></div>';
		document.getElementById('defil_'+pos+'_'+idBloc).innerHTML = _htmlOutput; //'<img src="images/bnd/'+imgPath[a]+'" alt="" border="0" width="120" height="100" />'; //imgPath[a];
	} else {
		_imgParts = _imgTypes[1].split("_@_");
		if(_imgParts[1] != '') _htmlOutput += '<a href="http://'+_imgParts[1]+'" target="_blank">';
		_htmlOutput += '<img src="images/bnd/'+_imgParts[0]+'" alt="" border="0" width="120" height="100" />';
		if(_imgParts[1] != '') _htmlOutput += '</a>';
		document.getElementById('defil_'+pos+'_'+idBloc).innerHTML = _htmlOutput; //'<img src="images/bnd/'+imgPath[a]+'" alt="" border="0" width="120" height="100" />'; //imgPath[a];
		a++;
		tempo3 = setTimeout("defilimg("+a+", "+_imageCount+", '"+_imgList+"', "+idBloc+", '"+pos+"')",2000);
	}
}


function _checkNewsletterFormBtm() {
	if(!echeck($('subNsLr').value)) {
		alert('Veuillez saisir une adresse e-mail valide !');
		//return false;
	} else {
		document.subNsLr_frm.submit();
	}
}
