var current_url = location.href;
var query_string = '';

var http = 'http://';
	
if (location.href.indexOf('https://')>-1)
	http = 'https://';
	
var base = http + 'www.gowithcea.com/StudentAccount/'
			
if (current_url.indexOf('?') > -1)
{
	var temp = new Array();
	temp = current_url.split('?');
	query_string = temp[1];
}


$(document).ready(function() {
	$('#chat_top').click(function() {
		chat('top');
	});
	$('#chat_right').click(function() {
		chat('right');
	});
	$('#chat_bottom').click(function() {
		chat('bottom');
	});
	$('#chat_left').click(function() {
		chat('left');
	});
	$('#chat_body1').click(function() {
		chat('body1');
	});
	$('#chat_body2').click(function() {
		chat('body2');
	});
	$('#chat_body3').click(function() {
		chat('body3');
	});
	$('.chatX').click(function() {
		chat();
	});	
});

function chat(loc)
{
	  if (is_authenticated())
	  {
		window.open('/Chat/default.aspx?chat_loc=' + loc + '&UrlReferrer=' + location.href, '_blank', 'resizable=no,scrollbars=no,status=no,toolbar=no,height=320,width=472');
	  }
	  else
	  {
		  window.location = base + 'Route/default.aspx?Action=ChatNow&UrlReferrer=' + location.href;
	  }	
}

function is_authenticated()
{
	var options = {
		type: 'POST',
		url: base + 'Ajax.aspx/IsAuthenticated',
		data: '{ }',
		contentType: 'application/json; charset=utf-8',
		dataType: 'json',
		async: false,
		error: function(XMLHttpRequest, textStatus, errorThrown) {
			alert(textStatus);
		}
	};
	var authenticated = eval('(' + $.ajax(options).responseText + ')');
	return authenticated.d	
}