// Doorsturen gebruiker
function Snd(strLink) {
	window.location=strLink;
}

// Voor het laten verkleuren van de rijen in tabel
function ColorRow(FuncId) {
	if ( FuncId.style.backgroundColor == '') {
		FuncId.style.backgroundColor = '#F4F4F4';
	} else {
		FuncId.style.backgroundColor = '';
	}
}


// Functie om te verbergen
function Hide(ID) {
	$(ID).hide();
}

// Omzetten newlines naar linebreaks
function nl2br(text){
	text = escape(text);
	re_nlchar=[];
	if(text.indexOf('%0D%0A') > -1){
		re_nlchar = /%0D%0A/g ;
	} else if(text.indexOf('%0A') > -1){
		re_nlchar = /%0A/g ;
	} else if(text.indexOf('%0D') > -1){
		re_nlchar = /%0D/g ;
	}
	return unescape( text.replace(re_nlchar,'<br>') );
}

 
function ShowPayPopup() {
	$.openPopupLayer({ 
		name: "PayPopUp",
		width: 480,
		target: "PayBox"
	});
}

function ShowLoginBox() {
	$.openPopupLayer({
		name: "LoginBox",
		width: 400,
		target: "LoginBox"
	});
}

function showTellFriend(strNaam, strMail, intBedrijf) {
	$.openPopupLayer({
		name: "TellFriend",
		width: 500,
		url: "/ajaxTellFriend.php?Naam="+strNaam+"&Email="+strMail+"&bedrijfId="+intBedrijf
	});
}

function showHtmlForm(intHtmlId, intSize) {
	$.openPopupLayer({
		name: "htmlForm"+intHtmlId,
		width: (intSize ? intSize : 500),
		url: "/ajaxHtmlPopup.php?htmlId="+intHtmlId
	});
}

function showTransactieStatus(intSha) {
	$.openPopupLayer({
		name: "transStatus",
		width: 500,
		url: "/ajaxHtmlPopup.php?htmlId=5&transId="+intSha
	});
}

// Bijwerken cookie
function updateAcceptCookie() {
	// Ophalen waarde
	var curVal = $("#AccepteerDoorsturen").is(":checked")
	// Instellen cookie
	$.cookie('nextPlan', (curVal*1), { path: "/ajaxDoPay.php"})
}

// Checken van formulier
function friendFormCheck() {
	// Ophalen data
	intBedrijfId = $('.TellFriendForm input[name="bedrijfId"]').val()
	strNaam = $('.TellFriendForm input[name="Naam"]').val()
	strEmail = $('.TellFriendForm input[name="Email"]').val()
	strEmailVriend = $('.TellFriendForm input[name="EmailOntvanger"]').val()
	strBericht = $('.TellFriendForm textarea[name="Bericht"]').val()
		
	// Bijwerken popup
	$('#popupLayer_TellFriend').load("/ajaxTellFriend.php", "formSubmit=1&bedrijfId="+intBedrijfId+"&Naam="+strNaam+"&Email="+strEmail+"&EmailOntvanger="+strEmailVriend+"&Bericht="+strBericht)
	
	return false;
}

// Fixt logo positie in 6 hoeken
function fixLogoPosition(strLogoId) {
	$(strLogoId).load(function(){
		// Hoogte uitrekenen
		var intDiff = 101 - $(strLogoId).height();
		var intMargin = intDiff/2;
		$(strLogoId).css('margin-top', intMargin)
	})
}

// Fixen alle logo posities
function fixLogoPosities() {
	$('.LogoBox img').each(function(i) {
		fixLogoPosition(this)
	})
}

// Omzetten float naar mooie currency
function formatCurrency(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num)){
		num = "0";
	}
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10) {
		cents = "0" + cents;
	}
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) {
		num = num.substring(0,num.length-(4*i+3))+'.'+ num.substring(num.length-(4*i+3));
	}
	
	return (((sign)?'':'-') + '&euro; ' + num + ',' + cents);
}

// Bijwerken aantal blokken lijst
function updateBlokList() {	
	// Huidige ID
	var invesId = $("select[name='curInvest'] :selected").val();
	
	// Checken of niet leeg
	if(invesId == "") {
		$("select[name='nrBlokken']").html('<option value="0">Kies eerst een investering</option>');
		// Stoppen
		return;
	}
	
	// Ophalen info
	var invesInfo = investAmounts[invesId];
	// Maken lijst
	var optionList = '';
	for (i=2; i<invesInfo[0]; i++) {
		optionList = optionList + '<option value="'+ i +'">'+ i +' delen - &euro; '+ (i*10) +',00</option>';
	}
	// Eerste en laatste optie toevoegen
	if(invesInfo[0] == 1) {
		// Maar 1 blok
		optionList = '<option value="1">1 deel - '+ formatCurrency(invesInfo[1]) +'</option>';
	} else {
		optionList = '<option value="1">1 deel - &euro; 10,00</option>'+ optionList;
		optionList = optionList +'<option value="'+ invesInfo[0] +'">'+ invesInfo[0] +' delen - '+ formatCurrency(invesInfo[1]) +'</option>';
	}
	// Toevoegen
	$("select[name='nrBlokken']").html(optionList)
}

// Voor verwijderen
function updateVerwijderBlokList() {	
	// Huidige ID
	var invesId = $("select[name='curVerwijderInvest'] :selected").val();
	
	// Checken of niet leeg
	if(invesId == "") {
		$("select[name='nrVerwijderBlokken']").html('<option value="0">Kies eerst een investering</option>');
		// Stoppen
		return;
	}
	
	// Ophalen info
	var invesInfo = investAmounts[invesId];
	// Maken lijst
	var optionList = '';
	for (i=2; i<invesInfo[0]; i++) {
		optionList = optionList + '<option value="'+ i +'">'+ i +' delen - &euro; '+ (i*10) +',00</option>';
	}
	// Eerste en laatste optie toevoegen
	if(invesInfo[0] == 1) {
		// Maar 1 blok
		optionList = '<option value="1">1 deel - '+ formatCurrency(invesInfo[1]) +'</option>';
	} else {
		optionList = '<option value="1">1 deel - &euro; 10,00</option>'+ optionList;
		optionList = optionList +'<option value="'+ invesInfo[0] +'">'+ invesInfo[0] +' delen - '+ formatCurrency(invesInfo[1]) +'</option>';
	}
	// Toevoegen
	$("select[name='nrVerwijderBlokken']").html(optionList)
}

// Block lijst bijwerken in geval van blokken uit account
function setBlockLimit(intLimit) {
	// Ophalen status box
	if(!$("input[name='FromAccount']").attr("checked")) {
		// Terug zetten origineel
		$("select[name='nrParts']").html(strBlocks)
		return;
	}
	// Aantal bloken
	var intBlockLimit = intLimit/10;
	// Maken lijst
	var optionList = '';
	for (i=2; i<intBlockLimit; i++) {
		optionList = optionList + '<option value="'+ i +'">'+ i +' delen - &euro; '+ (i*10) +',00</option>';
	}
	// Eerste en laatste optie toevoegen
	if(intBlockLimit == 1) {
		// Maar 1 blok
		optionList = '<option value="1">1 deel - '+ formatCurrency(intLimit) +'</option>';
	} else {
		optionList = '<option value="1">1 deel - &euro; 10,00</option>'+ optionList;
		optionList = optionList +'<option value="'+ intBlockLimit +'">'+ intBlockLimit +' delen - '+ formatCurrency(intLimit) +'</option>';
	}
	// Toevoegen
	$("select[name='nrParts']").html(optionList)
}

// Popup instellingen
$.setupJMPopups({
	screenLockerBackground: "#FA7711",
	screenLockerOpacity: "0.7"
});


