var context = "";
var sorryMessage = "This site is under construction. Please try again later.";


function searchStores() {
	var obj = getHtmlControl("StoreKeyword");
	load(context + "/cashback/store-search?kwd=" + obj.value);
}

function searchOnEnter(inputField, e) {
	var keyCode;
	if (window.event) keyCode = window.event.keyCode;
	else if (e) keyCode = e.which;
	else return true;
	
	if (keyCode == 13) {
		searchStores();
		return false;
	}
	else {
	   return true;
	}
}

function login() {
	load(context + "/cashback/login");
}

function signup() {
	load(context + "/cashback/login");
}

function openCoupon(couponId, storeId, type) {
	if  (isUndefined(type) || type == 1) {
		openNewTab(context + "/cashback/visit-store?v=c" + couponId);
	} else {
	//	showMessageTimed("Please wait while we locate the selected coupon on store site...", 7000);
		storewin = shopAtStore(storeId);
		var page = context + "/cashback/visit-store?v=c" + couponId;
		setTimeout("locatePage(storewin,'" + page + "')", 5000);
	}
}


function showClippedCoupon() {
	openNewTab(context + "/cashback/clipped-coupons");
}

function shopAtStore(storeId) {
	return openNewTab(context + "/cashback/visit-store?v=s" + storeId);
}


//function openCoupon(couponId, storeId, type) {
//	alert(sorryMessage);
//}

//function shopAtStore(){
//	alert(sorryMessage);
//}

function load(url) {
	window.location.href =url;
}

function locatePage(win, url) {
	win.location.href = url;
}

function switchDeal(obj) {
	this.innerHTML='';
	var el = document.getElementById(obj);
	if ( el.style.display != "none" ) {
		el.style.display = 'none';
	}
	else {
		el.style.display = '';
	}
}

function handleOver() {
	if (document.images) document.imgName.src=img_on.src;
}

function handleOut() {
	if (document.images) document.imgName.src=img_off.src;
}

function showDiv(objectID) {
	var theElementStyle = document.getElementById(objectID);
	if(theElementStyle.style.display == "block"){
		theElementStyle.style.display = "none";
	}else{
		theElementStyle.style.display = "block";
	}
}

function getPageOffsetLeft(el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) {
		ol += el.offsetLeft;
	}
	return ol;
}

function getPageOffsetTop(el) {
	var ol=el.offsetTop;
	while ((el=el.offsetParent) != null) {
		ol += el.offsetTop;
	}
	return ol;
}

function showMessage(text){
	showMessageTimed(text, 3000);	// default delay of 3 sec
}

function hideMessage(){
	var msgBox = getHtmlControl("popupMessage");
	msgBox.style.display = "none";
}

function showMessageTimed(text, delay){
	if (isUndefined(delay) || delay < 2000 || delay > 9000) {
		delay = 2000;
	}
	var msgBox = getHtmlControl("popupMessage");
	msgBox.innerHTML = text;
	if (isIE()) {
		msgBox.style.top = document.documentElement.scrollTop;
		msgBox.style.left = document.documentElement.scrollLeft;
	} else {
		msgBox.style.top = window.pageYOffset + 'px';
		msgBox.style.left = window.pageXOffset + 'px';
	}
	msgBox.style.display="block";
	setTimeout("hideMessage()", delay);
}


function writeReview(storeId) {
	openNewTab(context + "/cashback/write-review?s="+storeId);
}

