
	var cx = "";
	var qstring_values = "";
	var soumis = 0;
	var search_string = "";
	var page_lang = $("html").attr("lang");
	var pas_repondu = (page_lang == "en") ? "Please let us know if you are satisfied" : "Veuillez choisir une réponse";
	var deja_soumis = (page_lang == "en") ? "You have already submitted the survey" : "Vous avez déja soumis ce sondage.";
	var suffix = (page_lang == "en") ? "_en" : "";
	
	jQuery.qstring_value_pairs = function() {
		var r = {};
		var q = location.toString()
		q = q.replace(/\&$/,''); // remove the trailing &
		q = q.split('?')
		if(q[1]){
			jQuery.each(q[1].split('&'), function(index){
				var key = this.split('=')[0];
				var val = this.split('=')[1];
				// ingnore empty values
				if(val){
					r[key] = val;
				}
			});
			return r;
		}else{
			return "";
		}
	};
	
	function radioSelect(groupeBouton) {
		for (var i = 0; i < groupeBouton.length; i++) {
			if (groupeBouton[i].checked) {
				return i
			}
		}
		return -1
	}
	
	function assign_action(){
		var pageNameString = location.toString();
		$('#nom').attr('value', search_string);
		$('#prenom').attr('value', '<a href="'+pageNameString+'" target="_blank">Google</a>');
		$('#adresse_courriel').attr('value', $('#sondage input:checked').val() + '@tisf.ait');
		doSubmit(document.forms[0]);
	}
	
	function doSubmit(Form){
		var MsgErreurs = new Array();
		var i = 0;
	
		// Validation prenom
		if(radioSelect(Form.satisfaction) == -1){
			MsgErreurs[i++]= pas_repondu;
		}
		
		// Validation finale
		if(MsgErreurs.length == 0){
			if(soumis == 1){
				alert(deja_soumis);
			}
			else {
				soumis = 1;
		//		alert("FORMULAIRE EN DEVELOPEMENT");
				openWindow('https://transaction.hydroquebec.com/kf/SefcoServlet', 'popupWin', 350, 300);
				Form.submit();
			}
		}
		else {
			var strErreur = "";
			for (var j = 0; j < MsgErreurs.length; j++) {
			strErreur += "  " + MsgErreurs[j] + "\n";
			}
		alert(strErreur);
		}
	}
	
	function openWindow(url, wname, width, height) {
		window.open(url, wname, "height=" + height + ",width=" + width + "location = 0, status = 1, resizable = 0, scrollbars=1, toolbar = 0");
		return true;
	}
	
	$(function(){
		qstring_values = $.qstring_value_pairs();
		if(qstring_values != ""){
			search_string = unescape(qstring_values['q']).replace(/\+/g, ' ');
			$('#search_box').attr('value', search_string );
			cx = qstring_values['cx'];
			if(cx!=""){
				$('#bloc-sondage').show();
				$('#l-suggestions').hide();
			}
		}
		$("#search_box").focus(function(){
			// only select if the text has not changed
			if($(this).value == $(this).defaultValue){
				$(this).select();
			}
		})
	})