﻿if(typeof navig == 'undefined') {
	var navig = {};
}
navig.IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
// exactly Internet Explorer 7
navig.IE7 = false /*@cc_on || @_jscript_version == 5.7 @*/;
// at least Internet Explorer 7
navig.gteIE7 = false /*@cc_on || @_jscript_version >= 5.7 @*/;
// any Internet Explorer (thanks to Dean)
navig.isMSIE = /*@cc_on!@*/false;
var strChUserAgent = navigator.userAgent;
var intSplitStart = strChUserAgent.indexOf("(",0);
var intSplitEnd = strChUserAgent.indexOf(")",0);
var strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd);
navig.IE6 = (strChMid.indexOf("MSIE 6") != -1) ? true : false;
//forcer nombres pour input saisie
function verif_nombre(champ){
	var chiffres = new RegExp("[0-9]");
	//var chiffres = new RegExp("[0-9\a-z\A-Z]");
	var verif;
	var points = 0;
	for(x = 0; x < champ.value.length; x++){
		verif = chiffres.test(champ.value.charAt(x));
		if(champ.value.charAt(x) == "."){
			points++;
		}
		if(points > 1){
			verif = false; 
			points = 1;
		} 
		if(verif == false){
			champ.value = champ.value.substr(0,x) + champ.value.substr(x+1,champ.value.length-x+1);
			x--;
		}
	}
}
//tests mails
isEmail = function(emailStr) {
	var checkTLD = 1;
	var knownDomsPat = /^(com|net|org|edu|int|mil|gov|arpa|biz|aero|name|coop|info|­pro|museum|fr)$/;
	var emailPat = /^(.+)@(.+)$/;
	var specialChars = "\\(\\)><@,;:\\\\\\\"\\.\\[\\]";
	var validChars = "\[^\\s" + specialChars + "\]";
	var quotedUser = "(\"[^\"]*\")";
	var ipDomainPat = /^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
	var atom = validChars + '+';
	var word = "(" + atom + "|" + quotedUser + ")";
	var userPat = new RegExp("^" + word + "(\\." + word + ")*$");
	var domainPat = new RegExp("^" + atom + "(\\." + atom +")*$");
	var matchArray = emailStr.match(emailPat);
	if (matchArray == null) { return false; }
	var user = matchArray[1];
	var domain = matchArray[2];
	for (i=0; i<user.length; i++) {
		if (user.charCodeAt(i) > 127) { return false; }
	}
	for (i=0; i<domain.length; i++) {
		if (domain.charCodeAt(i) > 127) { return false; }
	}
	if (user.match(userPat) == null) { return false; }
	var IPArray=domain.match(ipDomainPat);
	if (IPArray != null) {
		for (var i=1; i<=4; i++) {
			if (IPArray[i] > 255) { return false; }
		}
		return true;
	}
	var atomPat = new RegExp("^" + atom + "$");
	var domArr = domain.split(".");
	var len = domArr.length;
	for (i=0; i<len; i++) {
		if (domArr[i].search(atomPat) == -1) { return false; }
	}
	if (checkTLD && domArr[domArr.length-1].length!=2 && domArr[domArr.length-1].search(knownDomsPat)==-1) { return false; }
	if (len < 2) { return false; }
	return true;
}
function bonmail(mailteste){
	var reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]­{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');

	if(reg.test(mailteste)){
		return(true);
	}
	else{
		return(false);
	}
}

//biblio dates / ages
function get_Date(strDate){	 
	// Cette fonction reçoit une date JJ/MM/AAA et retourne un objet Date 
	day = strDate.substring(0,2);
	month = strDate.substring(3,5);
	year = strDate.substring(6,10);
	d = new Date();
	d.setDate(day);
	d.setMonth(month-1);
	d.setFullYear(year); 
	return d;  
}
function tjs_age(dt) {
	// Cette fonction calcule l'âge à partir de la date de naissance
	// Cette fonction reçoit un objet Date et retourne une chaîne de type : "15 ans et 6 mois"
	var d = get_Date(dt);
	var m = new Date();
	var age = ""; var age_a = 0; var age_m = 0;
	if (d != 0) {
		if (d.getTime() > m.getTime()) {
			age = gLabels.ageError1;
		}
		age_a = m.getFullYear() - d.getFullYear();
		m.setYear(d.getYear());
		if ((d.getTime() > m.getTime()) && (d.getMonth() - m.getMonth()!=0)) {age_a--;}
		if (d.getMonth() >= m.getMonth()) {
			age_m = 12 - (d.getMonth() - m.getMonth())
		}
		else {
			age_m = (m.getMonth() - d.getMonth())
		}
		if (age_m == 12) {age_m = 0;}
		if (age_a == 1) { age = age_a + gLabels.ageYear;}
		if (age_a > 1) { age = age_a + gLabels.ageYears;}
		//on n'écrit pas les mois
		//if ((age_a>0)&&(age_m>0)) {age+=" et "}
		//if (age_m>0) {age+=age_m+" mois"}
		if (age == "") { age = gLabels.ageLess;}
	}
	else {
		age = gLabels.ageError2;
	}
	return age;
}

// biblio XML
var XML = {};

/**  
* Create a new Document object. If no arguments are specified,  
* the document will be empty. If a root tag is specified, the document  
* will contain that single root tag. If the root tag has a namespace  
* prefix, the second argument must specify the URL that identifies the  
* namespace.  
*/ 
 
XML.newDocument = function(rootTagName, namespaceURL) {   
 if (!rootTagName) rootTagName = "";   
  if (!namespaceURL) namespaceURL = "";   
  if (document.implementation && document.implementation.createDocument) {   
    // This is the W3C standard way to do it   
    return document.implementation.createDocument(namespaceURL, rootTagName, null);   
  }   
  else { // This is the IE way to do it   
    // Create an empty document as an ActiveX object   
    // If there is no root element, this is all we have to do   
    var doc = new ActiveXObject("MSXML2.DOMDocument");   
    // If there is a root tag, initialize the document   
    if (rootTagName) {   
      // Look for a namespace prefix   
      var prefix = "";   
      var tagname = rootTagName;   
      var p = rootTagName.indexOf(':');   
      if (p != -1) {   
        prefix = rootTagName.substring(0, p);   
        tagname = rootTagName.substring(p+1);   
      }   
      // If we have a namespace, we must have a namespace prefix   
      // If we don't have a namespace, we discard any prefix   
      if (namespaceURL) {   
        if (!prefix) prefix = "a0"; // What Firefox uses   
      }   
      else prefix = "";   
      // Create the root element (with optional namespace) as a   
      // string of text   
      var text = "<" + (prefix?(prefix+":"):"") +  tagname +   
          (namespaceURL   
           ?(" xmlns:" + prefix + '="' + namespaceURL +'"')   
           :"") +   
          "/>";   
      // And parse that text into the empty document   
      doc.loadXML(text);   
    }   
    return doc;   
  }   
};   


 /**  
 * Synchronously load the XML document at the specified URL and  
 * return it as a Document object  
 */  
XML.load = function(url) {   
	//NE MARCHE PAS AVEC SAFARI PC CAR xmldoc.load EST UNDEFINED...
   // Create a new document with the previously defined function   
   var xmldoc = XML.newDocument();  
   xmldoc.async = false;  // We want to load synchronously   
   xmldoc.load(url);      // Load and parse   
    return xmldoc;         // Return the document   
};   

/**  
* Asynchronously load and parse an XML document from the specified URL.  
* When the document is ready, pass it to the specified callback function.  
* This function returns immediately with no return value.  
*/  
XML.loadAsync = function(url, callback) {   
    var xmldoc = XML.newDocument();   
    // If we created the XML document using createDocument, use   
    // onload to determine when it is loaded   
    if (document.implementation && document.implementation.createDocument) {   
        xmldoc.onload = function() { callback(xmldoc); };   
    }   
    // Otherwise, use onreadystatechange as with XMLHttpRequest   
    else {   
        xmldoc.onreadystatechange = function() {   
            if (xmldoc.readyState == 4) callback(xmldoc);   
        };   
    }   
    // Now go start the download and parsing   
    xmldoc.load(url);   
};  

/**  
* Parse the XML document contained in the string argument and return  
* a Document object that represents it.  
*/  
XML.parse = function(text) {   
    if (typeof DOMParser != "undefined") {   
        // Mozilla, Firefox, and related browsers   
        return (new DOMParser()).parseFromString(text, "application/xml");   
    }   
    else if (typeof ActiveXObject != "undefined") {   
        // Internet Explorer.   
        var doc = XML.newDocument();  // Create an empty document   
        doc.loadXML(text);            // Parse text into it   
        return doc;                   // Return it   
    }   
    else {   
        // As a last resort, try loading the document from a data: URL   
        // This is supposed to work in Safari. Thanks to Manos Batsis and   
        // his Sarissa library (sarissa.sourceforge.net) for this technique.   
        var url = "data:text/xml;charset=utf-8," + encodeURIComponent(text);   
        var request = new XMLHttpRequest();   
        request.open("GET", url, false);   
        request.send(null);   
        return request.responseXML;   
    }   
};
//petites fonctions pour palier pb de whitespaces FF
//à utiliser à la place des propriétés natives nextSibling, previousSibling ou firstChild 
XML.get_nextSibling = function(n){
	y = n.nextSibling;
	while (y.nodeType!=1){
		y = y.nextSibling;
	}
	return y;
}

XML.get_previousSibling = function(n){
	y = n.previousSibling;
	while (y.nodeType!=1){
		y = y.previousSibling;
	}
	return y;
}

XML.get_firstChild = function(n){
	y = n.firstChild;
	while (y.nodeType!=1){
		y = y.nextSibling;
	}
	return y;
}
//fonctions pour ouverture MAGAZINE PDF (fournies par prestataire)
var WidthCata = screen.width;
var HeightCata = screen.height;
var redim=true;
var page = "";
var onglet = "";
var idprod = "";
var urlSuppl = "";
var ns4 = (document.layers)? true:false;
var ie4 = (document.all)? true:false;
var dom = (document.getElementById)? true:false;
var DefaultWidth = 1024;
var DefaultHeight = 768;
var ssuppl=window.location.search;

if (ie4 || dom)	{
	xMax = screen.width;
	yMax = screen.height;
} else if (ns4) {
	xMax = window.outerWidth;
	yMax = window.outerHeight;
} else {
	xMax = DefaultWidth;
	yMax = DefaultHeight;
}

function launchwin(winurl,winname,winWidth,winHeight)
	{
	var xMax, yMax, xOffset, yOffset;
	if (ie4 || dom)
		{
		xMax = screen.width;
		yMax = screen.height;
		}
	else if (ns4)
		{
		xMax = window.outerWidth;
		yMax = window.outerHeight;
		}
	else
		{
		xMax = 800;
		yMax = 600;
		}
	xOffset = (xMax - winWidth)/2;
	yOffset = (yMax - winHeight)/2;
	ktawin=window.open(winurl,winname,'width='+winWidth
+',height='+winHeight
+',screenX='+xOffset
+',screenY='+yOffset
+',top='+yOffset
+',left='+xOffset
+',scrollbars=no,resizable=yes,status=no,menubar=no');
	ktawin.focus();
	//ktawin.redim=redim;
	//ktawin.resizeTo(winWidth,winHeight);
}

function launch_catalogue(urlbasekta,param,WidthCataClient,HeightCataClient) {
	if(WidthCataClient!=undefined) WidthCata=WidthCataClient;
	if(HeightCataClient!=undefined) HeightCata=HeightCataClient;
	if(!urlbasekta) urlbasekta="appli.htm";
	if (urlbasekta.indexOf("appli")<0) urlbasekta=urlbasekta+"appli.htm";
	if(!param){ 
		launchwin(urlbasekta+ssuppl,'catalogue',WidthCata,HeightCata); 
		}
	else{
		launchwin(urlbasekta+'?'+param,'catalogue',WidthCata,HeightCata);
	}
}
