
/**
 * @short When there is an A inside a boto, botonV or botonVright, predate it
 *        with the A behaviour.
 */
aButton = function(){
	connectButtonToA=function(td){

		connect(td,'onclick',function(src){ 
			href=''
			ok=true
			forEach(src.src().childNodes, function(ch){
				if (ch.tagName=='A'){
					if (href!=''){
						ok=false
						return
					}
					href=ch.href
				}
			})
			if (href!='' && ok)
				window.location=href

		})
		td.style.cursor="pointer"
	}


	ids=getElementsByTagAndClassName("td", "boton");
	forEach(ids, connectButtonToA);
	ids=getElementsByTagAndClassName("td", "botonV");
	forEach(ids, connectButtonToA);
	ids=getElementsByTagAndClassName("span", "botonVright");
	forEach(ids, connectButtonToA);
}


/**
 * @short Global events to add on all pages.
 */
addLoadEvent(function(){
	aButton();
})



openUserSelect = function(label){
	window.open('/users/select/?inputid='+label,'select_user','width=500,height=330,scrollbars=yes,resizable=yes,location=no')
}

openUserSelectFilter = function(label,filter){
	window.open('/users/select/?filter='+filter+'&inputid='+label,'select_user','width=500,height=330,scrollbars=yes,resizable=yes,location=no')
}

/**
 * @short Opens a user select window, and calls the given function with 
 *        (id, username, full name, usertype)
 */
openUserSelectWithFunc = function(label){
	window.open('/users/select/?set_value_func='+label,'select_user','width=500,height=330,scrollbars=yes,resizable=yes,location=no')
}

/**
 * @short onsubmit handler that opens a file upload progress dialog.
 *
 * to use it you also need to set enctype="multipart/form-data" and action="/mp/upload/upload"
 *
 * if all this is set, then the form saves the file at that action, and send the other form contents
 * (plus <filename>_realname field with the filename) to the original document, like if no
 * action where set.
 *
 * It is only opened if there is really a file.
 */
progressUpload = function(filefield, uploadId){
	if (!uploadId)
		uploadId=filefield

	if (!$(filefield))
		return;
	try{
		filename=$(filefield).value.split(/[\\\/]/g)
		filename=filename[filename.length-1]
	
		if (filename!='')
			progressWindow=window.open('/upload/?uploadId='+uploadId,
					'attachmentprogress','width=400,height=300,scrollbars=yes,resizable=yes,location=no')
	}
	catch(e){
		log(e)
	}
}

/**
 * @short Trick to close progress windows.. the drawback is that is may reopen a window. (and close)
 */
closeProgressWindow = function(){
/*
// DOES NOT WORK... If you have any ideo on how to make it work...

	window.open('','attachmentprogress',
				'width=400,height=200,scrollbars=yes,resizable=yes,location=no').close();
*/
}


var languageCode='en'
var translations={'es':{'Please wait...':'Por favor espere...'}}


var print_mode=false;

setPrintMode = function(){
	print_mode=true;
}
