//========================================================================================================================
//===  AJAX   ===
//========================================================================================================================




// ----------------------
// -- CHANGE FONT SIZE --
// ----------------------
function getFontSize(delta) {
    displayLoading();
    var url = strPath + '/_inc/font_size.ajax.php?delta=' + delta;

    // If the user is using IE7/Mozilla/Firefox/Safari/etc
    if (window.XMLHttpRequest) {
        //Intiate the object
        xmlhttp = new XMLHttpRequest();
        //Set the mime type
//        xmlhttp.overrideMimeType('text/xml');
    }
    // If the user is using IE6
    //else if (window.ActiveXObject) {
    else {
        //Intiate the object
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }

    xmlhttp.open('GET', url, true);
    //Check that the PHP script has finished sending us the result
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            //Get current and new font size
            newSize = xmlhttp.responseText;
            if (newSize != 0) {
                changeFontSize(newSize);
            }
        } else {
            //If the PHP script fails to send a response, or sends back an error, display a simple user-friendly notification
            //alert('Error');
        }
    };
    xmlhttp.send(null);
    hideLoading();
}


// --------------------------------------
// -- DISPLAY DYNAMIC CONTENT IN A DIV --
// --------------------------------------
function getDynamicContent(divId, strUrl) {
    displayLoading();
    // If the user is using IE7/Mozilla/Firefox/Safari/etc
    if (window.XMLHttpRequest) {
        //Intiate the object
        xmlhttp = new XMLHttpRequest();
        //Set the mime type
//        xmlhttp.overrideMimeType('text/xml');
    }
    // If the user is using IE6
    //else if (window.ActiveXObject) {
    else {
        //Intiate the object
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open('GET', strUrl, true);
    //Check that the PHP script has finished sending us the result
    xmlhttp.onreadystatechange = function() {
        if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
            //Get div where result must appear
            divContent = document.getElementById(divId);
            //Feed div with PHP result
            divContent.innerHTML = xmlhttp.responseText;
        } else {
            //If the PHP script fails to send a response, or sends back an error, display a simple user-friendly notification
            //alert('Error');
        }
    };
    xmlhttp.send(null);
    hideLoading();
}


//========================================================================================================================
//===  OTHER   ===
//========================================================================================================================

function changeFontSize(newSize) {
    var colCss = document.getElementsByTagName('link');
    //Always enable style1.css
    colCss[0].disabled = false;
    //Start from style2.css
    for(var i = 1; i < colCss.length ; i++)
    {
        if (i == newSize - 1) {
            colCss[i].disabled = false;
        } else {
            colCss[i].disabled = true;
        }
    }
}

function displayLoading()
{
    document.getElementById("loading").style.visibility = 'visible';
}

function hideLoading()
{
    document.getElementById("loading").style.visibility = 'hidden';
}

function openWindow(strUrl, iHeight, iWidth) {
    //window.open(strUrl, 'Schmutz-opticiens', 'height=' + iHeight + ', width=' + iWidth + ', screenX=100, screenY=50, scrollbars=no, menubar=no, resizable=yes, toolbar=no, location=no, status=no');
    window.open(strUrl, '', 'height=' + iHeight + ', width=' + iWidth + ', screenX=100, screenY=50, scrollbars=no, menubar=no, resizable=yes, toolbar=no, location=no, status=no');
    //alert('height=' + iHeight + ', width=' + iWidth + ', screenX=100, screenY=50, scrollbars=no, menubar=no, resizable=yes, toolbar=no, location=no, status=no');
}

function doPreload(){
	var the_images = new Array('S/home_S_1.jpg','S/lunettes_S_1.jpg','S/lentilles_S_1.jpg','S/jumelles_S_1.jpg','S/bassevision_S_1.jpg','S/garanties_S_1.jpg','S/contact_S_1.jpg');
	preloadImages(the_images);
}


function preloadImages(the_images_array) {
	for(loop = 0; loop < the_images_array.length; loop++) {
		var an_image = new Image();
		an_image.src = the_images_array[loop];
	}
}


function WM_imageSwap(daImage, daSrc)
{
	var objStr,obj;
	if(document.images){
		if (typeof(daImage) == 'string') {
			objStr = 'document.' + daImage;
			obj = eval(objStr);
			obj.src = daSrc;
		} else if ((typeof(daImage) == 'object') && daImage && daImage.src) {
			daImage.src = daSrc;
		}
	}
}
