
var hashok = 0;
var urlfilled = 0;
var emailformat = 1;
var count = 0;

function addUrlField(count) {
	count = count*1;
	var targetcount = count+1;
	if(count<30)
	{
	$('urlbox_'+targetcount).setStyle('display','block');
	return targetcount;
	}
	else
	{
		alert('You are allowed up to 30 URLs.');
		return count;
	}
}



function removeUrlField(count) {
	count = count*1;
	var targetcount = count-1;
	if(count>1)
	{
	$('urlfield_'+count).set('value','');
	$('urlbox_'+count).setStyle('display','none');
	return targetcount;
	}
	else
	{
		alert('You need at least one URL.');
		return 1;
	}
}

function checkUrlFields() {
	var maxcount = 31;
	var start = 1;
	urlfilled = 0;
	while(start<maxcount) {
		if($('urlfield_'+start).value!='')
		{
			urlfilled = 1;
		}
		start++;
	}
	return urlfilled;
}

function checkHash(hash) {
	if(hash!='')
	{
		$('hashmessage').setStyle('color','#333333');
		$('hashmessage').innerHTML = '<img src="/images/ajax-loader.gif"> Checking for availability...';
		var target = "http://krunchd.com/checkhash.php";
		var req = new Request({url:target, 
						  method:'post',
						  
			onSuccess: function(txt) {
			if(txt==0)
			{
			$('hashmessage').setStyle('color','#00cc00');
			$('hashmessage').innerHTML = '<img src="/images/tick.png" align="absmiddle" width="40" height="40"> The text you selected is available!';
			hashok = 0;
			}
			else if(txt==1)
			{
			$('hashmessage').setStyle('color','#ff0000');
			$('hashmessage').innerHTML = '<img src="/images/warning.png" align="absmiddle" width="40" height="40">The text you selected is already being used.';
			hashok = 1;
			}
			else if(txt==2)
			{
			$('hashmessage').setStyle('color','#ff0000');
			$('hashmessage').innerHTML = '<img src="/images/warning.png" align="absmiddle" width="40" height="40">Special characters are not allowed.';
			hashok = 1;
			}
			},
			onFailure: function() {
			alert('Hash verification module failed.');
			}
		}).send('hash='+hash);
	}
	else
	{
		// hash became blank..
		$('hashmessage').innerHTML = '';
		hashok = 0;
	}
}


function checkEmail() {
var email = $('email').value;
//check for valid email

	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;

	if(email=='') {
	emailformat = 1;
	}
	else if(email.test(reg)==false)
	{
	alert('Your email appears to be invalid.');
	emailformat = 0;
	}
	{
	emailformat=1;
	}
	
	
	
}

