// JavaScript Document
function aj_logout()
{
	$.get(ROOT_PATH+'aj_request.php?aj=home&logout=1&ajax_page=1','',logout_sucess);
}

function logout_sucess(res)
{	
    if(res=='sucesses')
	{
		$id('response').style.display='none';
		$id('login').style.display='';
		$id('edit_profile').style.display='none';
		$id('name').innerHTML='Guest';
		$id('logout').style.display='none';
		$id('nav_bar').style.display='none';
		$id('loggedinas').style.display='none';
		logbook_expand_variable='';
		wishlist_expand_variable='';
		$id('loggedout_logbook').style.display='';
		$id('loggedin_logbook').style.display='none';
		$id('loggedin_logbook_tr').style.display='none';
		if($id('logged_in') != null && $id('login_frm') != null ){
			$id('logged_in').style.display = 'none';
			$id('login_frm').style.display = '';
			return;
		}
		window.location.href=ROOT_PATH+'index.php';
	}
}

function aj_login(username, password , remember)
{
	if(username!='')
	{
		if(username.length>=3)
		{
			if(password!='')
			{	
				$.post(ROOT_PATH+'aj_request.php?aj=user.login','username='+username+'&password='+password+'&remember='+remember+'&ajax_page=1', function(resp){$('#response').html(resp), login_sucess(resp)});
			}
			else
			{
				alert("Invalid password");
			}
		}
		else
		{
			alert("Minimum length of username should be 3 characters");
		}
	}
	else
	{
	alert("Invalid username");
	}
}	

function login_sucess(res)
{
	try{
		var name = $id('name1').value;
		if($id('user_name_1') != null && $id('user_name_2') != null){
			$id('user_name_1').innerHTML = $id('name1').value;
			$id('user_name_2').innerHTML = $id('name1').value;
			$id('login_frm').style.display = 'none';
			$id('register').style.display = 'none';
			$id('logged_in').style.display = '';			
		}
	}catch(e){
		if($id('user_name_1') != null && $id('user_name_2') != null){
			$id('error_resp').innerHTML = res;
		}
	}
	if(!name)
	{
		$id('response').style.display='';
		if( $id('login_frm') == null || id('disabled_div').style.display != 'none')
			showLogin();
		$id('login').style.display='';
		$id('logout').style.display='none';
		
	}
	else
	{
		try{
			if($id('t_user_exists'))
			{
				var t_user=	$id('t_user_exists').value;
				if(confirm('Do You Want To Save User Data Which Has Been Created Before Login To Your Profile')	)
				{
					$.ajax({ 
						   url: ROOT_PATH+'aj_request.php?aj=user.copy_temp_user&t_user='+t_user,
						   type: "GET",
						   success: function(resp){ 
										if(resp=='success')
											alert('Saved Sucessfully');
										else
											alert('Failed To Save, Appologies For the Mistake');
						   			},
							async: false
						});
				}
			}
		}catch(e){}
		if($id('journey_form'))
		{
			
		}else
		{
			$id('loggedout_logbook').style.display='none';
			$id('loggedin_logbook').style.display='';
			$id('loggedin_logbook_tr').style.display='';
			if($id('plan_holiday_link')){
				$id('plan_holiday_link').onclick=function(){ setLocation('itinerary_expand'); return false; };
				$id('plan_holiday_link').href=ROOT_PATH+"index.php?p=user.select_itinerary";
			}
			if($id('plan_holiday_home_link')){
				$id('plan_holiday_home_link').onclick=function(){ setLocation('itinerary_expand'); return false; };
				$id('plan_holiday_home_link').href=ROOT_PATH+"index.php?p=user.select_itinerary";
			}
			expand_logbook();
		}

		$id('loggedinas').style.display='';
		$id('response').style.display='none';
		$id('name').innerHTML=name;
		hideDisableDiv('login_div');
		$id('login').style.display='none';
		$id('edit_profile').style.display='';
		$id('logout').style.display='';
		$id('nav_bar').style.display='';
		
		// call back for addToWishlist() function...
		
		if(typeof callback != 'undefined' && function_exists(callback)) {
			eval(callback+"()");
			callback = '';
		}
	}
}
function show_error_login_div()
{
	$id('response').style.display='';
	$id('response').innerHTML='<span class="error">Please login to use our features</span>';
	 //$id('username').value='';
	 //$id('password').value='';
 	showLogin();
	/*if(func != '' && function_exists(func)) {
		alert(eval(func));
	
	if(typeof func != 'undefined' && function_exists(func)) {
		eval(func+"()");
	}}*/
}