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(waitMessage);
		}
	}
}
function displayMessage(message) {
	var browser = navigator.appName;
	if(browser == "Netscape") {
		document.getElementById("dvMessage").innerHTML = "<table width='200' cellpadding='0' cellspacing='0' bgcolor='#f5f5f5' style='border:double #4883bf'><tr><td width='200' height='100' align='center' class='allBox'>"+message+"</td></tr></table>";
	} else {
		window.frames['frmMessage'].document.getElementById('divMessage').innerHTML = "<table width='200' cellpadding='0' cellspacing='0' bgcolor='#f5f5f5' style='border:double #4883bf'><tr><td width='200' height='94' align='center' class='allBox'>"+message+"</td></tr></table>";
	}
	document.getElementById("dvMessage").style.visibility = 'visible';
}
function closeMessage() {
	document.getElementById("dvMessage").style.visibility = 'hidden';
}
function closeForm() {
	document.getElementById("dvForms").style.visibility = 'hidden';
}
function checkLocation() {
	var fTop = (screen.height)/4;
	var fLeft = ((screen.width)-200)/2;
	if(navigator.appName == "Netscape") {
		document.getElementById("dvMessage").style.top = window.pageYOffset+fTop;
		document.getElementById("dvMessage").style.left = window.pageXOffset+fLeft;
	} else {
		document.getElementById("dvMessage").style.top = document.body.scrollTop+fTop;
		document.getElementById("dvMessage").style.left = document.body.scrollLeft+fLeft;
	}
	setTimeout("checkLocation()",10);
}
function newForm(request,correction) {
	xmlhttpPost(correction+'ajax/processAjax.php','action=NewForm&sec='+request+'&corr='+correction,displayForms,'Loading '+request+' Form.<br>Please wait...');
}
function editForm(request,id) {
	xmlhttpPost('ajax/processAjax.php','action=EditForm&sec='+request+'&rId='+id,displayForms,'Loading '+request+' Form.<br>Please wait...');
}
//shehan
function deleteCoupon(id,cId){
	if(!confirm("Are you sure you want to delete?"))
	{
		return false;	
	}
	xmlhttpPost('ajax/processAjax1.php','action=delCoupons&bId='+id+'&cId='+cId,deleteCouponConfirm,'Deleting...<br>Please wait...');
}
function printCoupon(bId){
	xmlhttpPost('ajax/processAjax1.php','action=printCoupon&bId='+bId,printCouponConfirm,'Loading...<br>Please wait...');
}
function printCouponConfirm(str) {
	document.getElementById('dvPrint').innerHTML = str;
	closeMessage();
}
function deleteCouponConfirm(str) {
	parent.location.href='index.php';
	closeMessage();
}
function coupons(request,id) {
	xmlhttpPost('ajax/processAjax.php','action=coupons&sec='+request+'&bId='+id,displayForms,'Loading '+request+' Form.<br>Please wait...');
}
function getTemplates(cat,bId,ref) {
	xmlhttpPost('ajax/processAjax1.php','action=getTemplates&cat='+cat+'&bId='+bId+'&ref='+ref,confirmTemplates,'Loading Templates.<br>Please wait...');
}
function chooseTemplate(id,path,bId) {
	xmlhttpPost('ajax/processAjax1.php','action=chooseTemplate&templateId='+id+'&path='+path+'&bId='+bId,displayForms,'Loading Selected Tempalte.<br>Please wait...');
}
function editTemplate(id,path,bId) {
	xmlhttpPost('ajax/processAjax1.php','action=editTemplate&templateId='+id+'&path='+path+'&bId='+bId,displayForms,'Loading Selected Tempalte.<br>Please wait...');
}
function edit_coupons(bId) {
	xmlhttpPost('ajax/processAjax1.php','action=edit_coupons&bId='+bId,displayForms,'Loading Edit Screen.<br>Please wait...');
}
function downloadCoupon(bId,cId) {
	var qstring = "action=downloadCoupon&bId="+bId+'&cId='+cId;
	xmlhttpPost('../../ajax/processAjax1.php',qstring,displayForms,'Loading Downloading Form.<br>Please wait...');
}
function showTerms(bId) {
	var qstring = "action=showTerms&bId="+bId;
	xmlhttpPost('../../ajax/processAjax1.php',qstring,displayForms,'Loading Terms and Condition Form.<br>Please wait...');
}
function confirmTemplates(str) {
	document.getElementById('tempList').innerHTML = str;
	closeMessage();
}
function sendToFriend(id,corr) {
	xmlhttpPost(corr+'ajax/processAjax.php','action=SendtoFriend&cId='+id+'&corr='+corr,displayForms,'Loading Send to Friend Form.<br>Please wait...');
}
function submittedPages(type,pg) {
	xmlhttpPost('ajax/processAjax.php','action=SubmittedPages&cType='+type+'&page='+pg,confirmSubmittedPages,'Loading Pages.<br>Please wait...');
}
function confirmSubmittedPages(str) {
	result = str.split("<split>");
	document.getElementById('dvSubmitted').innerHTML = result[0];
	document.getElementById('dvSubmittedPages').innerHTML = result[1];
	closeMessage();
}
function joinedPages(type,pg) {
	xmlhttpPost('ajax/processAjax.php','action=JoinedPages&cType='+type+'&page='+pg,confirmJoinedPages,'Loading Pages.<br>Please wait...');
}
function confirmJoinedPages(str) {
	result = str.split("<split>");
	document.getElementById('dvJoined').innerHTML = result[0];
	document.getElementById('dvJoinedPages').innerHTML = result[1];
	closeMessage();
}
function checkAvailability(request,val,correction) {
	if(val == "") {
		alert("Please fill the "+request+" Field.");
		return false;
	}
	xmlhttpPost(correction+'ajax/processAjax.php','action=CheckAvailability&sec='+request+'&value='+val,ConfirmCheckAvailability,'Checking Availability of '+request+'.<br>Please wait...');
}
function ConfirmCheckAvailability(str) {
	displayMessage(str+'<br><br><input name="btnClose" type="button" class="momrev_buttons" id="btnClose" value="Close" onClick="parent.closeMessage()">');
}
function reviewBusiness(id) {
	var qstring = "action=ReviewBusiness&bId="+id;
	xmlhttpPost('../../ajax/processAjax.php',qstring,displayForms,'Loading Review Form.<br>Please wait...');
}
function claimBusiness(id) {
	var qstring = "action=ClaimBusiness&bId="+id;
	xmlhttpPost('../../ajax/processAjax.php',qstring,displayForms,'Loading Claim Business Form.<br>Please wait...');
}
function reviewsPage(pg,id) {
	var qstring = "action=ReviewsPage&page="+pg+"&bId="+id;
	xmlhttpPost('../../ajax/processAjax.php',qstring,confirmReviewsPage,'Loading Reviews.<br>Please wait...');
}
function myReviewPages(pg) {
	var qstring = "action=MyReviewsPage&page="+pg;
	xmlhttpPost('ajax/processAjax.php',qstring,confirmReviewsPage,'Loading Reviews.<br>Please wait...');
}
function mySubmittedPages(pg) {
	var qstring = "action=MySubmitPage&page="+pg;
	xmlhttpPost('ajax/processAjax.php',qstring,confirmMySubmittedPages,'Loading Submitted Businesses.<br>Please wait...');
}
function mySugestedPages(pg) {
	var qstring = "action=MySugestPage&page="+pg;
	xmlhttpPost('ajax/processAjax.php',qstring,confirmMySugestedPages,'Loading Suggested Businesses.<br>Please wait...');
}
function confirmMySugestedPages(str) {
	result = str.split("<split>");
	document.getElementById('dvMySugested').innerHTML = result[0];
	document.getElementById('dvSugestedPages').innerHTML = result[1];
	closeMessage();
}
function confirmMySubmittedPages(str) {
	result = str.split("<split>");
	document.getElementById('dvMySubmitted').innerHTML = result[0];
	document.getElementById('dvSubmittedPages').innerHTML = result[1];
	closeMessage();
}
function deleteAlert(type,id) {
	alert(type+" cannot be deleted. Please make a request to administrator with fllowing listing ID.\nListing ID = "+id);
	return false;
}
function confirmReviewsPage(str) {
	result = str.split("<split>");
	document.getElementById('dvReviews').innerHTML = result[0];
	document.getElementById('dvReviewPages').innerHTML = result[1];
	closeMessage();
}
function displayForms(str) {
	result = str.split("<split>");
	var fTop = (screen.height)/6;
	var fLeft = ((screen.width)-538)/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 viewAllStates() {
	var fTop = (screen.height)/6;
	var fLeft = ((screen.width)-450)/2;
	if(navigator.appName == "Netscape") {
		document.getElementById("dvAllStates").style.top = window.pageYOffset+fTop;
		document.getElementById("dvAllStates").style.left = window.pageXOffset+fLeft;
	} else {
		document.getElementById("dvAllStates").style.top = document.body.scrollTop+fTop;
		document.getElementById("dvAllStates").style.left = document.body.scrollLeft+fLeft;
	}
	document.getElementById("dvAllStates").style.visibility = 'visible';
}
function viewAllCities() {
	var fTop = (screen.height)/6;
	var fLeft = ((screen.width)-450)/2;
	if(navigator.appName == "Netscape") {
		document.getElementById("dvAllCities").style.top = window.pageYOffset+fTop;
		document.getElementById("dvAllCities").style.left = window.pageXOffset+fLeft;
	} else {
		document.getElementById("dvAllCities").style.top = document.body.scrollTop+fTop;
		document.getElementById("dvAllCities").style.left = document.body.scrollLeft+fLeft;
	}
	document.getElementById("dvAllCities").style.visibility = 'visible';
}
function closeAllStates() {
	document.getElementById("dvAllStates").style.visibility = 'hidden';
}
function closeAllCities() {
	document.getElementById("dvAllCities").style.visibility = 'hidden';
}
function reviewInstructions() {
	var mesg = "<table width=\"100%\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td class=\"h10\" align=\"center\" valign=\"middle\" style=\"padding:15px 15px 15px 15px\">";
	mesg += "Add a review to an existing business by searching for a business you know through our search bar or simply browse around.";
	mesg += "</td></tr></table>";
	displayForms("Review This Business<split>"+mesg);
}
function showMemberArea(correction) {
	var qstring = "action=ShowMemberArea&corr="+correction;
	xmlhttpPost(correction+'ajax/processAjax.php',qstring,confirmShowMemberArea,'');
}
function confirmShowMemberArea(str) {
	if(str != 0) {
		document.getElementById('dvMemberArea').innerHTML = str;
	}
	closeMessage();
}
function confirmForgotPass(str) {
	displayMessage(str+'<br><br><input name="btnClose" type="button" class="momrev_signup_buttons" id="btnClose" value="Close" onClick="parent.closeMessage()">');
}
function validateLogin() {
	var user = document.getElementById('userName').value;
	var pass = document.getElementById('passWord').value;
	if(user.length < 1 || pass.length < 1) {
		alert("Please fill in User Name and Password fields");
		return false;
	}
}
function displayAlerts() {
	var url = window.location.href;
	result = url.split("?");
	var message = result[1];
	switch(message) {
		case "mes=1":
			displayMessage('Invalid User Name or Password<br><br><input name="btnClose" type="button" class="momrev_signup_buttons" id="btnClose" value="Close" onClick="parent.closeMessage()">');
		break;
		case "mes=2":
			displayMessage('Invalid Password Reset Link<br><br><input name="btnClose" type="button" class="momrev_signup_buttons" id="btnClose" value="Close" onClick="parent.closeMessage()">');
		break;
		case "mes=3":
			displayMessage('Password Reset Successfully. Please check your email account.<br><br><input name="btnClose" type="button" class="momrev_signup_buttons" id="btnClose" value="Close" onClick="parent.closeMessage()">');
		break;
		case "mes=4":
			displayMessage('Please Log-in to access Member Area<br><br><input name="btnClose" type="button" class="momrev_signup_buttons" id="btnClose" value="Close" onClick="parent.closeMessage()">');
		break;
	}
}
function confirmDelete(type) {
	var is_confirmed = confirm("Are you sure you want to delete this "+type+"?");
    if(is_confirmed == false) {
		return false;
	}
}
