// function _copy2clipboard(text) {
  // var clipboard = _getService("@mozilla.org/widget/clipboard;1","nsIClipboard");
 // Create tranferable that will transfer the text.
  // var transferable = _createInstance("@mozilla.org/widget/transferable;1","nsITransferable");

  // if (clipboard && transferable) {
    // transferable.addDataFlavor("text/unicode");
    // var data = _createInstance("@mozilla.org/supports-string;1","nsISupportsString");
    // if (data) {
      // data.data = text;
      // transferable.setTransferData("text/unicode", data, text.length * 2);
      // clipboard.setData(transferable, null,Components.interfaces.nsIClipboard.kGlobalClipboard);
    // }
  // }
// }

// function _createInstance(contractId, iidName) {
   // var iid = Components.interfaces[iidName];
   // return Components.classes[contractId].createInstance(iid);
// }

// function _getService(contractId, iidName) {
   // var iid = Components.interfaces[iidName];
   // return Components.classes[contractId].getService(iid);
// }

function copy(text)
{
	window.clipboardData.setData("Text", text);
}
$(document).ready(function(){
	modalite();
	// alert('trtr');
	// On vérifie le nom du navigateur
	if(navigator.appName=="Microsoft Internet Explorer")
	{
		var ie = true;
	}
	else
	{
		var ie = false;
	}

	/* Dans le cas de IE, je met le contenu que je veux copier en paramètre de la fonction copy */

		$('.viewer').each(function(){
			var toCopy = $(this).attr('rel');
			if(ie){
			$(this).html('<a href="#" onClick="copy('+toCopy+')">Copier les emails</a>');
			}else{
			$(this).html("<object width='30' height='10'><PARAM NAME=FlashVars VALUE='txtToCopy="+ toCopy +"'><param name='movie' value='http://www.corporate.be/files/flash/copyButton.swf'><embed src='http://www.corporate.be/files/flash/copyButton.swf' flashvars='txtToCopy="+ toCopy +"' width='30' height='10'></embed>");
			}
			
		});

	/* Avec Firefox, j'utilise un fichier swf qui va me permettre de copier le contenu souhaité dans le presse papier*/
	
	

});

function modalite(){
// alert('modalité');
	$("input.button.toModal").click(
		function () {
			// alert('clicked');
			$("#osx-modal-content").modal({
				overlayId: 'osx-overlay',
				containerId: 'osx-container',
				closeHTML: null,
				minHeight: 80,
				opacity: 65, 
				position: ['0',],
				overlayClose: true,
				height:'auto'
				});
			show_();
			newcontent($(this).parent());
			verif($(this).parent('form'));
			$('#osx-container').css({'height':'auto'});
			return false;
				});
			
	
}

function show_(){
	$('#show').css({'display':'none'});
}

function newcontent(form){
	$("input.licenceTest").click(function(){ 
		if ($(this).attr('id')=='hasLicence'){
			$("#show").show();
			$("#hide").hide();
		}else{
			// alert(form);
			form.append('<input type="hidden" name="shop_fill" value="val" />');
			$(form).submit();
		}
		return false;
	});
}

function verif(form){
	$("input#submitter").click(function(){
										var txt = $("#licence").val();
										if(txt.length==12){
											$.post("http://www.corporate.be/do/verifLicence.php", { 'licenceNum': txt},
												function(data) {
													// alert(data);
													if (data=='valid'){
														form.append('<input type="hidden" name="productVar" value="'+txt+'" /><input type="hidden" name="shop_fill" value="val" />');
														form.submit();
													}else{
														$('#lError').show();
													}
													
												});
											
										}else{
											$('#lError').show();
										}
										return false;
									 });
									 
}



