////////
/// FUNCTIONS FILTERS BUTTONS
////////
var currentFilterDialog = null;
var currentFilterZoneHeight = 356;
var currentExpanding = true;
var currentFilterZone = null;
function showFilterButton(el, zone) {
if(currentFilterDialog == null) {//expand and show new dialog
el.className += " filterCouponButtonExpanded";
var div = document.getElementById("topCenter");
currentExpanding = true;
div.style['height'] = '464px';
//expandFilterZone.defer(10, this, [div]);
currentFilterDialog = el;
} else {
currentFilterDialog.className = currentFilterDialog.className.replace("filterCouponButtonExpanded", " ");
if(el == currentFilterDialog) {//must hide dialog
var div = document.getElementById("topCenter");
currentExpanding = false;
div.style['height'] = '356px';
currentFilterDialog = null;
} else {//show new dialog
el.className += " filterCouponButtonExpanded";
currentFilterDialog = el;
}
}
showFilterDialog(zone);
}
function showFilterDialog(zone) {
if(currentFilterZone != null) {
document.getElementById("filter"+currentFilterZone).style["display"] = "none";
}
if(zone != currentFilterZone) {
var div = document.getElementById("filter"+zone);
div.style['display'] = 'block';
currentFilterZone = zone;
} else {
currentFilterZone = null;
}
}
function expandFilterZone(el) {
var bContinue = true;
var nextFilterZoneHeight;
if(currentExpanding) {
//nextFilterZoneHeight = currentFilterZoneHeight + 7;
nextFilterZoneHeight = 464;
if(nextFilterZoneHeight >= 464) {
nextFilterZoneHeight = 464;
bContinue = false;
}
} else {
//nextFilterZoneHeight = currentFilterZoneHeight - 7;
nextFilterZoneHeight = 356;
if(nextFilterZoneHeight <= 356) {
nextFilterZoneHeight = 356;
bContinue = false;
}
}
if(bContinue) {
expandFilterZone.defer(10, this, [el]);
}
el.style['height'] = (nextFilterZoneHeight)+'px';
currentFilterZoneHeight = nextFilterZoneHeight;
}
////////
/// END OF FUNCTIONS FILTERS BUTTONS
////////
////////
/// FUNCTIONS DETAIL IMAGE POP UP
////////
var currentCoupon = null;
var currentlyDetailBoxVisible = false;
function onMouseOverCoupon(el) {
if(el.getAttribute("detailImagePath") != "") {
currentCoupon = el.id.split("_")[1];
showCouponDetailBox.defer(500, this, [currentCoupon, el.getAttribute("detailImagePath"), el]);
}
}
function onMouseOutCoupon(el) {
var couponid = el.id.split("_")[1];
if(currentCoupon == couponid) {
hideCouponDetailBox.defer(25);
}
currentCoupon = null;
}
function showCouponDetailBox(CouponID, ImagePath, el) {
if(currentCoupon == CouponID) {
var windowWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
var windowHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
var curYScrollPos = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
currentlyDetailBoxVisible = true;
var divImage = document.getElementById("detailImage");
if(Ext.isIE) {
divImage.src = ImagePath;
divImage.height = el.getAttribute("thumbHeight");
divImage.width = el.getAttribute("thumbWidth");
var divBox = document.getElementById("detailImageBox");
var couponImage = Ext.get(el).getXY();
var topClass = "";
var yOffset = 35;
if(couponImage[1]+430-curYScrollPos > windowHeight) {
topClass = "Top";
yOffset = 300;
}
if(couponImage[0]+553 < windowWidth) {
divBox.style['left'] = (couponImage[0]+130)+'px';
divBox.className = "detailImageBox"+topClass+"";
} else {
divBox.style['left'] = (couponImage[0]-400)+'px';
divBox.className = "detailImageBox"+topClass+"Left";
}
divBox.style['top'] = (couponImage[1]-yOffset)+'px';
divBox.style["display"] = "inline";
} else {
divImage.src = ImagePath;
divImage.height = el.getAttribute("thumbHeight");
divImage.width = el.getAttribute("thumbWidth");
var divBox = document.getElementById("detailImageBox");
var couponImage = Ext.get(el).getXY();
var topClass = "";
var yOffset = 35;
if(couponImage[1]+430-curYScrollPos > windowHeight) {
topClass = "Top";
yOffset = 300;
}
if(couponImage[0]+553 < windowWidth) {
divBox.style['left'] = (couponImage[0]+130)+'px';
divBox.className = "detailImageBox"+topClass+"";
} else {
divBox.style['left'] = (couponImage[0]-400)+'px';
divBox.className = "detailImageBox"+topClass+"Left";
}
divBox.style['top'] = (couponImage[1]-yOffset)+'px';
divBox.style["display"] = "inline";
}
} else {
}
}
function hideCouponDetailBox() {
if(currentlyDetailBoxVisible) {
document.getElementById("detailImage").src = "/styles/default/images/spacer.gif";
document.getElementById("detailImageBox").style["display"] = "none";
}
}
////////
/// END OF FUNCTIONS DETAIL IMAGE POP UP
////////
////////
/// FUNCTIONS BOTTOM TASK BAR
////////
if(Ext.isIE6) {
window.onscroll = positionTaskBar;
window.onresize = positionTaskBar;
positionTaskBar();
function positionTaskBar() {
var curPos = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
var maxHeight = window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight;
var taskBarYPos = (maxHeight + curPos - 50) +'px';
var taskBar = document.getElementById("bottomTaskBar");
if(taskBar != null) {
taskBar.style["top"] = taskBarYPos;
}
positionSigninBox();
}
} else {
window.onresize = function() {
positionSigninBox();
}
}
////////
/// END OF FUNCTIONS BOTTOM TASK BAR
////////
function facebookLogout() {
if(FB.Connect.get_status().result == 1) {
FB.Connect.logoutAndRedirect('/modules/security/logout.php');
} else {
document.location.href = '/modules/security/logout.php';
}
}
function removeCoupon(couponId) {
executeToggleItem(couponId, 0, function(o, s, r) {
var results = Ext.decode(r.responseText);
var div = document.getElementById("Coupon_"+results.CouponID);
if(div != null) {
div.style["display"] = "none";
}
var div2 = document.getElementById('CurrentCouponCount');
if(div2 != null) {
div2.innerHTML = parseInt(document.getElementById('CurrentCouponCount').innerHTML) - 1;
}
});
}
function executeToggleItem(couponId, state, callback) {
Ext.Ajax.request({
url: "/modules/coupons/coupon.add.php?checked="+state+"&CouponID="+couponId,
method: 'GET',
callback: callback
});
}
function printSelections() {
if(document.location.href.indexOf("/modules/cart/index.php") >= 0) {
document.location.href = "/modules/cart/cart.print.php";
} else {
document.location.href = "/modules/cart/index.php";
}
}
function addItem(field) {
if(typeof field == "string") {
field = document.getElementById(field);
}
executeToggleItem(field.getAttribute("CouponID"), field.getAttribute("State"), function(o, s, r) {
if(s) {
var results = Ext.decode(r.responseText);
var field = document.getElementById("Coupon_"+results.CouponID);
if(field.getAttribute("State") == "1") {
document.getElementById("checkbox_"+results.CouponID).style['backgroundPosition'] = 'top';
field.setAttribute("State", 0);
} else {
document.getElementById("checkbox_"+results.CouponID).style['backgroundPosition'] = 'bottom';
field.setAttribute("State", 1);
}
div = document.getElementById("currentSavings");
if(div != null) {
div.innerHTML = results.NewSaving;
}
}
});
}
var coupons = new Array();
function closeCouponDetailsImage() {
var div = document.getElementById("detailImageDiv");
document.getElementById("detailImage").src = "/styles/default/images/spacer.gif";
div.style["display"] = "none";
}
function showCouponDetailsImage(couponId, imagePath) {
var div = document.getElementById("detailImageDiv");
if(div == null) {
div = document.createElement('div');
div.setAttribute('id', 'detailImageDiv');
div.setAttribute('class', 'ToolTipWrapper');
div.setAttribute('style', 'text-align: center;display: none;position: absolute;border:1px solid black;height: 400px; width: 310px;z-index: 100000;background-color:white;');
div.innerHTML = "
";
document.body.appendChild(div);
}
if(Ext.isIE) {
document.getElementById("detailImage").src = imagePath;
//document.getElementById("detailImageDiv").style['width'] = (this.width + 25)+'px';
//document.getElementById("detailImageDiv").style['height'] = (this.height + 25)+'px';
var size = getScreenSize();
var div = document.getElementById("detailImageDiv");
var offset = window.pageYOffset || document.documentElement.scrollTop || 0; var scrollLeft = window.pageXOffset || document.documentElement.scrollLeft || 0;
div.style["top"] = (((size.height - 350 + 25) / 2) + offset).toString() + "px";
div.style["left"] = ((size.width - 200 + 25) / 2).toString() + "px";
div.style["display"] = "";
} else {
document.getElementById("detailImage").onload = function() {
if(this.width > 1) {
document.getElementById("detailImageDiv").style['width'] = (this.width + 25)+'px';
document.getElementById("detailImageDiv").style['height'] = (this.height + 25)+'px';
var size = getScreenSize();
var div = document.getElementById("detailImageDiv");
div.style["top"] = (((size.height - this.height + 25) / 2) + window.pageYOffset).toString() + "px";
div.style["left"] = ((size.width - this.width + 25) / 2).toString() + "px";
div.style["display"] = "";
}
}
document.getElementById("detailImage").src = imagePath;
}
}
function getScreenSize() {
var myWidth = 0, myHeight = 0;
if( typeof( window.innerWidth ) == 'number' ) {
//Non-IE
myWidth = window.innerWidth;
myHeight = window.innerHeight;
} else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
//IE 6+ in 'standards compliant mode'
myWidth = document.documentElement.clientWidth;
myHeight = document.documentElement.clientHeight;
} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
//IE 4 compatible
myWidth = document.body.clientWidth;
myHeight = document.body.clientHeight;
}
return {width:myWidth, height:myHeight};
}
try {
if(Ext != null) {
Ext.onReady(function() {
Ext.EventManager.addListener(window, "keypress", function(e) {
if(e.getKey() == 27) {
closeCouponDetailsImage();
}
});
});
}
} catch(Ex) {
}
function shareFacebook(couponId, line1, line2, image, saveText) {
writeToWall(line1+' '+line2+' '+saveText, 'http://www.couponclick.ca/'+image, 'http://www.couponclick.ca/coupon.php?id='+couponId);
}
function writeToWall(msg, img, lnk) {
var attachment = {
'name': 'Couponclick.ca',
'href': lnk,
'description':msg,
'media': [
{
'type':'image',
'src':img + '',
'href':lnk + ''
}
]
};
if(FB.Connect.get_status().result == 1) {//connected
FB.Connect.streamPublish('', attachment);
} else {//not connected
FB.Connect.streamPublish('', attachment, null, null, '', function() {
switch(FB.Connect.get_status().result) {
case 1://user is connected... refresh to link accounts
document.location.href = '/modules/users/register.form.php';
break;
case 2://not connected, most likely user canceled publish
//do nothing
break;
case 3://app not accepted
//do nothing
break;
}
});
}
}
function onFacebookLogout() {
alert('Logedout');
document.location.href = '/modules/logout.php';
}
function onFacebookConnect() {
document.location.href = '/modules/users/register.form.php';
}
function signup() {
document.location.href = '/modules/users/register.form.php';
}
var signinBoxVisible = false;
function signin() {
var div = document.getElementById("signinBox");
if(div != null) {
if(signinBoxVisible) {
div.style['display'] = 'none';
} else {
div.style['display'] = 'block';
positionSigninBox(div);
}
signinBoxVisible = !signinBoxVisible;
}
}
function positionSigninBox(div) {
if(div == undefined) {
div = document.getElementById("signinBox");
}
var btn = Ext.get("signinButton");
if(div != null && btn != null) {
var btnPos = btn.getXY();
/* if(Ext.isSafari) {
div.style['left'] = (btnPos[0]-50)+'px';
} else {*/
div.style['left'] = (btnPos[0]-87)+'px';
//}
div.style['top'] = (btnPos[1]+32)+'px';
}
}
var couponEl = null;
var oldParams;
function showCoupons(el, params) {
couponEl = el;
params = Ext.applyIf(params, oldParams);
oldParams = params;
Ext.Ajax.request({
url: '/modules/coupons/coupon.view.php',
params: params,
method: 'GET',
callback: function(o, s, r) {
if(s) {
var results = Ext.decode(r.responseText);
var div = document.getElementById(couponEl);
div.innerHTML = results.content;
var pubDiv = document.getElementById("pubCouponHolder");
if(pubDiv != null) {
pubDiv.innerHTML = document.getElementById("pubPlaceholder").innerHTML;
}
if(results.location != "") {
if(results.location.length > 18) {
switch(results.location.length) {
case 19:
case 20:
case 21:
document.getElementById("filterLocationValue").style.fontSize = '10pt';
break;
case 22:
case 23:
case 24:
document.getElementById("filterLocationValue").style.fontSize = '9pt';
break;
case 25:
case 26:
case 27:
document.getElementById("filterLocationValue").style.fontSize = '7pt';
break;
default:
document.getElementById("filterLocationValue").style.fontSize = '6pt';
break;
}
} else {
document.getElementById("filterLocationValue").style.fontSize = '';
}
document.getElementById("filterLocationValue").innerHTML = results.location;
}
if(results.filters.brand != "") {
document.getElementById("brandSection").innerHTML = results.filters.brand;
}
if(results.filters.retailer != "") {
document.getElementById("retaillerSection").innerHTML = results.filters.retailer;
}
}
}
});
}
function orderBy(v) {
if(couponEl != null) {
showCoupons(couponEl, {orderBy: v});
}
}
var currentFilters = {category: new Array(), location: '', brand: new Array(), retailer: new Array()};
function setFilterConfig(objName, chkBox, updateList) {
if(chkBox.checked) {//add
var bFound = false;
for(var i=0;i