function xmlhttpPost(ajaxUrl,queryStr,returnFunc,waitMessage) {
	var xmlHttpReq = false;
	var self = this;
	if (window.XMLHttpRequest) {
        self.xmlHttpReq = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
	self.xmlHttpReq.open('POST',ajaxUrl,true);
	self.xmlHttpReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	self.xmlHttpReq.onreadystatechange = handleReturn;
    self.xmlHttpReq.send(queryStr);
	function handleReturn() {
		if (self.xmlHttpReq.readyState == 4) {
			if (self.xmlHttpReq.status == 200) {
				returnFunc(self.xmlHttpReq.responseText);
			} else {
				alert("There was a problem in request"); 
			}
		} else {
			displayMessage("<img src='images/wait.gif'><br><br>"+waitMessage);
		}
	}
}
function validateSignup() {
	clearHelp();
	parent.displayMessage("<img src='images/wait.gif'><br><br>Validating Your Information.<br>Please wait...");
	if (!validateField("txtName","Your Name","lettersonly","r"))
		return false;
	if (!validateField("txtCompany","Company/Institute","lettersonly","r"))
		return false;
	if (!validateField("txtWebsite","Website","url","r"))
		return false;
	if (!validateField("txtEmail","Personal Email Address","email","r"))
		return false;
	if (!validateField("txtLoginName","Log-in Name","loginname","r"))
		return false;
	var lName = document.getElementById('txtLoginName').value;
	var qstring = "action=verifyLoginName&loginName="+lName;
	parent.xmlhttpPost('ajax/processAjax.php',qstring,validateSignupSecondStep,'Checking availability of Log-in Name.<br>Please wait...');
}
function validateSignupSecondStep(str) {
	result = str.split("<split>");
	if(result[0] == "error"){
		document.getElementById('dvtxtLoginName').innerHTML = "<img src='images/wrong.gif'>";
		document.getElementById('dvFormHelp').innerHTML = result[1];
		parent.closeMessage();
		return false;
	} else {
		document.getElementById('dvtxtLoginName').innerHTML = "<img src='images/ok.jpg'>";
	}
	parent.displayMessage("<img src='images/wait.gif'><br><br>Validating Your Information.<br>Please wait...");
	if (!validateField("pwdPassword","Password","password","r"))
		return false;
	if (!validateField("pwdConfirm","Confirm Password","password","r"))
		return false;
	if (document.getElementById('pwdPassword').value != document.getElementById('pwdConfirm').value) {
		parent.closeMessage();
		document.getElementById('dvFormHelp').innerHTML = "Password and Confirm Password does not match.";
		document.getElementById('dvpwdConfirm').innerHTML = "<img src='images/wrong.gif'>";
		return false;
	} else {
		document.getElementById('dvpwdConfirm').innerHTML = "<img src='images/ok.jpg'>";
	}
	if (!validateField("numVerify","Verification Number","text","r"))
		return false;
	var vNumber = document.getElementById('numVerify').value;
	var qstring = "action=verifyNumber&number="+vNumber;
	parent.xmlhttpPost('ajax/processAjax.php',qstring,validateSignupThiredStep,'Validating Verification Number.<br>Please wait...');
}
function validateSignupThiredStep(str) {
	result = str.split("<split>");
	if(result[0] == "error"){
		document.getElementById('dvnumVerify').innerHTML = "<img src='images/wrong.gif'>";
		document.getElementById('dvFormHelp').innerHTML = result[1];
		parent.closeMessage();
		return false;
	} else {
		document.getElementById('dvnumVerify').innerHTML = "<img src='images/ok.jpg'>";
	}
	if(document.getElementById('chkAccept').checked == false) {
		document.getElementById('dvFormHelp').innerHTML = "Please read and accept Terms of Service & Privacy Policy";
		document.getElementById('dvchkAccept').innerHTML = "<img src='images/wrong.gif'>";
		parent.closeMessage();
		return false;
	} else {
		document.getElementById('dvchkAccept').innerHTML = "<img src='images/ok.jpg'>";
	}
	parent.displayMessage("<img src='images/wait.gif'><br><br>Creating Your Account.<br>Please wait...");
	document.getElementById('frmSignup').submit();
	return true;
}
function showHelp(field,title) {
	document.getElementById('dvFormHelp').innerHTML = title;
}
function clearHelp() {
	document.getElementById('dvFormHelp').innerHTML ="Fields marked with <strong>*</strong> are required.";
	document.getElementById('dvtxtName').innerHTML ="";
	document.getElementById('dvtxtCompany').innerHTML ="";
	document.getElementById('dvtxtWebsite').innerHTML ="";
	document.getElementById('dvtxtEmail').innerHTML ="";
	document.getElementById('dvtxtLoginName').innerHTML ="";
	document.getElementById('dvpwdPassword').innerHTML ="";
	document.getElementById('dvpwdConfirm').innerHTML ="";
	document.getElementById('dvnumVerify').innerHTML ="";
	document.getElementById('dvchkAccept').innerHTML = "";
}
function validateLoginName() {
	if (!validateField("txtLoginName","Log-in Name","username","r"))
		return false;
	var lName = document.getElementById('txtLoginName').value;
	var qstring = "action=verifyLoginName&loginName="+lName;
	parent.xmlhttpPost('ajax/processAjax.php',qstring,validateLoginNameConfirm,'Checking availability of Log-in Name.<br>Please wait...');
}
function validateLoginNameConfirm(str) {
	result = str.split("<split>");
	isok = result[0];
	switch(isok) {
		case "ok":
		document.getElementById('dvtxtLoginName').innerHTML = "<img src='images/ok.jpg'>";
		break;
		case "error":
		document.getElementById('dvtxtLoginName').innerHTML = "<img src='images/wrong.gif'>";
		break;
	}
	document.getElementById('dvFormHelp').innerHTML = result[1];
	parent.closeMessage();
}
function searchContacts(page,cid) {
	var qstring = "action=searchContacts&userId="+uid+"&page="+page+"&conId="+cid;
	for(var i=1; i<21; i++) {
		if (document.getElementById('SF'+i)) {
			qstring = qstring+'&SF'+i+'='+document.getElementById('SF'+i).value+'&TP'+i+'='+document.getElementById('SF'+i).type;
		}
	}
	qstring = qstring+'&refBy='+document.getElementById('cmbRefby').value;
	xmlhttpPost('ajax/processAjax.php',qstring,confirmSearch,'Searching Contacts.<br>Please wait...');
}
function exportSearchResults() {
	var qstring = "userId="+uid;
	for(var i=1; i<21; i++) {
		if (document.getElementById('SF'+i)) {
			qstring = qstring+'&SF'+i+'='+document.getElementById('SF'+i).value+'&TP'+i+'='+document.getElementById('SF'+i).type;
		}
	}
	qstring = qstring+'&refBy='+document.getElementById('cmbRefby').value;
	window.location = 'exportSearchResults.php?'+qstring;
}
function confirmSearch(str) {
	result = str.split("<split>");
	document.getElementById('dvContacts').innerHTML = result[0];
	document.getElementById('dvContactDetail').innerHTML = result[1];
	closeMessage();
}
function viewReports(id) {
	var qstring = "action=View Reports&userId="+uid+"&reportId="+id;
	xmlhttpPost('ajax/processAjax.php',qstring,manageContactsConfirm,'Loading Reports Screen.<br>Please wait...');
}
function manageContacts(pid,cid) {
	var qstring = "action=Manage Contacts&userId="+uid+"&page="+pid+"&conId="+cid;
	xmlhttpPost('ajax/processAjax.php',qstring,manageContactsConfirm,'Loading Manage Contacts Screen.<br>Please wait...');
}
function billPayments() {
	var qstring = "action=Bill Payments&userId="+uid;
	xmlhttpPost('ajax/processAjax.php',qstring,manageContactsConfirm,'Loading Bill Payments Screen.<br>Please wait...');
}
function showPendingBills() {
	var qstring = "action=Bill Payments&userId="+uid;
	xmlhttpPost('ajax/processAjax.php',qstring,manageContactsConfirm,'Loading Pending Bills.<br>Please wait...');
}
function showAllContacts() {
	var qstring = "action=Show All Contacts&userId="+uid;
	xmlhttpPost('ajax/processAjax.php',qstring,manageContactsConfirm,'Loading All Contacts Screen.<br>Please wait...');
}
function showCommentsAll(cid) {
	var qstring = "action=ShowAllComments&conId="+cid;
	xmlhttpPost('ajax/processAjax.php',qstring,displayForms,'Loading Comments.<br>Please wait...');
}
function uploadContacts(id) {
	var qstring = "action=UploadContacts&uId="+id;
	xmlhttpPost('ajax/processAjax.php',qstring,displayForms,'Loading Upload Contacts Form.<br>Please wait...');
}
function showTrackerAll(cid) {
	var qstring = "action=ShowAllTracker&conId="+cid;
	xmlhttpPost('ajax/processAjax.php',qstring,displayForms,'Loading Tracker.<br>Please wait...');
}
function showFollowupsAll(cid) {
	var qstring = "action=ShowAllFollowups&conId="+cid;
	xmlhttpPost('ajax/processAjax.php',qstring,displayForms,'Loading Follow-ups.<br>Please wait...');
}
function showPaidBills() {
	var qstring = "action=Paid Bills&userId="+uid;
	xmlhttpPost('ajax/processAjax.php',qstring,manageContactsConfirm,'Loading Paid Bills.<br>Please wait...');
}
function processPayment(id) {
	var qstring = "action=Process Payment&invId="+id+"&userId="+uid;
	xmlhttpPost('ajax/processAjax.php',qstring,manageContactsConfirm,'Processing Bill Payment.<br>Please wait...');
}
function payBill(id) {
	var qstring = "action=Pay Bill&invId="+id;
	xmlhttpPost('ajax/processAjax.php',qstring,confirmPayBill,'Loading Payment Gateway.<br>Please wait...');
}
function confirmPayBill(str) {
	document.getElementById('dvBillDetails').innerHTML = str;
	closeMessage();
}
function manageMessages(folder) {
	var qstring = "action=ManageMessages&userId="+uid+"&folderId="+folder;
	xmlhttpPost('ajax/processAjax.php',qstring,manageContactsConfirm,'Loading Manage Messages Screen.<br>Please wait...');
}
function customizeForms() {
	var qstring = "action=custform&userId="+uid;
	xmlhttpPost('ajax/processAjax.php',qstring,manageContactsConfirm,'Loading Customize Form Screen.<br>Please wait...');
}
function editAccount() {
	var qstring = "action=Edit Account&userId="+uid;
	xmlhttpPost('ajax/processAjax.php',qstring,displayForms,'Loading Edit Account Form.<br>Please wait...');
}
function changePass() {
	var qstring = "action=ChangePass&userId="+uid;
	xmlhttpPost('ajax/processAjax.php',qstring,displayForms,'Loading Change Password Form.<br>Please wait...');
}
function newContact() {
	xmlhttpPost('ajax/processAjax.php','action=newContact&userId='+uid,displayForms,'Loading New Contacts Form.<br>Please wait...');
}
function displayForms(str) {
result = str.split("<split>");
	var fTop = (screen.height)/6;
	var fLeft = ((screen.width)-480)/2;
	if(navigator.appName == "Netscape") {
		document.getElementById("dvForms").style.top = window.pageYOffset+fTop;
		document.getElementById("dvForms").style.left = window.pageXOffset+fLeft;
	} else {
		document.getElementById("dvForms").style.top = document.body.scrollTop+fTop;
		document.getElementById("dvForms").style.left = document.body.scrollLeft+fLeft;
	}
	document.getElementById('dvFormBody').innerHTML = result[1];
	document.getElementById('dvFormTitle').innerHTML = result[0];
	document.getElementById("dvForms").style.visibility = 'visible';
	closeMessage();
}
function manageContactsConfirm(str) {
	document.getElementById('dvMain').innerHTML = str;
	document.getElementById("dvForms").style.visibility = 'hidden';
	closeMessage();
}
function createContact(str) {
	result = str.split("<split>");
	if(result[0] == "Error") {
		displayMessage(result[1]);
	} else {
		document.getElementById('dvContacts').innerHTML = result[0];
		document.getElementById('dvContactDetail').innerHTML = result[1];
		closeMessage();
		closeForm();
	}
}
function showContactDetail(conid) {
	var page = document.getElementById('hdPage').value;
	xmlhttpPost('ajax/processAjax.php','action=showContactDetail&conId='+conid+'&userId='+uid+'&page='+page,showContactDetailConfirm,'Loading Contact Details.<br>Please wait...');
}
function showContactDetailConfirm(str) {
	document.getElementById('dvContactDetail').innerHTML = str;
	closeMessage();
}
function contactPage(page) {
	xmlhttpPost('ajax/processAjax.php','action=ContactPage&userId='+uid+'&page='+page,contactPageConfirm,'Loading Contacts Page.<br>Please wait...');
}
function contactPageConfirm(str) {
	result = str.split("<split>");
	document.getElementById('dvContacts').innerHTML = result[0];
	document.getElementById('dvContactDetail').innerHTML = result[1];
	closeMessage();
}
function changePerm() {
	if(document.getElementById('mailType').value == 1) {
		document.getElementById('txtMailbox').disabled = true;
		document.getElementById('pwdMailPass').disabled = true;
		document.getElementById('pwdMailConfirm').disabled = true;
		document.getElementById('txtMailbox').value = document.getElementById('hdtxtMailbox').value;
		document.getElementById('pwdMailPass').value = "";
		document.getElementById('pwdMailConfirm').value = "";
	} else {
		document.getElementById('txtMailbox').disabled = false;
		document.getElementById('pwdMailPass').disabled = false;
		document.getElementById('pwdMailConfirm').disabled = false;
		if(document.getElementById('hdCurrentBox').value == document.getElementById('hdtxtMailbox').value) {
			document.getElementById('txtMailbox').value = "";
		} else {
			document.getElementById('txtMailbox').value = document.getElementById('hdCurrentBox').value;
		}
	}
}
function updatePass() {
	document.getElementById('dvpwdPass').innerHTML ="";
	document.getElementById('dvpwdNewPass').innerHTML ="";
	document.getElementById('dvpwdConfirm').innerHTML ="";
	parent.displayMessage("<img src='images/wait.gif'><br><br>Validating Your Information.<br>Please wait...");
	if (!validateField("pwdPass","Existing Password","password","r"))
		return false;
	if (!validateField("pwdNewPass","New Password","password","r"))
		return false;
	if (!validateField("pwdConfirm","Confirm Password","password","r"))
		return false;
	if (document.getElementById('pwdNewPass').value != document.getElementById('pwdConfirm').value) {
		parent.closeMessage();
		document.getElementById('dvFormHelp').innerHTML = "Password and Confirm Password does not match.";
		document.getElementById('dvpwdConfirm').innerHTML = "<img src='images/wrong.gif'>";
		return false;
	} else {
		document.getElementById('dvpwdConfirm').innerHTML = "<img src='images/ok.jpg'>";
	}
}
function validateUpdate() {
	document.getElementById('dvtxtName').innerHTML ="";
	document.getElementById('dvtxtCompany').innerHTML ="";
	document.getElementById('dvtxtWebsite').innerHTML ="";
	document.getElementById('dvtxtEmail').innerHTML ="";
	document.getElementById('dvtxtMailbox').innerHTML ="";
	document.getElementById('dvpwdMailPass').innerHTML ="";
	document.getElementById('dvpwdMailConfirm').innerHTML ="";
	document.getElementById('dvtxtSignature').innerHTML ="";
	parent.displayMessage("<img src='images/wait.gif'><br><br>Validating Your Information.<br>Please wait...");
	if (!validateField("txtName","Your Name","lettersonly","r"))
		return false;
	if (!validateField("txtCompany","Company/Institute","anytext","r"))
		return false;
	if (!validateField("txtWebsite","Website","url","r"))
		return false;
	if (!validateField("txtEmail","Personal Email Address","email","r"))
		return false;
	if (!validateField("txtMailbox","Email Address","email","r"))
		return false;
	if(document.getElementById('mailType').value == 2 && document.getElementById('txtMailbox').value != document.getElementById('hdCurrentBox').value) {
		if (!validateField("pwdMailPass","Password","password","r"))
			return false;
		if (!validateField("pwdMailConfirm","Confirm Password","password","r"))
			return false;
		if (document.getElementById('pwdMailPass').value != document.getElementById('pwdMailConfirm').value) {
			parent.closeMessage();
			document.getElementById('dvFormHelp').innerHTML = "Password and Confirm Password does not match.";
			document.getElementById('dvpwdMailConfirm').innerHTML = "<img src='images/wrong.gif'>";
			return false;
		} else {
			document.getElementById('dvpwdMailConfirm').innerHTML = "<img src='images/ok.jpg'>";
		}
	}
	var uid = document.getElementById('hdUserId').value;
	var name = document.getElementById('txtName').value;
	var company = document.getElementById('txtCompany').value;
	var website = document.getElementById('txtWebsite').value;
	var email = document.getElementById('txtEmail').value;
	var mtype = document.getElementById('mailType').value;
	var mbox = document.getElementById('txtMailbox').value;
	var cbox = document.getElementById('hdCurrentBox').value;
	var sysp = document.getElementById('pwdMailPass').value;
	var sign = document.getElementById('txtSignature').value;
	var qstring = "action=Update Account&userId="+uid+"&txtName="+name+"&txtCompany="+company+"&txtWebsite="+website+"&txtEmail="+email+"&mailType="+mtype+"&txtMailbox="+mbox+"&mailPass="+sysp+"&txtSignature="+sign+"&currentBox="+cbox;
	parent.xmlhttpPost('ajax/processAjax.php',qstring,confirmUpdate,'Updating Account Details.<br>Please wait...');
}
function confirmUpdate(str) {
	parent.closeForm();
	parent.displayMessage(str+'<br><br><input name="btnClose" type="button" class="FormButton" id="btnCancel" value="Close" onClick="parent.closeMessage()">');
}
function popContactDetail(cid) {
	xmlhttpPost('ajax/processAjax.php','action=popDetails&conId='+cid+'&userId='+uid,displayForms,'Loading Contact Details.<br>Please wait...');
}
function editContactDetail(cid,pid) {
	xmlhttpPost('ajax/processAjax.php','action=editDetails&conId='+cid+'&userId='+uid+'&page='+pid,displayForms,'Loading Edit Contact Form.<br>Please wait...');
}
function editContactAll(cid) {
	xmlhttpPost('ajax/processAjax.php','action=editDetails&conId='+cid+'&userId='+uid,displayForms,'Loading Edit Contact Form.<br>Please wait...');
}
function deleteContact(cid) {
	var is_confirmed = confirm("Are you sure you want to delete this contact?");
    if(is_confirmed == true) {
		xmlhttpPost('ajax/processAjax.php','action=deleteContact&conId='+cid+'&userId='+uid,confirmSearch,'Deleting Contact.<br>Please wait...');
	}
}
function mcNewMessage(cid) {
	xmlhttpPost('ajax/processAjax.php','action=newMessage&conId='+cid+'&userId='+uid,displayForms,'Loading New Message Form.<br>Please wait...');
}
function replyEmail(mid,cid) {
	xmlhttpPost('ajax/processAjax.php','action=repEmail&mesId='+mid+'&conId='+cid+'&userId='+uid,displayForms,'Loading Reply Email Form.<br>Please wait...');
}
function deleteMessage(mid,cid,fol) {
	xmlhttpPost('ajax/processAjax.php','action=delMessage&mesId='+mid+'&conId='+cid+'&userId='+uid+'&folder='+fol,showOutboxConfirm,'Deleting Message.<br>Please wait...');
}
function deleteFollowup(mid,cid) {
	xmlhttpPost('ajax/processAjax.php','action=delFollowup&mesId='+mid+'&conId='+cid+'&userId='+uid,showOutboxConfirm,'Deleting Followup.<br>Please wait...');
}
function closeFollowup(mid,cid) {
	xmlhttpPost('ajax/processAjax.php','action=closeFollowup&mesId='+mid+'&conId='+cid+'&userId='+uid,displayForms,'Closing Followup.<br>Please wait...');
}
function editFollowup(mid,cid,frm) {
	xmlhttpPost('ajax/processAjax.php','action=EditFollowup&mesId='+mid+'&conId='+cid+'&userId='+uid+'&from='+frm,displayForms,'Loading Edit Followup Form.<br>Please wait...');
}
function mmdeleteFollowup(mid,cid) {
	xmlhttpPost('ajax/processAjax.php','action=mmdelFollowup&mesId='+mid+'&conId='+cid+'&userId='+uid,mmAllMessagesConfirm,'Deleting Followup.<br>Please wait...');
}
function mmcloseFollowup(mid,cid) {
	xmlhttpPost('ajax/processAjax.php','action=mmcloseFollowup&mesId='+mid+'&conId='+cid+'&userId='+uid,displayForms,'Closing Followup.<br>Please wait...');
}
function deleteEmail(mid,cid) {
	xmlhttpPost('ajax/processAjax.php','action=delEmail&mesId='+mid+'&conId='+cid+'&userId='+uid,showOutboxConfirm,'Deleting Email Message.<br>Please wait...');
}
function forwardMessage(mid,cid) {
	xmlhttpPost('ajax/processAjax.php','action=fwdMessage&mesId='+mid+'&conId='+cid+'&userId='+uid,showOutboxConfirm,'Re-sending Message.<br>Please wait...');
}
function showDraft(mid,cid) {
	xmlhttpPost('ajax/processAjax.php','action=showDraft&mesId='+mid+'&conId='+cid+'&userId='+uid,displayForms,'Loading Draft.<br>Please wait...');
}
//Manage Contacts Functions
function mmAllMessages(fd,pg,co,od) {
	xmlhttpPost('ajax/processAjax.php','action=mmAllMessages&folder='+fd+'&page='+pg+'&column='+co+'&order='+od+'&userId='+uid,mmAllMessagesConfirm,'Loading Messages.<br>Please wait...');
}
function mmAllMessagesConfirm(str) {
	document.getElementById('dvMessages').innerHTML = str;
	closeMessage();
	closeForm();
}
function mmMessageDetail(mid) {
	xmlhttpPost('ajax/processAjax.php','action=mmMessageDetail&mesId='+mid+'&userId='+uid,mmEmailDetailConfirm,'Loading Message Details.<br>Please wait...');
}
function mmFollowupDetail(mid) {
	xmlhttpPost('ajax/processAjax.php','action=mmFollowupDetail&mesId='+mid+'&userId='+uid,mmEmailDetailConfirm,'Loading Follow-up Details.<br>Please wait...');
}
function mmEmailDetail(eid) {
	xmlhttpPost('ajax/processAjax.php','action=mmEmailDetail&hdId='+eid,mmEmailDetailConfirm,'Loading Email Details.<br>Please wait...');
}
function mmEmailDetailConfirm(str) {
	document.getElementById('dvMessageDetail').innerHTML = str;
	closeMessage();
}
function mmDeleteEmail(mid,cid) {
	xmlhttpPost('ajax/processAjax.php','action=mmDelEmail&mesId='+mid+'&conId='+cid+'&userId='+uid,mmAllMessagesConfirm,'Deleting Email Message.<br>Please wait...');
}
function mmReplyEmail(mid,cid) {
	xmlhttpPost('ajax/processAjax.php','action=mmRepEmail&mesId='+mid+'&conId='+cid+'&userId='+uid,displayForms,'Loading Reply Email Form.<br>Please wait...');
}
function mmDeleteMessage(mid,cid,fol) {
	xmlhttpPost('ajax/processAjax.php','action=mmDelMessage&mesId='+mid+'&conId='+cid+'&userId='+uid+'&folder='+fol,mmAllMessagesConfirm,'Deleting Message.<br>Please wait...');
}
function mmShowDraft(mid,cid) {
	xmlhttpPost('ajax/processAjax.php','action=mmShowDraft&mesId='+mid+'&conId='+cid+'&userId='+uid,displayForms,'Loading Draft.<br>Please wait...');
}

//End
function messageDetail(mid) {
	xmlhttpPost('ajax/processAjax.php','action=MessageDetail&mesId='+mid+'&userId='+uid,showMessage,'Loading Message Details.<br>Please wait...');
}
function followupDetail(mid) {
	xmlhttpPost('ajax/processAjax.php','action=FollowupDetail&mesId='+mid+'&userId='+uid,showMessage,'Loading Follow-up Details.<br>Please wait...');
}
function emailDetail(eid,cid) {
	xmlhttpPost('ajax/processAjax.php','action=EmailDetail&hdId='+eid+'&conId='+cid,showMessage,'Loading Email Details.<br>Please wait...');
}
function followupsPage(cid,page) {
	xmlhttpPost('ajax/processAjax.php','action=FollowupPage&conId='+cid+'&pagex='+page,confirmMessagePage,'Loading Follow-ups.<br>Please wait...');
}
function messagesPage(cid,folder,page) {
	xmlhttpPost('ajax/processAjax.php','action=MessagePage&conId='+cid+'&folder='+folder+'&page='+page,confirmMessagePage,'Loading Messages.<br>Please wait...');
}
function emailPage(cid,page) {
	xmlhttpPost('ajax/processAjax.php','action=EmailPage&conId='+cid+'&page='+page,confirmMessagePage,'Loading Emails.<br>Please wait...');
}
function confirmMessagePage(str) {
	document.getElementById('dvContactMessages').innerHTML = str;
	document.getElementById('dvMessageDetail').innerHTML = "";
	closeMessage();
}
function showMessage(str) {
	document.getElementById('dvMessageDetail').innerHTML = str;
	closeMessage();
}
function newCall(cid) {
	xmlhttpPost('ajax/processAjax.php','action=newCall&conId='+cid+'&userId='+uid,displayForms,'Loading New Call Form.<br>Please wait...');
}
function newFollowup(cid) {
	xmlhttpPost('ajax/processAjax.php','action=newFollowup&conId='+cid+'&userId='+uid,displayForms,'Loading New Followup Form.<br>Please wait...');
}
function showOutbox(cid) {
	xmlhttpPost('ajax/processAjax.php','action=showOut&conId='+cid+'&userId='+uid,showOutboxConfirm,'Loading Sent Messages.<br>Please wait...');
}
function showDrafts(cid) {
	xmlhttpPost('ajax/processAjax.php','action=showDrafts&conId='+cid+'&userId='+uid,showOutboxConfirm,'Loading Drafts.<br>Please wait...');
}
function showCalls(cid) {
	xmlhttpPost('ajax/processAjax.php','action=showCalls&conId='+cid+'&userId='+uid,showOutboxConfirm,'Loading Calls.<br>Please wait...');
}
function showFollowups(cid) {
	xmlhttpPost('ajax/processAjax.php','action=showFollowups&conId='+cid+'&userId='+uid,showOutboxConfirm,'Loading Followups.<br>Please wait...');
}
function showInbox(cid) {
	xmlhttpPost('ajax/processAjax.php','action=showInbox&conId='+cid+'&userId='+uid,showOutboxConfirm,'Loading Inbox.<br>Please wait...');
}
function showOutboxConfirm(str) {
	result = str.split("<split>");
	document.getElementById('dvFolders').innerHTML = result[0];
	document.getElementById('dvContactMessages').innerHTML = result[1];
	document.getElementById('dvMessageDetail').innerHTML = "";
	closeMessage();
}
function sendMessageConfirm(str) {
	result = str.split("<split>");
	document.getElementById('dvFolders').innerHTML = result[0];
	document.getElementById('dvContactMessages').innerHTML = result[1];
	//document.getElementById('dvMessageDetail').innerHTML = "";
	closeMessage();
	closeForm();
}
function addToFavorites(cid) {
	xmlhttpPost('ajax/processAjax.php','action=addTofav&conId='+cid+'&userId='+uid,addToFavoritesConfirm,'Adding contact to favorites.<br>Please wait...');
}
function removeFavorites(cid) {
	xmlhttpPost('ajax/processAjax.php','action=removeFav&conId='+cid+'&userId='+uid,addToFavoritesConfirm,'Removing contact from favorites.<br>Please wait...');
}
function addToFavoritesConfirm(str) {
	result = str.split("<split>");
	document.getElementById('dvbtnFavorite').innerHTML = result[0];
	document.getElementById('dvimgFavorite').innerHTML = result[1];
	closeMessage();
}
function showFavorites() {
	xmlhttpPost('ajax/processAjax.php','action=showFav&userId='+uid,createContact,'Loading favorite contacts.<br>Please wait...');
}
function addNewField() {
	xmlhttpPost('ajax/processAjax.php','action=newField&userId='+uid,confirmAddNewField,'Adding New Field.<br>Please wait...');
}
function confirmAddNewField(str) {
	document.getElementById('dvNewField').innerHTML += str;
	closeMessage();
}
function removeField(id) {
	xmlhttpPost('ajax/processAjax.php','action=remField&fid='+id+'&userId='+uid,confirmRemoveField,'Removing Field.<br>Please wait...');
}
function confirmRemoveField(str) {
	document.getElementById('dvMain').innerHTML = str;
	closeMessage();
}
function custParas(field,number) {
	var typevalue=field.options[field.selectedIndex].text;
	xmlhttpPost('ajax/processAjax.php','action=changeField&fNum='+number+'&fType='+typevalue+'&userId='+uid,confirmAddOption,'Changing Field Type.<br>Please wait...');
}
function addOption(number) {
	var qstring = "action=addOpt&userId="+uid+"&fNum="+number;
	for(var i=0; i<41; i++) {
		if (document.getElementById('F'+number+'Opt'+i)) {
			qstring = qstring+'&F'+number+'Opt'+i+'='+document.getElementById('F'+number+'Opt'+i).value;

		}
	}
	xmlhttpPost('ajax/processAjax.php',qstring,confirmAddOption,'Adding New Option.<br>Please wait...');
}
function removeOption(number,opt) {
	var qstring = "action=remOpt&userId="+uid+"&fNum="+number+"&optNum="+opt;
	for(var i=0; i<41; i++) {
		if (document.getElementById('F'+number+'Opt'+i)) {
			qstring = qstring+'&F'+number+'Opt'+i+'='+document.getElementById('F'+number+'Opt'+i).value;
		}
	}
	xmlhttpPost('ajax/processAjax.php',qstring,confirmAddOption,'Removing Option.<br>Please wait...');
}
function confirmAddOption(str) {
	result = str.split("<split>");
	document.getElementById(result[0]).innerHTML = result[1];
	closeMessage();
}
function saveChanges() {
	if (!validateField2("txtTitle","Form Title","lettersonly","r"))
		return false;
	if (!validateField2("txtDesc","Form Description","lettersonly","r"))
		return false;
	if (!validateField2("txtMessage","Thank You Message","lettersonly","r"))
		return false;
	document.getElementById('frmCust').submit();
}