//http://www.code20.com/common replaced common/. It is ok to do this now that all development is done in site root. This should fix inaccessiblity problems (I. Ukpo, 1/16/2012)

function add_remove_class(search,replace,element_id)
{
	if (jQuery('#' + element_id).hasClass(search))
	{
		jQuery('#' + element_id).removeClass(search);
	}
	jQuery('#' + element_id).addClass(replace);
}

function toggle_check_cross(search,val)
{
		if (val==1)
		{
			jQuery('#' + search).attr('src', 'images/cross.png');
		}

		else if (val==0)
		{
			jQuery('#' + search).attr('src', 'images/tick.png');
		}
		else
		{
			jQuery('#' + search).attr('src', 'images/transparent16_16.png');
		}		
}

function getTodaysDate() 
{
        var date = new Date();
        var str = (date.getMonth()+1) + "/" + date.getDate() +  "/" + date.getFullYear();

        return str;
}

function setTodaysDate(fieldname,theval)
{
	jQuery('#' + fieldname).val(theval);
}

function logout(errfield,sessid)
{
		$.ajax({
		url : 'http://www.code20.com/common/dologout.php',
		type : 'post',
		data :  {sid: sessid},
		dataType : 'text',
		timeout : 20000,
		tryCount : 0,
		retryLimit : 3,
		success : function(data) {
			window.location.replace(data);
		},
		error : function(xhr, textStatus, errorThrown ) {
				this.tryCount++;
				if (this.tryCount <= this.retryLimit) {
					//try again
					$.ajax(this);
					return;
				}
				//alert('We have tried ' + this.retryLimit + ' times and it is still not working. We give in. Sorry.');
				/*add_remove_class('success','error',errfield);
				jQuery('#'+errfield).html("Cannot perform logout. Please try again.");
				return;*/
				else
				{
					err_str=xhr.status+" Server internal error. Please try again.";
					add_remove_class('success','error',errfield);
					jQuery('#'+errfield).html(err_str);
				}
		}
	});
}

function goBack()
{
	//window.history.back();
	//history.go(-1);
	history.back(); 
	return false;
}

function navigateTo(url)
{
	window.location.replace(url);
}
