var ajax = new sack();
	//var currentClientID=false;

function getClientData(clientId){
	if(clientId==''){
				return false;
	}
	var pars = 'id=' + clientId;
	var url = 'find_ajax.php?'+pars;	
	showLoad();
	new Ajax(url, {
		method: 'get',
		evalScripts:true,
		update: $('ajax'),
		onComplete: function(){ showClientData(); }		
	}).request();
	
}



function getProfile(clientId,search_id){
	
	window.location = 'profile.php?search_id='+search_id;
	/*if(clientId==''){
				return false;
	}
	var pars = 'id=' + clientId+'&search_id='+search_id;
	var url = 'find_ajax.php?'+pars;	
	showLoad();
	new Ajax(url, {
		method: 'get',
		evalScripts:true,
		update: $('ajax'),
		onComplete: function(){ showClientData(); }		
	}).request();*/
	
}


function getClientInData(clientId){
	if(clientId==''){
				return false;
	}
	var pars = 'id=' + clientId;
	var url = 'find_in_ajax.php?'+pars;
	showLoad();
	new Ajax(url, {
		method: 'get',
		update: $('in_ajax'),
		evalScripts:true,
		onComplete: function(){ showClientData(); }		
	}).request();
	
}

function get_pontous(){
	var url = 'ajax_include/free_sms/show_pontous.php';
	new Ajax(url, {
		method: 'get',
		update: $('pontoi'),
		evalScripts:true,
		onComplete: function(){ document.getElementById('MultiBoxLoading2').style.display="none"; }
	}).request();
	
}

function get_mailbox(){
	var url = 'ajax_include/mailbox/show_mails.php';
	new Ajax(url, {
		method: 'get',
		update: $('mails'),
		evalScripts:true,
		onComplete: function(){ document.getElementById('MultiBoxLoading2').style.display="none"; }
	}).request();
	
}

function update_online_members(){
	var url = 'ajax_include/miniscripts/onlinemembers.php';
	new Ajax(url, {
		method: 'get',
		update: $('onlinemembers'),
		evalScripts:true,
		onComplete: function(){ document.getElementById('MultiBoxLoading2').style.display="none"; }
	}).request();
	
}

function just_do_something(url){
	showLoad();
	new Ajax(url, {
		method: 'get',
		evalScripts:true,
		onComplete: function(){ showClientData(); }		
	}).request();
	
}
function getClientGetData(url){
	
	//var url = 'find_in_ajax.php?'+pars;
	showLoad();
	new Ajax(url, {
		method: 'get',
		update: $('in_ajax'),
		evalScripts:true,
		onComplete: function(){ showClientData(); }		
	}).request();
	
}

function showLoad () {
	document.getElementById('MultiBoxLoading2').style.display="block";
}
	
	
function showClientData()
{											
		
		new MultiBox('mb', {descClassName: 'multiBoxDesc2'});
	
	//alert($('multiBoxDesc'));
	document.getElementById('MultiBoxLoading2').style.display="none";
}

function showClientfData()
{											
		
		new MultiBox('mb2', {descClassName: 'multiBoxDesc'});
		
	document.getElementById('MultiBoxLoading2').style.display="none";
}

function showClientInData()
{											
	new MultiBox('mb', {descClassName: 'multiBoxDesc2'});
	document.getElementById('MultiBoxLoading2').style.display="none";
}
	
	
   
   function addRowToTable()
      {
          
		  var tbl = document.getElementById('tblSample');
          var lastRow = tbl.rows.length;         
		  if(lastRow==15){
		  	return false;
		  }
		  var iteration = lastRow;   
          var row = tbl.insertRow(lastRow);
          var cellLeft = row.insertCell(0);
		  cellLeft.align='right';
          var textNode = document.createTextNode('Όνομα Παραλήπτη:');
          cellLeft.appendChild(textNode);
          //document.all("TXTCount").value = iteration;
          
		  var cellRight = row.insertCell(1);                 
		  var el = document.createElement('input');
		  el.name='receiver_name['+iteration+']';          
		  cellRight.appendChild(el);

		  var cellRight = row.insertCell(2);
		  cellRight.align='right'; 
          var textNode = document.createTextNode('E-mail Παραλήπτη:');
          cellRight.appendChild(textNode);
		 
		 
		  var cellRight = row.insertCell(3);                
		  var el = document.createElement('input');
		  el.name='receiver_mail['+iteration+']';          
		  cellRight.appendChild(el);
		  
      }
      
      function removeRowToTable()
      {
          var tbl = document.getElementById('tblSample');
          var lastRow = tbl.rows.length;		     
		  var iteration = lastRow;   
		  if(lastRow==1){
		  	return false;
		  }
		  else
		  {
          	var row = tbl.deleteRow(lastRow-1);
          }
          
		  
      }
	
function post_form(obj,id,but_id,stage){
		ajax.resetData();
		var elements = obj.elements;
    	var pairs = new Array();
	    ajax.evalScripts  =true;
		ajax.setVar('identify',id);
		ajax.setVar('but_id',but_id);
		for (var i = 0; i < elements.length; i++) {

        if ((name = elements[i].name) && (value = elements[i].value))             						
					if(elements[i].type=="checkbox"){
      					if(elements[i].checked){
							ajax.setVar(name,value);
						}
    				}
					else
					{
						if(elements[i].type=="radio"){
      						if(elements[i].checked){
								ajax.setVar(name,value);
							}
    					}
						else
						{
							ajax.setVar(name,value);
						}
					}	
    	}
		
		if(stage==1){			
			ajax.requestFile = 'do_post.php';	// Specifying which file to get			
		}
		else
		{
			ajax.requestFile = 'do_post_txt.php';	// Specifying which file to get
		}
		ajax.onCompletion = function(){ posted_form(id,stage); };	
		ajax.runAJAX();				
	}
	
	function posted_form(id,stage){
		var newData = ajax.response;
		//alert(newData);
		if(newData.indexOf('<ERROR>')>-1){		
			var y=newData.indexOf('<ERROR>');
			var z=newData.indexOf('</ERROR>');
			var length=z-(y+7);
			alert_id=newData.substr(y+7,length);		
			read_alert_data(alert_id);			
			return false;
		}
		if(stage==1){
			if(newData.indexOf('<CLIENT>')>-1){		
				var y=newData.indexOf('<CLIENT>');
				var z=newData.indexOf('</CLIENT>');
				var length=z-(y+8);
				alert_id=newData.substr(y+8,length);		
				id=alert_id;				
			}	
			if(newData.indexOf('<SUCCESS>')>-1){		
				var y=newData.indexOf('<SUCCESS>');
				var z=newData.indexOf('</SUCCESS>');
				var length=z-(y+9);
				alert_id=newData.substr(y+9,length);		
				show_success_window(alert_id,id);			
				return false;
			}
			
			getClientInData(id);
		}
		else
		{
			if(id==1){
				var y=newData.indexOf('<SESSION>');
				var z=newData.indexOf('</SESSION>');
				var length=z-(y+9);
				alert_id=newData.substr(y+9,length);
				window.location = 'register.php?step=4&my_hash='+alert_id;
			}
			else
			{
				getClientData(id);
			}
		}
	}
	
	
function getClientInData_and_fill(clientId,tower,topic)
{			

	if(clientId==''){
				return false;
	}
	var pars = 'id=' + clientId;
	ajax.onLoading=function() { showLoad(); };
	ajax.requestFile = 'find_in_ajax.php?'+pars;	// Specifying which file to get
	ajax.evalScripts=true;
	ajax.onCompletion = function(){ showClientInData_and_fill(tower,topic); };	
	ajax.runAJAX();
	}
	
function showClientInData_and_fill(tower,topic)
{											
	
	var newData = ajax.response;
	document.getElementById('in_ajax').innerHTML =newData;	
	new MultiBox('mb', {descClassName: 'multiBoxDesc'});
	document.getElementById('to').value=tower;
	document.getElementById('topic').value=topic;
	document.getElementById('MultiBoxLoading2').style.display="none";
}


function read_alert_data(id_to_read){
	var pars = 'id=' + id_to_read;
	ajax.onLoading=function() { showLoad(); };
	ajax.requestFile = 'ajax_include/alert_data.php?'+pars;	// Specifying which file to get
	ajax.evalScripts=true;
	ajax.onCompletion = function(){ show_alert_window(); };	
	ajax.runAJAX();
	
}

function show_alert_window(){
	document.getElementById('MultiBoxLoading2').style.display="none";
	Growl.Bezel({
	title: 'Error',
	text: ajax.response,
	duration: 4
	});
	return false;
}


function show_success_window(data,id,profile,search_id){
	 profile = profile || 0;
	 search_id = search_id || 0; 
	document.getElementById('MultiBoxLoading2').style.display="none";
	Growl.Bezel({
	title: 'Success',
	text: data,
	duration: 4
	});
	if(profile==0){
			if(id==9) { id=6; }
			if(id==53) { id=24; }
			if(id==31) { id=30; }
			if(id==32) { id=54; }
		getClientInData(id);
	}
	else
	{		
		getProfile(id,search_id);	
	}
	return false;
}

function just_show(title,data){
	Growl.Bezel({
	title: title,
	text: data,
	duration: 4
	});
	return false;
}

function select_all(){
for (i=0; i<document.forms[1].elements.length; i++) {
		if (document.forms[1].elements[i].type == 'checkbox') {
			if(document.forms[1].elements[i].checked == false){
				document.forms[1].elements[i].checked = 'checked';
			}
		}	
}	
}

function unselect_all(){
for (i=0; i<document.forms[1].elements.length; i++) {
		if (document.forms[1].elements[i].type == 'checkbox') {
			if(document.forms[1].elements[i].checked == true){
				document.forms[1].elements[i].checked = false;
			}
		}	
}	
}

function change_situation(){
for (i=0; i<document.forms[1].elements.length; i++) {
		if (document.forms[1].elements[i].type == 'checkbox') {
			if(document.forms[1].elements[i].checked == false){
				document.forms[1].elements[i].checked = 'checked';
			}
			else
			{
					document.forms[1].elements[i].checked =false;
			}
		}	
}
}
