// Run on docready
$(document).ready(function(){
	
	// Nav Corner
	if(Modernizr.canvas){
		var canvas = document.getElementById('nav-corner');
		canvas.width = 25;
		canvas.height = 26;
		
		var context = canvas.getContext('2d');
		context.beginPath();
		context.moveTo(0, 26);
		context.lineTo(25, 0);
		context.lineTo(25, 26);
		context.lineTo(0, 26);
		context.closePath();
		
		var grd = context.createLinearGradient(0, 0, 0, 26);
		grd.addColorStop(0, "#d0d0d0");
		grd.addColorStop(1, "#a7a7a7");
		context.fillStyle = grd;
		context.fill();
		
		context.beginPath();
		context.moveTo(25, 0);
		context.lineTo(25, 26);
		context.lineWidth = 1;
		context.strokeStyle = "#999999";
		context.stroke();
		
		context.beginPath();
		context.moveTo(-1, 26);
		context.lineTo(24, 0);
		context.lineWidth = 1;
		context.strokeStyle = "#999999";
		context.stroke();
	}
	
});


// Show user a confirm dialog
function confirmDeletion(which,id,page,label,vars){
	var input_box=confirm("Are you sure you want to delete this "+label+"?");
	if (input_box==true){
		if(vars)
		 	window.location = page+"&d"+which+"="+id;
		else
			window.location = page+"?d"+which+"="+id;
	} else {
		//do nothing
	}
}

// Mask an email address
function maskEmail(user,site,message){
	document.write('<a href=\"mailto:'+ user + '@' + site + '\">'); 
	document.write(message+'</a>');
}

// Force a maximum length on a textarea or other input
function forceMaxLength(obj, maxlength){
	if (obj.value.length > maxlength)
		obj.value = obj.value.substring(0,maxlength)
}

// This functions like 'placeholder'
function checkInput(obj, value, fontColor){
	if(fontColor==undefined) fontColor = '#000000';
	if(obj.value == ""){
		obj.value = value;
		obj.style.color = '#999999';
	} else if(obj.value == value){
		obj.value = "";
		obj.style.color = fontColor;
	}
}

// Regex to wrap a URL with an <a> tag
function replaceURLWithHTMLLinks(text){
	var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
	return text.replace(exp,"<a href='$1' target='_blank'>$1</a>"); 
}



