$.ajaxSetup ({
    // Disable caching of AJAX responses */
    cache: false
});

$(document).ready(function(){
	$('a.external,a[href$=.pdf]').attr('target','_blank'); /* add target="_blank" to pdf links & links with class external */
	window.makeMailLinks?makeMailLinks():null;
	$().uploadify?uploadifyInit():null;
	window.enhanceIntFields?enhanceIntFields():null;
	});
/* <span class="email">x (at) x.com</span> becomes <a href="x@x.com">x@x.com</a> 
* this is an anti-spam measure
*/
function makeMailLinks(){
		$('span.email').each(function(){
			var theAddress = $(this).text().replace(/ \(at\) /, "@");
			$(this).replaceWith($('<a href="mailto:'+theAddress+'">'+theAddress+'</a>'));
			});
	}
function uploadifyInit(){
	var uid = $('input[name=uid]').val();
$("#uploadify").uploadify({
		'uploader'		:	'js/uploadify.swf',
		'script'			:	'js/uploadify.php',
		'checkScript'	:	'js/check.php',
		'cancelImg'		:	'img/cancel.png',
		'folder'		:	'upload/'+uid,
		'queueID'		:	'fileQueue',
		'multi'			:	true,
		'onInit'		:	function(){
							$('form').submit(function()
								{
									if($('#filelisting').text()==''){
										window.alert('Gelieve eerst je bestanden door te sturen door op de knop \'UPLOAD!\' te klikken');
										return false;
									}
								});
							},
		'onComplete'	: function(){$('#uploadedfiles').load('live/uploaded_files.lasso?uid='+uid);},
		'onAllComplete'	: function(){$('form').unbind();},
		'fileDesc'		:	"foto's of documenten (pdf, doc, docx, jpg of jpeg)",
		'fileExt'		:	'*.pdf;*.doc;*.docx;*.jpg;*.jpeg;*.PDF;*.DOC;*.DOCX;*.JPG;*.JPEG'
						});
	$('#uploadbutton').click(function(){
			$('#uploadify').uploadifyUpload();
			});
			}
function deleteFile(uid,file){
		if(window.confirm('Ben je zeker dat je "'+file+'" wil wissen?')){
			$('#uploadedfiles').load('live/uploaded_files.lasso', {uid: uid,createfolder: 'false',deletefile: file});
		}
		
	}

/* adds arrows that allow you to increment/decrement an int field (old-school js tweaked so it works in jquery )*/
function enhanceIntFields()	{
	var incrementImage='img/arrow_up.png';
	var decrementImage='img/arrow_down.png';
	var intFields = $('input.int');
	for(i=0;i<intFields.length;i++)
		{
		// add - 
		img = document.createElement("img");
		img.setAttribute("src",decrementImage);
		img.setAttribute("alt","-");
		img.setAttribute("title","remove an item");
		img.setAttribute("class","fieldmodify"); //good browsers
		img.setAttribute("className","fieldmodify"); //IE
		img.onclick = function(){incrementField(this.previousSibling.previousSibling,-1);};
		intFields[i].parentNode.insertBefore(img,intFields[i].nextSibling);
		
		// add + 
		img = document.createElement("img");
		img.setAttribute("class","fieldmodify"); //good browsers
		img.setAttribute("className","fieldmodify"); //IE
		img.setAttribute("src",incrementImage);
		img.setAttribute("alt","+");
		img.setAttribute("title","add an item");
		
		img.onclick = function(){incrementField(this.previousSibling,1);};
		intFields[i].parentNode.insertBefore(img,intFields[i].nextSibling);
		
		intFields[i].onfocus = function(){this.select();}
		}
	}
function incrementField(field,amount,negative)
	{
	if((negative!=true && (parseInt(field.value)+amount)<0) ||isNaN(parseInt(field.value)))
		{
		field.value=0;
		field.setAttribute("value",0);
		field.onchange(); 
		return;
		}
	field.value=parseInt(field.value)+amount;
	field.setAttribute("value",parseInt(field.value));
	$('input[name=attendees]').change(); //trigger change event
	}



