// remote scripting library
// (c) copyright 2005 modernmethod, inc
var sajax_debug_mode = false;
var sajax_request_type = "GET";
var fsms_ajax_response = '1';
var __SITE_URL__  = 'http://localhost/myworks/newaboki/';
/**
* if sajax_debug_mode is true, this function outputs given the message into 
* the element with id = sajax_debug; if no such element exists in the document, 
* it is injected.
*/

function sajax_debug(text) {
	if (!sajax_debug_mode) return false;

	var e= document.getElementById('sajax_debug');

	if (!e) {
		e= document.createElement("p");
		e.className= 'sajax_debug';
		e.id= 'sajax_debug';

		var b= document.getElementsByTagName("body")[0];

		if (b.firstChild) b.insertBefore(e, b.firstChild);
		else b.appendChild(e);
	}

	var m= document.createElement("div");
	m.appendChild( document.createTextNode( text ) );

	e.appendChild( m );

	return true;
}

/**
* compatibility wrapper for creating a new XMLHttpRequest object.
*/
function sajax_init_object() {
	sajax_debug("sajax_init_object() called..")
	var A;
	try {
		// Try the new style before ActiveX so we don't
		// unnecessarily trigger warnings in IE 7 when
		// set to prompt about ActiveX usage
		A = new XMLHttpRequest();
	} catch (e) {
		try {
			A=new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try {
				A=new ActiveXObject("Microsoft.XMLHTTP");
			} catch (oc) {
				A=null;
			}
		}
	}
	if (!A)	alert("Could not create connection object.");
	
	return A;
		
}




function create_div(div_id) {
	var c = document.createElement("div");
	//var s = document.getElementById(r);
	//var pos = os_getElementPosition(r);
	//alert(window.screen.width);	
	
	var left = window.screen.width/3;
	var top = window.screen.height/5;
	c.style.border = "0px solid #999999";
	c.style.background = "#660066";
	c.style.position = 'absolute';
	//c.style.height = '200px'
	c.style.padding = '20px'
	c.style.width = '400px'
	c.style.top = top+'px';
	c.style.left = left+'px';
	c.style.display = 'none';
	//c.setAttribute("id", );	
	document.body.appendChild(c);
	
	c.innerHTML = '<div id="'+div_id+'" width="100%" height="100%" style="position:relative; padding:10px; background:#ffffff;"></div>'; 
	 Effect.Appear(c);
	 //Effect.Grow(c);
	 return c;
}
function startTimeline() {
    // 3x highlight in front
    //for(var i=0; i<3; i++)
     // new Effect.Highlight('d3', { duration: 1.0, queue: 'front' });
    
    // insert scale at very beginning
   
    
    // parallel implied, delay 0.5 sec
    //new Effect.Highlight('d1', { delay: 0.5 }); 
    
    // puff at end
   // new Effect.Puff('d2', { duration: 4.0, queue: 'end' });
  }
function set_content(container, thecontent) {
	document.getElementById(container).innerHTML = thecontent;
}
function send_sms_div() {
	var new_div = create_div('funsms_div_content');
	//xmlhttp = sajax_init_object("GET", '<?= SITE_URL ?>webservice/ajax_server.php', true, 'div_content' );
	var content = xmlhttp.responseText;
	set_content('funsms_div_content', content);
	//return false;
}
function the_ajax_responseText(cont, resp) {
		//var fsms_ajax_response = resp;
		if(document.getElementById(cont) != null) the_set_content(cont, resp);
		fsms_ajax_response = resp;
		//alert(fsms_ajax_response);
}
function ajaxResponse() {
		//var fsms_ajax_response = resp;
		//if(document.getElementById(cont) != null) the_set_content(cont, resp);
		alert(fsms_ajax_response);
		//alert();
}
 function the_set_content(container, thecontent) {
		document.getElementById(container).innerHTML = thecontent;
		//alert(thecontent);
	}
function create_dynamic_div (val, title, type_) {
		var new_page = new fsms_page;
		if(document.getElementById('funsms_cover_new_div_0') != null) {
			//document.body.removeChild('funsms_cover_new_div_0');	
			start_remove_content('funsms_main_new_div_0');
			start_remove_content('funsms_cover_new_div_0');
		}
		var new_div = new_page.create_div('funsms_div_content', title);
		if(type_ == 'ajax') {
			ajax = new_page.new_ajax_connect("GET", val, true, 'funsms_div_content' );
		}else if(type_ == 'html') {
			var new_div = new_page.create_div('funsms_div_content', title);
			new_div.innerHTML=val;
			
		}
		//var content = fsms_ajax_response;
		//alert(content);
		
	}
function sms_send__(to, title) {
	//alert(__SITE_URL__);
	if(title == null) title = 'Send SMS';
	create_dynamic_div(''+__SITE_URL__+'webservice/actions/send_sms.php?to='+to+'', title, 'ajax');
	
}
function do_friend_request__(to, message, captcha) {
	//alert(__SITE_URL__);
	var err = '';
	var new_page = new fsms_page;
	if(to == '') err = 'You must supply a receiver';
	//if(document.getElementById(message).value == '') err = 'You must enter a message';
	if(document.getElementById(captcha).value == '') err = 'You must enter the security code';
	
	if(err != '') {
		alert(err);
		//return false;
	}else{
		path = ''+__SITE_URL__+'webservice/actions/friend_request.php?status=2&to='+to+'&message='+document.getElementById(message).value+'&captcha='+document.getElementById(captcha).value+'';
		//new_page.ajax_connect("GET", path, true, true, 'funsms_div_content' );
		new Ajax.Request(path,
	  {
		method:'post',
		onSuccess: function(transport){
		  var response = transport.responseText || "no response text";
		  //if(response == 'deleted') 
		 // alert(response);// return true;
		  if(response != 'completed') {
			  //alert( document.getElementById('funsms_div_content').innerHTML);
			  document.getElementById('funsms_div_content').innerHTML=response;
			  
		  }else{
			// start_remove_content('funsms_main_new_div_0');
			Effect.Fade(document.getElementById('funsms_main_new_div_0'));
				start_remove_content('funsms_cover_new_div_0');
				fsms_show_notice('Friend request successfully sent');
		  }
		},
		onFailure: function(){ alert('Could not connect to server'); return false; }
	  });
	}
}
function do_send_sms__(to, message, captcha) {
	//alert(__SITE_URL__);
	var err = '';
	var new_page = new fsms_page;
	if(to == '') err = 'You must supply a receiver';
	//if(document.getElementById(message).value == '') err = 'You must enter a message';
	if(document.getElementById(captcha).value == '') err = 'You must enter the security code';
	
	if(err != '') {
		alert(err);
		//return false;
	}else{
		
		 //alert(document.getElementById('funsms_main_new_div_0').innerHTML);
		path = ''+__SITE_URL__+'webservice/actions/send_sms.php?status=2&to='+to+'&message='+document.getElementById(message).value+'&captcha='+document.getElementById(captcha).value+'';
		
		 //alert(document.getElementById('funsms_main_new_div_0').innerHTML);
		//new_page.ajax_connect("GET", path, true, true, 'funsms_div_content' );
		
		 document.getElementById('funsms_div_content').innerHTML='Processing...';
		new Ajax.Request(path, 	  {
		method:'get',
		onSuccess: function(transport){
		  var response = transport.responseText || "no response text";
		  if(response=='completed') {
			  document.getElementById('funsms_main_new_div_0').innerHTML='';
			 removeBoxes();
			 show_notification('SMS message successfully sent');
		  }
		  document.getElementById('funsms_div_content').innerHTML=response;
		  //do_online_users_update(response);
		  //alert(response);
		  return false;
		},
		onFailure: function(){ alert('Could not connect to server'); return false; }
	  });
	
		
		
		
	}
}
function removeBoxes() {
	//start_remove_content('funsms_cover_new_div_0');
	//document.getElementById('funsms_cover_new_div_0').style.filter = 'Alpha(Opacity=30, FinishOpacity=30, Style=30, StartX=30, StartY=30, FinishX=30, FinishY=30)';
	document.getElementById('funsms_cover_new_div_0').style.display='none';
	Effect.Fade(document.getElementById('funsms_main_new_div_0'));
}
function friend_request__(to, title) {
	//alert(__SITE_URL__);
	if(title == null) title = 'Send a friend request';
	create_dynamic_div(''+__SITE_URL__+'webservice/actions/friend_request.php?to='+to+'', title, 'ajax');
	}
function start_remove_content (contid, type) {
	var e = document.body;
	
	if(type != null) {
		if(contid=='funsms_cover_new_div_0') {
			remove_content(document.getElementById(contid));
		}else{
			
			Effect.Fade(document.getElementById(contid));
		}
	}else{
		if( document.getElementById (contid) != null) {
			var l = document.getElementById (contid);
			remove_content(l);
			//Effect.Puff(l);
			//alert(l);
			//if(l != 'undefined' && l != null) {
				// setInterval("remove_content('"+l+"')", 2000);
			//}
			
		}
	}
}
	function remove_content (contid) {
		var e = document.body;
			e.removeChild(contid);			
	}
	function hide_notification() {
		clearInterval(do_rem);
		Effect.Fade('notification_d1',{duration:5});
		
	}
	function show_notification(msg) {
		
		if($('notification_d1').style.display != 'none' ) {
			clearInterval(do_rem);
			$('notification_d1').style.display='none';
		}
		document.getElementById('notification_span').innerHTML = msg;
		Effect.Appear('notification_d1',{duration:1});
		do_rem=setInterval("hide_notification()", 8000);
	}
	function show_cover() {
		//document.getElementById('notification_span').innerHTML = msg;
		Effect.Appear('myaboki_page_cover',{duration:1});
		//do_rem=setInterval("hide_notification()", 20000);
	}
	function hide_cover() {
		//document.getElementById('notification_span').innerHTML = msg;
		Effect.Fade('myaboki_page_cover',{duration:1});
		//do_rem=setInterval("hide_notification()", 20000);
	}
	function show_form_div(inner) {
		if($('form_div').style.display !='none') {
			clearInterval(do_rem_form_div);
			$('form_div').style.display='none';
		}
		$('form_div_span').innerHTML = inner;
		Effect.Appear('form_div',{duration:1});
	}
	function hide_form_div() {
		Effect.Fade('form_div',{duration:1});
	}
	function start_send_sms(receiver) {
		new Ajax.Request(__SITE_URL__+'webservice/actions/send_msg.php?to='+receiver+'&user_id=&time='+Math.random()+'',
	  {
		method:'get',
		onSuccess: function(transport){
		  var response = transport.responseText || "no response text";
		  show_form_div(response);
		  //$('form_div_span').innerHTML=response;
		  //do_online_users_update(response);
		  //alert(response);
		  return false;
		},
		onFailure: function(){ alert('Could not connect to server at this time. Please try again'); return false; }
	  });
	}
	function do_send_msg(receiver, subject, var2, var3) {
		if($('form_error_span') != null) $('form_error_span').innerHTML='';
		new Ajax.Request(__SITE_URL__+'webservice/actions/send_msg.php?to='+receiver+'&captcha='+$(var3).value+'&subject='+$(subject).value+'&message='+$(var2).value+'&time='+Math.random()+'',
	  {
		method:'post',
		onSuccess: function(transport){
		  var response = transport.responseText || "no response text";
		  //show_form_div(response);
		  if(response == 'completed') {
			  hide_form_div();
			  hide_cover();
			  show_notification('Your message was successfully sent!');
			  return false;
		  }
		  $('form_div_span').innerHTML=response;
		  //do_online_users_update(response);
		  //alert(response);
		  return false;
		},
		onFailure: function(){ alert('Could not connect to server at this time. Please try again'); return false; }
	  });
	}
		