/**
 * Ouvrir un document avec Microsoft Word
 */
function runApp(str, host) {
    var isIE = (navigator.appName == "Microsoft Internet Explorer");
    var msg;
    var extension = str.substr(str.lastIndexOf(".") + 1);
    var isExcel = (extension == 'xls' || extension == 'xlsx');  
    if(opencrm.config.webdav_on == 1) {
    	webdav_str = str.replace(/https:\/\//gi, "file://");
	    webdav_str = str.replace(/http:\/\//gi, "file://");
    	if(isIE) {
	    	try {
	    		try {
					if(isExcel) {
						var appWord = new ActiveXObject("Excel.Application");
					} else {
						var appWord = new ActiveXObject("Word.Application");
					}
				} catch(e) {
					msg = "Impossible d'ouvrir ce document en modification. Par mesure de sécurité, le serveur web doit figurer dans la liste de vos sites de confiance définis dans vos options de Internet Explorer.";
					msg = msg + "\n\n";
					msg = msg + "Pour ceci : ";
					msg = msg + "\n";
					msg = msg + "Ouvrez le menu 'Tools' --> Cliquez sur 'Internet Options...' --> Ouvrez l'onglet 'Security'";
					msg = msg + "\n";
					msg = msg + "Ensuite cliquez sur le bouton 'Trusted Site' --> Cliquez sur 'Sites...'";
					msg = msg + "\n";
					msg = msg + "Inscrivez '" + host + "' --> Cliquez 'Add' pour l'ajouter à la liste --> 'Ok' pour confirmer";
					alert(msg);
					return false;
				}
		        appWord.Visible = true;
		        if(isExcel) {
		        	appWord.workbooks.Open(webdav_str);
		        } else {
		        	appWord.Documents.open(webdav_str);
		        }
		        appWord.Activate();
	    	} catch (ex) {
	    	}
	    	
	    	return false;
	    } else {
	    	//must check if add on is present
	    	if(window.amster_opencrm){ //extension found
	    		webdav_str = webdav_str.replace(/file:\/\//gi, "amslocalfile://");
	    		
		    	var res = window.open(webdav_str, "amsfile_winhandler");
		    	res.close();
	    	}
	    	else{
	    		alert('You must install Amster OpenCRM Protocol Handler.\nYou will be redirected on the install page.');
	    		window.open("http://crm.alunys.com/extension/", "OpenCRM Protocol Handler");
	    	}
	    	
	    	return false;
	    }
    }
    else if(opencrm.config.webdav_on == 2) {
    	window.open(str);
    	return false;
    }
    
    if(!host) host = 'http://votre_serveur';
    if(isIE) {
		try {
			if(isExcel) {
				var appWord = new ActiveXObject("Excel.Application");
			} else {
				var appWord = new ActiveXObject("Word.Application");
			}
		} catch(e) {
			msg = "Impossible d'ouvrir ce document en modification. Par mesure de sécurité, le serveur web doit figurer dans la liste de vos sites de confiance définis dans vos options de Internet Explorer.";
			msg = msg + "\n\n";
			msg = msg + "Pour ceci : ";
			msg = msg + "\n";
			msg = msg + "Ouvrez le menu 'Tools' --> Cliquez sur 'Internet Options...' --> Ouvrez l'onglet 'Security'";
			msg = msg + "\n";
			msg = msg + "Ensuite cliquez sur le bouton 'Trusted Site' --> Cliquez sur 'Sites...'";
			msg = msg + "\n";
			msg = msg + "Inscrivez '" + host + "' --> Cliquez 'Add' pour l'ajouter à la liste --> 'Ok' pour confirmer";
			alert(msg);
			return false;
		}
        appWord.Visible = true;
        if(isExcel) {
        	appWord.workbooks.Open(str);
        } else {
        	appWord.Documents.open(str);
        }
        appWord.Activate();
    } else {
    	
    	//must check if add on is present
    	if(window.amster_opencrm){ //extension found
    		var newstr = null;
    		if(str.indexOf("https") >= 0){
    		 	newstr = str.replace(/https:\/\//gi, "amsfilesec://");
    		}
    		else if(str.indexOf("http") >= 0){
				newstr = str.replace(/http:\/\//gi, "amsfile://");
    		}
    		
    		if(!newstr){
    			alert("Protocol is not supported ...")
    			return false;
    		}
    		
	    	var res = window.open(newstr, "amsfile_winhandler");
	    	res.close();
    	}
    	else{
    		alert('You must install Amster OpenCRM Protocol Handler.\nYou will be redirected on the install page.');
    		window.open("http://crm.alunys.com/extension/", "OpenCRM Protocol Handler");
    	}
    	
        return false;
    }
    
    return false;
}


function selectAllOptions(select) {
	if(select) {
		for(var i = 0; i < select.options.length; i++) {
			select.options[i].selected = true;
		}
	}
}
