
//--switchpics
function switchpic(thepic, filename){
	thepic.src = "images/" + filename +".jpg";
}

function envoie(){
	var string01="mailto:info@zvisuel.com?subject=Demande de demonstration&body=Je suis interesse par les applications suivantes :%0D%0A%0D%0A";
	var vConfpresse="";
	var vCours="";
	var vAutre="";
	var vPrenom="";
	var vNom="";
	var vCompagnie="";
	var vPosition="";
	var vAdresse="";
	var vTel="";
	var vFax="";
	var vEmail="";
	var df=document.infoform;
	if (df.confpresse.checked){var vConfpresse = df.confpresse.value + "%0D%0A"}
	if (df.cours.checked){var vCours = df.cours.value + "%0D%0A"}
	if (df.autre.value!=""){var vAutre = "Autre : " + escape(df.autre.value) + "%0D%0A"}
	var string02 = vConfpresse + vCours + vAutre;
				
	if (df.prenom.value!=""){var vPrenom = "INFORMATIONS PERSONNELLES :%0D%0A%0D%0ANOM : " + df.prenom.value + "%20"}
	if (df.nom.value!=""){var vNom = df.nom.value + "%0D%0A"}
	if (df.compagnie.value!=""){var vCompagnie = "COMPAGNIE : " + df.compagnie.value + "%0D%0A"}
	if (df.position.value!=""){var vPosition = "POSITION : " + df.position.value + "%0D%0A"}						
	if (df.adresse.value!=""){var vAdresse = "ADRESSE :%0D%0A" + escape(df.adresse.value) + "%0D%0A"}
	if (df.tel.value!=""){var vTel = "TEL : " + df.tel.value + "%0D%0A"}
	if (df.fax.value!=""){var vFax = "FAX : " + df.fax.value + "%0D%0A"}
	if (df.email.value!=""){var vEmail = "E-MAIL : " + df.email.value + "%0D%0A"}
	
	var string03 = vPrenom + vNom + vCompagnie + vPosition + vAdresse + vTel + vFax + vEmail;

	if ((string02=="")||(df.prenom.value=="")||(df.nom.value=="")||(df.email.value=="")){alert("Veuillez remplir le formulaire correctement avant d'envoyer votre requete")}
	else {location.href=string01 + string02 + "%0D%0A" + string03;}
}
	







//---général: variations des langues
var langue = "FR";
var AlertString = "Veuillez entrer un terme dans la case de recherche";
var EnteteString = "Résultat de la recherche pour";
var NoresultString = "Ce terme n'apparait pas dans le site";
var unresultat = "1 résultat trouvé";
var pasderesultat = "Aucun résultat trouvé";
var resultats = "résultats trouvés";
var nbredematch = "Nombre de hits";
var lescore = "Score";
var CloseWindowString = "Fermer";

var howback = 1;

function setback(steps){
	howback = howback + steps;
}

function goback(){
	if (history.length > 0){
		history.go(-howback);
	}
}

function printsection(){
	texte.focus();
	print();
}


function removebackground(){
	document.body.bgColor="white";
	document.body.style.color="black";
}
function revertback(){
	document.body.bgColor="#6E2114";
	document.body.style.color="white";
}



function GotoResults(TargetTopic){
	location.href= TargetTopic;
	texte.close();
	//texte.focus();
}

//pass the query from other page;

function passquery(query){
	if (query.length == 0) {
        alert(AlertString);
	}
	else{
		top.querypassed = query;
		setback(1);
		location.href = "../../common/recherche/recherche.html";
	}
}


// ----------------------------------------------------------------------------
// Helper Functions
// ----------------------------------------------------------------------------


// Compares the two values, used for sorting output results
// Results that match all search terms are put first, highest score
function SortCompare (a, b)
{
    if (a[2] < b[2]) return 1;
    else if (a[2] > b[2]) return -1;
    else if (a[1] < b[1]) return 1;
    else if (a[1] > b[1]) return -1;
    else return 0;
}

function pattern2regexp(pattern) {
    pattern = pattern.replace(/\./g, "\\.");
    pattern = pattern.replace(/\*/g, ".*");
    pattern = pattern.replace(/\?/g, ".?");
    return "^" + pattern + "$";
}

// ----------------------------------------------------------------------------
// Parameters initialisation (globals)
// ----------------------------------------------------------------------------

var per_page = 100;

var page = 1;

var andq = 1;

var cat = -1;   // search all categories

UseCats = false;

var searchWords = new Array();
var data = new Array();
var output = new Array();


// ----------------------------------------------------------------------------
// Main search function starts here
// ----------------------------------------------------------------------------


function amssearch(query) {
    // give up early if no search words provided
	if (query.length == 0) {
        alert(AlertString);
        return;
    }

    query = query.replace(/[\+\_]/g, " "); // replace '+', '_' with spaces.
    // split search phrase into words
    searchWords = query.split(" "); // split by spaces.
	
	document.SearchForm.SearchString.value = query;
	texte.document.clear();
	texte.document.writeln("<html><head><title></title><link href='../../../common/ams.css' rel='stylesheet'>");
	texte.document.writeln('<script language="JavaScript" type="text/javascript" src="../../common/1ms.js"></script>');
	texte.document.writeln("</head>");
	texte.document.writeln('<body onbeforeprint="javascript:document.body.bgColor=' + "'white'" + ";document.body.style.color=" + "'black'" + '" onafterprint="javascript:document.body.bgColor=' + "'#6E2114'" + ";document.body.style.color=" + "'white'" + '">');
	texte.document.writeln(EnteteString + " <b>" + query + " </b>:<br><br>");

	numwords = searchWords.length;
    kw_ptr = 0;
    outputline = 0;
    usewildcards = 0;
    ipage = 0;
	//added by CG
	output.length = 0;
	//end of added by CG
	
    for (sw = 0; sw < numwords; sw++) {

        re = new RegExp(pattern2regexp(searchWords[sw]), "gi");

        for (kw_ptr = 0; kw_ptr < keywords.length; kw_ptr++) {
            data = keywords[kw_ptr].split(",");

            //match_result = searchWords[sw] == data[0];
            match_result = data[0].search(re);

            if (match_result != -1) {
                // keyword found, include it in the output list

                for (kw = 1; kw < data.length; kw += 2) {
                    // check if page is already in output list
                    pageexists = 0;
                    ipage = data[kw];
                    for (ol = 0; ol < outputline; ol++) {

                        if (output[ol][0] == ipage) {
                            // page is already in output list so add to count and extra
                            if (output[ol][1] > 10000) {
                                // take it easy if its too big (to prevent huge scores)
                                output[ol][1] += 1;
                            } else {
                                output[ol][1] += parseInt(data[kw+1]);  // add in score
                                output[ol][1] *= 2;             // double score as we have two words matching
                            }
                            output[ol][2] += 1;                 // increase word match count
                            pageexists = 1;
                        }
                    }
                    if (pageexists == 0) {
                        // new page to add to list
                        // create 3 fields for each output
                        output[outputline] = new Array(0,0,0);
                        // now fill in the values for each field
                        output[outputline][0] = ipage;      // page index
                        output[outputline][1] = parseInt(data[kw+1]);   // score
                        output[outputline][2] = 1;          // single word match only
                        outputline++;
                    }

                }
           }
        }
    }

    // Get number of pages matched
    matches = outputline;

    // Sort results in order of score, use "SortCompare" function
    if (matches > 1)
        output.sort(SortCompare);

    // Count number of output lines that match ALL search terms
    oline = 0;
    fullmatches = 0;

    if (numwords > 1 || (UseCats && cat != -1)) {
        origmatches = matches;
        while (oline < origmatches) {
            ResFiltered = false;
            if (UseCats && cat != -1) {
                //Using cats and not doing an "all cats" search
                if (catpages[output[oline][0]] != cat) {
                    matches = matches - 1;
                    ResFiltered = true;
                }
            }
            if (ResFiltered == false) {
                if (output[oline][2] == numwords) {
                    fullmatches++;
                } else if (andq == 1) {
                    matches = matches - 1
                    ResFiltered = true;
                }
            }
            oline++;
        }
        //if (andq == 1)
            //matches = fullmatches;
    }

    //Display search result information
    texte.document.writeln("<small>");
    if (matches == 1)
        texte.document.writeln("<i>" + unresultat + "</i><br>");
    else if (matches == 0)
        texte.document.writeln("<i>" + pasderesultat + "</i><br>");
    else if (numwords > 1 && andq == 1) //AND
        texte.document.writeln("<i>" + fullmatches + " " + resultats + "</i><br>");
    else
        texte.document.writeln("<i>" + matches + " " + resultats + "</i><br>");

    texte.document.write("</small><br>");

    // determine current line of result from the output array
        arrayline = 0;
        out_counter = 0;

    // display the results
    while (arrayline < output.length) {
        ipage = output[arrayline][0];
        score = output[arrayline][1];
        texte.document.writeln("<b>" + out_counter + ".</b>&nbsp;<a href='javascript:parent.GotoResults(" + '"' + urls[ipage] + '"' + ")'>" + titles[ipage] + "</a><br>");
		texte.document.writeln("<i>" + descriptions[ipage] + "<br>");
        texte.document.writeln("<small>" + nbredematch + ": " + output[arrayline][2]);  
		texte.document.writeln(" " + lescore + ": " + score + "</i></small></font><br><br>");
        arrayline++;
        out_counter++;
    }
	texte.document.writeln("</body></html>");
	texte.document.close();
	top.querypassed = "";
	//optionnally sets the back button to go back n steps directly to section before search was entered.
	//setback(1);
}


















