//set MD5 for password
function calculateValue() {
	var doc = document.frmLogin;
	var szPW = doc.password.value;
	szPW +=sharedValue;
	return calcValue(szPW);
}

function doLogin()
{
	var doc = document.frmLogin;
	if(doc.username.value == ""){
		pop_err(doc.username,"Please enter your username!")
		return false;
	}
	if(doc.password.value == ""){
		pop_err(doc.password,"Please enter your password!")
		return false;
	}
	var szPW = calculateValue();
	doc.strpassword.value=szPW;
	doc.password.value="";
	doc.act.value = 1;
	return true;
}

function doChangePW()
{
	var doc = document.frmRegister;
	var password = doc.password.value;
	var confirm_password = doc.confirm_password.value;
	if(doc.password.value == ""){
		pop_err(doc.password,"Please input password!")
		return false;
	}else{
		if(password != confirm_password){
			pop_err(doc.confirm_password,"Password and confirm password are different!")
			return false;
		}
	}

	doc.act.value = 2;
	return true;
}

function docheckall()
{
	var doc = document.frmList;
	var is_check = doc.chkall.checked;
	for(var i=0; i<doc.length; i++){
		if(doc.elements[i].type == "checkbox")
			doc.elements[i].checked = is_check;
	}
	if(is_check){
		doc.cmdDelete.disabled = false;
		if(typeof(doc.cmdSendEmail) == "object")
			doc.cmdSendEmail.disabled = false;
	}else{
		doc.cmdDelete.disabled = true;
		if(typeof(doc.cmdSendEmail) == "object")
			doc.cmdSendEmail.disabled = true;
	}
	if(typeof(doc.cmdUpdate) == "object"){
		doc.cmdUpdate.disabled = true;
	}
}

function docheckallcontactmail()
{
	var doc = document.frmList;
	var is_check = document.frmAddress.chkall.checked;
	for(var i=0; i<doc.length; i++){
		if(doc.elements[i].type == "checkbox")
			doc.elements[i].checked = is_check;
	}	
}

function docheckitem()
{
	var doc = document.frmList;
	var is_check = 0;
	for(var i=0; i<doc.length; i++){
		if(doc.elements[i].type == "checkbox" && doc.elements[i].checked == true && doc.elements[i].name == "chkitem")
			is_check = is_check + 1;
	}
	if(is_check > 0){
		doc.cmdDelete.disabled = false;
		if(typeof(doc.cmdSendEmail) == "object")
			doc.cmdSendEmail.disabled = false;
	}else{
		doc.cmdDelete.disabled = true;
		if(typeof(doc.cmdSendEmail) == "object")
			doc.cmdSendEmail.disabled = true;
	}
	if(typeof(doc.cmdUpdate) == "object"){
		if(is_check == 1)
			doc.cmdUpdate.disabled = false;
		else
			doc.cmdUpdate.disabled = true;
	}
	if(is_check == doc.total_item.value)
		doc.chkall.checked = true;
	else
		doc.chkall.checked = false;
}

function dopopcheckitem()
{
	var doc = document.frmList;
	var is_check = 0;
	for(var i=0; i<doc.length; i++){
		if(doc.elements[i].type == "checkbox" && doc.elements[i].checked == true && doc.elements[i].name != "chkall")
			is_check = is_check + 1;
	}	
	if(is_check == doc.total_item.value)
		document.frmAddress.chkall.checked = true;
	else
		document.frmAddress.chkall.checked = false;
}

function GoPage(n)
{							
	document.frmBackNext.CurRecord.value= n
	document.frmBackNext.submit()
}

function QuickSearch(strid)
{
	var doc = document.frmAddress;
	doc.strid.value = strid
	for(var i=0; i<doc.txtgroup.length; i++)
	{
		if(doc.txtgroup.options[i].selected==true)
		{
			var strid = doc.txtgroup.options[i].value;
			doc.idgroup.value = strid
		}
	}
	doc.submit()
}

function QuickSearchAccount(strid)
{
	var doc = document.frm;
	doc.strid.value = strid;
	doc.submit();
}

function QuickChangeList()
{
	var doc = document.frmAddress;
	for(var i=0; i<doc.txtgroup.length; i++)
	{
		if(doc.txtgroup.options[i].selected==true)
		{
			var strid = doc.txtgroup.options[i].value;
			doc.idgroup.value = strid
		}
	}
	doc.submit()
}

function DoAddnewContact()
{
	var doc = document.frmAddress;
	doc.action = "add_new_contact.asp"
	doc.submit()
}

function DoUpdateContact()
{
	var doc = document.frmList;
	doc.action = "update_contact.asp"
	doc.submit()
}

function DoDeleteContact()
{
	var doc = document.frmList;
	if(confirm('Are you sure you want to delete selected item(s)?')==true){
		doc.accept_delete.value = "OK"
		doc.submit()
	}
}

function DoSaveRegis()
{
	var doc = document.frmAdd;
	
	var m = doc.fuser.value
		if(m == "")
	{
		alert("User cannot Blank!")
		doc.fuser.focus();
		return false;
	}
	
	var m = doc.fpass.value
		if(m == "")
	{
		alert("Pass cannot Blank!")
		doc.fpass.focus();
		return false;
	}
	
	var m = doc.fname.value
		if(m == "")
	{
		alert("First Name cannot Blank!")
		doc.fname.focus();
		return false;
	}
	
	var m = doc.lname.value
		if(m == "")
	{
		alert("Last Name cannot blank!")
		doc.lname.focus();
		return false;
	}
	
	var m = doc.address1.value
		if(m == "")
	{
		alert("Address cannot blank!")
		doc.address1.focus();
		return false;
	}
	
	var m = doc.city.value
		if(m == "")
	{
		alert("City cannot blank!")
		doc.city.focus();
		return false;
	}
	
	var m = doc.state.value
		if(m == "")
	{
		alert("State cannot blank!")
		doc.state.focus();
		return false;
	}
	
	var m = doc.country.value
		if(m == "")
	{
		alert("Country cannot blank!")
		doc.country.focus();
		return false;
	}
	
	var m = doc.zipcode.value
		if(m == "")
	{
		alert("Zipcode cannot blank!")
		doc.zipcode.focus();
		return false;
	}
	
	var m = doc.phone.value
		if(m == "")
	{
		alert("Phone cannot blank!")
		doc.phone.focus();
		return false;
	}
	
	
	var szemail = doc.email.value
	if(isemailaddress(szemail) == false)
	{
		pop_err(doc.email,"Your e-mail is false. Please try again!")
		return false;
	}
	
	
	
	
	doc.accept_add.value = "OK";
	doc.submit();
	return;
}
 


function DoSaveContact()
{
	var doc = document.frmAdd;
	var szemail = doc.email.value
	if(isemailaddress(szemail) == false)
	{
		pop_err(doc.email,"Your e-mail is false. Please try again!")
		return false;
	}
	for(var i=0; i<doc.txtgroup.length; i++)
	{
		if(doc.txtgroup.options[i].selected == true)
		{
			if(doc.txtgroup.options[i].value == "")
			{
				pop_err(doc.txtgroup,"Please select group. Please try again!")
				return false;
			}
		}
	}
	doc.accept_add.value = "OK";
	doc.submit()
	return;
}

function DoSaveUpdateContact()
{
	var doc = document.frmAdd;
	var szemail = doc.email.value
	if(isemailaddress(szemail) == false)
	{
		pop_err(doc.email,"Your e-mail is false. Please try again!")
		return false;
	}
	for(var i=0; i<doc.txtgroup.length; i++)
	{
		if(doc.txtgroup.options[i].selected == true)
		{
			if(doc.txtgroup.options[i].value == "")
			{
				pop_err(doc.txtgroup,"Please select group. Please try again!")
				return false;
			}
		}
	}
	doc.accept_update.value = "OK";
	doc.submit()
	return;
}

function DoCancelUpdateContact()
{
	document.frmReturn.submit()
}

function DoCancelRegis()
{
	document.frmReturn.submit()
}

function DoCancelAddContact()
{
	document.frmReturn.submit()
}
function DoUpdateContact()
{
	var doc = document.frmList;
	doc.action = "update_contact.asp"
	doc.submit()
}

function validate_account(doc){
	var szfirstname = doc.firstname.value
	var szlastname = doc.lastname.value
	var szusername = doc.username.value
	var szpassword = doc.password.value
	var szconfirm_password = doc.confirm_password.value
	var szemail = doc.email.value;
	
	if(trim(szfirstname) == "")
	{
		pop_err(doc.firstname,"First name must be defined!")
		return false;
	}
	if(trim(szlastname) == "")
	{
		pop_err(doc.lastname,"Last name must be defined!")
		return false;
	}
	if(trim(szusername) == "")
	{
		pop_err(doc.username,"User name must be defined!")
		return false;
	}
	if(trim(szpassword) == "")
	{
		pop_err(doc.password,"Password must be defined!")
		return false;
	}
	else
	{
		if(szpassword != szconfirm_password){
			pop_err(doc.password,"Password and Confirm password is false! Please try again!")
			return false;
		}
	}
	if(isemailaddress(szemail) == false)
	{
		pop_err(doc.email,"Your e-mail is false. Please try again!")
		return false;
	}
	return true;
}
function DoSaveAccount()
{
	var doc = document.frm;
	if(validate_account(doc)){
		doc.accept_add.value = "OK";
		doc.submit()
	}else{
		return false;
	}
}
function DoAddnewAccount()
{
	var doc = document.frmList;
	doc.action = "add_new_account.asp"
	doc.submit()
}
function DoCancelUpdateAccount()
{
	document.frmReturn.submit()
}
function DoUpdateAccount()
{
	var doc = document.frmList;
	doc.action = "update_account.asp"
	doc.submit()
}
function DoSaveUpdateAccount()
{
	var doc = document.frm;
	if(validate_account(doc)){
		doc.accept_update.value = "OK";
		doc.submit()
	}else{
		return false;
	}
}
function DoDeleteAccount()
{
	var doc = document.frmList;
	if(confirm('Are you sure you want to delete selected item(s)?')==true)
	{
		doc.accept_delete.value = "OK"
		doc.submit()
	}
}
function DoAddnewGroup()
{
	document.getElementById("tblAddGroup").style.display = "block";
}

function DoUpdateGroup()
{
	var doc = document.frmList;
	doc.view_update.value = "OK";
	doc.submit()
}

function DoDeleteGroup()
{
	var doc = document.frmList;
	if(confirm('If you delete the group, its contacts will be deleted too. Are you sure you want to delete selected group(s)?')==true)
	{
		doc.accept_delete.value = "OK";
		doc.submit()
	}
}

function DoSaveDataGroup()
{
	var doc = document.frmList;
	doc.accept_addnew.value = "OK";
	doc.submit()
}

function DoUpdateDataGroup()
{
	var doc = document.frmList;
	doc.accept_update.value = "OK";
	doc.submit()
}

function DoCloseDataGroup()
{
	document.getElementById("tblAddGroup").style.display = "none";
	document.getElementById("tblUpdateGroup").style.display = "none";
}

function DoGoToContact(strid)
{
	var doc = document.frmList;
	doc.idgroup.value= strid
	doc.action = "manage_contact.asp"
	doc.submit()
}

function DoAddnewTemplate()
{
	var doc = document.frmList;
	doc.action = "add_new_template.asp"
	doc.submit()
}

function DoUpdateTemplate()
{
	var doc = document.frmList;
	doc.action = "update_template.asp"
	doc.submit()
}

function DoDeleteTemplate()
{
	var doc = document.frmList;
	if(confirm('Are you sure you want to delete selected item(s)?')==true){
		doc.accept_delete.value = "OK"
		doc.submit()
	}
}

function DoSaveTemplate()
{
	var doc = document.frmAdd
	if(doc.tempname.value=="")
	{
		pop_err(doc.tempname,"Please enter template name!")
		return false;
	}
	doc.accept_add.value="OK"
	doc.submit()
}

function DoUpdateRequestTemplate()
{
	var doc = document.frmAdd
	doc.accept_add.value="OK"
	doc.submit()
}

function DoAddnewAdv()
{
	var doc = document.frmList;
	doc.action = "add_new_adv.asp"
	doc.submit()
}

function DoUpdateAdv()
{
	var doc = document.frmList;
	doc.action = "update_adv.asp"
	doc.submit()
}

function DoDeleteAdv()
{
	var doc = document.frmList;
	if(confirm('Are you sure you want to delete selected item(s)?')==true)
	{
		doc.accept_delete.value = "OK"
		doc.submit()
	}
}

function doselectimportexport()
{
	var doc = document.frmAdd
	if(doc.chkimpexp[0].checked == true)
	{
		document.getElementById("tblImport").style.display = "block";
		document.getElementById("tblExport").style.display = "none";
	}
	if(doc.chkimpexp[1].checked == true)
	{
		document.getElementById("tblImport").style.display = "none";
		document.getElementById("tblExport").style.display = "block";
	}
}

function DoExportContact()
{
	var doc = document.frmExport
	doc.accept_export.value = "OK"
	doc.chktype.value = document.frmAdd.chkimpexp[1].value
	doc.submit();
}

function DoDownloadContact()
{
	var doc = document.frmExport
	var szfiledown = doc.exportfilename.value;
	document.location.replace(szfiledown)
}

function DoImportContact()
{
	var doc = document.frmImport
	for(var i=0; i<doc.txtgroupimport.length; i++)
	{
		if(doc.txtgroupimport.options[i].selected == true)
		{
			if(doc.txtgroupimport.options[i].value == "")
			{
				pop_err(doc.txtgroupimport,"Please select group import contact!")
				return false;
			}
		}		
	}
	if(doc.fileimport.value=="")
	{
		pop_err(doc.fileimport,"Please select file import contact!")
		return false;		
	}
	szValue = doc.fileimport.value;
	if((szValue.indexOf('.csv')==-1) && (szValue.indexOf('.xls')==-1) && (szValue.indexOf('.txt')==-1))
	{
		pop_err(doc.fileimport,"File import is false. Please select again!")		
		return false;
	}
	doc.chktypeimport.value = document.frmAdd.chkimpexp[0].value;
	doc.submit()
	return;
}

function DoSendChangeTemplate()
{
	var doc = document.frmAdd
	for(var i=0; i<doc.txttemplate.length; i++)
	{
		if(doc.txttemplate.options[i].selected == true)
		{
			if(doc.txttemplate.options[i].value != "")
			{
				doc.submit()
			}else{
				alert("Please select template e-mail!")
			}			
		}
	}
}

function DoInsertContactList()
{
	ns4 = (document.layers)? true:false
	ie4 = (document.all)? true:false

	winW = (ns4)? window.innerWidth-16 : document.body.offsetWidth-20
	winH = (ns4)? window.innerHeight : document.body.offsetHeight

	winTop = 95;
	winLeft = 115;
	szpage = "pop_contact_list.asp";
	sPro = "WIDTH=800,HEIGHT=600,scrollbars=auto,resize=no,menubar=no,resizable=no,left=" + winLeft + ",top=" + winTop
	window.open(szpage,"contactlist",sPro,true)
}

/* Type = 0: insert selected contacts, Type = 1: insert all contact */
function DoInsertSendContact(type)
{
	var strvalue = ""
	var strvaluesend = ""
	var doc = document.frmList;
	var parentdoc = window.opener.document.frmAdd;
	for(var i=0; i<doc.length; i++){
		if(type == 0){
			if(doc.elements[i].type == "checkbox" && doc.elements[i].name == "chkitem" && doc.elements[i].checked == true){			
				strvalue = strvalue + doc.elements[i].value + "; "
			}
		}
		if(type == 1){
			if(doc.elements[i].type == "checkbox" && doc.elements[i].name == "chkitem"){			
				strvalue = strvalue + doc.elements[i].value + "; "
			}
		}
	}
	strvaluesend = parentdoc.txtmailto.value;
	strvaluesend = strvaluesend + strvalue;
	parentdoc.txtmailto.value = strvaluesend;
	window.close()
}

function DoSendMail()
{
	var doc = document.frmAdd;
	var szmailfrom = doc.txtmailfrom.value;
	if(isemailaddress(szmailfrom) == false){
		pop_err(doc.txtmailfrom,"Your e-mail is invalid. Please try again!")
		return false;
	}
	if(doc.txtmailto.value==""){
		pop_err(doc.txtmailto,"Please insert e-mail to!")
		return false;
	}else{
		var arr_email_to = doc.txtmailto.value.split(";");
		if(arr_email_to.length > 501){
			pop_err(doc.txtmailto,"You cannot send mail template to more than 500 email addresses each time!")
			return false;
		}
	}
	if(doc.txtsubject.value==""){
		pop_err(doc.txtsubject,"Please enter e-mail subject!")
		return false;
	}
	doc.accept_send.value = "OK"
	doc.submit()
}

function doremoverequest()
{
	var doc = document.frmRev;
	var szmail = doc.txtemail.value;
	if(isemailaddress(szmail) == false)
	{
		pop_err(doc.txtemail,"Your e-mail is false. Please try again!")
		return false;
	}
	doc.accept_remove.value="OK"
	doc.submit()
}

function DoChangePassword(){
	var doc = document.frm;
	var szpassword = doc.password.value
	var sznew_password = doc.new_password.value
	var szconfirm_password = doc.confirm_password.value
	
	if(trim(szpassword) == "")
	{
		pop_err(doc.password,"Please input current password!")
		return false;
	}else{
		if(trim(sznew_password) == "")
		{
			pop_err(doc.new_password,"Please input new password!")
			return false;
		}
		else
		{
			if(sznew_password != szconfirm_password){
				pop_err(doc.new_password,"New password and Confirm password is false! Please try again!")
				return false;
			}
		}
	}
	doc.accept_change.value = "OK";
	doc.submit();
}

function DoSaveConnection()
{
	var doc = document.frmImport;
	if(doc.servername.value == ""){
		pop_err(doc.servername,"Please input server name!")
		return false;
	}
	if(doc.servername.value == ""){
		pop_err(doc.servername,"Please input server name!")
		return false;
	}
	if(doc.username.value == ""){
		pop_err(doc.username,"Please input user name!")
		return false;
	}
	if(doc.password.value == ""){
		pop_err(doc.password,"Please input password!")
		return false;
	}
	if(doc.databasename.value == ""){
		pop_err(doc.databasename,"Please input database name!")
		return false;
	}
	if(doc.tablename.value == ""){
		pop_err(doc.tablename,"Please input table name!")
		return false;
	}
	if(doc.firstname.value == ""){
		pop_err(doc.firstname,"Please input first name field!")
		return false;
	}
	if(doc.lastname.value == ""){
		pop_err(doc.lastname,"Please input last name field!")
		return false;
	}
	if(doc.email.value == ""){
		pop_err(doc.email,"Please input email field!")
		return false;
	}
	doc.act.value = "Save Connection";
	doc.submit()
}

function DoListClientContact()
{
	var doc = document.frmImport;
	if(doc.servername.value == "" || doc.username.value == "" || doc.password.value == "" || doc.databasename.value == "" || doc.tablename.value == "" || doc.firstname.value == "" || doc.lastname.value == "" || doc.email.value == ""){
		pop_err(doc.servername,"Please fill in all connection information!")
		return false;
	}
	doc.act.value = "List";
	doc.submit();
}

function DoImportClientContact(type)
{
	var doc = document.frmImport;
	if(doc.groupimport.value == ""){
		alert("Please select group to import!");
		return false;
	}
	if(type == 0)
		doc.act.value = "Import";
	if(type == 1)
		doc.act.value = "ImportAll";
	doc.submit();
}

function doloadviewcontact()
{
	var doc = document.frmList;
	
	doc.action = "view_contactus.asp"
	doc.submit()
}

function docheckallcontactimport()
{
	var doc = document.frmImport;
	var is_check = doc.chkall.checked;
	for(var i=0; i<doc.length; i++){
		if(doc.elements[i].type == "checkbox")
			doc.elements[i].checked = is_check;
	}
}

function docheckitemimport()
{
	var doc = document.frmImport;
	var total_contact = doc.total_contact.value;
	var num_check = 0;
	for(var i=0; i<total_contact; i++){
		if(document.getElementById("chkitem" + i).checked == true)
			num_check = num_check + 1;
	}
	if(num_check == total_contact)
		doc.chkall.checked = true;
	else
		doc.chkall.checked = false;
}

function pop_err(fieldname,err_msg)
{
	fieldname.focus();
	alert(err_msg);
}

function trim(st)
{
	index = 0;
	for (var i = 0; i < st.length; i++)
	{
		ch = st.charAt(i);
		if (ch == ' ')
			index++;
		else 
			break;
	}
	st = st.substring(index, st.length);
	index = st.length;
	for (i = index-1; i > 0; i--)
	{
		ch = st.charAt(i);
		if (ch==' ')
			index--;
		else
			break;
	}
	st = st.substring(0, index);
	return st;
}

function check_url(str_url)
{
	var arr = new Array();
	var re = /[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*:\/\/([0-9a-zA-Z-_`!@$&*+|\]\[:;?,~=]+)+(\.[0-9a-zA-Z-_`!@$&*+|\]\[:;?,~=]+)*(\/[0-9a-z A-Z-_`!@$&*+|\]\[:;?,~.=]*)*$/;
	str_url = trim(str_url);
	if(str_url.search(re)){
		return false;
	} else{
		pos_pointslash = str_url.indexOf("./");
		pos_slashpoint = str_url.indexOf("/.");
		if(pos_pointslash != -1 || pos_slashpoint != -1)
			return false;
		arr = str_url.split("//");
		if(arr.length > 2)
			return false;
		return true;
	}
}

function searchDirectoryContact(){
	var doc =	document.frmList;
	var sDateFormat = "mm/dd/yyyy";
	if (!isDate(doc.date_from.value, sDateFormat)) {
		pop_err(doc.date_from, "Please enter date from with format '" + sDateFormat + "'");
		return false;
	}
	if (!isDate(doc.date_to.value, sDateFormat)) {
		pop_err(doc.date_to, "Please enter date to with format '" + sDateFormat + "'");
		return false;
	}
	doc.submit();
}

function handle_divcreateweb(type){
	if(type == 0){
		document.getElementById("div_createweb").style.display = "none";
	}else{
		document.getElementById("div_createweb").style.display = "block";	
	}
}

function deleteDirectoryContact()
{
	var doc = document.frmList;
	if(confirm('Are you sure you want to delete selected item(s)!')==true)
	{
		doc.act.value = "delete";
		doc.submit();
	}
}

function show_DirectoryContact_SendEmail()
{
	var doc = document.frmList;
	doc.action = "directory_contact_sendemail.asp";
	doc.submit();
}

function show_DirectoryContact_InsertEmail()
{
	ns4 = (document.layers)? true:false
	ie4 = (document.all)? true:false

	winW = (ns4)? window.innerWidth-16 : document.body.offsetWidth-20
	winH = (ns4)? window.innerHeight : document.body.offsetHeight

	winTop = 50;
	winLeft = 115;
	szpage = "directory_contact_list_add_receiver.asp";
	sPro = "WIDTH=800,HEIGHT=650,scrollbars=auto,resize=no,menubar=no,resizable=no,left=" + winLeft + ",top=" + winTop
	window.open(szpage,"contactlist",sPro,true)
}

/* Type = 0: insert selected contacts, Type = 1: insert all contact */
function insertDirectoryContact(type)
{
	var strvalue = ""
	var strvaluesend = ""
	var doc = document.frmList;
	var parentdoc = window.opener.document.frmEmail;
	for(var i=0; i<doc.length; i++)
	{
		if(type == 0){
			if(doc.elements[i].checked == true && doc.elements[i].name == "chkitem")
			{			
				strvalue = strvalue + doc.elements[i].value + "; "
			}
		}
		if(type == 1){
			if(doc.elements[i].type == "checkbox" && doc.elements[i].name == "chkitem")
			{			
				strvalue = strvalue + doc.elements[i].value + "; "
			}
		}
	}
	strvaluesend = parentdoc.txtmailto.value;
	strvaluesend = strvaluesend + strvalue;
	parentdoc.txtmailto.value = strvaluesend;
	window.close()
}

function sendemailDirectoryContact()
{
	var doc = document.frmEmail;
	var szmailfrom = doc.txtmailfrom.value;
	if(isemailaddress(szmailfrom) == false)
	{
		pop_err(doc.txtmailfrom,"Please enter a valid email address!")
		return false;
	}
	if(doc.txtmailto.value=="")
	{
		pop_err(doc.txtmailto,"Please insert e-mail to!")
		return false;
	}
	if(doc.txtsubject.value=="")
	{
		pop_err(doc.txtsubject,"Please enter subject!")
		return false;
	}
	doc.act.value = "send"
	doc.submit()
}

function replyDirectoryContact(){
	var doc = document.frmList;
	doc.action = "directory_contact_sendemail.asp";
	doc.submit();
}

function showContactHistory(type){
	
	if(type == 0){
		document.getElementById("div_detail").style.display = "block";
		document.getElementById("div_history").style.display = "none";
		document.getElementById("link_detail").style.textDecoration = "none";
		document.getElementById("link_history").style.textDecoration = "underline";
	}else{
		document.getElementById("div_detail").style.display = "none";
		document.getElementById("div_history").style.display = "block";
		document.getElementById("link_detail").style.textDecoration = "underline";
		document.getElementById("link_history").style.textDecoration = "none";
	}
	
}

function exportDirectoryContact(){
	var doc = document.frmList;
	var export_str = "";
	var is_check = 0;
	for(var i=0; i<doc.length; i++){
		if(doc.elements[i].name == "chkitem" && doc.elements[i].checked == true){
			is_check = 1;
			export_str = export_str + doc.elements[i].value + ",";
		}
	}
	if(is_check == 0){
		if(!confirm("If you want to export all contact list, choose OK. If you want to export contacts of this page only, choose Cancel!")){
			for(var i=0; i<doc.length; i++){
				if(doc.elements[i].name == "chkitem")
					export_str = export_str + doc.elements[i].value + ",";
			}
		}else{
			export_str = "all";
		}
	}
	doc.export_str.value = export_str;
	doc.act.value = "export";
	doc.action = "directory_contact_export.asp";
	doc.submit();
}

function textLimit(field, maxlen) {
	if (field.value.length > maxlen){
		alert('Your input will be truncated because comment must be ' + maxlen + ' characters or less!');
		var new_len = maxlen - 1;
		field.value = field.value.substring(0, new_len);
	}
}

/* checkDate: Confirm date entered is of the correct format
 *   oDate = date string
 *   sDateFormat = date format string 
 *     acceptable formats: "yy-mm-dd" , "yyyy-mm-dd" , "yy-mmm-dd" , "yyyy-mmm-dd" ,
 *                                   "mm-dd-yy" , "mm-dd-yyyy" , "mmm-dd-yy" , "mmm-dd-yyyy" ,
 *                                   "dd-mm-yy" , "dd-mm-yyyy" , "dd-mmm-yy" , "dd-mmm-yyyy" 
 * Return 0: date is valid, 1: if date is invalid, 2: if dd is greater than days in month
 */
function isDate(sDate, sDateFormat) {
  var yr, mn, dy;
  
  var isError = 1;
  if( arguments.length < 2 ) 
    sDateFormat = "yyyy/mm/dd";

  if( sDate != "" ) {
    src = sDate.split('/');
    format = sDateFormat.split('/');
    
    for ( i = 0; i < src.length; i++ ) {
      tmp = format[i];
      val = src[i];
      if ( tmp == "dd" ){
				dy = val;
				if(val.length < 2)
					dy = "0" + val;
			}
      else if ( tmp == "mm" ){
        mn = val;
				if(val.length < 2)
					mn = "0" + val;
			}
      else if ( tmp == "mmm" )
        mn = changeMonthToMM(val);
      else if ( tmp == "yy" )
        yr = "20" + val;
      else if ( tmp == "yyyy" )
        yr = val;
    }
   	
		if( sDate.length > 10 ) { isError = 0; }
    else if( isNaN(mn) || isNaN(dy) || isNaN(yr) ) { isError = 0; }
    else if( dy.length != 2 || mn.length != 2 || yr.length != 4 ) { isError = 0;}
    else {
			if( yr <= 9999 && mn <= 12 && mn > 0 && yr >= 1900 && dy > 0) { 
        if( mn == 2 ) {
          if ( (yr % 4 == 0 && (yr % 100 != 0 || yr % 400 == 0)) ) { // nam nhuan
            if (dy > 29) isError = 0;
          }
          else if ( dy > 28 ) {isError = 0;}
        }
        else {
          if ( mn == 4 || mn == 6 || mn == 9 || mn == 11 ) {
            if ( dy > 30 ) isError = 0;
          }
          else {
            if ( dy > 31 ) isError = 0;
          }
        }
      }
      else 
        isError = 0;
    }
  } 
	return isError;
}

function isemailaddress(str_email){
	var re = /^[0-9a-z-A-Z-_~=:,|\/\\\'\"]+(\.[0-9a-z-A-Z-_~=:,|\/\\\'\"]+)*@[0-9a-z-A-Z-_~=:,|\/\\\'\"]+(\.[0-9a-z-A-Z-_~=:,|\/\\\'\"]+)+(\.[0-9a-z-A-Z-_~=:,|\/\\\'\"]+)*$/;
	var pos = str_email.search(re);
	if(pos == -1){
		return false;
	}else{
		return true;
	}
}

function isnumeric(num){
	var re = /^[0-9]*$/;
	var pos = num.search(re);
	if(pos == -1){
		return false;
	}else{
		return true;
	}
}