var checked = new Array();
var counts = new Array();
var ids = new Array();
if (document.images) {
	// TRy preloading the images, to avoid a delai when clicking the javascript
	minImage = new Image;
	plusImage = new Image;
	minImage.src = "/_img/icons/min.gif";
	plusImage.src = "/_img/icons/plus.gif";
}

function check_module(pt,id)
{
    if( pt.checked == 1 )
    {
        checked[id] = counts[id];
    }
    else
    {
        checked[id] = parseInt(0);
    }
    
    for(i=0; i< counts[id] ; i++)
    {
		document.getElementById(id + '_' + ids[id][i]).checked = pt.checked;
    }
}

function check_group(pt,modname)
{
		if( pt.checked )
    {
		document.forms['discounts'].elements[modname].checked = 1;
		checked[modname]++;
    } else {
		checked[modname]--;
		if (checked[modname] == 0) {
			document.forms['discounts'].elements[modname].checked = 0;
			
		}
	}
}


if (document.images) {
	// TRy preloading the images, to avoid a delai when clicking the javascript
	minImage = new Image;
	plusImage = new Image;
	minImage.src = "/_img/icons/min.gif";
	plusImage.src = "/_img/icons/plus.gif";
}

function checkAll() {
	NbElt=allChecks.length;
	for(cpt=0;cpt<NbElt;cpt++) {
		checkb = document.getElementById(allChecks[cpt]);
		checka = document.getElementById('all');
		checkb.checked = checka.checked;
	}
}
function toggle(spanId) {
	if (document.getElementById) {
		currentStyle 			= document.getElementById(spanId).style;
		currentStyle.display 	= (currentStyle.display == "block")? "none" : "block";
		if (document.images) {
			newImage					= (currentStyle.display == "none") ? "plusImage.src" : "minImage.src";
			currentImage 				= spanId + 'img';
			document[currentImage].src 	= eval(newImage);
		}
	}
}	

function ShowHide(Show, Hide) {
	if (document.getElementById) {
		thisHide 			= document.getElementById(Hide).style;
		thisHide.display 	= "none";
		thisShow 			= document.getElementById(Show).style;
		thisShow.display 	= "block";
	} else {
		alert('Votre navigateur n\'est pas capable de changer la visibilité de l\'objet');
	}
	return Show;
}

function ColourToggle(Colour) {
	SpanId		= 'colour' + Colour;
	CheckBox	= 'colourcheck' + Colour;
	if (document.getElementById) {
		SwapId 			= document.getElementById(SpanId).style;
		Checked			= document.edit[CheckBox].checked;
		SwapId.display 	= (Checked) ? "block" :  "none";	
	} else {
		alert('Votre navigateur n\'est pas capable de changer la visibilité de l\'objet');
	}
}

function DirectToggle(Id) {
	SpanId	= 'article_' + Id
	CheckId	= 'check_' + Id
	if (document.getElementById) {
		SwapId 			= document.getElementById(SpanId).style;
		Checked			= document.getElementById(CheckId).checked;
		SwapId.display 	= (Checked) ? "block" :  "none";
	} else {
		alert('Votre navigateur n\'est pas capable de changer la visibilité de l\'objet');
	}
}

PhotoValue		= 1;
	CountryValue 	= 1;
	PaymentValue 	= 1;
	VarValue 		= 1;
	ColourValue		= 1;
function UpdateText(FieldName, NewText, ThisTab) {
		if (FieldName == 'keywords') {
			if (!NewText) {
				return FALSE;
			}
			NewText = '<input type="hidden" name="keywords\[\]" value="' + NewText + '">' + NewText + ', '; 
		} 
		if (FieldName == 'photos') {
			FieldName += PhotoValue;
			PhotoValue++;
		}
		if (FieldName == 'countries') {
			FieldName += CountryValue;
			CountryValue++;
		}
		if (FieldName == 'payments') {
			FieldName += PaymentValue;
			PaymentValue++;
		}
		if (FieldName == 'variation') {
			FieldName += VarValue;
			VarValue++;
		}
		if (FieldName == 'colour') {
			FieldName += ColourValue;
			VarValue++;
		}
		if (document.getElementById) {
			if (FieldName == 'keywords') {
				thisTeam = document.getElementById(FieldName);
				thisTeam.innerHTML = thisTeam.innerHTML + NewText;
			} else {
				if (PhotoValue <= 11) {
					thisTeam = document.getElementById(FieldName).style;
					thisTeam.display = "block";
				} else {
					alert('Vous ne pouvez ajouter que 10 photos ŕ la fois');
				}
			}
		}
	}


function popwindow(name, url, width, height, toolbar, menubar, statusbar, scrollbar, resizable) {
	var adj=10
	var w = screen.width;
	var h = screen.height;
	var byFactor=1;

	var lift=0.93;
	if(w<740){
	  lift=0.90;
	}
	if(w>=740 & w<835){
	  lift=0.91;
	}
	var scrWidth = w-adj;
	var scrHeight = (h*lift)-adj;
	var top=0;
	var left=0;
	top =  ((h-height/lift-adj)/2);
	left = ((w-width-adj)/2);
	top = parseInt(top);
	left = parseInt(left);

	toolbar_str = toolbar ? 'yes' : 'no';
	menubar_str = menubar ? 'yes' : 'no';
	statusbar_str = statusbar ? 'yes' : 'no';
	scrollbar_str = scrollbar ? 'yes' : 'no';
	resizable_str = resizable ? 'yes' : 'no';
 	window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
}
