
function init(){
	$(".mocjob-list").children("li").children(".header").click(showHideFullstory);
	$(".mocjob-list").children("li").children(".teaser").click(showHideFullstory);
	$(".printlink").click(printJob);
	$(".csc-mailform-submit").parent("form").submit(doTipAFriend);
	$(".tip-a-friend-form").children("form").children("input").focus(tipFieldFocus);
	$(".tip-a-friend-form").children("form").children("input").blur(tipFieldBlur);
	jQuery.ajaxSetup({cache:false});
};

function tipFieldFocus(){
	if($(this).attr("id")=="tip-a-friend-name"){
		if($(this).val() == "Dit navn"){
			$(this).val("");
		}
	}
	else if($(this).attr("id")=="tip-a-friend-email"){
		if($(this).val() == "Modtagers e-mail"){
			$(this).val("");
		}
	}
}

function tipFieldBlur(){
	if($(this).attr("id")=="tip-a-friend-name"){
		if($(this).val() == ""){
			$(this).val("Dit navn");
		}
	}
	else if($(this).attr("id")=="tip-a-friend-email"){
		if($(this).val() == ""){
			$(this).val("Modtagers e-mail");
		}
	}
}

function showHideFullstory(){
	var active = $(".act");
	var image = $(this).parent("li").children(".header").children(".plus").children("img");
	 if($(this).parent("li").hasClass("act")){
	  	$(this).parent("li").removeClass("act");
	  	$(this).parent("li").addClass("no");
	  	$(this).siblings(".fullstory").slideUp(400);
	  	$(image).attr("src",newFilename($(image).attr("src"), "plus.gif"));
	 }
	 else{
	  	$(this).parent("li").removeClass("no");
	  	$(this).parent("li").addClass("act");
	  	$(this).siblings(".fullstory").slideDown(400); //show
		$(image).attr("src",newFilename($(image).attr("src"), "minus.gif"));
	 }
	 $(active).addClass("no");
	 $(active).removeClass("act");
	 $(active).children(".fullstory").hide();
	init();
};

function printJob(){
	window.open("http://www.ekspresbank.dk/fileadmin/templates/mocjob_print_template.html","Job", "width=800px, height=600px, resizable");
	return false;
}

function newFilename(filepath, newfilename){
	var parts = filepath.split('/');
	parts.pop();
	parts.push(newfilename);
	return parts.join('/');
}

function doTipAFriend(){
	var theForm = $(this);
	var url = 'index.php?eID=tx_mocjob_eid1';
	var reqData = {"sender":$(this).children("#tip-a-friend-name").val(),"email":$(this).children("#tip-a-friend-email").val(),"tiplink":$(this).children("#tip-a-friend-link").val()};

	$.post(url, reqData,function(data){
		if(data == "OK"){
			$(theForm).parent(".tip-a-friend-form").siblings(".tip-another-friend").show();
			$(theForm).parent(".tip-a-friend-form").hide();
			$(theForm).children("#tip-a-friend-email").val("");
		}else{
			$(theForm).parent(".tip-a-friend-form").hide();
			$(theForm).parent(".tip-a-friend-form").siblings(".tip-another-friend").show();
			$(theForm).parent(".tip-a-friend-form").siblings(".tip-another-friend").html("<p style=\"color:red;\">Du mangler at udfylde felterne korrekt.</p><p><a onclick=\"tipAnotherFriend(this)\">[ OK ]</a>");
		}
	});
	return false;
}

function tipAnotherFriend(sender){
	$(sender).parent("p").parent("div").hide();
	$(sender).parent("p").parent("div").siblings(".tip-a-friend-form").show();
}

$(document).ready(function(){
	init();
	$(".act").children(".fullstory").show();
});

