// JavaScript Document
ImageListBtn = new Array();
ImageListBtnHover = new Array();

$(document).ready(function(){

});

function user_view(txtpath, formid, cssid, txtpath_email) {
	$('#'+cssid).html("Loading");
	$("#"+cssid).dialog({
			height: 400,
			width:500,
			modal: true
		});
	$.post(txtpath, 
	$("#"+formid).serialize(),
		function(data){
			$('#'+cssid).html(data);
	});
}

function clear_txtbox(txtbox) {
	$('#'+txtbox).val("");
}

function add_to_group(txtpath) {
	$.ajax({
	  url: txtpath+"/sendtoid/"+$("#sendto_id").val(),
	  success: function(data) {
		$('#petrus-admin-ajax-load').html(data);
	  }
	});
}

function remove_to_group(txtpath) {
	$.ajax({
	  url: txtpath+"/sendtoid/"+$("#sendto_id").val(),
	  success: function(data) {
		$('#petrus-admin-ajax-load').html(data);
	  }
	});
}

// Send Email E-Invite
var email_timer;
var email_data;
var email_answer;
var jcount_new;

function user_view1(txtpath, formid, cssid, txtpath_email) {
	$('#'+cssid).html("Loading");
	$("#"+cssid).dialog({
			height: 400,
			width:500,
			modal: true
		});
	$.post(txtpath, 
	$("#"+formid).serialize(),
		function(data){
			alert(data[(0)].sendto_id);
	},"json");
}

function get_sendtos(txtpath, formid, cssid, txtpath_email) {
	$('#'+cssid).html("Loading...");
	$("#"+cssid).dialog({
			height: 400,
			width:500,
			modal: true
		});
	$.post(txtpath, 
	$("#"+formid).serialize(),
		function(data){
			email_data = data;
		jcount = 0;
		jsonlength = email_data.length;
		$("#"+cssid).html("<h2>Sending...</h2>");
		email_timer=setTimeout("get_sendto('"+txtpath_email+"',"+jcount+","+jsonlength+",'"+cssid+"')",5000);
	},"json");
}

function get_sendto(txtpath_email, jcount, jsonlength, cssid) {
	jcount_new = jcount;
	$.ajax({
	  url: txtpath_email+"/"+email_data[(jcount)].sendto_id,
	  success: function(data) {
		var str=data;
		var timer;
		if (str.search(/Already Send/i) > 0) {
			timer = 1;
		} else {
			timer = 5000;
		}
		
		$("#"+cssid).append(data);
		if (jcount <= jsonlength) {
			jcount++;
			email_timer=setTimeout("get_sendto('"+txtpath_email+"',"+jcount+","+jsonlength+",'"+cssid+"')",timer);
			if ((Math.round(((jcount)/jsonlength)*100)) == 100) {
				//$("#stud-enrollment").dialog('close');
				clearTimeout(email_timer);
				$("#"+cssid).append("<h2>DONE</h2>");
			}
		}
	  }
	});
}
