//provide a random timestamp with each call to foil caching
function getTimestamp()
{
	var t = new Date();
	var r = "" + t.getFullYear() + t.getMonth() + t.getDate() + t.getHours() + t.getMinutes() + t.getSeconds(); 

	return(r);
}

function getAffiliateID(element)
{
	var url = '/admin/services/getaffiliateid.php';
	var myAjax = new Ajax.Request(url, { method: 'get', evalScripts: true, onSuccess: function(response) { $(element).value = response.responseText; } }); 
}

function getUserCode(element)
{
	var url = '/admin/services/getusercode.php';
	var myAjax = new Ajax.Request(url, { method: 'get', evalScripts: true, onSuccess: function(response) { $(element).value = response.responseText; } }); 
}

function toggleCodes()
{
	if($('expandlink').innerHTML == 'expand all')
	{
		$$('tr.code').each(function(n) {n.show();}); 
		$$('tr.summary').each(function(n) {n.hide();});
		$('expandlink').innerHTML = 'hide all';
	}
	else
	{
		$$('tr.code').each(function(n) {n.hide();}); 
		$$('tr.summary').each(function(n) {n.show();});
		$$('tr.unclaimed').each(function(n) {n.hide();});
		$('expandlink').innerHTML = 'expand all';
	}
	
	return void(0);
}

function updateGroupInput()
{
	if($F('group_dropdown') == 'new')
	{
		$('group').value = '';
		$('groupdiv').show();
	}
	else if($F('group_dropdown'))
	{
		$('groupdiv').hide();
		$('group').value = $F('group_dropdown');		
	}
	else
	{
		$('group').value = '';
		$('groupdiv').hide();
	}
}

//ask user before proceeding
function checkFirst(text, url)
{
	var answer = confirm (text);
	
	if (answer)
		window.location=url;
}

//validate the RQ tool step 1 form
function validate_rels()
{
	if(!$F('rel1') || !$F('rel2') || !$F('rel3') || !$F('rel4') || !$F('rel5'))
	{
		alert('Please enter a name for ALL 5 relationship fields.');
		return false;
	}
	else
	{
		return validate_objs();
	}
}

function validate_objs()
{
	if(!$F('obj1') || !$F('obj2') || !$F('obj3') || !$F('obj4') || !$F('obj5'))
	{
		alert('Please enter an objective for ALL 5 relationships.');
		return false;
	}
	else
	{
		return true;
	}
}