function ValiderAdrMail(monAdresse) {

    var indexAro = monAdresse.indexOf('@');
    if (indexAro == -1) {
        return false;
    }
    var otherIndexAro = monAdresse.indexOf('@', indexAro + 1);
    if (otherIndexAro != -1) {
        return false;
    }
    if ((indexAro == 0) || (indexAro == monAdresse.length - 1)) {
        return false;
    }
    var indexPoint = monAdresse.indexOf('.');
    if ((indexPoint == -1) || (indexPoint == 0)) {
        return false;
    }
    var otherIndexPoint = monAdresse.indexOf('.', indexPoint);
    while (otherIndexPoint != -1) {
        if ((indexPoint + 1 == otherIndexPoint) || (otherIndexPoint == indexAro - 1) || (otherIndexPoint == indexAro + 1)) {
            return false;
        }
        indexPoint = otherIndexPoint;
        otherIndexPoint = monAdresse.indexOf('.', indexPoint + 1);
    }
    if ((indexPoint == monAdresse.length + 1) || (indexAro > indexPoint) || (indexPoint == monAdresse.length - 1)) {
        return false;
    }
    if (!(isAdrMail(monAdresse))) {
        return false;
    }
    return true;

}


function PopupCentrer(url) {
    window.open(url, '', 'resizable=no, location=no, width=700, height=500, menubar=no, status=no, scrollbars=no, menubar=no');
}


function PopupNoSizes(url, width, height) {
    window.open(url, '', 'resizable=no, location=no, width=' + width + ', height=' + height + ', menubar=no, status=no, scrollbars=yes, menubar=no');
}


function GotoLink(where) {
    window.location.href = where;
}


function ValidateSearch(searchTextBoxID, errorMessage, length) {
    if (length == null)
        length = 3;
    textToSearch = jQuery.trim(document.getElementById(searchTextBoxID).value);
    textToSearch = escape(textToSearch);
    if (textToSearch.length >= length) {
        //window.location = "/search/results.aspx?query=" + textToSearch;
        return true;

    }
    else {
        document.getElementById(searchTextBoxID).value = errorMessage;

    }
    return false;
}


function openPopUp(url, name, w, h) {

    w += 32;
    h += 96;
    wleft = (screen.width - w) / 2;
    wtop = (screen.height - h) / 2;

    if (wleft < 0) {
        w = screen.width;
        wleft = 0;
    }

    if (wtop < 0) {
        h = screen.height;
        wtop = 0;
    }

    var win = window.open(url, name, 'width=' + w + ', height=' + h + ', ' +
	'left=' + wleft + ', top=' + wtop + ', ' + 'location=no, menubar=no, ' +
	'status=no, toolbar=no, scrollbars=yes, resizable=no');

    win.resizeTo(w, h);
    win.moveTo(wleft, wtop);
    win.focus();

}


function UpperText(textBoxToUpper) {

    //
    // http://daniellarson.spaces.live.com/?_c11_BlogPart_BlogPart=blogview&_c=BlogPart&partqs=amonth%3D11%26ayear%3D2006
    // http://tlt.its.psu.edu/suggestions/international/bylanguage/greekchart.html
    //

    textBoxToUpper.value = textBoxToUpper.value.toUpperCase();

    for (i = 0; i < textBoxToUpper.value.length; i++) {
        textBoxToUpper.value = textBoxToUpper.value.replace(String.fromCharCode(902), String.fromCharCode(0x0391)); // ALPHA
        textBoxToUpper.value = textBoxToUpper.value.replace(String.fromCharCode(904), String.fromCharCode(0x0395)); // EPSILON
        textBoxToUpper.value = textBoxToUpper.value.replace(String.fromCharCode(905), String.fromCharCode(0x0397)); // ETA
        textBoxToUpper.value = textBoxToUpper.value.replace(String.fromCharCode(906), String.fromCharCode(0x0399)); // IOTA
        textBoxToUpper.value = textBoxToUpper.value.replace(String.fromCharCode(908), String.fromCharCode(0x039f)); // OMICRON
        textBoxToUpper.value = textBoxToUpper.value.replace(String.fromCharCode(910), String.fromCharCode(0x03a5)); // UPSILON
        textBoxToUpper.value = textBoxToUpper.value.replace(String.fromCharCode(911), String.fromCharCode(0x03a9)); // OMEGA
        textBoxToUpper.value = textBoxToUpper.value.replace(String.fromCharCode(962), String.fromCharCode(931));
    }

}


function ProperText(textBoxToUpper) {
    textBoxToUpper.value = textBoxToUpper.value.toProperCase();
}


function CheckKeyCode(event) {

    var Key = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;

    if ((Key == 189 || Key == 109) ||
	     (Key >= 48 && Key <= 57) ||
	     (Key == 8) || (Key == 9) ||
	     (Key == 17) || (Key == 116) ||
	     (Key == 8) || (Key == 46) ||
	     (Key == 17) || (Key == 86) ||
	     (Key >= 37 && Key <= 40) ||
	     (Key >= 96 && Key <= 105) ||
	     (Key == 13)) {
        return true;
    }
    else {
        return false;
    }

}


function URLEscape(url) {
    return url.replace(/\?/g, "$**$").replace(/&/g, "$*$");
}


function LogVisit(sessionGUID, sessionID, source) {

    /*
    var b_lang = navigator.userLanguage;
    var os = navigator.oscpu;
    var resolution = screen.width + " x " + screen.height;
    */

    var browser = navigator.userAgent;
    var refer = document.referrer;
    var currentURL = document.location.pathname + document.location.search; //page+query string
    currentURL = URLEscape(currentURL);
    refer = URLEscape(refer);

    //var logURL= "http://"+document.domain+"/logging/VisitLog.aspx?ran="+Math.random();    
    var logURL = "/logging/visitlog.aspx?ran=" + Math.random();
    var qstring = "&uastring=" + browser + "&referrer=" + refer + "&currentPage=" + currentURL + "&sessionid=" + sessionID + "&visitorGuid=" + sessionGUID + "&source=" + source;

    var img = new Image(0, 0);
    img.src = logURL + qstring;

}


function getAjaxRequest() {

    var r

    r = false;

    if (window.XMLHttpRequest) {
        try {
            r = new XMLHttpRequest();
        }
        catch (e) {
            r = false;
        }
    }

    if (window.ActiveXObject) {
        try {
            r = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (e) {
            r = false;
        }
    }

    return r;

}


function LogModuleClick(sessionGUID, moduleName, moduleGuid, collectionID) {
    var logURL = "http://" + document.domain + "/logging/moduleclicklog.aspx?ran=" + Math.random();
    var qstring = "&sessionid=" + sessionGUID + "&module=" + moduleName + "&moduleGuid=" + moduleGuid + "&collectionID=" + collectionID + "&actionid=1";
    var req = getAjaxRequest();
    req.onreadystatechange = function () { };
    req.open("GET", logURL + qstring);
    req.send(null);
}


function ScrollToBottom() {
    $(document).ready
	(
		function () {
		    window.scrollTo(0, 1500);
		}
	);
}

function UpdateCartCount(value) {

    $('.spanCartCount').html("(" + value + ")");
}

function ShowPopup(elementId, height, width, title) {
    if (title == null)
        title = $("#" + elementId).attr("title");
    if (width == null)
        width = 450;
    if (height == null)
        height = 175;
    dhtmlmodal.open('popup', 'div', elementId, title, 'width=' + width + 'px,height=' + height + 'px,center=1,resize=0,scrolling=1');
}

function SwitchLanguage(curLang) {
    var userLang = (navigator.language) ? navigator.language : navigator.userLanguage;

    $.ajax({
        url: "/logging/ajax.aspx?method=setlanguage&clientLang=" + userLang + "&curLang=" + curLang,
        dataType: "text",
        async: true,
        cache: true,
        success: function (res) {
            if (res != "" && res != " ") {
                window.location = res;
            }
        }
    }
	);
}

function SetSession(sessionVar, sessionValue) {
    var userLang = (navigator.language) ? navigator.language : navigator.userLanguage;

    $.ajax({
        url: "/logging/ajax.aspx?method=setsession&sessionVar=" + sessionVar + "&sessionValue=" + sessionValue,
        dataType: "text",
        async: false,
        cache: false,
        success: null
    }
	);
}

function SetUniqueRadioButton(nameregex, current) {
    re = new RegExp(nameregex);
    for (i = 0; i < document.forms[0].elements.length; i++) {
        elm = document.forms[0].elements[i]
        if (elm.type == 'radio') {
            if (re.test(elm.name)) {
                elm.checked = false;
            }
        }
    }
    current.checked = true;
}

function HideBrokenImage(img) {
    img.style.display = "none";
    img.onerror = "";
    return true;
}

function displaySkyscraperInWideScreens(div) {
    if (screen.width < 1025) {
        div.style.display = 'none';
    }
}

/*
$(function () {
$('.txtNumeric').keydown(function(e)
{
var key = e.charCode || e.keyCode || 0;
// allow backspace, tab, delete, numbers and keypad numbers only
return (
key == 8 || // backspace
//key == 9 || // tab
key == 46 || //delete
(key >= 48 && key <= 57));     // numbers            
//(key >= 96 && key <= 105)); // keypad
})

});
*/


$('.txtNumeric').live('keydown', function (e) {
    var key = e.charCode || e.keyCode || 0;
    // allow backspace, tab, delete, numbers and keypad numbers only
    return (
                key == 8 || // backspace
    //key == 9 || // tab
                key == 46 || //delete
                (key >= 48 && key <= 57) ||     // numbers            
                (key >= 96 && key <= 105)); // keypad
})

function ShowMultiVariateQuickZoomButton(variation) {
    if (variation == 'a') {
        SetSession('QuickZoomButtonVariation', 'a');
        $(".pnlZoomButtonSizeList").css("display", "");
		
    }
    else {
        SetSession('QuickZoomButtonVariation', 'b');
        $(".pnlZoomButtonDefault").css("display", "");
    }
	/*var useParent = false;
	if (typeof (s_gi) == 'undefined')
	{
		s_gi = parent.s_gi;
		useParent = true;
	}
	if (useParent)
		s_account = parent.s_account;
	var s = s_gi(s_account);
	s.prop33 = 'QuickZoomButtonVariant'+variation;
	s.tl(true, 'o');	*/	
}

//-- Retain to ensure error handling in IE8 (3311598) --//
function handleError (err, url, line) {
    if (err.indexOf('UpdatePanel') != -1) {      
      return true;
    }
    else
      return false; // let the browser handle the error
  }

window.onerror = handleError;

