var isIE = document.all;
var isIE6 = isIE && document.implementation;
var isIE5 = isIE && window.print && !isIE6;
var isIE4 = isIE && !isIEDOM2 && navigator.cookieEnabled;
var isIE3 = isIE && !isIE4 && !isIEDOM2;
var isNS = navigator.mimeTypes && !isIE;
var isNS3 = isNS && !navigator.language;
var isNS4 = document.layers;
var isNS6 = document.getElementById && !isIE;
var isNS7 = isNS6;
var isNS71 = document.designMode;
var isNSDOM2 = isNS6;
var isDOM2 = isIEDOM2 || isNSDOM2;
var isMacIE = document.all && !window.print;
var isWin = navigator.userAgent.indexOf("Win") > -1;
var isMac = navigator.userAgent.indexOf("Mac") > -1;
var isOpera = (navigator.userAgent.toLowerCase().indexOf('opera') > -1); 
var isIEDOM2 = isIE5 || isIE6 && !isOpera;
var IsDom = document.getElementById
var IsSP2 = window.navigator.userAgent.indexOf("SV1") > -1

function PLg(obj){return document.getElementById(obj)}

function ResetField(obj){if(obj.value != ""){obj.value=''}}

String.prototype.Trim = function () {
	return this.replace(/\s+/g,"");
}

//methode sur la classe String : validité d'un email
/*String.prototype.isValidEmail = function () {
    var re=/^[a-z\d]+((\.|-|_)[a-z\d]+)*@((?![-\d])[a-z\d-]{0,62}[a-z\d]\.){1,4}[a-z]{2,6}$/gi;
    return re.test(this);
}
*/

//methode sur la classe String : validité d'un email
String.prototype.isValidEmail=function(){
	var A=/^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
	return A.test(this)};


function OpenWin(theURL,winName,varWidth, varHeight){window.open(theURL, winName,'width='+varWidth+',height='+varHeight+',resizable=no,scrollbars=yes')}

// redimensionner une page en fonction de la taille de l'image
function PopupImage(img) {
	titre="Popup";
	w=open("",'image','width=400,height=400,toolbar=no,scrollbars=no,resizable=yes');	
	w.document.write("<HTML><HEAD><TITLE>"+titre+"</TITLE>");
	w.document.write("<SC"+"RIPT language=java"+"script> function checksize()  { if (document.images['img'].complete) {  window.resizeTo(document.images[0].width + 15,document.images[0].height + 30); window.focus();} else { setTimeout('checksize()',250) } }</"+"SCRIPT></HEAD>");
	w.document.write("<BODY onload='checksize();window.print();' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0><IMG src='"+img+"' border=0 name='img'>");
	w.document.write("");
	w.document.write("</BODY></HTML>");
	w.document.close();
}


// Suppression des espaces
function trim(string) 
{ 
return string.replace(/(^\s*)|(\s*$)/g,''); 
} 

String.prototype.checkValue = function (TheTitle) {
	if(this.Trim() == TheTitle.Trim() || !this.Trim().length) return false
	else return true
}

function PopUp(theURL,twidth,theight){
if(!twidth)twidth=500
if(!theight)theight=360
params ='location=no,status=no,menubar=no,toolbar=no,resizable=no,scrollbars=yes,width='+twidth+',height='+theight+',left = 10,top =10';
	
	window.open(theURL,'fotodiscount',params);
}

function PLgetPosLeft(obj){if (obj.offsetParent)return (obj.offsetLeft + PLgetPosLeft(obj.offsetParent));else return (obj.offsetLeft)}
function PLgetPosTop(obj){if (obj.offsetParent)return (obj.offsetTop + PLgetPosTop(obj.offsetParent));else return (obj.offsetTop)}

function GTO(Otype){
	return document.getElementsByTagName(Otype)
}

function LogOut(){
	if(confirm(trads[1])){
		document.location = '/logout.cfm?'+ValueString
	}
}

var ResDtype=null

function FieldFocus(obj,Dtype){
	obj.className = 'inputs_A'
	if(obj.value.Trim() == obj.title.Trim()){obj.value=''}
	if(!Dtype){ResDtype = null}
	else{ResDtype = Dtype}
	
	if(obj.title!=""){
		PLg("fieldComment").innerHTML=obj.title
		if(obj.lang==1)PLg("fieldComment").innerHTML+=' <em class=red>('+trads[2]+')</em>'
		vdecal = -13; hdecal=0
		if(isOpera){vdecal = -10; hdecal=3}
		PLg("fieldComment").style.top = PLgetPosTop(obj)+vdecal
		PLg("fieldComment").style.left = PLgetPosLeft(obj)+hdecal
	}
	obj.onblur = UnFieldFocus
}

function UnFieldFocus(){
	this.className = 'inputs_'
	PLg("fieldComment").style.top = -500
	PLg("fieldComment").style.left = -500
	this.onblur = null

	if(ResDtype){
		if(ResDtype=='num'){
			if(!this.value.Trim().length || isNaN(this.value.Trim()) || this.value < 0 || this.value.indexOf(".")>-1){this.value = 1;alert(trads[3])}
		}
		if(ResDtype=='email'){
			if(this.value.Trim().length && !this.value.isValidEmail()){alert(trads[4])}
		}
		ResDtype = null
	}
	if(this.tagName == 'SELECT'){
		if(isNS) this.parentNode.style.border='0px solid white'
		else this.parentElement.style.border='0px solid white'
	}
	else{
		if(this.value.Trim() == ''){this.value = this.title}
	}
}

function DisplayFieldComment(str,Target){
	PLg("fieldComment").innerHTML=str
	PLg("fieldComment").style.top = PLgetPosTop(Target)
	PLg("fieldComment").style.left = PLgetPosLeft(Target)
}

function DisplayPopUp(data,isEscap){
	checkFormObjects(1)
	PLg('PopupReceptor').innerHTML='<div id="DivShadow"></div><div class="DivPopups" id="PopupBox">'+data+'</div>'	
	
	if(!isEscap)document.body.onkeypress=EscapeForCancelPopup
	
	refreshPopUp()
	onresize=refreshPopUp
	window.setTimeout("CallPopupBack()", 1)
}

function CallPopupBack(){PLg('PopupBack').style.visibility = 'visible'}

function PlaceDivPopup(arg){
	Xdecal = 3;	Ydecal = 5
	PLg(arg).style.left = PLgetPosLeft(PLg('MainTable'))+Xdecal;
	if(isIE){
		PLg(arg).style.top = PLgetPosTop(PLg('MainTable'))+Ydecal+document.body.scrollTop;
		PLg(arg).style.width='590px';
	}
	else{
		PLg(arg).style.top = PLgetPosTop(PLg('MainTable'))+Ydecal+window.pageYOffset
	}
}
// Repositionne calques modaux
function refreshPopUp(){
	PlaceDivPopup('PopupBox')
	PlaceDivPopup('DivShadow')
	PLg('DivShadow').style.height=PLg('PopupBox').offsetHeight
	if(PLg('PopupBack').offsetWidth < 10)PLg('PopupBack').style.width=GetWinSize('w')
	PLg('PopupBack').style.height=GetWinSize('h')
}
// Annule Popup
function CancelPopupDiv(){
	PLg('PopupReceptor').innerHTML=''
	PLg('PopupBack').style.visibility = 'hidden'
	PLg('PopupBack').style.height='100px';
	checkFormObjects(0)
	onresize=null
}

// escape annulation popup
function EscapeForCancelPopup(e){
	var TheEvent=(e)? e.keyCode : event.keyCode;
	if(TheEvent==27){
		CancelPopupDiv()
	}
	document.body.onkeypress=null
}

// Retourne la taille du browser
function GetWinSize(arg){
	if(isMacIE){
		if(arg=='w'){return parseInt(document.body.clientWidth-15,10)}
		else{
			return parseInt(document.body.clientHeight,10)+parseInt(document.body.scrollTop,10)
		}
	}
	else if(isIE){
		if(arg=='w'){return parseInt(document.body.clientWidth,10)}
		else{
			if(parseInt(document.body.scrollHeight,10) > parseInt(document.body.clientHeight,10)){
				return parseInt(document.body.scrollHeight,10)
			}
			else{
				return parseInt(document.body.clientHeight,10)
			}
		}
	}
	else{
		if(arg=='w'){return parseInt(window.innerWidth,10)-15;}
		else{return parseInt(window.innerHeight+window.pageYOffset,10)}
	}
}



// Masque/affiche inputs pour calques modaux
var Selects
function checkFormObjects(arg){
if(isIE){
	if(arg){
		Selects=document.getElementsByTagName("select")
		for(i=0;i<Selects.length;i++){
				Selects[i].style.visibility='hidden'
		}
	}
	else{
		if(Selects.length>0){
			for(i=0;i<Selects.length;i++){
				Selects[i].style.visibility='visible'
			}
		}
	}
}
}


//Redimensionnement d'une page enfonction des largeur et hauteur de l'image
function PopupImage(img) {
	titre="Image";
	w=open("",'image','width=400,height=400,toolbar=no,scrollbars=no,resizable=no');	
	w.document.write("<HTML><HEAD><TITLE>"+titre+"</TITLE></HEAD>");
	w.document.write("<SCRIPT language=javascript>function checksize()  { if (document.images[0].complete) {  window.resizeTo(document.images[0].width+12,document.images[0].height+30); window.focus();} else { setTimeout('check()',250) } }</"+"SCRIPT>");
	w.document.write("<BODY onload='checksize()' leftMargin=0 topMargin=0 marginwidth=0 marginheight=0><IMG src='"+img+"' border=0>");
	w.document.write("");
	w.document.write("</BODY></HTML>");
	w.document.close();
}

String.prototype.isValidDate = function () {
	/* si la date est au format dd/mm/yyyy */   
   var ladate = (this).split("/");
	
   if ((ladate.length != 3) || isNaN(parseInt(ladate[0])) || isNaN(parseInt(ladate[1])) || isNaN(parseInt(ladate[2]))) return false;

   var unedate = new Date(eval(ladate[2]),eval(ladate[1])-1,eval(ladate[0]));
   
   var annee = unedate.getYear();
   if ((Math.abs(annee)+"").length < 4) annee = annee + 1900;

   return ((unedate.getDate() == eval(ladate[0])) && (unedate.getMonth() == eval(ladate[1])-1) && (annee == eval(ladate[2])));
}



// Verif des dates
function verif_date(input)
{
	var regex = new RegExp("[/]");
	var date = input.split(regex);
	var nbJours = new Array('',31,28,31,30,31,30,31,31,30,31,30,31);
	var result = true;
	
	if ( date['2']%4 == 0 && date['2']%100 > 0 || date['2']%400 == 0 )
	nbJours['2'] = 29;
	
	if( isNaN(date['2']) || date['2'] > 2100 || date['2'] < 1890 )
	result=false;
	
	if ( isNaN(date['1']) || date['1'] > 12 || date['1'] < 1 )
	result=false;
	
	if ( isNaN(date['0']) || date['0'] > nbJours[Math.round(date['1'])] || date['0'] < 1 )
	result=false;
	
	return result;
}

	
function placeObj(px,py) 
		{
			var div1 = document.getElementById("diver").style;
			var objet;
	  	div1.left=px;
	  	div1.top=py;
	 	}

function voirGdeImg() 
		{
	  	var posy;
	  	if (navigator.appName=="Microsoft Internet Explorer") 
			{
				offsety = document.body.scrollTop;
				offsetx = document.body.scrollLeft;
			}
	  	else 
			{
				offsety = window.pageYOffset;
				offsetx = window.pageXOffset;				
			}
	  placeObj(400,offsety + 200);
		tempo = setTimeout("voirGdeImg()",10);
		}



function Photo_Show(src) {
	document.all["large_photo"].src = src;
	var div=document.all.item("diver");
	voirGdeImg();
	//div.style.posTop=20;
	//div.style.posLeft=150;
	div.style.visibility="";
}

function Cache(num)
{
	var div=document.all.item("diver");
	div.style.visibility="hidden";
	document.all["large_photo"].src = "";
}


function OpenWindowToPrint(image)
{
	windowUrl = 'print.php?image=' + image
	windowParam = 'width=1,height=1,left=10,top=10,scrollbars=0,menubar=0'
	window.open(windowUrl,'Commande',windowParam);
}


function PollDisplayPopUp(data,isEscap){
	checkFormObjects(1)
	PLg('PopupReceptor').innerHTML='<div id="DivShadow"></div><div class="DivPopups" id="PopupBox">'+data+'</div>'	
	if(!isEscap)document.body.onkeypress=PollEscapeForCancelPopup
	
	PollrefreshPopUp()
	onresize=PollrefreshPopUp
	window.setTimeout("PollCallPopupBack()", 1)
}

function PollCallPopupBack(){PLg('PopupBack').style.visibility = 'visible'}

function PollPlaceDivPopup(arg){
	Xdecal = 100;	Ydecal = 5
	PLg(arg).style.left = PLgetPosLeft(PLg('MainTable'))+Xdecal;
	if(isIE){
		PLg(arg).style.top = 250+document.body.scrollTop;
		PLg(arg).style.width='850px';
	}
	else{
		PLg(arg).style.top = 250+window.pageYOffset;
	}
}
// Repositionne calques modaux
function PollrefreshPopUp(){
	PollPlaceDivPopup('PopupBox')
	PollPlaceDivPopup('DivShadow')
	PLg('DivShadow').style.height=PLg('PopupBox').offsetHeight
	if(PLg('PopupBack').offsetWidth < 10)PLg('PopupBack').style.width=GetWinSize('w')
	PLg('PopupBack').style.height=GetWinSize('h')
}
// Annule Popup
function PollCancelPopupDiv(){
	PLg('PopupReceptor').innerHTML=''
	PLg('PopupBack').style.visibility = 'hidden'
	PLg('PopupBack').style.height='100px';
	checkFormObjects(0)
	onresize=null
}

// escape annulation popup
function PollEscapeForCancelPopup(e){
	var TheEvent=(e)? e.keyCode : event.keyCode;
	if(TheEvent==27){
		PollCancelPopupDiv()
	}
	document.body.onkeypress=null
}

function GTO(Otype){
	return document.getElementsByTagName(Otype)
}



function ejs_img_fx(img) {
	if(img && img.filters && img.filters[0]) {
		img.filters[0].apply();
		img.filters[0].play();
	}
}

function StartAnim() {
	if (document.images) {
			document.write('<A HREF="#" target="_blank" onClick="ImgDest();return(false)"><IMG SRC="'+i0.src+'" BORDER="1" ALT="" NAME="defil" style="filter:progid:DXImageTransform.Microsoft.Pixelate(MaxSquare=100,Duration=1)" WIDTH="120" height="160" style="border-color:#000000"></A>');
			defilimg()
	} else {
		document.write('<IMG SRC="'+i0.src+'" alt="">');
	}
}



function ImgDest() {
	//document.location.href = SiClickGoTo[a-1];
	window.open(SiClickGoTo[a-1],'openSite','top=10,left=10,location=yes,status=yes,menubar=yes,toolbar=yes,resizable=yes,scrollbars=yes');
}

function defilimg() {
	if (a == imgPath.length) {
		a = 0;
	}
	if (document.images) {
		ejs_img_fx(document.defil)
		document.defil.src = imgPath[a];
		tempo3 = setTimeout("defilimg()",4000);
		a++;
	}
}

// /function anim





function counter() {
	PLg('compteur').value = 1000 - PLg('description').value.length;
}


function TestRegion() {
	if (document.f.elements['idregion[]'].options[0].selected == true) {
		Nb = document.f.elements['idregion[]'].length;
		nb_idregion_selected = 0;
		for (i=1;i<Nb;i++) 	{ 
			document.f.elements['idregion[]'].options[i].selected = false;
		} 
	}
	else {
		document.f.elements['idregion[]'].options[0].selected == false;
	}
}

function VerifPlan() {
	
	erreur_msg = '';
	
	// verif idfamily
	Nb = document.f.elements['idfamily[]'].length;
	nb_idfamily_selected = 0;
	for (i=0;i<Nb;i++) { 
		if(document.f.elements['idfamily[]'].options[i].selected){ nb_idfamily_selected++; } 
	} 
	if (nb_idfamily_selected == 0) {erreur_msg = erreur_msg + 'Vous devez choisir au moins une famille.\n';}
	

	// verif idtype
	Nb = document.f.elements['idtype[]'].length;
	nb_idtype_selected = 0;
	for (i=0;i<Nb;i++) 	{ 
		if(document.f.elements['idtype[]'].options[i].selected){ nb_idtype_selected++; } 
	} 
	if (nb_idtype_selected == 0) { erreur_msg = erreur_msg + 'Vous devez choisir au moins un type.\n';}
	
	// verif idregion
	Nb = document.f.elements['idregion[]'].length;
	nb_idregion_selected = 0;
	for (i=0;i<Nb;i++) 	{ 
		if(document.f.elements['idregion[]'].options[i].selected){ nb_idregion_selected++; } 
	} 
	if (nb_idregion_selected == 0) { erreur_msg = erreur_msg + 'Vous devez choisir au moins une région ou la France entière.\n';}
	
	// Verif champs
	if(PLg('lbplan').value == '') { erreur_msg = erreur_msg + 'Remplissez le nom du plan.\n';}
	if(PLg('description').value == '') { erreur_msg = erreur_msg + 'Remplissez la description du plan.\n';}

	// Verif Dates
	if(verif_date(PLg('dtstart').value)==false || verif_date(PLg('dtend').value)==false) { erreur_msg = erreur_msg + 'Une des dates ne semble pas valide.\n';}
	
	
	if (erreur_msg != '') { 
		alert(erreur_msg);
	}
	else {
		f.submit();
	}
}


function placeObj(px,py) 
		{
			var div1 = document.getElementById("diver").style;
			var objet;
	  	div1.left=px;
	  	div1.top=py;
	 	}

function voirGdeImg() 
		{
	  	var posy;
	  	if (navigator.appName=="Microsoft Internet Explorer") 
			{
				offsety = document.body.scrollTop;
				offsetx = document.body.scrollLeft;
			}
	  	else 
			{
				offsety = window.pageYOffset;
				offsetx = window.pageXOffset;				
			}
	  placeObj(400,offsety + 200);
		tempo = setTimeout("voirGdeImg()",10);
		}



function Photo_Show(src) {
	document.all["large_photo"].src = src;
	var div=document.all.item("diver");
	voirGdeImg();
	//div.style.posTop=20;
	//div.style.posLeft=150;
	div.style.visibility="";
}

function Cache(num)
{
	var div=document.all.item("diver");
	div.style.visibility="hidden";
	document.all["large_photo"].src = "";
}

function pushMe(obj){
	if(typeof obj != 'object')return
	SetOpacity(obj,50)
	setGlobalEvent(obj,"mouseup",function(){SetOpacity(obj,100)})
	setGlobalEvent(obj,"mouseout",function(){SetOpacity(obj,100)})
}


function SetOpacity(obj,val){
	obj.style.opacity = val/100;
	obj.style.filter = 'alpha(opacity=' + val + ')';
}

function setGlobalEvent(obj,evt,fnc){
	if(obj.addEventListener){ // Mozilla
		obj.addEventListener(evt,fnc,false);
	}
	else if (obj.attachEvent){ // IE
		obj.attachEvent('on'+evt,fnc);
	}
}

function testeAlphaNumerique(texte) {
	// on teste ici si la chaîne ne contient bien 
	// que des caractères alphanumérique, minuscules ou majuscules
	// sur 8 caractères, comme pour un mot de passe par exemple
	var comparaison = /^[a-zA-Z0-9]{0,50}$/g;
	if ( comparaison.test(texte)){
		return true;
	} else {
		return false;
	}
}


function FocusRouge(champ) {
	PLg(champ).style.borderColor = 'F10';
}