

// GENERAL VARS AND FUNCTIONS ////////////////////////////////////////////////////////////////////


// general IE and Windows catch
var IE = (navigator.appName == "Microsoft Internet Explorer" ? true : false);
var Version;
if (IE) {
    var appV = navigator.appVersion.split("MSIE");
    Version = parseFloat(appV[1]);
}
var Win = (navigator.userAgent.indexOf('Win') == -1 ? true : false);



// img preloader (needed to give priority to rollovers & bkgd imgs)
function imgPreloader(imgStr) {
    var imgObj = new Array();
    for (i=0; i<imgStr.length; i++) {
        imgObj[i] = new Image();
        imgObj[i].src = imgStr[i];
    }
}



// returns object with window (body) size
function windowSize() {
	var winsize = new Object();
	
	if ( typeof( window.innerWidth ) == 'number' ) {
		//Non-IE
		winsize.width = window.innerWidth;
		winsize.height = window.innerHeight;
	} else if ( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
		//IE 6+ in 'standards compliant mode'
		winsize.width = document.documentElement.clientWidth;
		winsize.height = document.documentElement.clientHeight;
	} else if ( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
		//IE 4 compatible
		winsize.width = document.body.clientWidth;
		winsize.height = document.body.clientHeight;
	}
	
	return winsize;
}



/*// general mouse position tracking
if (!IE) {
    document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove = getMouseXY;
var MouseX = 0
var MouseY = 0

function getMouseXY(e) {
  if (IE) {
    MouseX = event.clientX + document.body.scrollLeft
    MouseY = event.clientY + document.body.scrollTop
  } else {
    MouseX = e.pageX
    MouseY = e.pageY
  }  
  // catch possible negative values in NS4
  if (MouseX < 0){MouseX = 0}
  if (MouseY < 0){MouseY = 0}  

  return true
}*/
        


// general popups
function poponclick(u,n,w,h,s) {
	popwin = window.open(u,n,"width="+w+",height="+h+",toolbar=no,menubar=no,directories=no,status=no,location=no,resize=yes,top=80,left=250,scrollbars="+s);
    popwin.moveTo(250,80);
    popwin.resizeTo(w,h);
    if (window.focus) {
        popwin.focus();
    }
}



// general full screen popup
function fullpoponclick(url) {
    if ((Win) && (IE)) {
        fullpop = window.open(url,"fullpop_name","scrollbars=no","fullscreen=yes");
        fullpop.moveTo(0,0);
        fullpop.resizeBy(16,0);
    } else {
        fullpop = window.open(url,"fullpop_name","width="+screen.availWidth+",height="+screen.availHeight+",toolbar=no,menubar=no,directories=no,status=no,location=no,resize=yes,scrollbars=no");
        fullpop.moveTo(0,0);
        fullpop.resizeTo(screen.availWidth,screen.availHeight);
    }
    if (window.focus) {
        fullpop.focus();
    }
}



// general button imgs rollovers
function rollon(o) {
    offPath=o.src;
    newPath=offPath.replace(/_off/, "_on");
    o.src=newPath;  
}
function rollonIEpng(o) {
    offPath=o.style.filter;
    newPath=offPath.replace(/_off/, "_on");
    o.style.filter=newPath;
}
function rolloff(o) {
    onPath=o.src;
    newPath=onPath.replace(/_on/, "_off");
    o.src=newPath;
}
function rolloffIEpng(o) {
    onPath=o.style.filter;
    newPath=onPath.replace(/_on/, "_off");
    o.style.filter=newPath;
}



// general href function
function linkTo(url) {
    window.location.href = url;
}



// general text size function
function changefontsize(id, size) {
document.getElementById(id).style.fontSize = size + "px";
}



// href ajax processing (GET)
var Xhro = null;
var Id;
var Callback;

function XHRhref(url,id,callback,loader) {
    Id = id;
    Callback = callback;
    
    // display loading gif
		if (loader) {
            var previousHTML = document.getElementById(Id).innerHTML;
    		document.getElementById(Id).innerHTML = "<img src=\"./layout/loading.gif\" style=\"margin:15px;\" alt=\"Loading...\" />" + "<div style=\"margin:0; margin-top:-102px; padding:0; opacity:.40; filter:alpha(opacity=40); min-height:204px; background:transparent; border:none;\">"+previousHTML+"</div>";
        } else {
            // probably back-office
        }
	
    // Create the XML request object
    if(window.XMLHttpRequest) { // Firefox, Opera...
		Xhro = new XMLHttpRequest();
    } else if (window.ActiveXObject) { // MSIE
		Xhro = new ActiveXObject("Microsoft.XMLHTTP");
    } else {
		alert('Sorry, your browser does not support the data display system implemented here. Please update there :\r\n http://www.mozilla.org/products/firefox/');
		return; // Failed to create the request
	}
	
    // Make the request
	Xhro.onreadystatechange = handleResponseText;
    Xhro.open ('GET',url,true);
    //alert(navigator.vendor.substring(0,5)); / .vendor pour detecter Safari et pas Netscape en gŽnŽral avec .appName et faire alterner le utf8_decode
    Xhro.send (null); // null cuz GET method
}

function handleResponseText() { // function to handle changed request states
	if (Xhro.readyState == 4) {
		//doSomethingWithData(Xhro.responseXML.getElementsByTagName('quote')[0].firstChild.data); // Retrieve the data between the <quote> tags
		if (Id != '') {
    		document.getElementById(Id).innerHTML = Xhro.responseText;
    		setTimeout(Callback,10);
        } else {
            // back-office
    		setTimeout(Callback,10);
        }
	}
}




// using jQuery
function rollOpacity(o, op) {
    $("#"+o.id).animate({opacity:op}, 100, "linear", function() {});
}

