// Bibliothèque de scripts - Auvergne Convention Bureau 
var arrImg = new Array();

//****************************************************************
// Affichage des sous-menus 
//****************************************************************

sfHover = function() {
        if (document.getElementById('navigation'))
                {
                var sfEls = document.getElementById('navigation').getElementsByTagName("LI");
                for (var i=0; i<sfEls.length; i++) {
                        sfEls[i].onmouseover=function() {
                                this.className+=" sfhover";
                        }
                        sfEls[i].onmouseout=function() {
                        this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
                        }
                }
                }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


//sfHover = function() {
//        if (document.getElementById('boutons'))
//                {
//                var sfEls = document.getElementById('boutons').getElementsByTagName("LI");
//                for (var i=0; i<sfEls.length; i++) {
//                        sfEls[i].onmouseover=function() {
//                                this.className+=" sfhover";
//                        }
//                        sfEls[i].onmouseout=function() {
//                        this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
//                        }
//                }
//                }
//}
//if (window.attachEvent) window.attachEvent("onload", sfHover);


//****************************************************************
// Positionnement du pied de page 
//****************************************************************

function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	}
	else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}
		else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}
function setFooter() {
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight > 0) {
			var contentHeight = document.getElementById('page').offsetHeight;
			var footerElement = document.getElementById('foot');
			var footerHeight  = footerElement.offsetHeight;
			if (windowHeight - (contentHeight + footerHeight) >= 0) {
				footerElement.style.position = 'relative';
				footerElement.style.top = (windowHeight - (contentHeight + footerHeight)) + 'px';
			}
			else {
				footerElement.style.position = 'static';
			}
		}
	}
}


//****************************************************************
// Affichage des libellés de la boîte à outils 
//****************************************************************

sfHover = function() {
        if (document.getElementById('tools'))
                {
                var sfEls = document.getElementById('tools').getElementsByTagName("LI");
                for (var i=0; i<sfEls.length; i++) {
                        sfEls[i].onmouseover=function() {
                                this.className+=" sfhover";
                        }
                        sfEls[i].onmouseout=function() {
                        this.className=this.className.replace(new RegExp(" sfhover\\b"), "");
                        }
                }
                }
}
if (window.attachEvent) window.attachEvent("onload", sfHover);


//****************************************************************
// Fonction d'import des animations Flash 
//****************************************************************

function RunFlash(swf, hauteur, largeur, nom) {
	document.write("<object width=\""+largeur+"\" height=\""+hauteur+"\" id=\""+nom+"\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0\">\n");
	document.write("<param name=\"quality\" value=\"high\">\n");
	document.write("<param name=\"wmode\" value=\"transparent\">\n");
	document.write("<param name=\"movie\" value=\""+swf+"\">\n");
	document.write("<embed src=\""+swf+"\" quality=\"high\" wmode=\"transparent\" width=\""+largeur+"\" height=\""+hauteur+"\" name=\""+nom+"\" align=\"middle\" type=\"application/x-shockwave-flash\" pluginspage=\"http://www.macromedia.com/go/getflashplayer\">\n");
	document.write("</object>\n");
}


//****************************************************************
// Fonction gérant l'affichage des DIV IN DISPLAY 
//****************************************************************

function funcDisplayDiv(varObj)
{
if (varObj.style.display == "block")
	{
	varObj.style.display = "none";
	}
else if (varObj.style.display == "none")
	{
	varObj.style.display = "block";
	}
else
	{
	varObj.style.display = "none";
	}
}


//****************************************************************
// Fonction gérant les styles des liens non HTML 
//****************************************************************
function fileLinks() {
    var fileLink;
    if (document.getElementsByTagName('a')) {
        for (var i = 0; (fileLink = document.getElementsByTagName('a')[i]); i++) {
            if (fileLink.href.indexOf('.pdf') != -1) {
                fileLink.setAttribute('target', '_blank');
            }
        }
    }
}
window.onload = function() {
    fileLinks();
}


//****************************************************************
// Affichage des POPUP 
//****************************************************************

function funcPopup(varUrl, varWidth, varHeight, varResize) {
	var ScreenW = screen.availWidth;
	var ScreenH = screen.availHeight;
	var WinPopUp = window.open(varUrl, 'popup', "toolbar=no, menubar=no, scrollbars=yes, resizable=" + varResize + ", location=no, directories=no, status=no, width=" + varWidth + ", height=" + varHeight);
	WinPopUp.moveTo(Math.round((ScreenW-varWidth)/2), Math.round((ScreenH-varHeight)/2));	
}


//****************************************************************
// Gestion des onglets du formulaire de messagerie 
//****************************************************************

function funcFormTab(varObjId) {
	//Attribution du style actif à l'onglet
	document.getElementById("formContactTab1").className = "";
	document.getElementById("formContactTab2").className = "";
	document.getElementById("formContactTab"+varObjId).className = "actif";
	
	//Affichage du bloc de recherche
	document.getElementById("formContactTr1").style.display = "none";
	document.getElementById("formContactTr2").style.display = "none";
	document.getElementById("formContactTr"+varObjId).style.display = "inline";
	
}


//-------------------------------------------------------------------------------
//	Fonction de suppression d'une image en base
//-------------------------------------------------------------------------------
function funcImgDelToDb(varTable, varFieldImgName, varId)
	{
	var oXmlHttp = null;
	// Mozilla
	if (window.XMLHttpRequest)
		{
		oXmlHttp = new XMLHttpRequest();
		}
	// IE
	else if (window.ActiveXObject)
		{
		oXmlHttp = new ActiveXObject("Microsoft.XmlHttp");
		}
		
	if (oXmlHttp != null)
		{
		oXmlHttp.open("GET","../_inc/XML_ImgDelete.asp?ms="+ new Date().getTime() + "&strTable=" + varTable + "&strFieldImgName=" + varFieldImgName + "&strId=" + varId, false);
		oXmlHttp.setRequestHeader('Content-Type','text/html; charset=iso-8859-1')
		oXmlHttp.setRequestHeader("Cache-Control","no-cache");
		oXmlHttp.setRequestHeader('Pragma','no-cache');
		oXmlHttp.send(null);
		}
		
	if (oXmlHttp.responseText == '')
		alert('L\'image a été supprimée de la base de donnée');
	else
		alert(oXmlHttp.responseText);
	}

	
//-------------------------------------------------------------------------------
//	Fonction de lancement d'un upload d'image en base
//-------------------------------------------------------------------------------
function funcImgToDb(varPath, varTable, varSelectField, varSelectValue, varFileField, varBlnMsg, varReload)
	{
   // create ADO-stream Object
   var ado_stream = new ActiveXObject("ADODB.Stream");

   // create XML document with default header and primary node
   var xml_dom = new ActiveXObject("MSXML2.DOMDocument");
   xml_dom.loadXML('<?xml version="1.0" ?> <root/>');
   // specify namespaces datatypes
   xml_dom.documentElement.setAttribute("xmlns:dt", "urn:schemas-microsoft-com:datatypes");

   // create a new node and set binary content
   var l_node1 = xml_dom.createElement("file1");
   l_node1.dataType = "bin.base64";
	if (varPath != "")
	   	{
		// open stream object and read source file
		ado_stream.Type = 1;  // 1=adTypeBinary 
		ado_stream.Open(); 
		ado_stream.LoadFromFile(varPath);
	
	   // store file content into XML node
	   l_node1.nodeTypedValue = ado_stream.Read(-1); // -1=adReadAll
	   ado_stream.Close();
	   xml_dom.documentElement.appendChild(l_node1);
		// send XML document to SysWeb server
		var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		xmlhttp.open("POST","../_inc/funcImgUpload.asp?strAction=upload&strTable="+ varTable +"&strSelectField="+ varSelectField +"&strSelectValue="+ varSelectValue +"&strFileField=" + varFileField + "&strPath=" + varPath, false);
		xmlhttp.send(xml_dom);
		}
	else
		{
		// send XML document to SysWeb server
		var xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		xmlhttp.open("POST","../_inc/funcImgUpload.asp?strAction=delete&strTable="+ varTable +"&strSelectField="+ varSelectField +"&strSelectValue="+ varSelectValue +"&strFileField="+ varFileField, false);
		xmlhttp.send(xml_dom);
		}
	
   // show server message in message-area
	if (varBlnMsg)
		alert(xmlhttp.responseText);

	if (varReload == 1)
		window.location.href = window.location.href;
}

//-------------------------------------------------------------------------------
// Fonction de suppression d'une image
//-------------------------------------------------------------------------------
function funcImgDelete(varImg)
	{
	varImg.outerHTML = '<img alt="' + varImg.alt + '" id="' + varImg.id + '" title="Photo" src="../images/NoFile.gif" onLoad="funcRedimImg(this,200,200);">';
//	alert(varImg.outerHTML);
	}

function funcImgChange(varImg, varSrc)
	{
	varImg.outerHTML = '<img alt="' + varImg.alt + '" id="' + varImg.id + '" title="Photo" src="' + rewriteLocalURL(varSrc) + '" onLoad="funcRedimImg(this,200,200);">';
	varImg.src = varSrc;
//	alert('ImgChange : ' +varImg.outerHTML);
	}

function rewriteLocalURL(url) { 
                var uri = url; 
				var spaceMatch = / /gi; 
		        var slashMatch = /\\/gi;
                /* identify Windows-Scheme */ 
                if ((uri.charAt(1) == ':') && (uri.charAt(2) == '\\'))
					{ 
                    uri = 'file:///' + uri.replace(slashMatch, "/");
					uri = uri.replace(spaceMatch, "%20"); 

//replace(/\\+/, '/'); 
	                } 
                /* identify Linux-Scheme */ 
                else if (uri.charAt(0) == '/') { 
                        uri = 'file:///' + uri; 
                } 
                return uri; 
        } 


//-------------------------------------------------------------------------------
//	Fonction de redimensionnement des images
//-------------------------------------------------------------------------------
function funcRedimImg(varImg, varWidth, varHeight)
	{
	var oldWidth = varImg.width;
	var oldHeight = varImg.height;
	arrImg[varImg.alt] = varImg.width + 'X' + varImg.height;
//	alert(varImg.alt + ' - ' + arrImg[varImg.alt]);
//	alert(varImg.width + ' X ' + varImg.height);
	var newWidth = oldWidth;
	var newHeight = oldHeight;
	if (varImg.width > varWidth)
		{
		newWidth = varWidth;
		newHeight = Math.round((varWidth/oldWidth) * oldHeight);
		varImg.width = newWidth;
		varImg.height = newHeight;
		oldWidth = newWidth;
		oldHeight = newHeight;
		}
	if (newHeight > varHeight)
		{
		newHeight = varHeight;
		newWidth = Math.round((varHeight/oldHeight) * newWidth);
		varImg.width = newWidth;
		varImg.height = newHeight;
		}
	}

function funcAddDetail(varNode, varRow, varTableDetail, varTable, varFicheId, varLib)
	{
	var oXmlHttp = null;
	var strResponse = '';
	var strId = '';
	var cell;
	// Mozilla
	if (window.XMLHttpRequest)
		{
		oXmlHttp = new XMLHttpRequest();
		}
	// IE
	else if (window.ActiveXObject)
		{
		oXmlHttp = new ActiveXObject("Microsoft.XmlHttp");
		}
		
	if (oXmlHttp != null)
		{
		oXmlHttp.open("GET","../_inc/XML_funcDetail.asp?ms="+ new Date().getTime() +"&strNode=" + varNode + "&strTableDetail=" + varTableDetail + "&strTable=" + varTable + "&strFicheId=" + varFicheId + "&strLib=" + varLib, false);
		oXmlHttp.setRequestHeader('Content-Type','text/html; charset=iso-8859-1')
		oXmlHttp.setRequestHeader("Cache-Control","no-cache");
		oXmlHttp.setRequestHeader('Pragma','no-cache');
		oXmlHttp.send(null);
		}
	if (oXmlHttp.responseText != '')
		{
//alert (oXmlHttp.responseText);			
		strResponse = oXmlHttp.responseText;
		strId = strResponse.substring(0,strResponse.indexOf("|"));
//alert(strId);		
		strResponse = strResponse.substring(strResponse.indexOf("|")+1);
//alert(strResponse);		
		var row = document.getElementById(varNode).insertRow(-1);
		row.id = varRow + strId;		
		if (strResponse != '')
			{
			cell = row.insertCell(0);
			cell.colspan= 3;
			cell.innerHTML = strResponse;
			}
		else
			{
			switch (varTableDetail.toLowerCase())
				{
				case "kbficheespace1" :
					{
					cell = row.insertCell(0);
					cell.innerHTML = "<img title='Supprimer la ligne' src='../images/ico-cancel.gif' onClick=\"funcDelDetail('tableEspaces', 'trEspace_"  + strId + "', 'KbFicheEspace1', '" + varFicheId + "', '" + strId + "');\">";
					cell = row.insertCell(1);
					cell.innerHTML = "<input type='text' name='KbFicheEspace1Lib_" + strId + "' id='KbFicheEspace1Lib_" + strId + "' rows='3' size='30' style='width:100%;' maxlength='100' value=\"" + varLib + "\" title='' alt='Nom:Nom espace|Type:Txt|Requis:Oui|Defaut:'>";
					cell = row.insertCell(2);
					cell.innerHTML = "<input type='text' name='KbFicheEspace1Nb_" + strId + "' id='KbFicheEspace1Nb_" + strId + "' size='5' style='width:100%;' maxlength='100' value='' title='' alt='Nom:|Type:Num|Requis:Non|Defaut:'>";
					cell = row.insertCell(3);
					cell.innerHTML = "<input type='text' name='KbFicheEspace1Surf_" + strId + "' id='KbFicheEspace1Surf_" + strId + "' size='5' style='width:100%;' maxlength='100' value='' title='' alt='Nom:|Type:Num|Requis:Non|Defaut:'>";
					cell = row.insertCell(4);
					cell.innerHTML = "<input type='text' name='KbFicheEspace1Orga1_" + strId + "' id='KbFicheEspace1Orga1_" + strId + "' size='5' style='width:100%;' maxlength='100' value='' title='' alt='Nom:|Type:Num|Requis:Non|Defaut:'>";
					cell = row.insertCell(5);
					cell.innerHTML = "<input type='text' name='KbFicheEspace1Orga2_" + strId + "' id='KbFicheEspace1Orga2_" + strId + "' size='5' style='width:100%;' maxlength='100' value='' title='' alt='Nom:|Type:Num|Requis:Non|Defaut:'>";
					cell = row.insertCell(6);
					cell.innerHTML = "<input type='text' name='KbFicheEspace1Orga3_" + strId + "' id='KbFicheEspace1Orga3_" + strId + "' size='5' style='width:100%;' maxlength='100' value='' title='' alt='Nom:|Type:Num|Requis:Non|Defaut:'>";
					cell = row.insertCell(7);
					cell.innerHTML = "<input type='text' name='KbFicheEspace1Orga4_" + strId + "' id='KbFicheEspace1Orga4_" + strId + "' size='5' style='width:100%;' maxlength='100' value='' title='' alt='Nom:|Type:Num|Requis:Non|Defaut:'>";
					cell = row.insertCell(8);
					cell.innerHTML = "<input type='text' name='KbFicheEspace1Orga5_" + strId + "' id='KbFicheEspace1Orga5_" + strId + "' size='5' style='width:100%;' maxlength='100' value='' title='' alt='Nom:|Type:Num|Requis:Non|Defaut:'>";
					cell = row.insertCell(9);
					cell.innerHTML = "<input type='text' name='KbFicheEspace1Orga6_" + strId + "' id='KbFicheEspace1Orga6_" + strId + "' size='5' style='width:100%;' maxlength='100' value='' title='' alt='Nom:|Type:Num|Requis:Non|Defaut:'>";
					break;
					}
				case "kbficheespace6" :
					{
					cell = row.insertCell(0);
					cell.innerHTML = "<img title='Supprimer la ligne' src='../images/ico-cancel.gif' onClick=\"funcDelDetail('tableEspaces', 'trEspace_"  + strId + "', 'KbFicheEspace6', '" + varFicheId + "', '" + strId + "');\">";
					cell = row.insertCell(1);
					cell.innerHTML = "<input type='text' name='KbFicheEspace6Lib_" + strId + "' id='KbFicheEspace6Lib_" + strId + "' rows='3' size='30' style='width:100%;' maxlength='100' value=\"" + varLib + "\" title='' alt='Nom:Nom espace|Type:Txt|Requis:Oui|Defaut:'>";
					cell = row.insertCell(2);
					cell.innerHTML = "<input type='text' name='KbFicheEspace6Nb_" + strId + "' id='KbFicheEspace6Nb_" + strId + "' size='5' style='width:100%;' maxlength='100' value='' title='' alt='Nom:|Type:Num|Requis:Non|Defaut:'>";
					cell = row.insertCell(3);
					cell.innerHTML = "<input type='text' name='KbFicheEspace6Surf_" + strId + "' id='KbFicheEspace6Surf_" + strId + "' size='5' style='width:100%;' maxlength='100' value='' title='' alt='Nom:|Type:Num|Requis:Non|Defaut:'>";
					cell = row.insertCell(4);
					cell.innerHTML = "<input type='text' name='KbFicheEspace6Orga1_" + strId + "' id='KbFicheEspace6Orga1_" + strId + "' size='5' style='width:100%;' maxlength='100' value='' title='' alt='Nom:|Type:Num|Requis:Non|Defaut:'>";
					cell = row.insertCell(5);
					cell.innerHTML = "<input type='text' name='KbFicheEspace6Orga2_" + strId + "' id='KbFicheEspace6Orga2_" + strId + "' size='5' style='width:100%;' maxlength='100' value='' title='' alt='Nom:|Type:Num|Requis:Non|Defaut:'>";
					cell = row.insertCell(6);
					cell.innerHTML = "<input type='text' name='KbFicheEspace6Orga3_" + strId + "' id='KbFicheEspace6Orga3_" + strId + "' size='5' style='width:100%;' maxlength='100' value='' title='' alt='Nom:|Type:Num|Requis:Non|Defaut:'>";
					cell = row.insertCell(7);
					cell.innerHTML = "<input type='text' name='KbFicheEspace6Orga4_" + strId + "' id='KbFicheEspace6Orga4_" + strId + "' size='5' style='width:100%;' maxlength='100' value='' title='' alt='Nom:|Type:Num|Requis:Non|Defaut:'>";
					break;
					}
				case "kbficheespace8" :
					{
					cell = row.insertCell(0);
					cell.innerHTML = "<img title='Supprimer la ligne' src='../images/ico-cancel.gif' onClick=\"funcDelDetail('tableEspaces', 'trEspace_"  + strId + "', 'KbFicheEspace8', '" + varFicheId + "', '" + strId + "');\">";
					cell = row.insertCell(1);
					cell.innerHTML = "<input type='text' name='KbFicheEspace8Lib_" + strId + "' id='KbFicheEspace8Lib_" + strId + "' rows='3' size='30' style='width:100%;' maxlength='100' value=\"" + varLib + "\" title='' alt='Nom:Nom espace|Type:Txt|Requis:Oui|Defaut:'>";
					cell = row.insertCell(2);
					cell.innerHTML = "<input type='text' name='KbFicheEspace8Nb_" + strId + "' id='KbFicheEspace8Nb_" + strId + "' size='5' style='width:100%;' maxlength='100' value='' title='' alt='Nom:|Type:Num|Requis:Non|Defaut:'>";
					cell = row.insertCell(3);
					cell.innerHTML = "<input type='text' name='KbFicheEspace8Surf_" + strId + "' id='KbFicheEspace8Surf_" + strId + "' size='5' style='width:100%;' maxlength='100' value='' title='' alt='Nom:|Type:Num|Requis:Non|Defaut:'>";
					cell = row.insertCell(4);
					cell.innerHTML = "<input type='text' name='KbFicheEspace8Orga1_" + strId + "' id='KbFicheEspace8Orga1_" + strId + "' size='5' style='width:100%;' maxlength='100' value='' title='' alt='Nom:|Type:Num|Requis:Non|Defaut:'>";
					break;
					}
				}
				
			}
		}
	}

// Suppression d'un détail de la synthèse
function funcDelDetail(varNode, varRow, varTableDetail, varFicheId, varId)
	{
	var oXmlHttp = null;
	// Mozilla
	if (window.XMLHttpRequest)
		{
		oXmlHttp = new XMLHttpRequest();
		}
	// IE
	else if (window.ActiveXObject)
		{
		oXmlHttp = new ActiveXObject("Microsoft.XmlHttp");
		}
		
	if (oXmlHttp != null)
		{
		oXmlHttp.open("GET","../_inc/XML_funcDetail.asp?ms="+ new Date().getTime() + "&strTableDetail=" + varTableDetail + "&strId=" + varId + "&strFicheId=" + varFicheId, false);
		oXmlHttp.setRequestHeader('Content-Type','text/html; charset=iso-8859-1')
		oXmlHttp.setRequestHeader("Cache-Control","no-cache");
		oXmlHttp.setRequestHeader('Pragma','no-cache');
		oXmlHttp.send(null);
		}
	if (oXmlHttp.responseText == '')
		{
		document.getElementById(varNode).deleteRow(document.getElementById(varRow).rowIndex);
		}
	}



// Recup pro selectionnes pour appels d'offres
function funcAppelOffreSelect() {

	var objFrm 		= document.getElementById('frmAppelOffreCheckbox');
	var tabElt 		= objFrm.element;
	var blnSelect 	= false;
	var proSelect	= "";
	
	// Pour chaque type de fiche
	for (var k=1; k<=15; k++) {
		
		proSelect = "";
		
		// Parcours des checkbox
		for (i=0; i<objFrm.length; i++) {
			
			// Si checkbox coche
			if (objFrm.elements[i].type == "checkbox" && objFrm.elements[i].name.indexOf("appelOffrePro_KbFiche"+k+"_") >= 0 && objFrm.elements[i].checked) {
				
				if (proSelect != "") {
					proSelect = proSelect + ", ";
				}
				
				proSelect = proSelect + objFrm.elements[i].value;
				blnSelect = true;
			}
		}
		
		// On stocke les fiches selectionnes pour le type de fiche
		document.getElementById('ao'+k).value = proSelect;
	}

	if (blnSelect) {
		document.getElementById('frmAppelOffreSelect').submit();
	} else {
		alert("Vous devez sélectionner un professionnel");
	}
}
	

// Recup pro selectionnes pour appels d'offres dans intranet
function funcAppelOffreAdherentSelect() {
	
	var objFrm 		= document.getElementById('frmAccountAppelOffreCheckbox');
	var tabElt 		= objFrm.element;
	var blnSelect 	= false;
	var proSelect	= "";
		
	// Parcours des checkbox
	for (i=0; i<objFrm.length; i++) {
		
		// Si checkbox coche
		if (objFrm.elements[i].type == "checkbox" && objFrm.elements[i].name.indexOf("appelOffreAdh_") >= 0 && objFrm.elements[i].checked) {
			
			if (proSelect != "") {
				proSelect = proSelect + ", ";
			}
			
			proSelect = proSelect + objFrm.elements[i].value;
			blnSelect = true;
		}
	}
	
	// On stocke les fiches selectionnes pour le type de fiche
	document.getElementById('adhSelect').value = proSelect;

	// validation formulaire
	document.getElementById('formAccountAppelOffreSelect').submit();
}
