// JavaScript Document
 function popup_window(url,w,h,name) {
	 properties = 'toolbar=no,menubar=no,resizable=no,scrollbars=no,status=no,location=no,width=' + w + ',height=' + h;
	 newWindow = window.open(url, name, properties);
	 newWindow.focus();
 }
 function popup_image(url,w,h,name,image_name) {
	 frm_gen_code.radio5.checked=true
	 properties = 'toolbar=no,menubar=no,resizable=no,scrollbars=no,status=no,location=no,width=' + w + ',height=' + h;
	 var tmp_image = '';
	 if (image_name=='online') {
		 tmp_image = frm_gen_code.online_image.value;
	 } else {
		 tmp_image = frm_gen_code.offline_image.value;
	 }
	 url += "?image_name="+tmp_image;
	 newWindow = window.open(url, name, properties);
	 newWindow.focus();
 } 
 function check_null() {
	 if (frm_add_account.username.value=='' || frm_add_account.username.value==null) {
		 frm_add_account.username.focus();
		 return false;				 
	 }
	 if (frm_add_account.password.value=='' || frm_add_account.password.value==null) {
		 frm_add_account.password.focus();
		 return false;				 
	 }
	 if (frm_add_account.name.value=='' || frm_add_account.name.value==null) {
		 frm_add_account.name.focus();
		 return false;				 
	 }
	 Insert_Account();
 }
 function Show_manage_image(acc_id,type) {
	try{
		var url = "user_manage_picture.php";
		var param = "acc_id="+acc_id+"&type="+type;
		if (type==2){
			param += "&"+Form.serialize('frm_manage_image');
		}
		new Ajax.Request(url, { parameters : param, onComplete : Show_manage_image_OK } );
	}catch(e){
		alert(e.description);
	}
 }
 function Show_manage_image_OK(req){
	try{
		if (req.responseText==1) {
		    $('info').innerHTML = 'Info : Update online and offline picture Success';
		    Show_Insert_Acc();
		} else {
		    $('manage_account').innerHTML = req.responseText;
		}
		Load_Account();
	}catch(e){
		alert(e.description);
	}
 }
 function Show_Insert_Acc() {
	try{
		var url = "user_frm_insert.php";
		var param = "";
		new Ajax.Request(url, { parameters : param, onComplete : Show_Insert_Acc_OK } );
	}catch(e){
		alert(e.description);
	}
 }
 function Show_Insert_Acc_OK(req){
	try{
		$('manage_account').innerHTML = req.responseText;
		Load_Account();
	}catch(e){
		alert(e.description);
	}
 }
 function Insert_Account(type){
	try{
		var url = "user_insert_account.php";
		var param = Form.serialize('frm_add_account');
		new Ajax.Request(url, { parameters : param, onComplete : Insert_Account_OK } );
	}catch(e){
		alert(e.description);
	}
 }
 function Insert_Account_OK(req){
	try{
		$('info').innerHTML = req.responseText;
		frm_add_account.username.value='';
		frm_add_account.password.value='';
		frm_add_account.name.value='';
		Load_Account();
	}catch(e){
		alert(e.description);
	}
 }
 function Confirm_Delete(sub_id,name) {
	 if (confirm('Do you want delete sub account ' + name + " ? ")) {
		 Delete_Account(sub_id,name);
	 } else {
		 return false;
	 }
 }
 function Delete_Account(sub_id,name){
	try{
		var url = "user_delete_account.php";
		var param = "sub_id=" + sub_id + "&name=" + name;
		new Ajax.Request(url, { parameters : param, onComplete : Delete_Account_OK } );
	}catch(e){
		alert(e.description);
	}
 }
 function Delete_Account_OK(req){
	try{
		$('info').innerHTML = req.responseText;
		Load_Account();
	}catch(e){
		alert(e.description);
	}
 }
 function Edit_Account(acc_id,type){
	try{
		var url = "user_edit_account.php";
		var param = "acc_id=" + acc_id + "&type=" + type;
		if (type==2){
			param += "&" + Form.serialize('frm_edit_account');
		}
		new Ajax.Request(url, { parameters : param, onComplete : Edit_Account_OK } );
	}catch(e){
		alert(e.description);
	}
 }
 function Edit_Account_OK(req){
	try{
		if (req.responseText==1) {
		    $('info').innerHTML = 'Info : Update info Live chat sub account Success';
			Show_Insert_Acc();
		} else {
		    $('manage_account').innerHTML = req.responseText;
		}
		Load_Account();
	}catch(e){
		alert(e.description);
	}
 }
 function Edit_Sub_Account(sub_acc_id,type){
	try{
		var url = "user_edit_sub_account.php";
		var param = "sub_acc_id=" + sub_acc_id + "&type=" + type;
		if (type==2){
			param += "&" + Form.serialize('frm_edit_sub_account');
		}
		new Ajax.Request(url, { parameters : param, onComplete : Edit_Sub_Account_OK } );
	}catch(e){
		alert(e.description);
	}
 }
 function Edit_Sub_Account_OK(req){
	try{
		if (req.responseText==1) {
		    $('info').innerHTML = 'Info : Update info Live chat sub account Success';
			Show_Insert_Acc();
		} else {
		    $('manage_account').innerHTML = req.responseText;
		}
		Load_Account();
	}catch(e){
		alert(e.description);
	}
 }
 function Edit_Email(acc_id,type){
	try{
		var url = "user_edit_email.php";
		var param = "acc_id=" + acc_id + "&type=" + type;
		if (type==2){
			param += "&" + Form.serialize('frm_manage_email');
		}
		new Ajax.Request(url, { parameters : param, onComplete : Edit_Email_OK } );
	}catch(e){
		alert(e.description);
	}
 }
 function Edit_Email_OK(req){
	try{
		if (req.responseText==1) {
		    $('info').innerHTML = 'Info : Update Live chat E-Mail Success';
		    Show_Insert_Acc();
		} else {
		    $('manage_account').innerHTML = req.responseText;
		}
		Load_Account();
	}catch(e){
		alert(e.description);
	}
 }
function Load_Account(){
	try{
		var url = "user_show_account.php";
		var param = "";
		new Ajax.Request(url, { parameters : param, onComplete : Load_Account_OK } );
	}catch(e){
		alert(e.description);
	}
 }
 function Load_Account_OK(req){
	try{
		$('show_result').innerHTML = req.responseText;
	}catch(e){
		alert(e.description);
	}
 }
function User_Login(){
	try{
		var url = "user_login.php";
		//var param = Form.serialize('frm_user_login');
		$('info').innerHTML = "Process login please wait...";
		var param = "username="+$F('username')+"&password="+$F('password');
		new Ajax.Request(url, { parameters : param, onComplete : User_Login_OK } );
	}catch(e){
		alert(e.description);
	}
 }
 function User_Login_OK(req){
	try{
		if (req.responseText==1) {
			window.location = 'main.php';
		} else {
		    $('info').innerHTML = req.responseText;
		}
	}catch(e){
		alert(e.description);
	}
 } 
 
 function Edit_Form_Login(acc_id,type){
	try{
		var url = "user_edit_form.php";
		var param = "acc_id=" + acc_id + "&type=" + type;
		if (type==2){
			param += "&" + Form.serialize('frm_edit_form');
		}
		new Ajax.Request(url, { parameters : param, onComplete : Edit_Form_Login_OK } );
	}catch(e){
		alert(e.description);
	}
 }
 function Edit_Form_Login_OK(req){
	try{
		if (req.responseText==1) {
		    $('info').innerHTML = 'Info : Update form user login Success';
			Show_Insert_Acc();
		} else {
		    $('manage_account').innerHTML = req.responseText;
		}
		Load_Account();
	}catch(e){
		alert(e.description);
	}
 }
