
function validation(NomForm, NomDivResult) {

    var form = document.getElementById(NomForm);
    if (document.getElementsByTagName)//make sure were on a newer browser
    {
        var objInput = document.getElementsByTagName('input');

        var para = $("#" + NomForm).serialize();

        //para = "{" + para + "}";

        $(document).ready(function() {
            //$.post("/inc/validation-form.asp", eval('(' + para + ')'),
            $.post("/inc/validation-form.asp", para,
		    function(xmlDoc) {
		        var objInput = document.getElementsByTagName('input');
		        var message = '';
		        //for (var iCounter = 0; iCounter < objInput.length; iCounter++) {
		        //    objInput[iCounter].className = '';
		        //}
		        if (xmlDoc.getElementsByTagName("result")[0].childNodes[0].nodeValue == 'erreur') {
		            var xmlChamps = xmlDoc.documentElement;
		            for (i = 0; i < xmlDoc.getElementsByTagName("champ").length; i++) {
		                message += "<p>" + unescape(xmlDoc.getElementsByTagName("champ")[i].getAttribute("message")) + "</p>";
		                //document.getElementById(xmlDoc.getElementsByTagName("champ")[i].getAttribute("id")).className = xmlDoc.getElementsByTagName("champ")[i].getAttribute("class")
		                if (xmlDoc.getElementsByTagName("champ")[i].getAttribute("message") == '') {
		                    $("#" + xmlDoc.getElementsByTagName("champ")[i].getAttribute("id")).parent().removeClass(xmlDoc.getElementsByTagName("champ")[i].getAttribute("class"));
		                }
		                else {
		                    $("#" + xmlDoc.getElementsByTagName("champ")[i].getAttribute("id")).parent().addClass(xmlDoc.getElementsByTagName("champ")[i].getAttribute("class"));
		                }
		            }
		            document.getElementById(NomDivResult).innerHTML = message;
		            document.getElementById(NomDivResult).style.display = 'block';
		        }
		        else {
		            form.submit();
		        }
		    }
		    , "xml");
        });

    }
}

function getSelect(nomSelect, chaineSQL) {
    if (document.getElementsByTagName)//make sure were on a newer browser
    {
        var para = {sql:encodeURI(chaineSQL)};
        $(document).ready(function() {
        $.post("/module/inc/getSelect.asp", jQuery.param(para),
            function(result) {
                $("#" + nomSelect).html(result);
            });
        });
    }
}

function callURL(url, para, zoneResult) {
    $(document).ready(function() {
        $('div.waiting').css('display', 'block');
        $('#global').css('opacity', 0.5);
        $.post(url, jQuery.param(para),
            function(result) {
                $(zoneResult).replaceWith(unescape(result));
                $('#global').css('opacity', 1);
                $('div.waiting').css('display', 'none');
            });
    });
}

function getModuleAjax(url, divResultID, module) {
    $(document).ready(function () {
        url = url.replace(/&amp;/gi, "&");
        $.post(url,
        function (result) {
            $('#' + divResultID).html(unescape(result));
            switch (module) {
                case "album":
                    Shadowbox.init({ skipSetup: true }); Shadowbox.setup();
            }
        });
    });
}

function encodeAccent(texte) {
    texte = texte.replace(RegExp(String.fromCharCode(195) + String.fromCharCode(160),"g"), "&agrave;");
    texte = texte.replace(RegExp(String.fromCharCode(195) + String.fromCharCode(162),"g"), "&acirc;");
    texte = texte.replace(RegExp(String.fromCharCode(195) + String.fromCharCode(164),"g"), "&auml;");
    texte = texte.replace(RegExp(String.fromCharCode(195) + String.fromCharCode(167),"g"), "&ccedil;");
    texte = texte.replace(RegExp(String.fromCharCode(195) + String.fromCharCode(168),"g"), "&egrave;");
    texte = texte.replace(RegExp(String.fromCharCode(195) + String.fromCharCode(169),"g"), "&eacute;");
    texte = texte.replace(RegExp(String.fromCharCode(195) + String.fromCharCode(169),"g"), "&eacute;");
    texte = texte.replace(RegExp(String.fromCharCode(195) + String.fromCharCode(170),"g"), "&ecirc;");
    texte = texte.replace(RegExp(String.fromCharCode(195) + String.fromCharCode(171),"g"), "&euml;");
    texte = texte.replace(RegExp(String.fromCharCode(195) + String.fromCharCode(174),"g"), "&icirc;");
    texte = texte.replace(RegExp(String.fromCharCode(195) + String.fromCharCode(175),"g"), "&iuml;");
    texte = texte.replace(RegExp(String.fromCharCode(195) + String.fromCharCode(180),"g"), "&ocirc;");
    texte = texte.replace(RegExp(String.fromCharCode(195) + String.fromCharCode(182),"g"), "&ouml;");
    texte = texte.replace(RegExp(String.fromCharCode(195) + String.fromCharCode(185),"g"), "&ugrave;");
    texte = texte.replace(RegExp(String.fromCharCode(195) + String.fromCharCode(187),"g"), "&ucirc;");
    texte = texte.replace(RegExp(String.fromCharCode(195) + String.fromCharCode(188),"g"), "&uuml;");
    texte = texte.replace(RegExp(String.fromCharCode(226) + String.fromCharCode(128) & String.fromCharCode(153), "g"), "'");
    
    return texte
}


function changeImages() {
	for (var i=0; i<changeImages.arguments.length; i+=2) {
		changeImages.arguments[i].src = changeImages.arguments[i+1];
	}
}

function codeTouche(evenement)
{
        for (prop in evenement)
        {
                if(prop == 'which') return(evenement.which);
        }
        return(evenement.keyCode);
}

function scanTouche(evenement)
{
        var reCarValides = /[\w-_]/;
		var reCarSpeciaux = /[\x00\x08\x0D]/;
		
        var codeDecimal  = codeTouche(evenement);
        var car = String.fromCharCode(codeDecimal);
        var autorisation = reCarValides.test(car) || reCarSpeciaux.test(car);

        return autorisation;
}

function resize(DeltaWidth, DeltaHeight){
	w = document.pic.width;
	h = document.pic.height;
	window.resizeTo(w+DeltaWidth,h+DeltaHeight);
	focus();
}

function showTR(obj)
{
  var currentRow = obj;
  var tbl =  currentRow.parentNode;
  var rIndex = currentRow.sectionRowIndex + 1;
  var nextRow = tbl.rows[rIndex];
  if(tbl.rows[rIndex].style.display == "")
       tbl.rows[rIndex].style.display = "none";
  else
       tbl.rows[rIndex].style.display = "";
}

function showThisTR(obj)
{
  var currentRow = obj;
  var tbl =  currentRow.parentNode;
  var rIndex = currentRow.sectionRowIndex;
  var nextRow = tbl.rows[rIndex];
  if(tbl.rows[rIndex].style.display == "")
       tbl.rows[rIndex].style.display = "none";
  else
       tbl.rows[rIndex].style.display = "";
}

function visibleThisTR(obj)
{
  var currentRow = obj;
  var tbl =  currentRow.parentNode;
  var rIndex = currentRow.sectionRowIndex;
  var nextRow = tbl.rows[rIndex];
  tbl.rows[rIndex].style.display = "";
}

function hideThisTR(obj)
{
  var currentRow = obj;
  var tbl =  currentRow.parentNode;
  var rIndex = currentRow.sectionRowIndex;
  var nextRow = tbl.rows[rIndex];
  tbl.rows[rIndex].style.display = "none";
}

function showAdresseLivraison(Etat, tr)
{
	if (Etat)
		{document.getElementById(tr).style.display='none';}
	else
		{document.getElementById(tr).style.display='';}
}


 function getAbsoluteLeft(objectId) {
	// Get an object left position from the upper left viewport corner
	// Tested with relative and nested objects
	o = document.getElementById(objectId)
	oLeft = o.offsetLeft            // Get left position from the parent object
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent    // Get parent object reference
		oLeft += oParent.offsetLeft // Add parent left position
		o = oParent
	}
	// Return left postion
	return oLeft
}

 function getAbsoluteTop(objectId) {
	// Get an object left position from the upper left viewport corner
	// Tested with relative and nested objects
	o = document.getElementById(objectId)
	oTop = o.offsetTop            // Get left position from the parent object
	while(o.offsetParent!=null) {   // Parse the parent hierarchy up to the document element
		oParent = o.offsetParent    // Get parent object reference
		oTop += oParent.offsetTop // Add parent left position
		o = oParent
	}
	// Return left postion
	return oTop
}

function storeCaret (textEl)
{
if (textEl.createTextRange) 
textEl.caretPos = document.selection.createRange().duplicate();
alert(document.selection.createRange().duplicate());
}
function insertAtCaret (textEl, text)
{
if (textEl.createTextRange && textEl.caretPos)
{
var caretPos = textEl.caretPos;
caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ? text + ' ' : text;
}
else
textEl.value  = text;
}
