
var ie=document.all;var discountObj=null;function checkcoupons(){var zip=document.getElementById('zip');checkcoupons_xmlHttp=GetXmlHttpObject();if(checkcoupons_xmlHttp==null)
{alert("Browser does not support HTTP Request");return;}
if(checkcoupons_xmlHttp.readyState!=0){checkcoupons_xmlHttp.abort();alert("xmlHttp was aborted because xmlHttp.readyState != 0");}
var url="../Scripts/search_coupons.php";url+="?zip="+zip.value;checkcoupons_xmlHttp.open("GET",url,true);checkcoupons_xmlHttp.onreadystatechange=stateChanged_checkCoupons;checkcoupons_xmlHttp.send(null);}
function stateChanged_checkCoupons(){if(checkcoupons_xmlHttp.readyState==4||checkcoupons_xmlHttp.readyState=="completed"){var couponresponse=checkcoupons_xmlHttp.responseText;if(couponresponse=="-1"){showSuggestStores();}else{showAvailableCoupons(couponresponse);}}}
function showSuggestStores(){hideDiv('zipsearch');showDiv('enterstores');}
function showAvailableCoupons(coupons){hideDiv('zipsearch');showDiv('showcoupons');var zip=document.getElementById('zip').value;document.getElementById('thezip').appendChild(document.createTextNode(zip));cpns="("+coupons+")";var obj=eval(cpns);discountObj=obj;var disc=document.getElementById('discounts');for(var i=0;i<obj.discounts.length;i++){if(i>7)
break;var div=document.createElement('div');div.setAttribute('style','margin:5px 0;');var a=document.createElement('a');a.setAttribute('id',obj.discounts[i].discountid);try{var item=obj.discounts[i];var title=item.item_name;}catch(exp){}
a.appendChild(document.createTextNode(title));this.theItem=item;a.onclick=function(){addRowFromCollect(this);fadeMe("collectlocation");};div.appendChild(a);p=document.createElement('p');p.setAttribute('style','margin:0; padding:0;');p.appendChild(document.createTextNode(obj.discounts[i].description));div.appendChild(p);pp=document.createElement('p');pp.setAttribute('style','font-size:11px; margin:0; padding:0;');pp.appendChild(document.createTextNode(obj.discounts[i].merchantname));pp.appendChild(document.createElement('br'));pp.appendChild(document.createTextNode(obj.discounts[i].merchant_address));pp.appendChild(document.createElement('br'));pp.appendChild(document.createTextNode(obj.discounts[i].merchant_city+', '+obj.discounts[i].merchant_state));div.appendChild(pp);disc.appendChild(div);}}
function addRowFromCollect(obj){var a=document.getElementById(obj.id);addRowToTableHelper(a.firstChild.nodeValue,obj.id,a.firstChild.nodeValue,"0.05",false);addInfoBox(obj.id);}
function sendStoreInfo(){var info=document.getElementById('storeinfo');var zipcode=document.getElementById('zip').value;sendinfo_xmlHttp=GetXmlHttpObject();if(sendinfo_xmlHttp==null)
{alert("Browser does not support HTTP Request");return;}
if(sendinfo_xmlHttp.readyState!=0){sendinfo_xmlHttp.abort();alert("xmlHttp was aborted because xmlHttp.readyState != 0");}
var url="../Scripts/add_suggested_stores.php";info=info.value.replace(/^\s+|\s+$/g,'');url+="?info="+info;url+="&zip="+zipcode;sendinfo_xmlHttp.open("GET",url,true);sendinfo_xmlHttp.onreadystatechange=function(){if(sendinfo_xmlHttp.readyState==4||sendinfo_xmlHttp.readyState=="completed"){if(sendinfo_xmlHttp.responseText=="1"){hideDiv('enterstores');showDiv('sendsuccess');}}}
sendinfo_xmlHttp.send(null);}
function checkIE(){return(document.compatMode&&document.compatMode!="BackCompat")?document.documentElement:document.body;}
function getposOffset(overlay,offsettype){var totaloffset=(offsettype=="left")?overlay.offsetLeft:overlay.offsetTop;var parentEl=overlay.offsetParent;while(parentEl!=null){totaloffset=(offsettype=="left")?totaloffset+parentEl.offsetLeft:totaloffset+parentEl.offsetTop;parentEl=parentEl.offsetParent;}
return totaloffset;}
function showdivlayer(curobj,divID,showcpsearch){if(document.getElementById){var divobj=document.getElementById(divID);Effect.Appear(divID,{duration:.3});divobj.style.zIndex=4000;centerDiv(divID);try{if(document.getElementById('city').visibility=="visible")
document.getElementById('city').focus();}catch(exp){}
if(divID=='collectlocation'){if(!ie)
document.getElementById('zip').addEventListener('keypress',itemHandler,false);else
document.getElementById('zip').attachEvent('onkeypress',itemHandler);}
if(showcpsearch=='no'&&divID=='collectlocation'){hideDiv('zipsearch');showDiv('enterstores');hideDiv('nouser');hideDiv('showcoupons');showDiv('user');try{document.getElementById('storeinfo').focus();}catch(exp){}}
return false;}else{return true;}}
function centerDiv(divID){var divobj=document.getElementById(divID);var xpos=(document.body.clientWidth/2)-275;divobj.style.left=xpos+"px";}
function divlayerclose(divID){theDiv=document.getElementById(divID)
Effect.Fade(divID,{duration:.2});setItemsFocus();}
function getOpacity(divID,theDiv){if(divID!=''&&theDiv==null){theDiv=document.getElementById(divID);}
var opacity=-1;opacity=theDiv.style.opacity;if(opacity<0){if(theDiv.style.filter!=null){var tmp=theDiv.style.filter.replace('alpha(opacity=','');opacity=parseInt(tmp.replace(')',''));}else{opacity=0;}}
return opacity;}
function itemHandler(evt){if(evt.keyCode=='13'){checkcoupons();}
return true;}
function changeOpacity(obj,opacity){var ie=(document.all)?1:0;var p=(ie)?"filter":"MozOpacity";v=(ie)?"alpha(opacity="+opacity+")":opacity/100;obj.style[p]=v;}
function submitNotUser(){showdivlayer(this,'signup','');}
function fadeMe(div){theDiv=document.getElementById(div);changeOpacity(theDiv,40);window.setTimeout('fadeBack("'+div+'")',800)}
function fadeBack(div){theDiv=document.getElementById(div);changeOpacity(theDiv,100);}