function terk_copyAddress(){


var ok = document.getElementById('jd_livra_idem').checked;


if (ok){
var lesInputs = document.getElementsByTagName('input');
var lim= lesInputs.length;
var temp;
var cible = null;
for(var n = 0; n < lim; n++){
	
	temp = lesInputs[n];
	if(temp.name.indexOf('jd_fact_') ===-1){continue;}
	
	cible = document.getElementById(temp.name.replace('jd_fact_','jd_livra_'));
	cible.value = temp.value;
	cible.disabled = true;
	}

// on change aussi le menu civilité :

document.getElementById('jd_livra_civilite').selectedIndex = document.getElementById('jd_fact_civilite').selectedIndex ;
document.getElementById('jd_livra_civilite').disabled = true;

} else {

var lesInputs = document.getElementsByTagName('input');
var lim= lesInputs.length;
var cible = null;

for(var n = 0; n < lim; n++){
	cible = lesInputs[n];
	if(cible.name.indexOf('jd_livra_') ===-1){continue;}
	cible.value = cible.defaultValue;
	cible.disabled = false;
	}
document.getElementById('jd_livra_civilite').disabled = false;
}

}
//--------------------------------------------
//
//
//--------------------------------------------

function terk_check_client_addresses(formu){




if (document.getElementById('jd_fact_nom').value.length == 0){ 
	alert("Le champs nom est obligatoire");
	return false;
	}

if (document.getElementById('jd_fact_rue1').value.length == 0){ 
	alert("Le champs adresse est obligatoire");
	return false;
	}
	
if (document.getElementById('jd_fact_ville').value.length == 0){ 
	alert("Le champs Ville est obligatoire");
	return false;
	}	

if (document.getElementById('jd_fact_cp').value.length == 0){ 
	alert("Le champs code postal est obligatoire");
	return false;
	}	

// livraison

if(document.getElementById('jd_livra_idem').checked){terk_copyAddress();}


if( (document.getElementById('jd_livra_nom').value.length == 0) || (document.getElementById('jd_livra_rue1').value.length == 0) || (document.getElementById('jd_livra_ville').value.length == 0) ){
		terk_copyAddress();
	}


return true;

}
//--------------------------------------------
//
//
//--------------------------------------------
function terk_check_new_client(f){
var email = f.elements['terk_email'].value;
var pass = f.elements['terk_password'].value;

if (!isValidEmail(email) ){
		alert('Un email valide est requis');
		return false;
	}

if (pass.length < 4){
	alert('le mot de passe est trop court');
	return false;
	}
	
if( pass != f.elements['terk_password2'].value){
	alert('Les mots de passe de sont pas identiques');
	return false;
	}
return true;

}
//--------------------------------------------
//
//
//--------------------------------------------
function terk_changeAmount(val){

if (!val){return true;}
	var montant = parseFloat(val.replace(',','.'));
	if(isNaN(montant)){return true;}
	
	document.getElementById('zone_montant').innerHTML = ' &euro; ' + montant.toFixed(2).replace('.',',');
	return true;
}
//--------------------------------------------
//
//
//--------------------------------------------
function terk_checkAmount(ceChamps){
	ceChamps.value = parseFloat(ceChamps.value.replace(',','.')).toFixed(2);
	return true;
}
//--------------------------------------------
//
//
//--------------------------------------------
function terk_cheque_cadeau_confirm(ceForm){

// on met un nombre acceptable :

terk_checkAmount(ceForm.elements['cadeau_montant']);
montant = ceForm.elements['cadeau_montant'].value ;

var email = ceForm.elements['cadeau_email'].value.trim();
var email2 = ceForm.elements['cadeau_email2'].value.trim();


if (!isNum(montant) || (montant.length == 0) || (montant <= 0)){
		alert('Un montant num\xe9rique est requis');
		return false;
	}

if (!isValidEmail(email) ||  (email.length == 0) ){
		alert('Un email valide est requis');
		return false;
	}

if (email != email2 ){
		alert('Les deux emails saisis sont diff\xe9rents');
		return false;
	}

var jd_ok = confirm('Vous ne pourrez plus modifier l\'email du b\xe9n\xe9ficiare ni le message. Confirmez l\'exp\xe9dition ?');
if (!jd_ok){
	return false;
	}

return true;

}
//--------------------------------------------
//
//
//--------------------------------------------
String.prototype.trim = function() {
    return this.replace( /^\s+|\s+$/, '' );
}
//--------------------------------------------
//
//
//--------------------------------------------
function isNum(num){
	
	return ! isNaN(num);
}
//--------------------------------------------
//
//
//--------------------------------------------
function isValidEmail(email){
		var re = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		return re.test(email);
}
//--------------------------------------------
//
//
//--------------------------------------------
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.com
//
function trk_getPageScroll(){

	var xScroll, yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
		xScroll = self.pageXOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
		xScroll = document.documentElement.scrollLeft;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
		xScroll = document.body.scrollLeft;	
	}

	arrayPageScroll = new Array(xScroll,yScroll) 
	return arrayPageScroll;
}

//------------------------
//
//------------------------
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.com
// Edit for Firefox by pHaez
//
function trk_getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = window.innerWidth + window.scrollMaxX;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	
//	console.log(self.innerWidth);
//	console.log(document.documentElement.clientWidth);

	if (self.innerHeight) {	// all except Explorer
		if(document.documentElement.clientWidth){
			windowWidth = document.documentElement.clientWidth; 
		} else {
			windowWidth = self.innerWidth;
		}
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

//	console.log("xScroll " + xScroll)
//	console.log("windowWidth " + windowWidth)

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = xScroll;		
	} else {
		pageWidth = windowWidth;
	}
//	console.log("pageWidth " + pageWidth)

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}




//------------------------
//
//------------------------
function trk_isImageOk(img) {
    // During the onload event, IE correctly identifies any images that
    // weren't downloaded as not complete. Others should too. Gecko-based
    // browsers act like NS4 in that they report this incorrectly.
    if (!img.complete) {
        return false;
    }

    // However, they do have two very useful properties: naturalWidth and
    // naturalHeight. These give the true size of the image. If it failed
    // to load, either of these should be zero.
    if (typeof img.naturalWidth != "undefined" && img.naturalWidth == 0) {
        return false;
    }

    // No other way of checking: assume it's ok.
    return true;
}

//------------------------
//
//------------------------
function trk_checkForBrokenImages(callback) {
    trk_doAttach(window, "load", function() {
        for (var i = 0; i < document.images.length; i++) {
        
            if (! trk_isImageOk(document.images[i])) {
                callback(document.images[i]);
            }
        }
    });
}

//------------------------
//
//------------------------
function jd_swap(what, temoin){ // fiche
	document.getElementById(temoin).src = document.getElementById(what).src;
}
//------------------------
//
//------------------------
function jd_changeColor(coloris, temoin){ // fiche


		
	// rendre invisibles toutes les lignes miniatures
	var lesLignes = document.getElementsByTagName('p');
	var combien = lesLignes.length;
	for (var n = 0 ; n < combien ; n++){
		if(lesLignes[n].className.indexOf('ligne_miniatures') === -1){continue;}
		lesLignes[n].style.display = 'none';
		}
	
	// rendre visible les bonnes miniatures
	document.getElementById('ligne_miniature_coloris_' + coloris).style.display ='block';
	
	// changer l'image principale
	
	document.getElementById(temoin).src = document.getElementById('jd_coloris_'+ coloris +'_miniature_0').src;
	
	// masquer tous les menus taille :
	var LesMenus = document.getElementsByTagName('select');
	var combien = LesMenus.length;
	for (var n = 0 ; n < combien ; n++){
		if(LesMenus[n].name.indexOf('fi_taille_') === -1){continue;}
		LesMenus[n].style.display = 'none';
		}
	// rendre visible le bon :
	document.getElementById('fi_taille_'+ coloris ).style.display = 'inline';
	
	// connaitre la premiere "value"
	var indexPrix = document.getElementById('fi_taille_'+ coloris ).options[0].value;
	// remettre le menu "en haut"
	document.getElementById('fi_taille_'+ coloris ).selectedIndex = 0;
	// recalculer le prix
	terk_updateWithSize(indexPrix);

	
}


//------------------------
//
//------------------------

//$$$$$$$$$$$$$$$$$$$$
function trk_doAttach( obj, eventName, callback){
if (obj.addEventListener){
	// 'onmousedown' --> 'mousedown'
	var shortEventName = (eventName.substring(0,2).toLowerCase()=='on') ?eventName.substring(2):eventName ;
	obj.addEventListener(shortEventName,callback, false);
} else if(obj.attachEvent){
	obj.attachEvent(eventName,callback );

} else {
	if(document.captureEvents){
	// 'mousedown' --> 'onmousedown'
	var longEventName = (eventName.substring(0,2).toLowerCase()!='on') ? 'on'+eventName:eventName ;
	document.captureEvents(Event.CLICK | Event.KEYUP | Event.MOUSEOVER | Event.MOUSEDOWN);
	}
	obj[eventName] = callback;
	}
}

//$$$$$$$$$$$$$$$$$$$$

