var pWindow   = null;
var name = '';
var action = '';
function favWindow(){
   if( pWindow && !pWindow.closed ) { pWindow.close(); }
   pWindow = window.open( "", "favoritesWindow", "resizable=no,height=202,width=265,top=350,left=0, top=0" )
}
   
function confirmFavAdd() {
     displayConfirmAddFavBox('block');
     setTimeout("displayConfirmAddFavBox('none')",4000);
}
   
function displayConfirmAddFavBox(state) {
      var iebody=(document.compatMode && document.compatMode != "BackCompat")? document.documentElement : document.body;
      var dsoctop=document.all? iebody.scrollTop : pageYOffset;
    
      if(state == 'block') {
         var addBoxTextBlock = document.getElementById('confirmAddFavText');
         if(action == 'add') {
            document.getElementById('confirmAddFavBox').style.background = 'transparent url(/images/category/stores/popup_bground2.png)';
            addBoxTextBlock.style.fontSize = '10pt';
            addBoxTextBlock.innerHTML = "<div style='width:78%;position:relative; margin-top:30px; margin-left:30px; margin-right:15px;'><strong id='confirmAddFavStoreName'>"+name.replace("^","'")+"</strong> <br/> has been added to your favorites<div style='width:90%; margin-top:20px; margin-left:0px;'><img id='icon_exclamation' src='/images/category/stores/icon_checkmark.gif'/></div><a style='right:-5px;top:-11px;position:absolute;cursor:pointer;width:13px;height:13px;display:block;' onclick='hideconfirmbox();'></a></div>";
         }else if(action == 'acountfull') {
            document.getElementById('confirmAddFavBox').style.background = 'transparent url(/images/category/stores/popup_bground2.png)';
            addBoxTextBlock.style.fontSize = '10pt';
            addBoxTextBlock.innerHTML = "<div style='width:78%;position:relative; margin-top:30px; margin-left:30px; margin-right:15px;'><strong id='confirmAddFavStoreName'> </strong> <b>OOPS! </b><br /> You can only add a maximum of 50 stores to your favorites list. You have reached the limit. <a style='text-decoration:underline;color:#008000;' href= '/my/favorites.htm'>Click here</a> to edit <br /> your Favorites list.<div style='width:90%; margin-top:20px; margin-left:0px;'><img id='icon_exclamation' src='/images/category/stores/icon_exclamation.gif'/></div><a style='right:-5px;top:-11px;position:absolute;cursor:pointer;width:13px;height:13px;display:block;' onclick='hideconfirmbox();'></a></div>";
	 } else {         
            document.getElementById('confirmAddFavBox').style.background = 'transparent url(/images/category/stores/popup_bground1.png)';
            addBoxTextBlock.style.fontSize = '10pt';
	    addBoxTextBlock.innerHTML = "<div style='width:78%;position:relative; margin-top:30px; margin-left:30px; margin-right:15px;'><strong id='confirmAddFavStoreName'>"+name.replace("^","'")+"</strong> <br /> has been removed from your Favorites list.<div style='width:90%; margin-top:20px; margin-left:0px;'><img id='icon_exclamation' src='/images/category/stores/icon_deletion.gif'/></div><a style='right:-5px;top:-11px;position:absolute;cursor:pointer;width:13px;height:13px;display:block;' onclick='hideconfirmbox();'></a></div>";
         }
      }
      
      document.getElementById('confirmAddFavBox').style.display = state;
      document.getElementById('confirmAddFavBox').style.top = dsoctop+'px';      
}

function hideconfirmbox(){document.getElementById('confirmAddFavBox').style.display = 'none'; }

function addToFavoritesSection(fav,favAction,storeName) {
	  	var favsForm = document.forms.add_favorites_form;
         action = favAction;
         name = storeName;
         var sup = favsForm['sup'].value;
         var cparent = favsForm['cparent'].value;
         var storeID = fav;
         createRequest();
         if(favAction == 'delete') {
		    var url = "/my/removeFavorites.do?cat_id=$currentCatId&subcat_id=$currentSubCatId";
            var idFieldName = 'deletefromfav';
         }
         else {
		    var url = "/my/addFavorites.do";
            var idFieldName = 'addtofav';
         }
         request.open("post",url,true);
         confirmFavAdd();
         request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
         request.send('action='+action+'&sup='+sup+'&cparent='+cparent+'&'+idFieldName+'='+storeID);
}
function checkAdd(target,storeId,storeName){
	
	if(document.getElementById('counter'))
	{
	    var  v=document.getElementById('counter').value;
		if(target.attr("class") == "fav-n ui2012" || target.attr("class") == "fav-n"){
			
			if(v<50){
				target.attr("class","fav-s ui2012");
			    addToFavorites(storeId,"add",storeName);
    	        v=parseInt(v)+1;
    	    }else{
            	target.attr("class","fav-n ui2012");
			    addToFavorites(storeId,"acountfull",storeName);
        	}
			
		}else{
			target.attr("class","fav-n ui2012");
			addToFavorites(storeId,"delete",storeName);
    	    v=parseInt(v)-1;
    	    document.getElementById('counter').value=v;
		}
	}
	else{	
		window.location = '/auth/getLogonForm.do?pageName=/common_templates/login.vm';
	}	
}    

