window.addEvent('domready', function() {
	

	
	
	var r = new MooRainbow('ColorPicker01', {
		id: 'DivColorPicker01',
		wheel: false,
		onChange: function(color) {
			$('color1').value = color.hex;
			$('ColorPicker01').setStyle('background-color', color.hex);
		},
		onComplete: function(color) {
			$('color1').value = color.hex;
			$('ColorPicker01').setStyle('background-color', color.hex);
			UpdateColors()
		}
	});
	
	var r = new MooRainbow('ColorPicker02', {
		id: 'DivColorPicker02',
		wheel: false,
		onChange: function(color) {
			$('color2').value = color.hex;
			$('ColorPicker02').setStyle('background-color', color.hex);
		},
		onComplete: function(color) {
			$('color2').value = color.hex;
			$('ColorPicker02').setStyle('background-color', color.hex);
		}
	});
	
	var r = new MooRainbow('ColorPicker03', {
		id: 'DivColorPicker03',
		wheel: false,
		onChange: function(color) {
			$('color3').value = color.hex;
			$('ColorPicker03').setStyle('background-color', color.hex);
		},
		onComplete: function(color) {
			$('color3').value = color.hex;
			$('ColorPicker03').setStyle('background-color', color.hex);
		}
	});

	
});



function CopyCode(id)
{
	
	var box = $(id);
	
	switch(box.style.display)
	{
		
		case "none" : 
			box.style.display = 'block';
			break;
			
		case "block" : 
			box.style.display = 'none';
			break;
			
		default : 
			box.style.display = 'block';
			break;
		
	}
	
}
var alerted = 0;
var lastNewKeyword = 1;
var maxKeywords = 10;

function ValidateContact()
{
		var valid = true;
		

		if($('naam').value == "")
		{
			valid = false;
			alert("Je bent vergeten je naam in te vullen");
		}
		
		if($('email').value == "")
		{
			valid = false;
			alert("Je bent vergeten je e-mailadres in te vullen");
		}
		
		return valid;
}


function newKeyWord(lastId)
{
	
	if( lastId < lastNewKeyword ){
		return false;
	}
	if( (lastId+1) == maxKeywords ){
		if(alerted == 0)
		{
			// niet alerten, komen gewoon niet meer boxen
			//alert('Let op: U mag niet meer dan 9 keywords invoeren');
		}
		alerted = 1;
		return false;
	}
	lastNewKeyword++;
	var id = lastId + 1;
 
	var keywordinput = new Element('input', {
		'onfocus': 'newKeyWord(' + id + ');',
		'type': 'text',
		'name': 'accounts[]',
		'id': 'accounts_'+id,
		'value' : '@'
	});
	
	keywordinput.injectAfter('accounts_'+lastId);
}

function UpdateBox(amount, id)
{
	var box = document.getElementById('formcomments');
	

	
	var myRequest = new Request({url: '/boxinfo.php', method: 'get', onSuccess: function(responseText, responseXML) {
    
		box.innerHTML = responseText;
		
		var myEffect = new Fx.Morph('formcomments', {duration: 'long'});
	
		myEffect.start({
		'background-color': ['#d7d7d7', '#efefef']
		});
		
		var myEffect = new Fx.Morph('formcomments', {duration: 'long'});
		 
		myEffect.start({
			'top': [box.style.top, amount + 'px']
		});
	
	}}).send('id=' + id);
}

function Toevoegen(id)
{
	
	var box = $('form_' + id);
	
	box.style.display = 'block';
}

function UpdateColors()
{

	var frame = $('tweetframe');
	var hash = $('hash');
	
	
	var fc = $('color1').value;
	fc = fc.replace('#', '');
	
	var lc = $('color2').value;
	lc = lc.replace('#', '');
	
	var ff = $('family').value;
	
	var bg = $('color3').value;
	bg = bg.replace('#', '');
	
	var fs = $('size').value;
	
	frame.src = 'http://www.tweetzz.nl/style.php?hash=' + hash.value +'&fc=' + fc + '&lc=' + lc + '&fs=' + fs + '&bg=' + bg + '&ff=' + ff;

}

function ValidateToevoegen()
{
	var valid = true;
		

		if($('naam').value == "")
		{
			valid = false;
			alert("Je bent vergeten je naam in te vullen");
		}
		
		if($('email').value == "")
		{
			valid = false;
			alert("Je bent vergeten je e-mailadres in te vullen");
		}
		
		if($('twitteraccount').value == "@")
		{
			valid = false;
			alert("Je bent vergeten een twitter account in te vullen");
		}
		
		return valid;
	
}

window.addEvent('domready', function() {
									 
		
	if($('register_form'))
	{
		
		
		
	$('register_form').addEvent('submit', function(e) {
		//$('maak-widget').disabled = true;					   
		e.stop();
		
		var error_log = '';
		
		var valid = true;
		
		$('all_accounts').getElements('input[type=text]').each(function(e) {
			
			if(e.value != "")
			{
				var box = $('valid_' + e.id);
				
				if(box.value == "FALSE")
				{
					var valid = false;	
					error_log = '\n' + e.value + ' is geen geldig twitter account';
				}
			}
		});
		
		
		if($('name').value == "")
		{
			valid = false;
			error_log = error_log + '\n' +"Je bent vergeten je naam in te vullen";
		}
		
		if($('email').value == "")
		{
			valid = false;
			error_log = error_log + '\n' + "Je bent vergeten je e-mailadres in te vullen";
		}
		
		if($('website').value == "http://")
		{
			valid = false;
			error_log = error_log + '\n' + "Je bent vergeten je website in te vullen";
		}
		
		if($('widget_title').value == "")
		{
			valid = false;
			error_log = error_log + '\n' + "Je bent vergeten een titel voor je widget in te vullen";
		}
		
		if(valid == true)
		{
			Validate();
		}
		
		if(error_log > "")
		{
			alert(error_log);	
		}
		
		//$('maak-widget').style.display = 'none'
		
		
	});
	
	 }
});

function Validate()
{
		
		
	
	
		$('register_form').style.display = 'none';
		
		$('info_box').style.display = 'block';
		
		
		var log = $('log_res').empty().addClass('ajax-loading');
		$('register_form').set('send', {onComplete: function(response) { 
		log.removeClass('ajax-loading');
		log.set('html', response);

		var total = 0;
	
		for(var i = 0; i < 20; i++)
		{
			
			var id = $('accounts' + i).value;	
			
			var myRequest = new Request({url: '/modules/fetch_user_updates.php', method: 'get', onSuccess: function(responseText, responseXML) {
				
			if(i == 19)
			{
			 $('volgende').style.display = 'block'; 
			 
			}
					
			}}).send('id=' + id);

		}
		
		$('log_res').style.display = 'block';
		$('info_box').style.display = 'none';
		
		}});
		$('register_form').send();
}


function ValidateAccounts(id)
{
	
	var account = $('accounts' + id).value;
	
	if(account == "")
	{
		$('loading_accounts' + id).set('html', '<img src="http://www.tweetzz.nl/images/ok.png" />');
		$('loading_accounts' + id).style.visibility = 'hidden';
	}
	else
	{
	
		$('loading_accounts' + id).style.visibility = 'visible';
	
		var myRequest = new Request({url: '/check_twitter_account.php', method: 'get', onSuccess: function(responseText, responseXML) {
			
			
			if(responseText == "1")
			{
				$('loading_accounts' + id).set('html', '<img src="http://www.tweetzz.nl/images/ok.png" />');
				$('valid_accounts' + id).value = "TRUE";
			}
			else
			{
				$('loading_accounts' + id).set('html', '<img src="http://www.tweetzz.nl/images/false.png" />');
				
				$('valid_accounts' + id).value = "FALSE";
				
			}
			
			//$('loading_accounts' + id).style.visibility = 'hidden';
			
		}}).send('id=' + account);
	
	}
	
	
}

