/**
 * @author Parrot Media Ltd.
 */

//ptBase.init('http://212.199.195.241/poketalk5/pt_proxy_curl.php', '1bea93b5a7e3d7c0826d3ff114d99d2d5f5c8c78');
ptBase.init('http://www.poketalk.com/pt_proxy_curl.php', '1bea93b5a7e3d7c0826d3ff114d99d2d5f5c8c78');

var countries_list = ptBase.get_countries('all');
//-------------------------------------------------------

function show_error(error_msg,modal){
	//alert('jopa');
	$("#error_message").html(error_msg);
	$("#error").dialog('open');	
	if (modal==false){
		$('#error').dialog('option', 'modal', false);
	}		
}
//-------------------------------------------------------

function show_msgbox(info_msg,modal){
	//alert('jopa');
	$("#info_message").html(info_msg);
	$("#msgbox").dialog('open');
	if (modal==false){
		$('#msgbox').dialog('option', 'modal', false);
	}	
}

function showhelp( alias ) {
	$.post(base+"index.php/help_c/page/"+alias,{}, function(r){
        $('body').append('<div id="help_page"></div>');
        var data = eval("(" + r + ")");
		if (data.result = true) {
			$("#help_page").dialog({
				modal: true,
				title: data['title'],
				autoOpen: false,
				width: 400,
				closeOnEscape: true,
				close: function(){
					$(this).dialog('destroy');
					$('#help_page').remove();
				},
				buttons: {
					"close": function(){
						$(this).dialog("close");
					}
				}
			});
			$('#help_page').html( data.text );
			$('#help_page').dialog('open');
		}
	});
}

//-------------------------------------------------------

function logout(){
	ptBase.logout();
	$.cookie('balance', null); // delete cookie
	$.cookie('fullname', null); // delete cookie
	$.cookie('is_underling', null); // delete cookie
	$.cookie('logged_in', null); // delete cookie
	$.cookie('tmp_splash', null); // delete cookie
	$.cookie('tmp_services_count', null); // delete cookie

	FB.Connect.get_status().waitUntilReady( 
		function( status ) { 
			switch ( status ) { 
				case FB.ConnectState.connected:
				FB.Connect.logoutAndRedirect(base);
				return;
				break; 
			}
		window.location = base;
		});
	//
	
}
//-------------------------------------------------------

function show_contact(){
	/* loads the contact us page */
	$.cookie('temp', "contact", { expires: 1, path: '/', secure: false });
	window.location = base+"index.php/pages_c/about/";	
}



$(document).ready(function(){
	
	ptBase.check_login(function(data){
		if (data.result) {
			$('#logout').empty().append('<a id="logout_link" href="javascript: void(0);" style="color:white;" onclick="logout();">logout</a>');
		}
	});
	
	$('img[src$=.png]').ifixpng();
	
	$("#error").dialog({
		modal: false,
		autoOpen: false,
		closeOnEscape: true,
		buttons: {
		"close": function(){
				$(this).dialog("close");
			}
		}
	});
	
	$("#msgbox").dialog({
		modal: false,
		autoOpen: false,
		closeOnEscape: true,
		buttons: {
		"close": function(){
				$(this).dialog("close");
			}
		}
	});	
	
});

