var joined_room = Array();
var selected_transport = '';
var bolDisplayBuddyList = true;
var intTimeOutToaster = false;
var strSelectedSize = 'medium'; // size embed

function login_handler(e)
{
	var asc = document.all ? event.keyCode : e.which;
	if(asc == 13) login(e);
	return asc != 13;
}

function search_handler(e,strPageType)
{
	var asc = document.all ? event.keyCode : e.which;
	if(asc == 13) SearchRoom(strPageType);
	return asc != 13;
}

function SearchRoom(strPageType)
{
	var intPage			= 1;
	var strKeyword 		= $('keyword').value;
	var strRoomCateCode = $('room_cate_code').value;
	if(!strRoomCateCode || strRoomCateCode=='' )
	{
		alert(Common.please_select_room_cate);
		return false;
	}
	if(strPageType=='ajax')
	{
		setTimeout("xajax_loadListRoom("+strRoomCateCode+",'"+strKeyword+"',1);", 1000);
	}
	else
	{
		linksearch = HOME_URL+"/rooms/category/" + strRoomCateCode + "/" + strKeyword + "/1";
		window.location=linksearch;
	}
}

function set_user_info (username, session_type)
{
	user 			= username;
	defaultTitle 	= parent.document.title = document.title + ': ' + init_displayname;
	//if(typeof(Buddylist) != 'undefined')
	//{
		Buddylist.create();
		pingTimer = setInterval(ping_msg, pingFrequency);
		$('buddylist').innerHTML = '';
		Buddylist.addGroup(Languages.get('offline'));
	//}
}

function set_contact_status(contactid,group_name,status,status_text)
{
	if(ZICZAC_DEBUG)
	{
		document.getElementById('ZZDebug').innerHTML+= "<strong>contactid</strong>: " + contactid + " <strong>group_name</strong>: "+ group_name + " <strong>status</strong>: " + status + " <strong>status_text</strong>: "+status_text+"<br><br>";	
	}
	if(status_text=='null')
	{
		status_text = '';
	}
	if(!$(Buddylist.listObjects[contactid].obj)) {
		return;
	}
	if (contactid.search("@conference")==-1)
	{	
		Buddylist.moveBuddy(contactid, group_name);
		if(status=='chat') status='online';
	
		 if(contactid.search("yahoo."+JSERVER) > 0)
		 {
			$(Buddylist.listObjects[contactid].img).src = STATIC_ZICZAC+'/themes/transport/yahoo-'+status+'.gif';
		 }
		 else if(contactid.search("gtalk."+JSERVER) > 0)
		 {
			$(Buddylist.listObjects[contactid].img).src = STATIC_ZICZAC+'/themes/transport/gtalk-'+status+'.gif';
		 }
		 else if(contactid.search("aim."+JSERVER) > 0)
		 {
			$(Buddylist.listObjects[contactid].img).src = STATIC_ZICZAC+'/themes/transport/aim-'+status+'.gif';
		 }
		 else if(contactid.search("msn."+JSERVER) > 0)
		 {
			$(Buddylist.listObjects[contactid].img).src = STATIC_ZICZAC+'/themes/transport/msn-'+status+'.gif';
		 }
		 else
		 {
			$(Buddylist.listObjects[contactid].img).src = STATIC_ZICZAC+'/themes/transport/ziczac-'+status+'.gif';
		 }

		
		if(status_text!='' && status_text!=chatnhe_get_username(contactid))
		{
			status_text = ' ('+status_text+')';
		}
		else
		{
			if (status=='xa')
				status_text = '(Be Right Back)';
			else if (status=='dnd')
				status_text = '(I\'m busy)';
			else if (status=='away')
				status_text = '(Stepped out)';
			else 
				status_text = '';
		}
		$(contactid+'_status').innerHTML = status_text;
		document.getElementById(contactid+'_blItem').title = status_text;
	}
	else
	{
	}
}

// ha`m kay username tu` chuo^~i. vd : tu` huytruong84@yahoo.com -> huytruong84
function chatnhe_get_username(strUsername)
{
	if(strUsername)
	{
		if(typeof(strUsername.split('@')[2]) != 'undefined')
		{
			return strUsername.split('@')[0] + '@' + strUsername.split('@')[1];
		}
		else
		{
			return strUsername.split('@')[0];
		}
	}
}

// ham lay nickname tu chuoi. vd : usera_1199613450@conference.mandepchai.com/usera
function chatnhe_get_nickname(str)
{
	if(str)
	{
		str = str.split('/');
		return str[1];
	}
}

// ham lay username ko kem resource. vd : huytruong84@mandepchai.com/Ziczac
function GetUsernameWithoutReource(strFullJid)
{
	if(strFullJid)
	{
		var arrInfo = strFullJid.split('/');
		var strJid = arrInfo[0];
		return strJid;
	}
}

function ping_msg()
{
	var CNNumChatCount = $("CNmsgCount");
	CNNumChatCount.value = 0;
	/*
	heartBeat++;
	if(heartBeat>100)
	{
		heartBeat = 0;
	}*/
}

function show_room(nick_name, room_name, room_type)
{
		if(!$(room_name + '_chat'))
		{
			Chatroom.create(room_name, room_name);
		}
		else
		{
			if(!Chatroom.windows[room_name].isVisible())
			{
				Chatroom.windows[room_name].show();
				setTimeout("scrollToBottom('" + room_name + "_rcvd')", 125);
			}
		}
		joined_room[room_name+'_chat'] = nick_name;

		Windows.close('newRoom');
		Chatroom.windows[room_name].toFront();
		setTimeout("$('"+Chatroom.windows[room_name].getId()+"_sendBox').focus()", 125);

}

//them buddy vao chatRoom
function addBuddyToRoom(nick_name, room_name, jid, role, affiliation)
{
	if(!$(nick_name+'_'+room_name+'_chatUser') && typeof(Chatroom.windows[room_name]) != 'undefined')
	{
		Stamp = new Date(); var h = String(Stamp.getHours()); var m = String(Stamp.getMinutes()); var s = String(Stamp.getSeconds());
        h = (h.length > 1) ? h : "0"+h; m = (m.length > 1) ? m : "0"+m;
		Chatroom.windows[room_name].addUser(nick_name, role, affiliation);
		var rcvdBox = $(Chatroom.windows[room_name].getId()+"_rcvd");
		rcvdBox.innerHTML = rcvdBox.innerHTML + "<b class=\"userB\">[" + h + ":" + m + "] <i>"+nick_name+" " + Languages.get('hasJoined') + "</i></b><br>";
		scrollToBottom(Chatroom.windows[room_name].getId()+"_rcvd");
	}
}

function removeBuddyFromRoom(nick_name, room_name)
{
	//Johnny: ve xem lai cho nay,
	if(typeof(Chatroom.windows[room_name]) != 'undefined' && $(nick_name+'_'+room_name+'_chatUser'))
	{

		Stamp = new Date(); var h = String(Stamp.getHours()); var m = String(Stamp.getMinutes()); var s = String(Stamp.getSeconds());
        h = (h.length > 1) ? h : "0"+h; m = (m.length > 1) ? m : "0"+m;
		Chatroom.windows[room_name].deleteUser(nick_name);
		var rcvdBox = $(Chatroom.windows[room_name].getId()+"_rcvd");
		rcvdBox.innerHTML = rcvdBox.innerHTML + "<b class=\"userB\">[" + h + ":" + m + "] <i>"+nick_name+" " + Languages.get('hasLeft') + "</i></b><br>";
		scrollToBottom(Chatroom.windows[room_name].getId()+"_rcvd");
	}
}

function moveNick()
{
	var list1 = $('list1');
	var list2 = $('list2');
	i=0;
	while (i < list1.length)	
	{
		if (list1.options[i].selected == true)
		{								
			flag = false;
			for(iback = list2.length-1; iback >= 0; iback--)
			{
				if (list1.options[i].value == list2.options[iback].value)
				{					
					flag = true;
					break;
				}					
			}
			if (!flag)
			{
				x = list2.length;
				if (x > 2)	
					list2.options[--x] = new Option(list1.options[i].text,list1.options[i].value);
				else
					list2.options[x++] = new Option(list1.options[i].text,list1.options[i].value);						
			}
				
		}
		i++;
	}
	//move thanh cong bo chon het list trai
	for(i=0; i<list1.length; i++)
	{
		list1.options[i].selected = false;
	}
}

//bo nick conference list 2
function removeNick() 
{		
	var list2 = $('list2');			
	i = list2.length -1;
	for (i; i > -1; i--) 
	{
		if (list2.options[i].selected) 
		{
			list2.options[i] = null;
		}
	}
}


function close_room(room_name)
{
	if ($(room_name)) 
	{
		Windows.getWindow(room_name).destroy();
	}
}

function denySubscribtion(from)
{
	objJS.dCt(from);
	Windows.getWindow('alertSubscribtionRequest_'+from).destroy();
	return;
}

function setTransportValue(transport)
{
	selected_transport = transport;
}

function addNewConnection()
{
	var transport = $('selected_transport').value;
	var transport_username = $('transport_username').value;
	var transport_password = $('transport_password').value;

	if(trim(transport_username).length == 0 || trim(transport_password).length == 0)
	{
		Dialogs.alertBasic('alertRegisterGatewayError1',Languages.get('registerGatewayMissValue'), transport+'.big-error.png');
		return;
	}
	else
	{	
		objJS.rGw(transport+'.'+JSERVER, transport_username, transport_password);
		xajax_registerGateway(transport, transport_username, transport_password);
	}
}

function onCompleteRegisterGateway(strTransport, strTransportUsername)
{
	rosterLoaded 	= false;
	strHtmlBuddyList= '';
	
	Gateways.list[strTransport] = strTransportUsername+'@'+strTransport+'.'+JSERVER;
	Windows.getWindow('addTransportDialog').destroy();
	Windows.getWindow('accountsDialog').destroy();
	Dialogs.accountsDialog();
	//setTimeout("callFetchGatewayRoster()", 7000); // call fetch full roster de nhan lai roster list moi
}

function unregister_transport(transport)
{
	strJustRemoveGateway = Gateways.list[transport];
	objJS.uRG(transport+'.'+JSERVER, user);
	xajax_unRegisterGateway(transport);
}

function onCompleteUnregisterGateway(strTransport)
{
	delete Gateways.list[strTransport];
	Windows.getWindow('accountsDialog').destroy();
	Dialogs.accountsDialog();
}

function change_transport_icons(transport)
{
	$('transport_icon').src = STATIC_ZICZAC+'/themes/transport/'+transport+'.gif';
}

function showContextMenu(buddy_id)
{
	var user_name = curSelected;
	var strDisplayName = chatnhe_get_username(user_name);
	$('CM1').innerHTML = '<ul class="right_context_menu"><li onmouseover="this.className=\'right_context_menu_li_selected\'" onmouseout="this.className=\'right_context_menu_li_none\'" onclick="IM.create(\''+user_name+'\', \''+chatnhe_get_username(user_name)+'\', \'normal\');">&nbsp;&nbsp;Chat</li><li onmouseover="this.className=\'right_context_menu_li_selected\'" onmouseout="this.className=\'right_context_menu_li_none\'" onclick="Dialogs.removeBuddy(\''+user_name+'\')">&nbsp;&nbsp;'+Languages.get('webRightMenuDelete')+' </li><li onmouseover="this.className=\'right_context_menu_li_selected\'" onmouseout="this.className=\'right_context_menu_li_none\'" onclick="Dialogs.showProfileDialog(\''+user_name+'\',\''+strDisplayName+'\');">&nbsp;&nbsp;'+Languages.get('webRightMenuViewProfile')+' </li><li onmouseover="this.className=\'right_context_menu_li_selected\'" onmouseout="this.className=\'right_context_menu_li_none\'">&nbsp;&nbsp;'+Languages.get('webRightMenuInvite2Room')+' </li></ul>';

}

var SimpleContextMenu = {

	// private attributes
	_menus : new Array,
	_attachedElement : null,
	_menuElement : null,
	_preventDefault : true,
	_preventForms : true,

	// public method. Sets up whole context menu stuff..
	setup : function (conf) {

		if ( document.all && document.getElementById && !window.opera ) {
			SimpleContextMenu.IE = true;
		}

		if ( !document.all && document.getElementById && !window.opera ) {
			SimpleContextMenu.FF = true;
		}

		if ( document.all && document.getElementById && window.opera ) {
			SimpleContextMenu.OP = true;
		}

		if ( SimpleContextMenu.IE || SimpleContextMenu.FF ) {

			document.oncontextmenu = SimpleContextMenu._show;
			document.onclick = SimpleContextMenu._hide;

			if (conf && typeof(conf.preventDefault) != "undefined") {
				SimpleContextMenu._preventDefault = conf.preventDefault;
			}

			if (conf && typeof(conf.preventForms) != "undefined") {
				SimpleContextMenu._preventForms = conf.preventForms;
			}

		}

	},

	// public method. Attaches context menus to specific class names
	attach : function (classNames, menuId) {
		if(classNames=='buddy')
		{
			if (typeof(classNames) == "string") {		
				SimpleContextMenu._menus[classNames] = menuId;
			}
	
			if (typeof(classNames) == "object") {
				for (x = 0; x < classNames.length; x++) {
	
					SimpleContextMenu._menus[classNames[x]] = menuId;
				}
			}
		}
		else
		{
			return;	
		}

	},


	// private method. Get which context menu to show
	_getMenuElementId : function (e) {

		if (SimpleContextMenu.IE) {
			SimpleContextMenu._attachedElement = event.srcElement;
		} else {
			SimpleContextMenu._attachedElement = e.target;
		}

		while(SimpleContextMenu._attachedElement != null) {

			var className = SimpleContextMenu._attachedElement.className;
			if(className=='buddy')
			{
				if (typeof(className) != "undefined") {
					className = className.replace(/^\s+/g, "").replace(/\s+$/g, "")
					var classArray = className.split(/[ ]+/g);
	
					for (i = 0; i < classArray.length; i++) {
						if (SimpleContextMenu._menus[classArray[i]]) {
							return SimpleContextMenu._menus[classArray[i]];
						}
					}
				}


				if (SimpleContextMenu.IE) {
					SimpleContextMenu._attachedElement = SimpleContextMenu._attachedElement.parentElement;
				} else {
					SimpleContextMenu._attachedElement = SimpleContextMenu._attachedElement.parentNode;
				}
			}
			else
			{
				return;	
			}
		}

		return null;

	},

	// private method. Shows context menu
	_getReturnValue : function (e) {

		var returnValue = true;
		var evt = SimpleContextMenu.IE ? window.event : e;

		if (evt.button != 1) {
			if (evt.target) {
				var el = evt.target;
			} else if (evt.srcElement) {
				var el = evt.srcElement;
			}

			var tname = el.tagName.toLowerCase();

			if ((tname == "input" || tname == "textarea")) {
				if (!SimpleContextMenu._preventForms) {
					returnValue = true;
				} else {
					returnValue = false;
				}
			} else {
				if (!SimpleContextMenu._preventDefault) {
					returnValue = true;
				} else {
					returnValue = false;
				}
			}
		}

		return returnValue;

	},

	// private method. Shows context menu
	_show : function (e) {

		SimpleContextMenu._hide();
		var menuElementId = SimpleContextMenu._getMenuElementId(e);
		var containerID   = SimpleContextMenu._getIdContainer(e);

		if (menuElementId) 
		{
			var m = SimpleContextMenu._getMousePosition(e);
			var s = SimpleContextMenu._getScrollPosition(e);

			showContextMenu(containerID);
			SimpleContextMenu._menuElement = document.getElementById(menuElementId);
			SimpleContextMenu._menuElement.style.left = m.x + s.x + 'px';
			SimpleContextMenu._menuElement.style.top = m.y + s.y + 'px';
			SimpleContextMenu._menuElement.style.display = 'block';
			return false;
		}

		return SimpleContextMenu._getReturnValue(e);

	},

	// private method. Hides context menu
	_hide : function () {

		if (SimpleContextMenu._menuElement) {
			SimpleContextMenu._menuElement.style.display = 'none';
		}

	},

	// private method. Returns mouse position
	_getMousePosition : function (e) {

		e = e ? e : window.event;
		var position = {
			'x' : e.clientX,
			'y' : e.clientY
		}

		return position;

	},

	_getIdContainer: function(e) {
		if (SimpleContextMenu.IE) 
		{
			SimpleContextMenu._attachedElement = event.srcElement;
		} 
		else 
		{
			SimpleContextMenu._attachedElement = e.target;
		}
	
		while(SimpleContextMenu._attachedElement != null) 
		{
			var className = SimpleContextMenu._attachedElement.className;
			if (className=='buddy')
			{
				if (typeof(className) != "undefined") 
				{
					className = className.replace(/^\s+/g, "").replace(/\s+$/g, "")
					var classArray = className.split(/[ ]+/g);
		
					for (i = 0; i < classArray.length; i++) 
					{
						if ( SimpleContextMenu._menus[classArray[i]] )
						{
							return SimpleContextMenu._attachedElement.id;
						}
					}
				}
			}
			else
			{
				return;	
			}
		}
		return null;
	},

	// private method. Get document scroll position
	_getScrollPosition : function () {

		var x = 0;
		var y = 0;

		if( typeof( window.pageYOffset ) == 'number' ) {
			x = window.pageXOffset;
			y = window.pageYOffset;
		} else if( document.documentElement && ( document.documentElement.scrollLeft || document.documentElement.scrollTop ) ) {
			x = document.documentElement.scrollLeft;
			y = document.documentElement.scrollTop;
		} else if( document.body && ( document.body.scrollLeft || document.body.scrollTop ) ) {
			x = document.body.scrollLeft;
			y = document.body.scrollTop;
		}

		var position = {
			'x' : x,
			'y' : y
		}

		return position;

	}

}


function SettingBuddyList(bolDisplay)
{
	bolDisplayBuddyList = bolDisplay;
}

function clearInputs() {
   var formInputs = document.getElementsByTagName('input');
   for (var i=0; i<formInputs.length; i++)
        if(formInputs[i].type == 'text' || formInputs[i].type == 'password') formInputs[i].value = '';
}

function recenterModal(event) {

   var windowScroll = WindowUtilities.getWindowScroll();    
   var pageSize = WindowUtilities.getPageSize();    

   var top = (pageSize.windowHeight - $('modal').getHeight())/2;
   top += windowScroll.top;
    
   var left = (pageSize.windowWidth - $('modal').getWidth())/2;
   left += windowScroll.left;

   //$('modal').setStyle({top: top + 'px', left: left + 'px', display: 'block'});
}

function showHide(evt) {
     if (!evt) { evt = window.event; }
     if (document.all) { trgObj = evt.srcElement; }
     else { trgObj = evt.target; }
     if (!trgObj) { return; }
     if ( user.length > 0 && 
		  trgObj.id != 'statusList' && 
		  trgObj.id != 'configOptionList' && 
		  trgObj.id != 'fontsList' && 
		  trgObj.id != 'statusSettings' && 
		  trgObj.id != 'curStatus' && 
		  trgObj.parentNode.id != 'statusList' &&
		  trgObj.parentNode.id != 'configOptionList' && 
          trgObj.parentNode.id != 'fontsList' && 
		  trgObj.id != 'customMessage' &&
          trgObj.parentNode.id != 'customMessage' && 
		  trgObj.id != 'emoticonList' &&
          trgObj.className != 'emotIcon' && 
		  trgObj.id != 'fontSizeList' &&
          trgObj.parentNode.id != 'fontSizeList' && 
		  trgObj.id != 'fontColorList' &&
          trgObj.className != 'colorItem' &&
          trgObj.className != 'tTable' && 
		  trgObj.id !='search_suggest' && 
		  trgObj.className != 'buddy') {
        Element.setStyle($('statusList'), {'display': 'none'});
		Element.setStyle($('configOptionList'), {'display': 'none'});
        Element.setStyle($('emoticonList'), {'display': 'none'});
        Element.setStyle($('fontsList'), {'display': 'none'});
        Element.setStyle($('fontSizeList'), {'display': 'none'});
        Element.setStyle($('fontColorList'), {'display': 'none'});
		
		$('strKeywordUname').value=Languages.get('searchforbuddy');
		$('search_suggest').style.display='none';
        return;
     }
}

function handleInput(e, func)
{
   var asc = document.all ? event.keyCode : e.which;
   
   if(asc == 13) {
      func();
      return false;
   }
   
   return true;
}

function regExpEscape(text)
{
  if (!arguments.callee.sRE) {
    var specials = [
      '/', '.', '*', '+', '?', '|',
      '(', ')', '[', ']', '{', '}', '\\'
    ];
    arguments.callee.sRE = new RegExp(
      '(\\' + specials.join('|\\') + ')', 'g'
    );
  }
  return text.replace(arguments.callee.sRE, '\\$1');
}

function scrollToBottom(id)
{
   $(id).scrollTop = $(id).scrollHeight - $(id).clientHeight;
}

function cleanStatusbar(id)
{
   $(id).innerHTML = '';
}

function trim(text)
{
   if(text == null) return null;
   return text.replace(/^[ \t]+|[ \t]+$/g, "");
}

function toggleAudio()
{
   if(audioNotify == true) {
      audioNotify = false;
      $('toggleaudio').src = STATIC_ZICZAC+'/themes/'+theme+'/window/audio_off.png';
   } else {
      audioNotify = true;
      $('toggleaudio').src = STATIC_ZICZAC+'/themes/'+theme+'/window/audio_on.png';
   }
}

function titlebarBlink(name, message, alter, chatroom)
{
	if(message=='')
	{
		return;
	}
   if(titlebarBlinker == false) {
      parent.document.title = defaultTitle;
      return;
   }
   
   if(trim(chatroom).length == 0 && IM.windows[name].detached) {
      IM.windows[name].popup.titlebarBlink(name, message, alter);
      return;
   }
   
   if(alter == 0) {
      parent.document.title = name + '!';
      blinkerTimer = setTimeout("titlebarBlink('"+name+"', '"+message+"', 1, '"+chatroom+"')", 1000);
   } else if(alter == 1) {
      parent.document.title = '"' + message.substring(0, 10) + (message.length > 10 ? '...' : '') + '"';
      blinkerTimer = setTimeout("titlebarBlink('"+name+"', '"+message+"', 2, '"+chatroom+"')", 1000);
   } else if(alter == 2) {
      parent.document.title = defaultTitle;
      blinkerTimer = setTimeout("titlebarBlink('"+name+"', '"+message+"', 0, '"+chatroom+"')", 1000);
   }
}

function blinkerOn(onoff)
{
   if(onoff == true)
      titlebarBlinker = true;
   else
      titlebarBlinker = false;
}

function buttonHover(el)
{
   var newsrc = el.src;
   newsrc = newsrc.replace(/_hover/, '');
   el.src = newsrc.replace(/\.png/, '_hover.png');
}

function buttonDown(el)
{
   el.src = el.src.replace(/_hover\.png/, '_down.png');
}

function buttonNormal(el)
{
   el.src = el.src.replace(/\_hover.png/, '.png').replace(/\_down.png/, '.png');
}


function checkEmailAddr(email)
{
   var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
   if (filter.test(email)) return true;
   else return false;
}

function randomString(length)
{
   var chars = "abcdefghijklmnopqrstuvwxyz1234567890";
   var pass = "";
   var charLength = chars.length;

   for(x=0;x<length;x++) {
      i = Math.floor(Math.random() * charLength);
      pass += chars.charAt(i);
   }

   return pass;
}

function inArray(arr, value)
// Returns true if the passed value is found in the
// array.  Returns false if it is not.
{
   var i;
   for (var group in arr) {
     // Matches identical (===), not just similar (==).
      for(i=0; i<arr[group].length; i++) {
         if(arr[group][i] === value)
            return true;
      }
   }
   return false;
}

function ShowAddTransport()
{
	if(init_type!='ziczac')
	{
		Dialogs.alertBasic('addTransportWin',Languages.get('pleaseregister'),'ziczac.big-error.png');	
	}
	else
	{
		if(Gateways.list['yahoo']||Gateways.list['msn']||Gateways.list['aim']||Gateways.list['gtalk'])
		{
			Dialogs.accountsDialog();	
		}
		if(!Gateways.list['yahoo']&&!Gateways.list['msn']&&!Gateways.list['aim']&&!Gateways.list['gtalk'])
		{
			Dialogs.accountsDialog();
			Dialogs.addTransportDialog('','');
		}
	}
	
}

function thisMovie(strObjectName)
{
	if (navigator.appName.indexOf("Microsoft") != -1)
	{

        return document.getElementById(strObjectName);
    }
    else
	{
        return document[strObjectName];
    }	
}

function showPreferencesDialog()
{
	Dialogs.alertBasic('notyetImplemented','Chức năng này đang được hoàn thiện', 'yahoo.big-error.png');	
}

function showHelp()
{
	window.open("http://ziczac.vn/help","Trợ giúp");
	//if (window.focus) {newwindow.focus()}
	//return false;
}

function selectEmbedCode()
{
	//var text_val=eval("document.EmbedRoom.type");
	var text_val=document.getElementById('EmbedRoom');
	text_val.focus();
	text_val.select();
}




// Begin main
function ePce(from,status,show,type,ready)
{
	// 3s update presence cho truong hop roster chua get ve day du
	if(from!='yahoo.'+JSERVER || from!='gtalk.'+JSERVER || from!='msn.'+JSERVER || from!='aim.'+JSERVER)
	{
		var strJid = GetUsernameWithoutReource(from).replace(' ','@');
		if(type=='online')
		{
			if(typeof(show) == 'undefined' || show == null) //socket ra undefined, http ra null
			{
				show = 'online';
			}

			Presences.list[strJid] = {};
			Presences.list[strJid].roster_status 	= (typeof(status) != 'undefined' ? status : '');
			Presences.list[strJid].roster_show 	= (typeof(show) != 'undefined' ? show : 'online');
			setTimeout("updateRosterItems()", 3000);
		}
	}
	if(rosterLoaded)//neu da load roster list xong
	{	
		if(type=='offline'){
			if(init_type!='ziczac') // Login direct
			{	
				if(from=='yahoo.'+JSERVER || from=='gtalk.'+JSERVER || from=='msn.'+JSERVER || from=='aim.'+JSERVER){
					xajax_quickLogout();
					System.logout(Languages.get('errorConflictNick'));
					return;
				}			
			}
			else{ // login tu ZicZac
				if(from=='yahoo.'+JSERVER || from=='gtalk.'+JSERVER || from=='msn.'+JSERVER || from=='aim.'+JSERVER){
					Dialogs.alertBasic('exit',from.split('.')[0].toUpperCase() + " : " + Languages.get('exitGateway'), from.split('.')[0]+ '.big-error.png');			
					setTimeout("ZCloseWindows('alertBasic_exit')", 3000);
				}
			}/**/
		}		
		var strJid = GetUsernameWithoutReource(from).replace(' ','@');
		var groupname = Buddylist.listObjects[strJid].group;
		if(type=='offline')
		{
			show 		= 'offline';
			groupname 	= 'Offline';
			status 		= '';			
		}
		if(type=='online')
		{
			if(typeof(show) == 'undefined' || show == null) //socket ra undefined, http ra null
			{
				show = 'online';
			}
		}
		if (typeof(Buddylist.listObjects[strJid]) != 'undefined'){
			set_contact_status(strJid,groupname,(typeof(show) != 'undefined' ? show : 'online'),(typeof(status) != 'undefined' ? status : ''));
			delete Presences.list[strJid] ;
			if($('toast_popup_main').style.display == 'none') {
				$('toastpopup_content').innerHTML = '&nbsp;&nbsp;&nbsp;'+strJid.split('@')[0]+ ' is now ' + type;
				Effect.toggle('toast_popup_main','appear');
					intTimeOutToaster = setTimeout("hideToastPopup()", 4000);
			}
			else
			{
				clearTimeout(intTimeOutToaster);
				$('toastpopup_content').innerHTML+= '<br>&nbsp;&nbsp;&nbsp;'+strJid.split('@')[0]+ ' is now ' + type;
				intTimeOutToaster = setTimeout("hideToastPopup()", 2000);
			}
		}

		if(typeof(IM.windows[strJid]) != 'undefined' && (ready !='normal' || type=='offline') )
		{
			var curIM = $(window['IM'].windows[strJid].getId()+"_rcvd");
			curIM.innerHTML += '&nbsp;&nbsp;<span style="color:'+(type=='online' ? '#ff928e' : '#CCCCCC')+'"><i>'+chatnhe_get_username(strJid) + ' ' + Languages.get('has'+type) + ' ' + IM.createTimestamp()+'</i></span><br>\n';
		}
	}
//	else // neu chua load rosterlist xong
	
}

function hideToastPopup()
{
	Effect.toggle('toast_popup_main','appear');
}

function eSRt(jid)
{
	Dialogs.alert_subscribtion_request(jid);
}

function eSdn(strRosterItem)
{
	var ingroup = null;
	var from = strRosterItem;
	for (var group in Buddylist.list)
	{
		if(typeof(Buddylist.list[group][strRosterItem]) !== 'undefined')
		{
			ingroup = group;
			break;
		}
	}
	Buddylist.deleteBuddy(strRosterItem);
	delete Buddylist.listObjects[strRosterItem];
	delete Buddylist.list[ingroup][strRosterItem];
	if(from=='yahoo.'+JSERVER || from=='gtalk.'+JSERVER || from=='msn.'+JSERVER || from=='aim.'+JSERVER)
		Dialogs.alertBasic('denySubscription',chatnhe_get_username(strRosterItem)+Languages.get('alertDenySubscription'), from.split('.')[0]+ '.big-error.png');
	else
		Dialogs.alertBasic('denySubscription',chatnhe_get_username(strRosterItem)+Languages.get('alertDenySubscription'), 'ziczac.big-error.png');
	RefreshGroup();
}

function eRgw(strGateway)
{
	strHtmlBuddyList= '';
	var intBuddyToRemove 	= 0;
	
	for (var roster in Buddylist.listObjects) 
	{
		if(typeof(roster)!=='undefined' && roster.indexOf('@'+strGateway)>-1 && Buddylist.listObjects[roster].jid == strJustRemoveGateway)
		{
			removeRosterItemGateWay(roster);
			delete Buddylist.listObjects[roster];
			intBuddyToRemove++;
		}
	}

	Windows.getWindow('accountsDialog').destroy();
	Dialogs.accountsDialog();
	setTimeout("RefreshGroup()", 1000);
}

function removeRosterItemGateWay(strRosterItem)
{
	var ingroup = null;
	for (var group in Buddylist.list)
	{
		if(typeof(Buddylist.list[group][strRosterItem]) !== 'undefined' && Buddylist.list[group][strRosterItem].username == strRosterItem)
		{
			ingroup = group;
			break;
		}
	}
	
	var buddyToRmv = $(Buddylist.listObjects[strRosterItem].obj);

	if(typeof(buddyToRmv) !== 'undefined')
	{
		buddyToRmv.parentNode.removeChild(buddyToRmv);
		if(Buddylist.list[ingroup])
		{
			delete Buddylist.list[ingroup][strRosterItem];
		}
	}
}

function receiveMessage(from,to,msg,type)
{
	if(ZICZAC_DEBUG)
	{
		document.getElementById('ZZDebug').innerHTML+= "<strong>From</strong>: " + from + " <strong>To</strong>: "+ to + " <strong>Msg</strong>: " + msg + " <strong>Type</strong>: "+type+"<br><br>";		
	}
	
	if(type=='groupchat')
	{
		return;	
	}
	
	if(type=='headline') //headline
	{
		if(from=='yahoo.'+JSERVER)
		{
			Dialogs.alertBasic('headlineYahoo',msg, 'yahoo.big-error.png');
			return;
		}
	}
	
	if(type=='headline') //headline
	{
		if(from=='gtalk.'+JSERVER)
		{
			Dialogs.alertBasic('headlineGtalk',msg, 'gtalk.big-error.png');
			return;
		}
	}
	
	if(type=='headline') //headline
	{
		if(from=='msn.'+JSERVER)
		{
			Dialogs.alertBasic('headlineMsn',msg, 'msn.big-error.png');
			return;
		}
	}
	
	if(type=='error') //error
	{
		if(from=='yahoo.'+JSERVER || from=='gtalk.'+JSERVER || from=='msn.'+JSERVER || from=='aim.'+JSERVER)
		{
			if(init_type=='ziczac')
			{
				Dialogs.alertBasic('error' + from.split('.')[0],msg, from.split('.')[0]+ '.big-error.png');
				return;
			}
			else
			{
				xajax_quickLogout();
				System.logout(Languages.get('errorTransportUsernamePassword'));
				return;
			}
		}
	}	
	
	var arrInfo = from.split('/');
	var from = arrInfo[0].replace(' ','@');
	
	if((typeof(type)=='undefined' || type=='undefined') && from==JSERVER)
	{
		Dialogs.alertBasic('alertFromServer',msg, 'ziczac.big-error.png');
		setTimeout("ZCloseWindows('alertBasic_alertFromServer')", 5000);
		return;
	}
	
	if(trim(msg).length == 0) return;	

	if(type=='chat')
	{
		var strImTitle = chatnhe_get_username(from);
	}
	else
	{
		var strImTitle = chatnhe_get_nickname(from);
	}
	

	var winId = null;
	try { winId = window[type!='chat' ? 'Chatroom' : 'IM'].windows[from].getId(); } catch(e) { };

	if(!$(winId))
	{
		if(type=='groupchat')
		{
			window['Chatroom'].create(from, from);
		}
		else
		{
			window['IM'].create(from, strImTitle, 'normal');
		}
	}
	else
	{
		if(!window[type!='chat' ? 'Chatroom' : 'IM'].windows[from].isVisible())
		{
			window[type!='chat' ? 'Chatroom' : 'IM'].windows[from].show();
			setTimeout("scrollToBottom('" + window[type!='chat' ? 'Chatroom' : 'IM'].windows[from].getId() + "_rcvd')", 125);
		}
	}	
	
	var curIM = $(window[type!='chat' ? 'Chatroom' : 'IM'].windows[from].getId()+"_rcvd");
	
	msg = msg.replace(/(\s|\n|>|^)(\w+:\/\/[^<\s\n]+)/, '$1<a href="$2" target="_blank">$2</a>');
	msg = IM.emoteReplace(msg, smilies);
			   
//alert(msg);
	curIM.innerHTML += "<span class=\"user" + (from == user && type=='chat' ? 'A' : 'B') + "\">" + " " + chatnhe_get_username(from) + ":</span> " + msg + "<br>\n";

	
	curIM.scrollTop = curIM.scrollHeight - curIM.clientHeight + 6;

	if(Windows.getFocusedWindow().getId() != window[type!='chat' ? 'Chatroom' : 'IM'].windows[from].getId() && pulsateTitles == true)
	{
		new Effect.Pulsate(window[type!='chat' ? 'Chatroom' : 'IM'].windows[from].getId() + '_top');
	}
	
	if(titlebarBlinker == true && useBlinker == true && msg!='' && typeof(msg)!='undefined')
	{
		//clearTimeout(blinkerTimer);
		//blinkerTimer = setTimeout("titlebarBlink('"+from+"', \""+msg.replace(/\"/, '\"').replace(/\\/ig,'').replace(/<([^>]+)>'/ig, '')+"\", 0, '"+from+"')", blinkSpeed);
	}
	curIM = null;
	var curStatusIM = $(window[type!='chat' ? 'Chatroom' : 'IM'].windows[from].getId()+"_statusbar");
        curStatusIM.innerHTML = '';
	curStatusIM = null; 
    if(audioNotify == true) soundManager.play('msg_in');


}
function eNotifyTyping(from,to,type,state)

{
	var arrInfo = from.split('/');
	var from = arrInfo[0].replace(' ','@');
	
	if(type=='chat')
	{
		var strImTitle = chatnhe_get_username(from);
	}
	else
	{
		var strImTitle = chatnhe_get_nickname(from);
	}
	
	var winId = null;
	try { winId = window[type!='chat' ? 'Chatroom' : 'IM'].windows[from].getId(); } catch(e) { };

	if(!$(winId))
		return;
   
	if(state!='undefined' && state!=null){
		var curStatusIM = $(window[type!='chat' ? 'Chatroom' : 'IM'].windows[from].getId()+"_statusbar");
		if (state == 'composing' || state == 'paused'){
			curStatusIM.innerHTML = '<b><font color="#800000">' + strImTitle + Languages.get('typing') + '</font></b>';
			setTimeout("cleanStatusbar('" + window[type!='chat' ? 'Chatroom' : 'IM'].windows[from].getId() + "_statusbar')", 12000);
		}
		else
			curStatusIM.innerHTML = '';
		curStatusIM = null;
	}

}

function eBuzzMessage(from,to,type)
{
	var arrInfo = from.split('/');
	var from = arrInfo[0].replace(' ','@');
	type = 'chat';
	if(type=='chat')
	{
		var strImTitle = chatnhe_get_username(from);
	}
	else
	{
		var strImTitle = chatnhe_get_nickname(from);
	}
	
	var winId = null;
	try { winId = window[type!='chat' ? 'Chatroom' : 'IM'].windows[from].getId(); } catch(e) { };

	if(!$(winId))
	{
		if(type=='groupchat')
		{
			window['Chatroom'].create(from, from);
		}
		else
		{
			window['IM'].create(from, strImTitle, 'normal');
		}
	}
	else
	{
		if(!window[type!='chat' ? 'Chatroom' : 'IM'].windows[from].isVisible())
		{
			window[type!='chat' ? 'Chatroom' : 'IM'].windows[from].show();
			setTimeout("scrollToBottom('" + window[type!='chat' ? 'Chatroom' : 'IM'].windows[from].getId() + "_rcvd')", 125);
		}
	}	
	var curIM = $(window[type!='chat' ? 'Chatroom' : 'IM'].windows[from].getId()+"_rcvd");
	
	msg = '<b><font color="#FF0000">BUZZ!!!</font></b>';
	curIM.innerHTML += "<span class=\"user" + (from == user && type=='chat' ? 'A' : 'B') + "\">" + " " + chatnhe_get_username(from) + ":</span> " + msg + "<br>\n";

	curIM.scrollTop = curIM.scrollHeight - curIM.clientHeight + 6;

	new Effect.Shake(window[type!='chat' ? 'Chatroom' : 'IM'].windows[from].getId());

	if(audioNotify == true) soundManager.play('msg_buzz');
}


function eFGr(arrGatewayRoster,arrFGroups)
{
 var i=0;
 /*var strBuddy= "";
 for (i=0;i<arrGatewayRoster.length;i++) 
	strBuddy  = strBuddy  + arrGatewayRoster[i] + "<br>";

 alert(strBuddy); 
 strBuddy= "";
 for (i=0;i<arrFGroups.length;i++) 
	strBuddy  = strBuddy  + arrFGroups[i] + "<br>";

 alert(strBuddy); 
/**/
	for (i=0;i<arrFGroups.length;i++) 
	{
		if(!$(arrFGroups[i].replace(/\s/, '_')+'_group') && arrFGroups[i] != 'toJSONString' && arrFGroups[i]!='Transports')
		{
			Buddylist.addGroup(arrFGroups[i]);
			if(!Buddylist.list[arrFGroups[i]])
			{
				Buddylist.list[arrFGroups[i]] = {};
			}
		}
	}

	for (i=0;i<arrGatewayRoster.length;i++) 
	{
		var BuddyInfo = arrGatewayRoster[i].split(',');
		var strJid = GetUsernameWithoutReource(BuddyInfo[0].replace(' ','@'));
//		if(typeof(Buddylist.listObjects[strJid]) == 'undefined' && strJid!='yahoo.'+JSERVER)
		if(typeof(Buddylist.listObjects[strJid]) == 'undefined' && (strJid!='yahoo.'+JSERVER && strJid!='gtalk.'+JSERVER && strJid!='msn.'+JSERVER && strJid!='aim.'+JSERVER))
		{
			Buddylist.list[BuddyInfo[2]][strJid] = {'username': strJid}
			Buddylist.addBuddy(strJid, BuddyInfo[2], 'build_roster');
		}
	}
	
	$(Languages.get('offline')+'_group').innerHTML+= strHtmlBuddyList;
	rosterLoaded = true;
	//setTimeout("PushPresence()", 1000);
}

function eFRt(arrFRoster, arrFGroups)
{
	//$('buddylist').innerHTML = '';
	//Buddylist.addGroup(Languages.get('offline'));
	
	// chuyen 2 ham ben tren len set_user_info de tu dong tao group offline, va clear di cai loading html trong buddylist
	
	for (i=0;i<arrFGroups.length;i++) 
	{
		if(!$(arrFGroups[i].replace(/\s/, '_')+'_group') && arrFGroups[i]!='Transports')
		{
			if(typeof(Buddylist.list[arrFGroups[i]]) == 'undefined')
				Buddylist.addGroup(arrFGroups[i]);
			if(!Buddylist.list[arrFGroups[i]])
			{
				Buddylist.list[arrFGroups[i]] = {};
			}
		}
	}

	for (i=0;i<arrFRoster.length;i++) 
	{
		var BuddyInfo = arrFRoster[i].split(',');
		var strJid = GetUsernameWithoutReource(BuddyInfo[0].replace(' ','@'));
		if(BuddyInfo[3]!='from' && BuddyInfo[3]!='none' && typeof(Buddylist.listObjects[strJid]) == 'undefined' && (strJid!='yahoo.'+JSERVER && strJid!='gtalk.'+JSERVER && strJid!='msn.'+JSERVER && strJid!='aim.'+JSERVER))
		{
			Buddylist.list[BuddyInfo[2]][strJid] = {'username': strJid}
			Buddylist.addBuddy(strJid, BuddyInfo[2], 'build_roster');
		}
	}
	
	// chuyen khuc ben duoi day xuong ePPce
	//do something Johnny does not know
	// ....
	//do something Johnny does not know

	
	$(Languages.get('offline')+'_group').innerHTML += strHtmlBuddyList;
	strHtmlBuddyList=''; // moi lan nhan ve 1 mang cac buddy va add len buddylist xong se empty html nay di
	
	
	// roster loaded = true se load khi ePPce call xong,(finish process)
	//rosterLoaded = true;
	//setTimeout("PushPresence()", 1000);
}

function ePPce()
{
	//do something Johnny does not know
	Event.observe(document, 'focus', function() { blinkerOn(false); });
	Event.observe(window, 'focus', function() { blinkerOn(false); });
	
	Event.observe(document, 'blur', function() { blinkerOn(true); });
	Event.observe(window, 'blur', function() { blinkerOn(true); });
	
	Event.observe(document, 'keypress', function(e) {
										  var evt = e || window.event;
										  if(Windows.focusedWindow.getId().indexOf('_im') != -1 && IM.sendBoxWithFocus == null) {
											 var sB = $(Windows.focusedWindow.getId() + '_sendBox');
											 sB.focus(); sB.value += String.fromCharCode(evt.charCode);
										  }
									   });

	Event.stopObserving(window, 'resize', recenterModal);
	//do something Johnny does not know
	
	
	for (var roster in Presences.list)
	{
		if(roster!='toJSONString' && roster!='gtalk.'+JSERVER && roster!='yahoo.'+JSERVER && roster!='msn.'+JSERVER && roster!='aim.'+JSERVER)
		{
			// tam thoi cho status gateway khoi tao la rong
			if (typeof(Buddylist.listObjects[roster]) != 'undefined'){
				var strJid = GetUsernameWithoutReource(roster).replace(' ','@');
				set_contact_status(strJid, Buddylist.listObjects[strJid].group, Presences.list[strJid].roster_show, Presences.list[strJid].roster_status);			
				delete Presences.list[strJid] ;
			}
		}
	}
	//Presences.list = {};
	rosterLoaded = true;
	$('initLoading').style.display='none';
	$('signintomore').style.display='block';
}

function updateRosterItems()
{
	for (var roster in Presences.list)
	{
		if(roster!='toJSONString' && roster!='gtalk.'+JSERVER && roster!='yahoo.'+JSERVER && roster!='msn.'+JSERVER && roster!='aim.'+JSERVER)
		{
			// tam thoi cho status gateway khoi tao la rong
			if (typeof(Buddylist.listObjects[roster]) != 'undefined'){
				var strJid = GetUsernameWithoutReource(roster).replace(' ','@');
				set_contact_status(strJid, Buddylist.listObjects[strJid].group, Presences.list[strJid].roster_show, Presences.list[strJid].roster_status);			
				delete Presences.list[strJid] ;
			}
		}
	}
}

function RefreshGroup()
{
	var bolGroupIsEmpty = true; //gourp ko co empty
	for(var group in Buddylist.list)
	{
		for(var roster in Buddylist.list[group])
		{
			if(roster!='toJSONString')
			{
				bolGroupIsEmpty = false;
				if(!bolGroupIsEmpty)
				{
					break;
				}
			}
			else
			{
				bolGroupIsEmpty = true;
				break;
			}
		}
		if(bolGroupIsEmpty)
		{
			delete Buddylist.list[group];
			Buddylist.deleteGroup(group);
		}
	}
}

function ZCloseWindows(strWindowId)
{
	Windows.close(''+strWindowId+'');
}

function callFetchFullRoster()
{
    objJS.fFr();
}

function callFetchGatewayRoster()
{
    objJS.fGR();
}

function createRoom(strType)
{
	var strRoomName 	= document.getElementById('w_room_name').value;
	var strRoomId 		= document.getElementById('w_room_id').value;
	var intRoomCate 	= document.getElementById('w_room_cate_id').value;
	var strRoomTopic 	= document.getElementById('w_room_topic').value;
	var strRoomDesc 	= document.getElementById('w_room_description').value;
	
	var strUseLocalIcon = document.getElementById('use_local_icon').value;
	var strIconValue	= document.getElementById('room_icon_value').value;

	var strUseLocalTheme = document.getElementById('use_local_theme').value;
	var strThemeValue	 = document.getElementById('room_theme_value').value;
	
	var strRoomBgColor 	= document.getElementById('w_theme_color').value;
	var strRoomUrl	 	= document.getElementById('w_room_url').value;
	var strRoomPassword	= document.getElementById('w_room_password').value;
	
	if(strType=='update')
	{
		xajax_updateRoom(strRoomName, strRoomId, intRoomCate, strRoomTopic, strRoomDesc, strUseLocalIcon, strIconValue, strUseLocalTheme, strThemeValue, strRoomBgColor, strRoomUrl, strRoomPassword);
	}
	else
	{
		xajax_createRoom(strRoomName, strRoomId, intRoomCate, strRoomTopic, strRoomDesc, strUseLocalIcon, strIconValue, strUseLocalTheme, strThemeValue, strRoomBgColor, strRoomUrl, strRoomPassword);
	}
}

function checkBlurCustomStatus()
{
	if($('customStatus').style.display != 'none') {
		$('customStatus').style.display = 'none';
		$('curStatus').style.display = 'block';
	}	
}

function checkSearchUname()
{
	if($('strKeywordUname').value==Languages.get('searchforbuddy'))
	{
		$('strKeywordUname').value='';
	}
	else
	{
		$('strKeywordUname').value=Languages.get('searchforbuddy');
		$('search_suggest').style.display='none';
	}
}

// End main


function Redirect(strUrl)
{
	window.location = strUrl;	
}

function getEmbedSize(strSize, strRoomName)
{
	$('watch-embed-size-radio-'+strSelectedSize).className = 'watch-embed-size-radio-link';
	$('watch-embed-size-radio-'+strSize).className=$('watch-embed-size-radio-'+strSize).className+' radio_selected';
	strSelectedSize = strSize;
	
	var intEmbedRoomWidth = 640;
	var intEmbedRoomHeight = 385;
	
	if(strSize=='default')
	{
		intEmbedRoomWidth = 560;
		intEmbedRoomHeight = 340;
	}
	if(strSize=='medium')
	{
		intEmbedRoomWidth = 640;
		intEmbedRoomHeight = 385;
	}
	if(strSize=='large')
	{
		intEmbedRoomWidth = 853;
		intEmbedRoomHeight = 505;
	}
	if(strSize=='hd720')
	{
		intEmbedRoomWidth = 1024;
		intEmbedRoomHeight = 606;
	}
	var strEmbedCode = '';
	strEmbedCode = '<embed width="'+intEmbedRoomWidth+'" height="'+intEmbedRoomHeight+'" src="http://static.ziczac.vn/zz/ziczac.swf" flashVars="UID='+strRoomName+'&WEBSITE=http://uploads.ziczac.vn" quality="high" name="preloader" align="middle" allowScriptAccess="always" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	$('txtEmbedCode').value = strEmbedCode;
	
}


function toggleConfigList()
{
	var obj = document.getElementById('statusSettings');
	var xlocation = parseInt(obj.offsetLeft)+370;
	var ylocation = parseInt(obj.offsetTop)+50;
	//alert(xlocation+' '+ylocation);
	var sL = $('configOptionList');
	
	if(sL.style.display == 'block') {
	 sL.hide();
	 if(sL.style.zIndex > Windows.maxZIndex) Windows.maxZIndex = sL.style.zIndex;
	} else {
	 Element.setStyle(sL, {left: xlocation,
						   top:  ylocation,
						   zIndex:  Windows.maxZIndex + 20,
						   display: 'block'});
	}
}

function changePasswordEmail()
{
	var strEmail 				= $('accSetting_email').value;
	var strNewPassword 			= $('accSetting_newpassword').value;
	var strNewPasswordRetype 	= $('accSetting_passwordretype').value;
	var strOldPassword			= $('accSetting_oldpassword').value;
	
	var a = b = c = 0;
	
	//---- Pass-------------
	a = CheckPassRegister(strNewPassword);
	//---- Pass-------------

	//---- Passverify-------------
	b = CheckPassverifyRegister(strNewPassword, strNewPasswordRetype);
	//---- Passverify-------------
	
	//---- Old Pass-------------
	c = CheckPassRegister(strOldPassword);
	//---- Old Pass-------------
	
	if( a == 1 && b == 1 && c == 1 )
	{
		xajax_updatePasswordAndEmail(strEmail, strNewPassword, strNewPasswordRetype, strOldPassword);
	}
	else
	{
		Dialogs.alertBasic('alertAccSettingErrEmail','Xin hãy kiểm tra lại các thông tin bạn nhập vào', 'ziczac.big-error.png');
	}
}