<!--
String.prototype.trim = function () {
    return this.replace(/^\s*/, "").replace(/\s*$/, "");
}
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_preloadImages() { //v3.0
 var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
   var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
   if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function toggleCategorySelection(url) {
	var show_selection_box = document.getElementById('show_selection_box');
	var sort_selection_box = document.getElementById('sort_selection_box');
	var show_category_box = document.getElementById('show_category_box');
	
	var show_selection_id = show_selection_box.options[show_selection_box.selectedIndex].value;
	var sort_selection_id = sort_selection_box.options[sort_selection_box.selectedIndex].value;
	var page_id = document.getElementById('pageid').innerHTML;
	var url = show_category_box.options[show_category_box.selectedIndex].value;
	
	if (show_selection_id != "hot_coupons" || sort_selection_id != "sortbystore") {
		url = url + '/' + show_selection_id + '/' + sort_selection_id + '/';
	}
	location.href = url;
}
function toggleLayout(url) {
	var show_selection_box = document.getElementById('show_selection_box');
	var sort_selection_box = document.getElementById('sort_selection_box');
	
	var show_selection_id = show_selection_box.options[show_selection_box.selectedIndex].value;
	var sort_selection_id = sort_selection_box.options[sort_selection_box.selectedIndex].value;
	var page_id = document.getElementById('pageid').innerHTML;
	
	if (show_selection_id != "hot_coupons" || sort_selection_id != "sortbystore") {
		url = url + '/' + show_selection_id + '/' + sort_selection_id + '/';
	}
	location.href = url;
}
function toggleStoreLayout(url, ysnShowCode) {
	var sort_selection_box = document.getElementById('sort_selection_box');
	var sort_selection_id = sort_selection_box.options[sort_selection_box.selectedIndex].value;
	if (ysnShowCode != '')
		url = url + '/' + sort_selection_id + '/false';
	else
		url = url + '/' + sort_selection_id + '/';

	location.href = url;
}
function reportGenericBrokenCoupon(mid, pid) {
	if (!pid) pid = 0;
	width = 325;
	height = 325;
	left = 0;
	wtop = 0;
	window.open('/forms/reportbrokencoupon.php?mid=' + mid + '&pid=' + pid, 'BrokenCouponStore' + mid, 'width=' + width + ', height=' + height + ', left=' + left + ', top=' + wtop + ', location=no, menubar=no, status=no, toolbar=no, scrollbars=yes, resizable=yes');
}
function reportBrokenCoupon(cid) {
	width = 325;
	height = 325;
	left = 0;
	wtop = 0;
	window.open('/forms/reportbrokencoupon.php?mcid=' + cid, 'BrokenCouponID' + cid, 'width=' + width + ', height=' + height + ', left=' + left + ', top=' + wtop + ', location=no, menubar=no, status=no, toolbar=no, scrollbars=yes, resizable=yes');
}
function reportBrokenCouponProd(cid, pid) {
	width = 325;
	height = 325;
	left = 0;
	wtop = 0;
	window.open('/forms/reportbrokencoupon.php?mcid=' + cid + '&pid=' + pid, 'BrokenCouponProdID' + cid, 'width=' + width + ', height=' + height + ', left=' + left + ', top=' + wtop + ', location=no, menubar=no, status=no, toolbar=no, scrollbars=yes, resizable=yes');
}
function rateItem(id, type) {
	width = 325;
	height = 400;
	left = 0;
	wtop = 0;
	window.open('/forms/giverating.php?id=' + id + '&type=' + type, 'Rate' + type + id, 'width=' + width + ', height=' + height + ', left=' + left + ', top=' + wtop + ', location=no, menubar=no, status=no, toolbar=no, scrollbars=yes, resizable=yes');
}
function submitTag(type,id,tag) {
	width = 325;
	height = 100;
	left = 0;
	wtop = 0;
	if (tag.trim()=='') {
		alert('Please enter a valid tag.');
	} else {
		window.open('/forms/submittag.php?' + escape(type) + '=' + id + '&tag=' + escape(tag), 'TagID' + id, 'width=' + width + ', height=' + height + ', left=' + left + ', top=' + wtop + ', location=no, menubar=no, status=no, toolbar=no, scrollbars=yes, resizable=yes');
	}
}
function submitCoupon(mid,code,mclink,desc,expir,userid) {
	width = 325;
	height = 100;
	left = 0;
	wtop = 0;
	if ((code.trim()=='' && mclink.trim()=='') || desc.trim()=='') {
		alert('Please enter a coupon code or link and a description of the coupon.');
	} else {
		window.open('/forms/submitcoupon.php?mid=' + mid + '&code=' + escape(code) + '&link=' + escape(mclink) + '&desc=' + escape(desc) + '&expir=' + escape(expir) + '&userid=' + escape(userid), 'SubmitCoupon' + mid, 'width=' + width + ', height=' + height + ', left=' + left + ', top=' + wtop + ', location=no, menubar=no, status=no, toolbar=no, scrollbars=yes, resizable=yes');
	}
}
function openMerchantCoupon(cid) {
	width = 340;
	height = 425;
	left = 0;
	wtop = 0;
	window.open('/categories/coupons/couponpoptop.php?mcid=' + cid, 'CouponCode' + cid, 'width=' + width + ', height=' + height + ', left=' + left + ', top=' + wtop + ', location=no, menubar=no, status=no, toolbar=no, scrollbars=yes, resizable=yes');
}
function openMerchantProductCoupon(cid, pid) {
	width = 340;
	height = 450;
	left = 0;
	wtop = 0;
	window.open('/categories/coupons/couponpoptop2.php?mcid=' + cid + '&pid=' + pid, 'CouponCode' + cid, 'width=' + width + ', height=' + height + ', left=' + left + ', top=' + wtop + ', location=no, menubar=no, status=no, toolbar=no, scrollbars=yes, resizable=yes');

}
function openRedeemOffer(cid) {
	openMerchantCoupon(cid);
	window.location = '/redeemoffer.php?mc_offer=' + cid;
}
function openRedeemProductOffer(cid, pid) {
	openMerchantProductCoupon(cid, pid);
	window.location = '/redeemoffer.php?mc_offer='  + cid + '&p_offer=' + pid;
}
function openMerchantCouponNoCode(cid) {
	width = 325;
	height = 300;
	left = 0;
	wtop = 0;
	window.open('/categories/coupons/couponconfirmation_nocode.php?mcid=' + cid, 'CouponConf' + cid, 'width=' + width + ', height=' + height + ', left=' + left + ', top=' + wtop + ', location=no, menubar=no, status=no, toolbar=no, scrollbars=yes, resizable=yes');
}
function submitCouponComments(cid) {
	width = 325;
	height = 325;
	left = 0;
	wtop = 0;
	window.open('/forms/submitcouponcomment.php?mcid=' + cid, 'CouponComments' + cid, 'width=' + width + ', height=' + height + ', left=' + left + ', top=' + wtop + ', location=no, menubar=no, status=no, toolbar=no, scrollbars=yes, resizable=yes');
}
function saveCoupon(cid,type,userid) {
	width = 325;
	height = 250;
	left = 0;
	wtop = 0;
	window.open('/forms/savecoupon.php?mcid=' + cid, 'CouponSave' + cid, 'width=' + width + ', height=' + height + ', left=' + left + ', top=' + wtop + ', location=no, menubar=no, status=no, toolbar=no, scrollbars=yes, resizable=yes');

	if (type == 'merchant' && userid != '0') {
		document.getElementById('saveoptions' + cid).innerHTML = 'Saved<img src="http://www.selectaware.net/images/coupon/confirmsave_icon.gif" border="0" style="vertical-align:bottom;" height="13" width="14">';
	}
}
function signUpForAlerts(mid,email_elt,ysnNews_elt) {
	if (validateEmail(email_elt)) {
		email = document.getElementById(email_elt).value;
		ysnNews = document.getElementById(ysnNews_elt).value;
		width = 325;
		height = 325;
		left = 0;
		wtop = 0;
		window.open('/forms/alertsignup.php?mid=' + mid + '&email=' + encodeURIComponent(email) + '&ysnNews=' + ysnNews, 'AlertSignup' + mid, 'width=' + width + ', height=' + height + ', left=' + left + ', top=' + wtop + ', location=no, menubar=no, status=no, toolbar=no, scrollbars=yes, resizable=yes');
	}
}
function removeSavedCoupon(cid) {
	width = 325;
	height = 150;
	left = 0;
	wtop = 0;
	window.open('/forms/removesavedcoupon.php?mcid=' + cid, 'RemoveSavedCoupon' + cid, 'width=' + width + ', height=' + height + ', left=' + left + ', top=' + wtop + ', location=no, menubar=no, status=no, toolbar=no, scrollbars=yes, resizable=yes');
}
function showCouponComments(coupon_id) {
	var obj = document.getElementById(coupon_id + '_comments');
	if (obj.style.display == 'none' || obj.style.display == '') {
		agt = navigator.userAgent.toLowerCase();
		if (agt.indexOf("msie") != -1) {	
			obj.style.display = 'inline-block';
		} else {
			obj.style.display = 'block';
		}
		//obj.style.visibility = 'visible';
	} else {
		closeCouponComments(coupon_id);
	}
}	
function closeCouponComments(coupon_id) {
	var obj = document.getElementById(coupon_id + '_comments');
	obj.style.display = 'none';
	//obj.style.visibility = 'hidden';
}	
function showLargerImage(e) {
	if(document.all)e = event;
	var obj = document.getElementById("prodpopimage");
	obj.style.display = 'block';
	
	var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0; 
	var leftPos = e.clientX;
	if(leftPos<0) leftPos = 0;
	var topPos = e.clientY;
	if(topPos<0) topPos = 0;
	obj.style.left = leftPos + 'px';
	obj.style.top = topPos + 'px';
}
function hideLargerImage() {
	document.getElementById('prodpopimage').style.display = 'none';
}
function showCouponToolTip(e,m_name,code) {
	if(document.all)e = event;
	
	if (code != "" && code.toLowerCase() != "coupon") { 
		var obj = document.getElementById('cctooltip');
		var obj2 = document.getElementById('cctooltip_content');	
		obj2.innerHTML = obj2.innerHTML.replace('{M_NAME}',m_name);
		obj2.innerHTML = obj2.innerHTML.replace('{CODE}',code);
		if (m_name == 'Brookstone') { 
			obj2.innerHTML = obj2.innerHTML.replace('coupon code','promotion code');
		}
	} else {
		var obj = document.getElementById('autctooltip');
		var obj2 = document.getElementById('autctooltip_content');	
		obj2.innerHTML = obj2.innerHTML.replace('{M_NAME}',m_name);	
	}
	obj.style.display = 'block';
	var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0; 
	var leftPos = e.clientX;
	if(leftPos<0)leftPos = 0;
	obj.style.left = leftPos + 'px';
	obj.style.top = e.clientY - obj.offsetHeight -13 + st + 'px';
}	
function hideCouponToolTip() {
	var obj = document.getElementById('autctooltip_content');
	var obj2 = document.getElementById('cctooltip_content');
	obj.innerHTML = obj.innerHTML = 'To use this coupon, click the "view this item" button and your coupon will be automatically applied at the {M_NAME} website. Simply add it to your shopping cart or continue to checkout to see the total savings.';
	obj2.innerHTML = obj2.innerHTML = 'To use this coupon, click the "view this item" button, and you will be prompted to enter the coupon code <span style="font-weight:bold;color:#067900;font-size:9pt;">{CODE}</span> in the shopping cart or during the checkout process at the {M_NAME} website.';
	document.getElementById('cctooltip').style.display = 'none';
	document.getElementById('autctooltip').style.display = 'none';
}
function showMDesc(e,mid) {
	if(document.all)e = event;
	
	var obj = document.getElementById(mid);
	obj.style.display = 'block';
	var st = Math.max(document.body.scrollTop,document.documentElement.scrollTop);
	if(navigator.userAgent.toLowerCase().indexOf('safari')>=0)st=0; 
	var leftPos = e.clientX;
	if(leftPos<0)leftPos = 0;
	obj.style.left = leftPos + 'px';
	obj.style.top = e.clientY - obj.offsetHeight -13 + st + 'px';
}
function showAMZReviews(amz_asin, amz_link) {
	returnAJAXGetRequest('/products/get_amz_reviews.php?asin=' + amz_asin, function() {
		if (xmlHttpReq.readyState == 4 && xmlHttpReq.status == 200) {
			var reviews = xmlHttpReq.responseXML.documentElement.getElementsByTagName("review");
    		for (i = 0; i < reviews.length; i++) {
				div = document.createElement('div');
				div.setAttribute('class', 'reviews');
				div.setAttribute('className', 'reviews');
				
				content = reviews[i].getElementsByTagName("content");
				fullname = reviews[i].getElementsByTagName("name");
				date = reviews[i].getElementsByTagName("date");
				rating = reviews[i].getElementsByTagName("rating");
				place = reviews[i].getElementsByTagName("location");
				
				{
					try {
						innText = '"' + content[0].firstChild.nodeValue + '"<br>\n<br>\n';
						innText += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
						
						for (j = 0; j < rating[0].firstChild.nodeValue; j++) {
							innText += "<img src=\"http://www.selectaware.net/images/coupon/ratestar.gif\" class=\"rateimg\" style=\"vertical-align:top\">&nbsp;";
						}
						for (j = 0; j < (5-rating[0].firstChild.nodeValue); j++) {
							innText += "<img src=\"http://www.selectaware.net/images/coupon/nratestar.gif\" class=\"rateimg\" style=\"vertical-align:top\">&nbsp;";
						}
          				innText += '&nbsp;';
						
						innText += date[0].firstChild.nodeValue + ' by ' + fullname[0].firstChild.nodeValue;
						
						if (place[0].firstChild)
							innText += ' (' + place[0].firstChild.nodeValue + ')';
					}  catch (err) {
						//alert(err);
						innText = '"' + content + '"<br>\n<br>\n';
						innText += '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
						
						for (j = 0; j < rating; j++) {
							innText += "<img src=\"http://www.selectaware.net/images/coupon/ratestar.gif\" class=\"rateimg\" style=\"vertical-align:top\">&nbsp;";
						}
						for (j = 0; j < (5-rating); j++) {
							innText += "<img src=\"http://www.selectaware.net/images/coupon/nratestar.gif\" class=\"rateimg\" style=\"vertical-align:top\">&nbsp;";
						}
          				innText += '&nbsp;';
						
						innText += date + ' by ' + fullname;
						
						if (place)
							innText += '(' + place + ')';
					}
				}
				
				div.innerHTML = innText;
				document.getElementById('amz_reviews').appendChild(div);
			}
			if (reviews.length > 0) {
				div = document.createElement('div');
				div.setAttribute('class', 'productlongdescrip');	
				div.setAttribute('className', 'productlongdescrip');	
				
				innText = '<img src="http://www.selectaware.net/images/coupon/genericcouponarrowside.gif" border="0" width="6" height="8" alt="=>"> <a target="_blank" href="' + amz_link + '">See more Amazon reviews</a>';
				
				div.innerHTML = innText;
				document.getElementById('amz_reviews').appendChild(div);
				
				document.getElementById('amz_reviews').style.display = "block";
				document.getElementById('amz_reviews').style.visibility = "visible";
				document.getElementById('showprodreviews').style.display = "inline";
				document.getElementById('showprodreviews').style.visibility = "visible";
				if (!isNaN(document.getElementById('numprodreviews').innerHTML))
					document.getElementById('numprodreviews').innerHTML = parseInt(document.getElementById('numprodreviews').innerHTML) + reviews.length;
				else
					document.getElementById('numprodreviews').innerHTML = reviews.length;
			}
		}
	});			
}
function hideMDesc(mid) {
	document.getElementById(mid).style.display = 'none';
}
function validateEmail(elt_name) {
	var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
	if (elt_name == '')
		elt_name = 'email';
	var email = document.getElementById(elt_name).value;
	if(reg.test(email) == false) {
		alert('Please enter a valid email address.');
		return false;
	} else {
		return true;
	}
}
function validatePassword(elt_name) {
	if (elt_name == '')
		elt_name = 'pw';
	var pw = document.getElementById(elt_name).value;
	if (pw.trim() && pw.trim().length > 5 && pw.trim().length < 21) {
		return true;
	} else {
		alert('Please enter a valid password.');
		return false;
	}
}
function validateNickname(elt_name) {
	if (elt_name == '')
		elt_name = 'nickname';
	var nickname = document.getElementById(elt_name).value;
	if (nickname.trim() && nickname.trim().length > 1 && nickname.trim().length < 26) {
		return true;
	} else {
		alert('Please enter a valid nickname.');
		return false;
	}
}
function bookmarkDelicious() {
	window.open('http://del.icio.us/post?v=4&noui&jump=close&url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'delicious','toolbar=no,width=700,height=400'); 
}
function stumbleIt() {
	window.open('http://www.stumbleupon.com/submit?url='+encodeURIComponent(location.href)+'&title='+encodeURIComponent(document.title), 'stumbleIt','width=790,height=530,location=no,menubar=no,status=no,toolbar=no,scrollbars=yes,resizable=yes'); 
}
function addToFavorites(ysnCurrentPage) {
	if (!ysnCurrentPage) {
		var url="http://www.selectaware.com";
		var title="SelectAware.com - Your Online Coupon Portal";
	} else {
		var url=location.href;
		var title=document.title;	
	}
		
	if (window.sidebar) { // Mozilla Firefox Bookmark
		window.sidebar.addPanel(title, url,"");
	} else if( window.external ) { // IE Favorite
		window.external.AddFavorite(url, title); 
	} else if(window.opera && window.print) { // Opera Hotlist
		return true;
	} else {
		var msg = "Don't forget to bookmark us!";
		alert(msg);
	}
}
function set_cookie(name, value, expires, path, domain, secure) {
	var today = new Date();
	today.setTime( today.getTime() );

	if (expires) {
		expires = expires * 1000 * 60 * 60 * 24;
	}
	var expires_date = new Date(today.getTime() + (expires));

	document.cookie = name + "=" + escape(value) +
		((expires) ? ";expires=" + expires_date.toGMTString() : "") +
		((path) ? ";path=" + path : "") +
		((domain) ? ";domain=" + domain : "") +
		((secure) ? ";secure" : "");
}
function returnAJAXGetRequest(url, cfunc) {
	if (url.length == 0)
		return null;
	
	if (window.XMLHttpRequest) {	// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlHttpReq = new XMLHttpRequest();
	} else {	// code for IE6, IE5
		xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
	}	
	
	xmlHttpReq.open("GET", url, true);
	xmlHttpReq.onreadystatechange = cfunc;
	xmlHttpReq.send();
}
//-->