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 removeMultipleCoupons() {
	var couponIds = [];
	var fieldobj = document.getElementsByName('cbs[]');
	for (var i=0; i < fieldobj.length; i++)	{
		if (fieldobj[i].checked) {
			couponIds.push(fieldobj[i].value);
		}
	}
	if(couponIds == "") {
		alert("Please select one or more coupons");
		return false;
	}
	rPath = escape(window.location);
	window.location = "my-coupons.php?act=multipleunclip&Ids="+couponIds+"&rPath="+rPath;
}
function displayMessage(message) {
	var fTop = (screen.height)/4;
	var fLeft = ((screen.width)-300)/2;
	var browser = navigator.appName;
	if(browser == "Netscape") {
		document.getElementById("dvMessage").style.top = window.pageYOffset+fTop+'px';
		document.getElementById("dvMessage").style.left = window.pageXOffset+fLeft+'px';
		document.getElementById("dvMessage").innerHTML = "<table width='300' cellpadding='0' cellspacing='0' border='0'><tr><td height='150' align='center' class='allBox'>"+message+"</td></tr></table>";
	} else {
		document.getElementById("dvMessage").style.top = document.body.scrollTop+fTop;
		document.getElementById("dvMessage").style.left = document.body.scrollLeft+fLeft;
		window.frames['frmMessage'].document.getElementById('divMessage').innerHTML = "<table width='300' cellpadding='0' cellspacing='0' border='0'><tr><td height='150' align='center' class='allBox'>"+message+"</td></tr></table>";
	}
	document.getElementById("dvMessage").style.display = 'block';
}
function closeMessage() {
	document.getElementById("dvMessage").style.display = 'none';
}
function closeForm() {
	document.getElementById("dvForms").style.visibility = 'hidden';
}
function closePopup() {
	document.getElementById("dvPopup").style.display = 'none';
}
function closePreview() {
	document.getElementById("dvPreview").style.display = 'none';
}
function checkLocation() {
	var fTop = (screen.height)/4;
	var fLeft = ((screen.width)-300)/2;
	if(navigator.appName == "Netscape") {
		document.getElementById("dvMessage").style.top = window.pageYOffset+fTop+'px';
		document.getElementById("dvMessage").style.left = window.pageXOffset+fLeft+'px';
	} else {
		document.getElementById("dvMessage").style.top = document.body.scrollTop+fTop;
		document.getElementById("dvMessage").style.left = document.body.scrollLeft+fLeft;
	}
	setTimeout("checkLocation()",10);
}
function displayPreview(wdth) {
	var fTop = 50;
	var fLeft = ((screen.width)-wdth)/2;
	if(navigator.appName == "Netscape") {
		document.getElementById("dvPreview").style.top = window.pageYOffset+fTop+'px';
		document.getElementById("dvPreview").style.left = window.pageXOffset+fLeft+'px';
	} else {
		document.getElementById("dvPreview").style.top = document.documentElement.scrollTop+fTop+'px';
		document.getElementById("dvPreview").style.left = document.documentElement.scrollLeft+fLeft+'px';
	}
	document.getElementById("dvPreview").style.display = 'block';
	closeMessage();
}
function printSelectedCoupons() {
	var couponIds = [];
	var fieldobj = document.getElementsByName('cbs[]');
	for (var i=0; i < fieldobj.length; i++)	{
		if (fieldobj[i].checked) {
			couponIds.push(fieldobj[i].id);
		}
	}
	if(couponIds == "") {
		alert("Please select one or more coupons");
		return false;
	}
	parent.openPopup('Print Selected Coupons',couponIds);
}

function clipMultipleCoupons() {
	var couponIds = [];
	var fieldobj = parent.document.getElementsByName('cbs[]');
	for (var i=0; i < fieldobj.length; i++)	{
		if (fieldobj[i].checked) {
			couponIds.push(fieldobj[i].id);
		}
	}
	if(couponIds == "") {
		alert("Please select one or more coupons");
		return false;
	}
	rPath = escape(window.location.search);
	//alert(rPath);
	window.location = "my-coupons.php?act=multipleclip&Ids="+couponIds+"&rPath="+rPath;
}
function showHideFields(type) {
	if(type == 0) {
		document.getElementById('sSub').style.display = "inline";
		document.getElementById('sKey').style.display = "none";
	} else {
		document.getElementById('sSub').style.display = "none";
		document.getElementById('sKey').style.display = "inline";
		if(type == 1) {
			document.getElementById('sKey').value = "Enter full or part of a business name";
		} else if(type == 2) {
			document.getElementById('sKey').value = "Enter the Brand Name you are looking for";
		} else {
			document.getElementById('sKey').value = "Enter the State or City name";
		}
	}
}
function openPopup(act,id) {
	var url;
	var wdth;
	switch(act) {
		case "Sign in to Bizymoms Coupons":
			url = "../couponsnew/sign-in.php";
			wdth = 600;
		break;
		case "Sign up to Bizymoms Coupons":
			url = "../couponsnew/sign-up.php";
			wdth = 600;
		break;
		case "Stay up to date with the coupons you love":
			url = "../couponsnew/stay-intuned.php";
			wdth = 600;
		break;
		case "Help us help you save more, send us your feedback":
			url = "../couponsnew/send-feedback.php";
			wdth = 600;
		break;
		case "Log Out":
			url = "../couponsnew/log-out.php";
			wdth = 600;
		break;
		case "Print this coupon":
			url = "../couponsnew/print-coupon.php?cId="+id;
			wdth = 600;
		break;
		case "Spread the joy, share the coupon with your friends":
			url = "../couponsnew/share-coupon.php?cId="+id;
			wdth = 600;
		break;
		case "Report Coupon":
			url = "../couponsnew/report-coupon.php?cId="+id;
			wdth = 600;
		break;
		case "What do you think of this coupon?":
			url = "../couponsnew/review-coupon.php?cId="+id;
			wdth = 600;
		break;
		case "Terms and Conditions":
			url = "../couponsnew/show-conditions.php?cId="+id;
			wdth = 600;
		break;
		case "Print All Coupons":
			url = "../couponsnew/print-all-coupons.php";
			wdth = 600;
		break;
		case "Create Coupon Image":
			url = "../couponsnew/select-template.php";
			wdth = 600;
		break;
		case "Print Selected Coupons":
			url = "../couponsnew/print-all-coupons.php?couponIds="+id;
			wdth = 600;
		break;
		case "View Bizymom coupon categories":
			url = "../couponsnew/list-all-subcategories.php?cType="+id;
			wdth = 600;
		break;
		case "Post a widget and Promote this coupon":
			url = "../couponsnew/promote-coupon.php?cId="+id;
			wdth = 600;
		break;
		case "Post a widget and Promote your business":
			url = "../couponsnew/promote-profile.php?mId="+id;
			wdth = 600;
		break;
		case "Spread the joy, share the coupon(s) with your friends":
			var couponIds = [];
			var fieldobj = document.getElementsByName('cbs[]');
			for (var i=0; i < fieldobj.length; i++)	{
				if (fieldobj[i].checked) {
					couponIds.push(fieldobj[i].id);
				}
			}
			if(couponIds == "") {
				alert("Please select one or more coupons");
				return false;
			}
			//alert(couponIds);
			url = "../couponsnew/share-coupon.php?cId="+couponIds;
			wdth = 600;
		break;
	}
	document.getElementById('dvPopupBody').innerHTML = "<IFRAME SRC='"+url+"' width='"+wdth+"' marginheight='0' marginwidth='0' height='120' frameborder='0' scrolling='no' id='frmPopup'></IFRAME>";
	document.getElementById('dvPopup').style.display = 'block';
	document.getElementById('dvPopupTitle').innerHTML = act;
	var fTop = (screen.height)/10;
	var fLeft = ((screen.width)-(wdth+22))/2;
	if(navigator.appName == "Netscape") {
		document.getElementById('dvPopup').style.top = window.pageYOffset+fTop+'px';
		document.getElementById('dvPopup').style.left = window.pageXOffset+fLeft+'px';
	} else {
		document.getElementById('dvPopup').style.top = document.documentElement.scrollTop+fTop+'px';
		document.getElementById('dvPopup').style.left = document.documentElement.scrollLeft+fLeft+'px';
	}
}
function displayForms(str) {
	result = str.split("<split>");
	var fTop = (screen.height)/6;
	var fLeft = ((screen.width)-540)/2;
	if(navigator.appName == "Netscape") {
		document.getElementById("dvForms").style.top = window.pageYOffset+fTop+'px';
		document.getElementById("dvForms").style.left = window.pageXOffset+fLeft+'px';
	} 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 newForm(request) {
	xmlhttpPost('ajax/processAjax.php','action=NewForm&sec='+request,displayForms,'Loading '+request+' Form.<br>Please wait...');
}
function confirmForgotPass(str) {
	closePopup();
	displayMessage(str+'<br><br><input name="btnClose" type="button" class="button" id="btnClose" value="Close" onClick="parent.closeMessage()">');
}
function deleteCoupon(cId){
	if(!confirm("Are you sure you want to delete this coupon?")) {
		return false;	
	} else {
		window.location = "control-panel.php?act=delete&cId="+cId;	
	}
}
