/*
*/

function doubleLogin(act) {
	$('#vb_login_username').val($('#u').val());
	//$('#vb_login_password').val($('#p').val());
	$('#vb_password').val($('#p').val());
	$('#cookieuser').val($('#k').val());
	md5hash($('#vb_login_password').get(0), $('#vb_login_md5password').get(0), $('#vb_login_md5password_utf').get(0), 0);	
	ajaxCallPage('forum/login.php#vb_login_username;vb_password;s;do;vb_login_md5password;vb_login_md5password_utf;cookieuser', 'POST', null, function(){
			ajaxCallPage('pages/login.submit.php#u;p;k', 'POST', null, function(rText){
					 if(rText==1) {
						 if(act=='loginFromForum') {
							 location.href='./forum/';
						 } else {
							 //location.href=location.reload();
							 window.location.reload();
						 }
					 } else alert(rText); 
				});
	});
	
}

function checkIn(){
	ajaxCallPage('../pages/checkin.submit.php#u;p;e', 'POST', null, function(rText){
						 if(rText==1) {
							 alert('Check-in επιτυχές!');
							 location.reload(true);
							 $('#u').val('');
							 $('#p').val('');
						 } else {
							 alert(rText); 
							 $('#p').val('');
						 }
					});
}
function checkIn_auth(){
	ajaxCallPage('../pages/checkin_auth.submit.php#p;e', 'POST', null, function(rText){
						 if(rText==1) {
							 alert('Login επιτυχές!');
							 location.reload(true);
							 $('#e').val('');
							 $('#p').val('');
						 } else {
							 alert(rText); 
							 $('#p').val('');
						 }
					});
}
function checkInByUser(userid){
	ajaxCallPage('../pages/checkinsms.submit.php?u='+userid+'#c;e', 'POST', null, function(rText){
						 if(rText==1) {
							 alert('Check-in επιτυχές!');
							 location.reload(true);
							 //$('#u').val('');
//							 $('#c').val('');
//							 $('#e').val('');
						 } else {
							 alert(rText); 
							 //$('#c').val('');
						 }
					});
}
function checkInTrusted(userid){
	ajaxCallPage('../pages/checkintrusted.submit.php?u='+userid+'#e', 'POST', null, function(rText){
						 if(rText==1) {
							 alert('Check-in επιτυχές!');
							 location.reload(true);
						 } else {
							 alert(rText); 
						 }
					});
}

function doubleLogout(logoutHash) {
	ajaxCallPage('forum/login.php?do=logout&logouthash='+logoutHash, 'GET', null, function(){
			ajaxCallPage('pages/logout.submit.php', 'POST', null, function(){location.href='./index.php'});
		});
}

function regUser() {
	$('#div_wait').show();
	$('#btn_register').hide();
	ajaxCallPage('pages/register.control.php?act=register#c_firstname;c_lastname;c_email;c_email_2;c_username;c_passa;c_passb','POST',null, function(rText){
		if(rText=='1'){
			location.href='http://www.pes-league.gr/index.php?page=register&act=regsuccess';
		} else {
			alert(rText);	
			$('#div_wait').hide();
			$('#btn_register').show();
		}
	});
}

function saveProfile() {
	var qVars = 'p_id;c_firstname;c_lastname;c_showname;p_gender;p_birthdate;p_tel;p_city;p_facebook;p_skype;p_msn;p_image;p_nationality;special_text;p_address;p_post';
	$('#div_wait').show();
	$('#btn_save').hide();
	ajaxCallPage('pages/user.control.php?act=saveprofile#'+qVars,'POST',null, function(rText){
		if(rText=='1'){
			alert('Το προφίλ σας αποθηκεύτηκε επιτυχώς!');	
			$('#div_wait').hide();
			$('#btn_save').show();
			location.href='http://www.pes-league.gr/';
		} else {
			alert(rText);	
			$('#div_wait').hide();
			$('#btn_save').show();
		}
	});
}
function savetrusted_step1() {
	var qVars = 'p_id;c_firstname;c_lastname;p_gender;p_birthdate;p_tel;p_city;p_address;p_post;trusted_image';
	$('#div_wait').show();
	$('#btn_save').hide();
	ajaxCallPage('pages/user.control.php?act=savetrusted_step1#'+qVars,'POST',null, function(rText){
		if(rText=='1'){
			alert('Το πρώτο βήμα ολοκληρώθηκε επιτυχώς!');	
			$('#div_wait').hide();
			$('#btn_save').show();
			location.href='http://www.pes-league.gr/trusted_player/';
		} else {
			alert(rText);	
			$('#div_wait').hide();
			$('#btn_save').show();
		}
	});
}
//function savetrusted_step2() {
//	var qVars = 'p_id;trusted_image';
//	$('#div_wait').show();
//	$('#btn_save').hide();
//	ajaxCallPage('pages/user.control.php?act=savetrusted_step2#'+qVars,'POST',null, function(rText){
//		if(rText=='1'){
//			alert('Η εικόνα αποθηκεύτηκε επιτυχώς!');	
//			$('#div_wait').hide();
//			$('#btn_save').show();
//			location.href='http://www.pes-league.gr/trusted_player/';
//		} else {
//			alert(rText);	
//			$('#div_wait').hide();
//			$('#btn_save').show();
//		}
//	});
//}
function savetrusted_step3() {
	var qVars = 'p_id;p_order';
	$('#div_wait').show();
	$('#btn_save').hide();
	ajaxCallPage('pages/user.control.php?act=savetrusted_step3#'+qVars,'POST',null, function(rText){
		if(rText=='1'){
			alert('Η παραγγελία σου στάλθηκε!');	
			$('#div_wait').hide();
			$('#btn_save').show();
			location.href='http://www.pes-league.gr/trusted_player/';
		} else {
			alert(rText);	
			$('#div_wait').hide();
			$('#btn_save').show();
		}
	});
}
function saveTeam() {
	var qVars = 'p_id;team_name;team_username;team_public;team_pass;team_sortdesc;team_desc;team_image;team_imagelogo;team_owner;team_captain';
	$('#div_wait').show();
	$('#btn_save').hide();
	ajaxCallPage('pages/user.control.php?act=saveteam#'+qVars,'POST',null, function(rText){
		if(rText=='1'){
			alert('Το προφίλ της ομάδα σας αποθηκεύτηκε επιτυχώς!');	
			$('#div_wait').hide();
			$('#btn_save').show();
			location.href='http://www.pes-league.gr/team/';
		} else {
			alert(rText);	
			$('#div_wait').hide();
			$('#btn_save').show();
		}
	});
}
function addTeam() {
	var qVars = 'team_name;team_pass';
	$('#div_wait').show();
	$('#btn_save').hide();
	ajaxCallPage('pages/user.control.php?act=addteam#'+qVars,'POST',null, function(rText){
		if(rText=='1'){
			alert('Η δημιουργία της ομάδας ολοκληρώθηκε!');	
			$('#div_wait').hide();
			$('#btn_save').show();
			location.href='http://www.pes-league.gr/team/';
		} else {
			alert(rText);	
			$('#div_wait').hide();
			$('#btn_save').show();

		}
	});
}
function buyplayer() {
	var qVars = 'username;teamid';
	$('#div_wait').show();
	$('#btn_save').hide();
	ajaxCallPage('pages/user.control.php?act=buyplayer#'+qVars,'POST',null, function(rText){
		if(rText=='1'){
			alert('Η πρόταση στάλθηκε!');	
			$('#div_wait').hide();
			$('#btn_save').show();
			//location.href='http://www.pes-league.gr/team/';
		} else {
			alert(rText);	
			$('#div_wait').hide();
			$('#btn_save').show();
		}
	});
}

function jointeam() {
	var qVars = 'code;teamid;userid';
	$('#div_wait').show();
	$('#btn_save').hide();
	ajaxCallPage('pages/user.control.php?act=jointeam#'+qVars,'POST',null, function(rText){
		if(rText=='1'){
			alert('Καλως ήρθες στην ομάδα!');	
			$('#div_wait').hide();
			$('#btn_save').show();
			//location.href='http://www.pes-league.gr/team/';
		} else {
			alert(rText);	
			$('#div_wait').hide();
			$('#btn_save').show();
		}
	});
}
function deleteplayer() {
	var qVars = 'teamid;userid';
	$('#div_wait').show();
	$('#btn_save').hide();
	ajaxCallPage('pages/user.control.php?act=deleteplayer#'+qVars,'POST',null, function(rText){
		if(rText=='1'){
			alert('Ο παίχτης διαγράφτηκε!');	
			$('#div_wait').hide();
			$('#btn_save').show();
			//location.href='http://www.pes-league.gr/team/';
		} else {
			alert(rText);	
			$('#div_wait').hide();
			$('#btn_save').show();
		}
	});
}
function offer() {
	var qVars = 'weeks;value;transferid;offer;team';
	$('#div_wait').show();
	$('#btn_save').hide();
	ajaxCallPage('pages/user.control.php?act=offer#'+qVars,'POST',null, function(rText){
		if(rText=='1'){
			alert('Η πρόταση στάλθηκε!');	
			$('#div_wait').hide();
			$('#btn_save').show();
			location.href='http://www.pes-league.gr/team/';
		} else {
			alert(rText);	
			$('#div_wait').hide();
			$('#btn_save').show();
		}
	});
}
function canceloffer() {
	var qVars = 'transferid';
	$('#div_wait').show();
	$('#btn_save').hide();
	ajaxCallPage('pages/user.control.php?act=canceloffer#'+qVars,'POST',null, function(rText){
		if(rText=='1'){
			alert('Η πρόταση ακυρώθηκε!');	
			$('#div_wait').hide();
			$('#btn_save').show();
			location.href='http://www.pes-league.gr/team/';
		} else {
			alert(rText);	
			$('#div_wait').hide();
			$('#btn_save').show();
		}
	});
}
function creatematch() {
	var qVars = 'username;datepicker';
	$('#div_wait').show();
	$('#btn_save').hide();
	ajaxCallPage('pages/user.control.php?act=creatematch#'+qVars,'POST',null, function(rText){
		if(rText=='1'){
			alert('Ο αγώνας δημιουργήθηκε!');	
			$('#div_wait').hide();
			$('#btn_save').show();
			//location.href='http://www.pes-league.gr/team/';
		} else {
			alert(rText);	
			$('#div_wait').hide();
			$('#btn_save').show();
		}
	});
}




//function inviteteammember() {
//	var qVars = 'p_id;username';
//	$('#div_wait').show();
//	$('#btn_save').hide();
//	ajaxCallPage('pages/user.control.php?act=inviteteammember#'+qVars,'POST',null, function(rText){
//		if(rText=='1'){
//			alert('Η πρόσκληση στάλθηκε με επιτυχία!');	
//			$('#div_wait').hide();
//			$('#btn_save').show();
//			location.href='http://www.pes-league.gr/edit-team/';
//		} else {
//			alert(rText);	
//			$('#div_wait').hide();
//			$('#btn_save').show();
//		}
//	});
//}

function acp(url, method, container, execf, tMCE){
	/* for using this method you need to have your inputs 
	with the same name as in your called page $_GETS or $_POSTS 
	example calls:
	url=index.php
	url=index.php?myvar=1
	url=index.php?myvar=1#gelem1;gelem2;gelem3
	gelem1 and so on must be <input id="gelem1" value="mplampla" />
	and the index.php will $_GET['gelem1'] or $_POST['gelem1']
	*/
	setBusy();
	method = (method=='GET' || method=='POST') ? method : 'GET';
	var varSend ="";
	var queryStr = (url.split("#")[1]) ? url.split("#")[1] : '';
	var nUrl = url.split("#")[0].split("?")[0];
	var exQstr = (url.split("#")[0].split("?")[1]) ? url.split("#")[0].split("?")[1] : '' ;
	if(queryStr.length > 0) { 
		for(i=0;i<queryStr.split(";").length;i++){
			if(gebi(queryStr.split(";")[i])) varSend += "&" + queryStr.split(";")[i] + "=" + encodeURIComponent(gebi(queryStr.split(";")[i]).value);
			else alert("WARNING: Element defined in url with id '"+queryStr.split(";")[i]+"' does not exist.");
		}
	}
	//alert(nUrl+"\n\n"+exQstr+"\n\n"+varSend);
	rq = createXHR();
	rq.onreadystatechange = function() {
		if (rq.readyState == 4 && rq.status == 200 && rq.responseText) { // Complete
			performPostLoadOperations(rq.responseText, container, execf, tMCE);

		} else if(rq.readyState == 4 && rq.status == 404) { // Page not found
			setNotBusy(); alert("404 ERROR: Page not found.\n\n"+nUrl+"\n\n ");
		}
	};
	
	if(method=='GET') { rq.open("GET", nUrl + "?" + exQstr + varSend); rq.send(""); } 
	else { rq.open("POST", nUrl + "?" + exQstr); rq.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); rq.send(varSend); }
}

