/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
function openwin(URL,TITLE,WIDTH,HEIGHT) {
    TITLE=TITLE.replace(/ /ig,'_');
    TITLE=TITLE.replace(/\./ig,'_');
    TITLE=TITLE.replace(/\//ig,'_');
    TITLE=TITLE.replace(/\-/ig,'_');
    fen = window.open (URL,TITLE,"toolbar=0,location=0,directories=0,menuBar=0,scrollbars=1,resizable=1,width="+WIDTH+",height="+HEIGHT+",left=10,top=10");
    if( self.focus ) fen.focus();
}
function Confirmation(URL,Texte){
    if(confirm(Texte)){
        document.location.href=URL
    }
}
function FindRadioValue(NomForm,NomChamp){
    var x;
    x = '';
    var elems = document.getElementById (NomForm);
    if (elems) {
        var inputs = elems.getElementsByTagName ('input');
        if (inputs) {
            for (var i = 0; i < inputs.length; ++i) {
                if (inputs[i].type == 'radio' && inputs[i].name == NomChamp && inputs[i].checked){
                    x = inputs[i].value;
                }
            }
        }
    }
    return x;
}
function FindCheckSelected(NomForm){
    var x;
    x = '';
    var elems = document.getElementById (NomForm);
    if (elems) {
        var inputs = elems.getElementsByTagName('input');
        if (inputs) {
            for (var i = 0; i < inputs.length; ++i) {
                if (inputs[i].type == 'checkbox' && inputs[i].checked){
                    x = x + inputs[i].value + ";";
                }
            }
        }
    }
    return x;
}
function MkURLFromHidden(NomForm){
    var x;
    x = '';
    var elems = document.getElementById (NomForm);
    if (elems) {
        var inputs = elems.getElementsByTagName ('input');
        if (inputs) {
            for (var i = 0; i < inputs.length; ++i) {
                if (inputs[i].type == 'hidden'){
                    var Patern = new RegExp(inputs[i].name,"g");
                    var CurrentValue = x;
                    var result = CurrentValue.match(Patern);
                    if(! result){
                        x = x + '&' + inputs[i].name + '=' + inputs[i].value;
                    }
                }
            }
        }
    }
    return x;
}
function changer(reference,nom) {
    var elems = document.getElementById (reference);
    if (elems) {
        elems.src=nom;
    }
}
function RgbDec2Hex(red,green,blue) {
    var result = "";
    var Colors = new Array(red,green,blue);
    hexChars = "0123456789ABCDEF";
    for(var num in Colors){
        dec = parseInt(Colors[num], 10);
        if (!isNaN(dec) && dec < 255){
            var i = dec % 16;
            var j = (dec - i) / 16;
            result += hexChars.charAt(j) + hexChars.charAt(i);
        }
    }
    if(result.length == 6){
        return result.toLowerCase();
    }
    else {
        return 0;
    }
}
function fichierSelectByThumb(DivID,Cate,ImgId,selectionId,BgColor,BgColorOri,HiddenID,UseAjax){
	var DivObj = document.getElementById(DivID);
	
	//var HiddenObj = document.getElementById(HiddenID);
	var CurrentColor = "";
	var OperationCourante = "";
	
	/*if(DivObj.style.background.substring(0, 3) == 'rgb'){*/
	if(DivObj.style.background.indexOf('rgb(') != -1){
		CurrentColors = DivObj.style.background.split("(");
		CurrentColors = CurrentColors[1].split(")");
		CurrentColors = CurrentColors[0].split(",");
		CurrentColor = RgbDec2Hex(CurrentColors[0].replace(' ',''),CurrentColors[1].replace(' ',''),CurrentColors[2].replace(' ',''));
		CurrentColor = "#" + CurrentColor;
	}
	
	if(DivObj.style.background == '' || CurrentColor == BgColorOri || DivObj.style.background == BgColorOri){
		DivObj.style.background=BgColor;
		//HiddenObj.value = HiddenObj.value + ";" + ImgId;
		OperationCourante = "add";
		
	}
	else if(CurrentColor == BgColor || DivObj.style.background == BgColor){
		
		DivObj.style.background=BgColorOri;
		//HiddenObj.value = HiddenObj.value.replace(ImgId,'');
		//HiddenObj.value = HiddenObj.value.replace(';;',';');
		OperationCourante = "supp";
		
	}
	OperationCourante = OperationCourante+Cate;
	if(OperationCourante != "" && UseAjax == 1){
		
		//makeRequestToElement('ajx_maj_selected.php','type=' + OperationCourante + '&id=' + ImgId,'POST','');
		//alert('index.php?action=vignetteClick&clickType=' + OperationCourante + '&vignetteId=' + ImgId +'&selectionId='+selectionId);
		makeRequestToElement('index.php?action=vignetteClick&clickType=' + OperationCourante + '&vignetteId=' + ImgId +'&selectionId='+selectionId,'','GET','');
	}
}
function fichierSelectByCheck(IdCheckBox,ImgId,selectionId,HiddenID){
	var DivObj = document.getElementById(IdCheckBox);
	var HiddenObj = document.getElementById(HiddenID);
	var OperationCourante = "";
	if(DivObj.checked){
		HiddenObj.value = HiddenObj.value + ";" + ImgId;
		OperationCourante = "add";
	}
	else{
		HiddenObj.value = HiddenObj.value.replace(ImgId,'');
		HiddenObj.value = HiddenObj.value.replace(';;',';');
		OperationCourante = "supp";
	}
	makeRequestToElement('index.php?action=vignetteClick&clickType=' + OperationCourante + '&vignetteId=' + ImgId +'&selectionId='+selectionId,'','GET','');
}
function noteit(noteListe, imgId, imgNote){
	noteListe[imgId] = imgNote;
	var SelectObj1 = document.getElementById('fichierAffichageNote');
	var SelectObj2 = document.getElementById('detailsNote');
	
	var optionsArray1 = SelectObj1.options;
	var optionsArray2 = SelectObj2.options;
		for(var i in optionsArray1){
			if(optionsArray1[i].value == ListeNoteFichier[imgId] && !optionsArray1[i].selected)
				optionsArray1[i].selected=true;
			if(optionsArray2[i].value == ListeNoteFichier[imgId] && !optionsArray2[i].selected)
				optionsArray2[i].selected=true;
		}
	if(SelectObj1.value){		
		
		makeRequestToElement('index.php?action=imgNote&imgId='+imgId+'&note='+SelectObj1.value,'','GET','');	
	}	
	//window.parent.opener.history.go(0);
	 setTimeout("window.parent.opener.document.getElementById('XForm').submit();",1500);
	
	//window.parent.opener.location.reload();
	
}
function registeForSearche(chaine){
	//alert('index.php?action=registeForSearch'+chaine);
	makeRequestToElement('index.php?action=registeForSearch'+chaine,'','GET','');	
}
function bigImgSelection(imgId){
	
	makeRequestToElement('index.php?action=bigImgSelection&imgId='+imgId,'','GET','');
	window.parent.opener.history.go(0);
}
function SelectAllSQL(BgColor,BgColorSelected, cate, filesPath, selectedId){	

	var HiddenObj = document.getElementById('fichierSelectAll');
	
	if(HiddenObj.value == '' || HiddenObj.value == 'add'){
		HiddenObj.value = "supp";
		OperationCourante = "add";
		CurrentBgColor = BgColorSelected;
	}
	else if(HiddenObj.value == 'supp'){
		HiddenObj.value = "add";
		OperationCourante = "supp";
		CurrentBgColor = BgColor;
	}
	
	var Elems = document.getElementById ('fichierForm');
	var Contenants = Elems.getElementsByTagName ('td');
	var ContenantsIdPatern = /^fichierThumb/;
	if (Contenants) {
		for (var i = 0; i < Contenants.length; ++i) {
			if(Contenants[i].id){
				var result = Contenants[i].id.match(ContenantsIdPatern);
				if (result){
					Contenants[i].style.background = CurrentBgColor;
				}
			}
		}
	}
	
	if(OperationCourante != ""){
		OperationCourante = OperationCourante+cate;
		//alert(OperationCourante+" "+'index.php?action=chooseAllVignettes&clickType=' + OperationCourante + '&filesPath=' + filesPath+'&selectionId='+selectedId);
		makeRequestToElement('index.php?action=chooseAllVignettes&clickType=' + OperationCourante + '&filesPath=' + filesPath+'&selectionId='+selectedId,'','GET','');
	}
}

function SearchAdv(photographer,illustrator){
	if(document.getElementById('searchavancee').style.display == 'none'){
		if(photographer.checked &&  !illustrator.checked)
		  var artist = 1 ; // serach photographer
		else if(!photographer.checked &&  illustrator.checked)
		  var artist = 2 ; // serach illustrator
		else if(photographer.checked &&  illustrator.checked)
		  var artist = 3 ; // serach photographer & illustrator
	    else{ 
		  var artist = 4 ;
		  window.alert("Please select Photography and/or Illustration for search.");// rien
		}
		
		if(artist!=4){  
		//document.getElementById('loading').style.display = 'block';
		document.getElementById('searchavancee').style.display = 'block';
				if(artist==1 || artist==3) 
				document.getElementById('searchavanceePhotographer').style.display = 'block';
				if(artist==2 || artist==3) 
				document.getElementById('searchavanceeIllustrator').style.display = 'block';
		
		document.getElementById('searchimgadv').src='images/search_adv_on.gif';
		//makeRequestToElement('index.php?action=getChampsResearchAvance&artist='+artist,'','GET','searchavancee');
		}
	}
	else{
		//document.getElementById('searchavancee').innerHTML = '';
		document.getElementById('searchavancee').style.display = 'none';
		document.getElementById('searchavanceePhotographer').style.display = 'none';
		document.getElementById('searchavanceeIllustrator').style.display = 'none';
		document.getElementById('searchimgadv').src='images/search_adv_off.gif';
	}
}
function ResetMainDefaultValue2(){
	
	if(document.getElementById('FiltreChampLibre').value == 'Search all fields'){
		document.getElementById('FiltreChampLibre').value = '';
	}
}

/*function SearchImgSelection(selection){
	makeRequestToElement('index.php?action=getImgSelectionOrder&selectionId='+selection,'','GET','filecontent');
}*/

