$(document).ready(function(){

	// Highlight Input Fields on Focus
	
	$("input:text, input:password, textarea, select").focus(function(){
		$(this).addClass("field-highlighted");
		$(this).parent().addClass("field-highlighted-holder");
	});
	
	// Remove Highlighting on Input Fields on Blur
	
	$("input:text, input:password, textarea, select").blur(function(){
		$(this).removeClass("field-highlighted");
		$(this).parent().removeClass("field-highlighted-holder");
	});

	// Show/Hide Support Login Forms
	
	$("#support-btn").click(function(){
		if ($("#telephone-number").css("display") == "none") {
			$("#support-logins").css({'width':'0px'}).hide();
			$("#support-logins").animate({opacity: 0}, {duration: 350, "easing": "linear", "complete": function(){ $("#telephone-number").css({'width':'550px'}).show(); } });
		} else {
			$("#telephone-number").css({'width':'0px'}).hide();
			$("#support-logins").animate({width: "600px", opacity: 1}, {duration: 350, "easing": "linear"});
		}
		return false;
	});
	
	// Confirm reset of a Form
	
	$(".form-reset").click(function(){
		return confirm('Are you sure you wish to reset this form?\nAny Information you have entered will be lost.');
	});

	// Returns to page in rel attribute
	
	$(".back-btn").click(function(){
		if ($(this).attr("rel") != '') {
			window.location = $(this).attr("rel");
		}
	});
		
	// Show/Hide Optional Fields in a Form
	
	$("#toggle_optional_fields_link").click(function(){
		$(".optional").toggle();
		if ($("#toggle_optional_fields_link").html() == 'Hide Optional Fields') {
			$("#toggle_optional_fields_link").html('Show Optional Fields');
		} else {
			$("#toggle_optional_fields_link").html('Hide Optional Fields');		
		}
		return false;
	});

	// Display Image in Portfolio
	
	$(".mini-portfolio-img").click(function(){
		var pic_num = $(this).attr("rel");
		$("#previewimgnav"+pic_num).trigger("click");
		return false;	
	});
	
	$(".confirm-del").click(function(){
		return confirm("Are you sure you wish to delete this "+$(this).attr("rel")+"?\nThis process is not reversible!");
	});
	
	$("#instant-support-link").click(function(){
		$.prompt('<h6>Instant Support Login</h6><p>Please enter your forename(s), surname and company name to log into instant support.</p><form id="instant-support-form" action="https://secure.logmeinrescue.com/Customer/Download.aspx" method="post"><input type="hidden" name="EntryID" value="816248417" /><div><label for="forenames">Forename(s)</label><input type="text" name="forenames" id="forenames" /><input type="hidden" name="name" id="fullname" /></div> <div><label for="surname">Surname</label><input type="text" name="surname" id="surname" /></div> <div><label for="comment1">Company</label><input type="text" name="comment1" id="comment1" /></div></form>',{
			buttons:{ Login:1,Cancel:2 },
			prefix:'colsJqi',
			show:'slideDown',
			submit: instantSupportPost
		}).corner();
		return false;
	});
	
	
});


function instantSupportPost(btn_num) {
	if (btn_num == 1) {
		if (document.getElementById('forenames').value.length > 1 && document.getElementById('surname').value.length > 1 && document.getElementById('comment1').value.length > 1 ) {
			document.getElementById('fullname').value = document.getElementById('forenames').value+' '+document.getElementById('surname').value;
			document.getElementById('instant-support-form').submit();
		} else {
			alert('Please ensure you enter all details.');
			return false;
		}
	}
	
	return true;
}