var userType;
 var saveListCount = 0;


$(function() {
        
    var code ='';
    var catEntryIds = '';
   	var searsOthrVendor = false;
   	var isCollection = false;
   	var isSpecialCharactersRemoved = false;
	_global='';
	divObject = '';
      
		if (typeof imagePath == "undefined")
		{
			imagePath = "/contentserver/StaticContent/Sears/";
		}
		if( $('input#searsOthrVendor').attr('value') == "true"){
			searsOthrVendor = true;
		}
		
			
	function displayErrorCollection(){
	
	 var errorDisplayed = false;
	
	 if(getTotalQuantity()==0 && !errorDisplayed){
	 
	 				$('#ULSaveToOpts, #ULSaveToOpts a, #ULSaveToOpts button').unbind()
	 				 code.fadeOut(100,function(){
                    	$(this).remove();
                    	_thissave.removeClass('active');
                	});	  
		              displayErrorMessage(selectQuantityWishlist );
		              errorDisplayed=true;
		         }
		  if(catEntryArray.length==0 && !errorDisplayed){
		  
		  $('#ULSaveToOpts, #ULSaveToOpts a, #ULSaveToOpts button').unbind()
		  				code.fadeOut(100,function(){
                    	$(this).remove();
                    	_thissave.removeClass('active');
                	});
		  			     displayErrorMessage(wishListClicked);
		      	         errorDisplayed=true;
		  	     }
		 if(catentryError==1 && !errorDisplayed){
		 
		 $('#ULSaveToOpts, #ULSaveToOpts a, #ULSaveToOpts button').unbind()
		 					code.fadeOut(100,function(){
                    			$(this).remove();
                    			_thissave.removeClass('active');
                			});			  		 					
     	                  displayErrorMessage(wishlistSingleMissing);
       	                  errorDisplayed=true;
	        }
	 if(catentryError>=2 && !errorDisplayed){
	 
	 $('#ULSaveToOpts, #ULSaveToOpts a, #ULSaveToOpts button').unbind()
	        	code.fadeOut(100,function(){
                    	$(this).remove();
                    	_thissave.removeClass('active');
                	});
	 			displayErrorMessage(wishlistSingleMissing);
	            errorDisplayed=true;
	       }
        	
			return errorDisplayed;
	}
		
	function editElement(newListName) {
        var spanValue = trim(newListName);
        if(spanValue != "" && spanValue != null && spanValue !=" '' "){
            var valWithUnsafeCharRemoved = spanValue.replace(/[\/\\\$\[\]\?\;:#~&<>|)(}{]/g, "");
                return valWithUnsafeCharRemoved;
        }
        else
        	return spanValue;
   }
	
		
    function addNewBind(){                      
		var newList = $('<li class="new_list"><a href="javascript:;"></a></li>'),
			price= $('#product .mainInfo .specs .saveStory .youPay .pricing').text(),
			errorDisplayed = false;

                        price = price.slice(2);                       
        	
        		$('#addNew').unbind().click( function(){       		
			var isPrivate, newListName, partNumber;
        		       		
          			$('#addNewOpts').toggle();
            		$('#addNewOpts button').unbind().click( function(){
				newListName = trim(editElement($(this).parent().find('input.new_list_name').val()));
                		if (typeof newListName == 'undefined'||(newListName == null) ||newListName.length == 0 || newListName == '')
            			{
					showErrorMsgPopUpBox(divObject,'Please enter the list name.','List Center');
               				$(this).parent().find('input.new_list_name').val("");
               				return;
            			}
            			else if(newListName == '721OFFRCNTRNAME721')
            			{
					showErrorMsgPopUpBox(divObject,'Please enter another name.','List Center');
               				$(this).parent().find('input.new_list_name').val("");
               				return;
            			}
                		
        					if(isCollection != false){
                		
        						catentryError=0;
        						createFormValues();       			
        						errorDisplayed = displayErrorCollection();
        						$('.attError').remove(); // TO remove Make list selection in collection page.
        					}
        			
        			if(errorDisplayed != true)
        			{
                		if($('#public').is(':checked'))
                		{
                			var isPrivate = false;
                		}
                		else if($('#private').is(':checked'))
                		{
                			var isPrivate = true;
                		}
                		
                		var createUrl = '/shc/s/UniversalListsCreateView?listname='+newListName+'&storeId='+storeId+'&catalogId='+catalogId+'&fwdURL=AddToWishListStatusView&GUIDValue='+cvalue+'&listType=QuickList&isPrivate='+isPrivate;
                		
                		
                		$.getJSON(createUrl, function(data){
                			if(data.respCode != null && data.respCode != 'undefined' && data.respCode == '406') {
				                			if($('#ProfErrMsg').length != 0)
												$('#ProfErrMsg').remove();
                			
											if($('#ProfErrMsg').length == 0) {
												$('li#addNewOpts').prepend('<span id="ProfErrMsg"><small style="font-size:9px;padding:5px 0;color:#FF0000">List name contains Profane Words. Please enter some other List name.</small></span><br>');
												$('input.new_list_name').val('');
												$('#ProfErrMsg').fadeOut(3000);
											}
                		} else {
                			
                			var createdListName = jQuery.trim(data.listName);
                			
            				if(isCollection == false){
            				
                		    var addUrl = '/shc/s/UniversalListsAddItemView?listName='+createdListName+'&storeId='+storeId+'&fwdURL=AddToWishListStatusView&GUIDValue='+cvalue+'&priority=1&itemType=SHC&listType=QuickList&catalogId='+catalogId+catEntryIds+'&logActivity=false';
                		    
                		    }else{
                		    
                		    	var collcatEntryIds = createURL();
                		    	
								if(collcatEntryIds == ""){
								
									 collcatEntryIds=getCatEntryIDFromURL();
								} 
								
							var addUrl = '/shc/s/UniversalListsAddItemView?listName='+createdListName+'&storeId='+storeId+'&fwdURL=AddToWishListStatusView&GUIDValue='+cvalue+'&priority=1&itemType=SHC&listType=QuickList&catalogId='+catalogId+collcatEntryIds+'&isCollection=true&logActivity=false';	
                		    
                		    }
                		
							$.getJSON(addUrl, function(data){
								
					  			 $('#addNewOpts').hide();					  			 				  			 
					   			 newList.find('a').text(createdListName);
					   			 addToList(newList,createdListName);
					   			 
					   			
					 		});
					 		}
			    		});
			    		
			    		
			    	}
			    	if(typeof s !="undefined"){
            		 s.linkTrackVars='events,products,prop12,channel,prop1,prop2,prop3,prop19,prop27,prop28';
            		 s.linkTrackEvents='event42,event58';
	                 s.prop12='Save to List > New List';
	                 s.events="event42,event58";
	                 	}
			 if(isCollection == false){                                     
			 if(typeof s !="undefined"){
	                 s.products=';'+partNumber+';;;event42='+price;
			                                 }
			                                 }
			    else{    
			                 var stringBuffer='';
			                 for (var i=0; i<catEntryArray.length; i++) {
			                                   var catEntryId =catEntryArray[i];
			                                   var partNumber =$("input#"+catEntryId+"_partNumber").val();
			                                   var parentcatentryid=parentCatEntryArray[i];
			                                   var price= $('#ss_'+parentcatentryid+ ' .youPay .pricing').text();
			                                   price = price.slice(2);
			                                   if(typeof s !="undefined"){
			                                   var string =';'+partNumber+';;;event42='+price;
			                                   }
			                                   if(i>0)
			                                   {
			                                    	stringBuffer = stringBuffer+','+string; 
			                                   }
			                                   else
			                                   {
			                                   	stringBuffer = string;
			                                   }
			                                   }
			                                   if(typeof s !="undefined"){
			                 s.products=stringBuffer;   
			                 }
			                 }
			    	if(typeof s !="undefined"){	
			 s.tl(true,'o','Save to List > New List');  
		         //sendListType('sears_psumm_reglist','Quick List');
		         	}
        		});
        		});
        	}
        	
       function codeHoverBind() {
            	code.hover(
                	function(){ inCheck = true; },
                	function(){
                    	inCheck = false;
                    	setTimeout( function(){
                        	if(!inCheck) {
                            	code.fadeOut(500,function(){
                            	        saveListCount = 0;
                                	$(this).remove();
                                	_thissave.removeClass('active');
                            	});
                        	}
                    	},2000);
                	}
            	);
        	}
        	function actionBind(actions) {
				actions.unbind().click(function(){
					var price= $('#product .mainInfo .specs .saveStory .youPay .pricing').text(); 
					price = price.slice(2);
					var errorDisplayed = false;
					_thisActionClick = $(this);
            		
            		if (isCollection != false){          			
            		
            				catentryError=0;
            				createFormValues();
            				errorDisplayed = displayErrorCollection();          				
            				 $('.attError').remove();
            		}
            		if(errorDisplayed != true)
        			{
            			var clickedlistName = $(this).text();
            			var listType = $(this).attr('listType');
            			var myUser = $(this).attr('myUser');
            			if(listType == "SaveforLaterList")
            				{
							var logonUrl = "GiftRegistrySignOnView?langId=-1&storeId="+storeId+"&catalogId="+catalogId+"&fromCreate=ProductPage";
            					var addToWishlistUrl = 'InterestItemDisplayCmd?storeId='+storeId+'&catalogId='+catalogId+'&listName='+clickedlistName;
            					var isPrivate = true;
            					var addUrl = '';
            					if (isCollection == false)
            						{            			
            			 addUrl = '/shc/s/UniversallistsAddSFLView?listName='+clickedlistName+'&storeId='+storeId+'&fwdURL=AddToWishListStatusView&priority=1&itemType=SHC&listType='+listType+'&catalogId='+catalogId+'&userType=REG'+catEntryIds+'&GUIDValue='+cvalue;
            			
            						}else{
            			
            						var collcatEntryIds = createURL();
            					addUrl = '/shc/s/UniversallistsAddSFLView?listName='+clickedlistName+'&storeId='+storeId+'&fwdURL=AddToWishListStatusView&priority=1&itemType=SHC&listType='+listType+'&catalogId='+catalogId+'&userType=REG'+collcatEntryIds+'&isCollection=true&GUIDValue='+cvalue;
            				
            				}
            			
                			$.getJSON(addUrl, function(data){
            				if(userType == "G"){
            				
					           viewURL = "javascript:fnShowLoginModal('WLAddItem','"+logonUrl+"',"+"'"+addToWishlistUrl+"');";
					            				
            				}else if(document.getElementById("remembered")!=null){
           						var remem = document.getElementById("remembered").value;
           						if(remem=="yes")
               						var viewURL	 = "javascript:fnShowLoginModal('WLAddItem','"+logonUrl+"',"+"'"+addToWishlistUrl+"');";
               					else
               						var viewURL = 'InterestItemDisplayCmd?storeId='+storeId+'&catalogId='+catalogId+'&listname='+clickedlistName;
        					}
        					else
        					{
        						var viewURL = 'InterestItemDisplayCmd?storeId='+storeId+'&catalogId='+catalogId+'&listname='+clickedlistName;
        					}
            				var targetLi = $(_thisActionClick);
            				fadeInOut(targetLi,viewURL,'list',listType);
            			});
					}
					else if((listType == 'Registry')||(listType == 'GT'))
					{
						var externalId = $(_thisActionClick).attr('externalId');
						var addUrl = '';
						
						if (isCollection == false)
            			{ 
						 addUrl = 'AddToGiftRegistry?frompage=prodPage&storeId='+storeId+'&catalogId='+catalogId+'&externalId='+externalId+catEntryIds;
						}else{
								
								var collcatEntryIds = createURL();
								if(collcatEntryIds==''){
								
									 collcatEntryIds=getCatEntryIDFromURL();
								} 
								
							 addUrl = 'AddToGiftRegistry?frompage=prodPage&storeId='+storeId+'&catalogId='+catalogId+'&externalId='+externalId+catEntryIds+collcatEntryIds;							
						}
						$.getJSON(addUrl, function(data){
						
							if(listType == 'Registry')
							{
								var RegistryType ='registry';
								var isGT = '';
								var logonUrl = "GiftRegistrySignOnView?langId=-1&storeId="+storeId+"&catalogId="+catalogId+"&fromCreate=ProductPage";
								var addToWishlistUrl = "GiftRegistryItemView?storeId="+storeId+"&catalogId="+catalogId+"&sortByItem=category&fileflag=false&externalId="+externalId+"&grUserType=REGISTRANT&fwdURL=GiftRegistryItemUpdateView";
								if(document.getElementById("remembered")!=null){
           							var remem = document.getElementById("remembered").value;
           							if(remem=="yes")
           								var viewURL	 = "javascript:fnShowLoginModal('WLAddItem','"+logonUrl+"',"+"'"+addToWishlistUrl+"');";
               						else
               							var viewURL = "GiftRegistryItemView?storeId="+storeId+"&catalogId="+catalogId+"&sortByItem=category&fileflag=false&externalId="+externalId+"&grUserType=REGISTRANT&fwdURL=GiftRegistryItemUpdateView";
        						}
        						else
        						{
        							if(userType == 'G')
        							{
        								var viewURL	 = "javascript:fnShowLoginModal('WLAddItem','"+logonUrl+"',"+"'"+addToWishlistUrl+"');";
        							}
        							else
        							{
        								var viewURL = "GiftRegistryItemView?storeId="+storeId+"&catalogId="+catalogId+"&sortByItem=category&fileflag=false&externalId="+externalId+"&grUserType=REGISTRANT&fwdURL=GiftRegistryItemUpdateView";
        							}
        						}
							}
							else
							{
								var RegistryType ='gt';
								var isGT = 'gt';
								var logonUrl = "GiftRegistrySignOnView?langId=-1&storeId="+storeId+"&catalogId="+catalogId+"&fromCreate=ProductPage";
								var addToWishlistUrl = "GiveTogether?giftRegistryId="+giftRegistryId+"&nextView=GTManageEventView&storeId="+storeId+"&catalogId="+catalogId+"&sortByItem=category&externalId="+externalId+"&grUserType=REGISTRANT";
								var giftRegistryId = $(_thisActionClick).attr('giftRegistryId');
								if(document.getElementById("remembered")!=null){
           							var remem = document.getElementById("remembered").value;
           							if(remem=="yes")
               							var viewURL	 = "javascript:fnShowLoginModal('WLAddItem','"+logonUrl+"',"+"'"+addToWishlistUrl+"');";
               						else
               							var viewURL = "GiveTogether?giftRegistryId="+giftRegistryId+"&nextView=GTManageEventView&storeId="+storeId+"&catalogId='+catalogId+'&sortByItem=category&externalId="+externalId+"&grUserType=REGISTRANT";
        						}
        						else
        						{
        							if(userType == 'G')
        							{
        								var viewURL	 = "javascript:fnShowLoginModal('WLAddItem','"+logonUrl+"',"+"'"+addToWishlistUrl+"');";
        							}
        							else
        							{
        								var viewURL = "GiveTogether?giftRegistryId="+giftRegistryId+"&nextView=GTManageEventView&storeId="+storeId+"&catalogId="+catalogId+"&sortByItem=category&externalId="+externalId+"&grUserType=REGISTRANT";
        							}
        						}
							}
							
							
							var targetLi = $(_thisActionClick);
							fadeInOut(targetLi,viewURL,data,listType);
						});
						
					}
            		else
            		{
					var logonUrl = "GiftRegistrySignOnView?langId=-1&storeId="+storeId+"&catalogId="+catalogId+"&fromCreate=ProductPage";
            			var addToWishlistUrl = 'InterestItemDisplayCmd?storeId='+storeId+'&catalogId='+catalogId+'&listName='+clickedlistName

            			var addUrl = '';
            			
            			if(isCollection == false){
            			
            			addUrl = '/shc/s/UniversalListsAddItemView?listName='+clickedlistName+'&storeId='+storeId+'&fwdURL=AddToWishListStatusView&priority=1&itemType=SHC&listType='+listType+'&catalogId='+catalogId+'&userType='+myUser+catEntryIds+'&GUIDValue='+cvalue;
            			
            			}else{
            			
            				var collcatEntryIds = createURL();
            				
								if(collcatEntryIds==''){
								
									 collcatEntryIds=getCatEntryIDFromURL();
								} 
								
							 addUrl =  '/shc/s/UniversalListsAddItemView?listName='+clickedlistName+'&storeId='+storeId+'&fwdURL=AddToWishListStatusView&priority=1&itemType=SHC&listType='+listType+'&catalogId='+catalogId+'&userType='+myUser+catEntryIds+'&GUIDValue='+cvalue+collcatEntryIds+'&isCollection=true';	
                		    
            			}
            			
            			
            			$.getJSON(addUrl, function(data){
            				
            				var targetLi = $(_thisActionClick);
            				if(document.getElementById("remembered")!=null){
           						var remem = document.getElementById("remembered").value;
           						if(remem=="yes")
               						var viewURL	 = "javascript:fnShowLoginModal('WLAddItem','"+logonUrl+"',"+"'"+addToWishlistUrl+"');";
               					else
               						var viewURL = 'InterestItemDisplayCmd?storeId='+storeId+'&catalogId='+catalogId+'&listname='+clickedlistName;
        					}
        					else
        					{
        						if(userType == 'G')
        							var viewURL	 = "javascript:fnShowLoginModal('WLAddItem','"+logonUrl+"',"+"'"+addToWishlistUrl+"');";
        						else
        							var viewURL = 'InterestItemDisplayCmd?storeId='+storeId+'&catalogId='+catalogId+'&listname='+clickedlistName;
        					}
            				fadeInOut(targetLi,viewURL,'list',listType);
            			});
            			
            		}
            		var omnlistType = '';
            		if(listType == "SaveforLaterList")
					{
						 omnlistType = "Save for Later"
            		}
					else if(listType == 'Registry')
					{
            			 omnlistType = "Gift Registry"
            		}
            		else if(listType == 'GT')
            		{
            			 omnlistType = "Give Together"
            		}
            		else if(listType == 'ToolsIOwnList')
            		{
            			 omnlistType = "Tools I Own"
            		}
            		else{
            			 omnlistType = "Quick List"
            		}
            		if(typeof s !="undefined"){
			s.linkTrackVars='events,products,prop12,channel,prop1,prop2,prop3,prop19,prop27,prop28';
			s.linkTrackEvents='event42,event58';
			s.events='event42,event58';
			}
			if(isCollection == false){                                     
			if(typeof s !="undefined"){
			s.products=';'+partNumber+';;;event42='+price;
						                                 }
						                                 }
						    else{    
						                 var stringBuffer='';
						                 for (var i=0; i<catEntryArray.length; i++) {
						                                   var catEntryId =catEntryArray[i];
						                                   var partNumber =$("input#"+catEntryId+"_partNumber").val();
						                                   var parentcatentryid=parentCatEntryArray[i];
						                                   var price= $('#ss_'+parentcatentryid+ ' .youPay .pricing').text(); 
						                                   price = price.slice(2);
						                                   if(typeof s !="undefined"){
						                                   var string =';'+partNumber+';;;event42='+price;
						                                   }
						                                   if(i>0)
						                                   {
						                                    	stringBuffer = stringBuffer+','+string; 
						                                   }
						                                   else
						                                   {
						                                   	stringBuffer = string;
						                                   }
						                                   }
						                                   if(typeof s !="undefined"){
						                 s.products=stringBuffer;   
			                 }
			                 }
			                 if(typeof s !="undefined"){
			s.tl(true,"o",'Save to List >'+ omnlistType);
			s.prop12='Save to List >'+ omnlistType;
			//sendListType('sears_psumm_reglist',omnlistType);			
                        }
                        }
		    	});
            	
			}
    
        	
    
    
    	function addToList(action,createdListName)
        	{
        		var logonUrl = "GiftRegistrySignOnView?langId=-1&storeId="+storeId+"&catalogId="+catalogId+"&fromCreate=ProductPage";
            	var addToWishlistUrl = 'InterestItemDisplayCmd?storeId='+storeId+'&catalogId='+catalogId+'&listName='+createdListName
        		$('#ULSaveToOpts').prepend(action);
        		if(document.getElementById("remembered")!=null){
           			var remem = document.getElementById("remembered").value;
           			if(remem=="yes")
               			var viewURL	 = "javascript:fnShowLoginModal('WLAddItem','"+logonUrl+"',"+"'"+addToWishlistUrl+"');";
               		else
               			var viewURL = 'InterestItemDisplayCmd?storeId='+storeId+'&catalogId='+catalogId+'&listname='+createdListName;
        		}
        		else
        		{
        				if(userType == 'G')
        				{
        					var viewURL	= "javascript:fnShowLoginModal('WLAddItem','"+logonUrl+"',"+"'"+addToWishlistUrl+"');";
        				}
        				else
        				{
        					var viewURL = 'InterestItemDisplayCmd?storeId='+storeId+'&catalogId='+catalogId+'&listname='+createdListName;
        				}
        		}
            	fadeInOut($('#ULSaveToOpts li:first a'),viewURL,'list','QuickList');
        	}
        	
        function fadeInOut(trgLi,viewURL,isItemExceeded,listType){
            	
            	var linkClicked = trgLi.parent().attr("class");
            	var successDiv = $('div#successSpans .'+linkClicked).html();
            	trgLi.parent().append(successDiv);
            	if(listType == 'Registry')
            	{
            		if(isItemExceeded == 'ItemsExceeded')
            		{
            			trgLi.parent().find("span.success").html('<img src="' + imagePath +'img/UniversalLists/lists_header/OM_check_img.gif" /> Item count exceeded<a style="display:inline; margin:2px;" href="javascript:;">View List</a>');
            		}
            		else
            		{
            			trgLi.parent().find("span.success").html('<img src="' + imagePath +'img/UniversalLists/lists_header/OM_check_img.gif" /> Item added to Registry<a style="display:inline; margin:2px;" href="javascript:;">View List</a>');
            		}
            	}
            	else if(listType == 'GT')
            	{
            		if(isItemExceeded == 'ItemsExceeded')
            		{
            			trgLi.parent().find("span.success").html('<img src="' + imagePath +'img/UniversalLists/lists_header/OM_check_img.gif" />Item count exceeded<a style="display:inline; margin:2px;" href="javascript:;">View List</a>');
            		}
            		else
            		{
            			trgLi.parent().find("span.success").html('<img src="' + imagePath +'img/UniversalLists/lists_header/OM_check_img.gif" />Item added to Give Together<a style="display:inline; margin:2px;" href="javascript:;">View List</a>');
            		}
            	}
            	trgLi.parent().find("span.success a").attr("href",viewURL);
            	$('#ULSaveToOpts, #ULSaveToOpts a, #ULSaveToOpts button').unbind();
            	trgLi.parent().find("span.success").fadeTo(3000,1);
            	setTimeout( function() {
                	$("span.success").fadeOut(3000);
                	code.fadeOut(3000,function(){
                    	$(this).remove();
                    	_thissave.removeClass('active');
                	});
            	},3000);
        	}     
    
    window._saveToLinkClickInputVen = function(){
    	
    
     if(saveListCount == 0) {
    	
		_thissave = $('input.vendorAddCartButton');
		catEntryIds = '';
		divObject = this;  
		
		if(document.cookie.indexOf("s_r") != -1){
			var cookievalue=$.cookie("s_r");
			cookievalue=unescape(cookievalue);
			if(cookievalue != null && cookievalue.indexOf("_Y") != -1){
				//s_r cookie has value with '_Y'. User is logged In
				userType ='R';
			}
			else
				userType = 'G';
	
		}
		else
		{
			userType = 'G';
		}
		domainURL = $('input.vendorAddCartButton').attr('domainURL');
		mktInd =$('input.vendorAddCartButton').attr('mktInd');
		var cattId = $('input.vendorAddCartButton').attr('cattId');
		
		if(typeof cattId != 'undefined' && cattId!='')
		{
		 	catEntryIds =  '&catEntryId_1='+ cattId +'&quantity_1=1';
		 	
		}
		
		// checking for softline options selections
		
        var variantOptionsFlag = checkVarient();
        
		if (variantOptionsFlag == false){		
				return;
			}
		
		
		$.getJSON("http://"+domainURL+"/shc/UniversalListcookieServlet?storeId="+storeId+"&catalogId="+catalogId+"&from=prodPage&callback=?",function(data){
			if(data != null)
	    	{	    	
	    		cname = data.myobject.name;
				cvalue = data.myobject.value;
			
			}
			if(userType == 'R')
			{
				userId = getCookie('wcid_'+storeId);
			}
	    

	
			 		retrieveUrl ='/shc/s/UniversalListCenterView?storeId='+storeId+'&catalogId='+catalogId+'&fwdURL=AddToWishListStatusView&GUIDValue='+cvalue;
		showSaveToList();
		saveListCount = 1;
		
		});
	
		} else {
		         
		      $('#ULSaveToOpts').remove();    
		      saveListCount = 0;
		        
    }
	
    };
    
	window._saveToLinkClick = function() {
    
     if(saveListCount == 0) {
    	
		_thissave = $('#saveToList');
		catEntryIds = '';
		divObject = this;  
		
		if(document.cookie.indexOf("s_r") != -1){
			var cookievalue=$.cookie("s_r");
			cookievalue=unescape(cookievalue);
			if(cookievalue != null && cookievalue.indexOf("_Y") != -1){
				//s_r cookie has value with '_Y'. User is logged In
				userType ='R';
			}
			else
				userType = 'G';
	
		}
		else
		{
			userType = 'G';
		}
		domainURL = $('#saveToList').attr('domainURL');
		mktInd =$('#saveToList').attr('mktInd');
		var cattId = $('#saveToList').attr('cattId');
		
		if(typeof cattId != 'undefined' && cattId != '')
		{
		 	catEntryIds =  '&catEntryId_1='+ cattId +'&quantity_1=1';
		 	
		 }
		 	
		// checking for softline options selections
		
        var variantOptionsFlag = checkVarient();
        
		if (variantOptionsFlag == false){		
				return;
			}
		
		$.getJSON("http://"+domainURL+"/shc/UniversalListcookieServlet?storeId="+storeId+"&catalogId="+catalogId+"&from=prodPage&callback=?",function(data){
		if(data != null)
	    	{	    	
	    		cname = data.myobject.name;
				cvalue = data.myobject.value;
			
			}
			if(userType == 'R')
			{
				userId = getCookie('wcid_'+storeId);
			}
	    

	
			 		retrieveUrl ='/shc/s/UniversalListCenterView?storeId='+storeId+'&catalogId='+catalogId+'&fwdURL=AddToWishListStatusView&GUIDValue='+cvalue;
				
		showSaveToList();
		saveListCount = 1;
		
    });
    
		} else {
    
		      $('#ULSaveToOpts').remove();    
		      saveListCount = 0;
		        
    }
	
    };
    
    window._saveToLinkClickClass = function(){
    
    
     if(saveListCount == 0) {
    	
		_thissave = $('.saveToList');
		catEntryIds = '';
		divObject =this;;  
		
		if(document.cookie.indexOf("s_r") != -1){
			var cookievalue=$.cookie("s_r");
			cookievalue=unescape(cookievalue);
			if(cookievalue != null && cookievalue.indexOf("_Y") != -1){
				//s_r cookie has value with '_Y'. User is logged In
				userType ='R';
			}
			else
				userType = 'G';
	
		}
		else
		{
			userType = 'G';
		}
		domainURL = $('.saveToList').attr('domainURL');
		mktInd =$('.saveToList').attr('mktInd');
		var cattId = $('.saveToList').attr('cattId');
		
		if(typeof cattId != 'undefined' && cattId != '')
		{
		 	catEntryIds =  '&catEntryId_1='+ cattId +'&quantity_1=1';
		 	
		 }
		 	
		// checking for softline options selections
		
        var variantOptionsFlag = checkVarient();
        
		if (variantOptionsFlag == false){		
				return;
			}
		
		
		$.getJSON("http://"+domainURL+"/shc/UniversalListcookieServlet?storeId="+storeId+"&catalogId="+catalogId+"&from=prodPage&callback=?",function(data){
			if(data != null)
	    	{	    	
	    		cname = data.myobject.name;
				cvalue = data.myobject.value;
			
			}
			if(userType == 'R')
			{
				userId = getCookie('wcid_'+storeId);
			}
	    
			 		retrieveUrl ='/shc/s/UniversalListCenterView?storeId='+storeId+'&catalogId='+catalogId+'fwdURL=AddToWishListStatusView&GUIDValue='+cvalue;
				
		showSaveToList();
		saveListCount = 1;
		
		});
		
		} else {
		         
		      $('#ULSaveToOpts').remove();    
		      saveListCount = 0;
		        
    }
	
    };
    
    
    	 window._saveToLinkImgClickClass = function(){ 
        
       
       
       if(saveListCount == 0) {	
        
       divObject = this;         	
 		if(document.cookie.indexOf("s_r") != -1){
			var cookievalue=$.cookie("s_r");
			cookievalue=unescape(cookievalue);
			if(cookievalue != null && cookievalue.indexOf("_Y") != -1){
				//s_r cookie has value with '_Y'. User is logged In
				userType ='R';
			}
			else
				userType = 'G';
	
		}
		else
		{
			userType = 'G';
		}
	
		_thissave = $(this);	
		
		catEntryIds = '';
		var cattId = $(this).attr('cattId');
				
		if(typeof cattId != 'undefined' && cattId!='')
		{
		 	catEntryIds =  '&catEntryId_1='+ cattId +'&quantity_1=1';
				 	
		}
		
		domainURL = $(this).attr('domainURL');
		isCollection = true;
		
				
		$.getJSON("http://"+domainURL+"/shc/UniversalListcookieServlet?storeId="+storeId+"&catalogId="+catalogId+"&from=prodPage&callback=?",function(data){
		
		if(data != null)
	    {	    	
	    	cname = data.myobject.name;
			cvalue = data.myobject.value;
			
		}
		if(userType == 'R')
		{
			userId = getCookie('wcid_'+storeId);
		}
	    
		retrieveUrl = '/shc/s/UniversalListCenterView?storeId='+storeId+'&catalogId='+catalogId+'&fwdURL=AddToWishListStatusView&GUIDValue='+cvalue;
		showSaveToList();
		saveListCount = 1;
		
		});
	
		   } else {
		         
		      $('#ULSaveToOpts').remove();    
		      saveListCount = 0;
		        
    }
	
    };
    
    
    
window._saveToLinkInputBtnClickClass = function(){    
        
     
   if(saveListCount == 0) {	
        
        catEntryIds = '';
       divObject =this; 
 		if(document.cookie.indexOf("s_r") != -1){
			var cookievalue=$.cookie("s_r");
			cookievalue=unescape(cookievalue);
			if(cookievalue != null && cookievalue.indexOf("_Y") != -1){
				//s_r cookie has value with '_Y'. User is logged In
				userType ='R';
			}
			else
				userType = 'G';
	
		}
		else
		{
			userType = 'G';
		}

		mktInd = $(this).attr('mktInd');	
		_thissave = $(this);
		var cattId = $(this).attr('cattId');
		domainURL = $(this).attr('domainURL');
		
		if(typeof cattId != 'undefined' && cattId!='')
		{
		 	catEntryIds =  '&catEntryId_1='+ cattId +'&quantity_1=1';
		 	
		}
		
		
			
		        var variantOptionsFlag = checkVarient();
		        
				if (variantOptionsFlag == false){		
						return;
			}
		$.getJSON("http://"+domainURL+"/shc/UniversalListcookieServlet?storeId="+storeId+"&catalogId="+catalogId+"&from=prodPage&callback=?",function(data){
		
		if(data != null)
	    {	    	
	    	cname = data.myobject.name;
			cvalue = data.myobject.value;
			
		}
		if(userType == 'R')
		{
			userId = getCookie('wcid_'+storeId);
		}
	
	
		retrieveUrl = '/shc/s/UniversalListCenterView?storeId='+storeId+'&catalogId='+catalogId+'&fwdURL=AddToWishListStatusView&GUIDValue='+cvalue;
	
	
	showSaveToList();
	saveListCount = 1;
	
    	});
    	
    	
    	 } else {
	         
	      $('#ULSaveToOpts').remove();    
	      saveListCount = 0;
	        
    }
    	
    };
    
   
    function showSaveToList(){ 
    
    	var STLCoords = _thissave.offset();
		 var userlist = "";
		 var registryList = "";
		 var gtList = "";
		 var flag = false;
		 if(typeof s !="undefined"){
		 s.linkTrackVars='prop12,channel,prop1,prop2,prop3,prop19,prop27,prop28';		
                 s.prop12='Save to List ';
                 s.tl(true,'o','Save to List');    
                 }
         /** TODO **/
         if((catEntryIds == ''|| typeof catEntryIds == 'undefined') && isCollection == false ){
         
         	if(searsOthrVendor == true){
         
		    	  catEntryIds = '&catEntryId_1='+$('input#searsItemCatId').attr('value')+'&quantity_1='+qty; 
		      
		  	} else {
		  
		    	  catEntryIds = getCatEntryIds();  
		  	}
		  
		  }
		 
		  
		  //ECOM-105180
		  
		                  
		  
		                     retrieveUrl ='/shc/s/UniversalListCenterView?storeId='+storeId+'&catalogId='+catalogId+'&fwdURL=AddToWishListStatusView&GUIDValue='+cvalue;
		 
		  
		 $.getJSON(retrieveUrl, function(data){
		 	var ulListCenterFlag = data.listCenterFlag;
		 	if(data.list.SHCItems != ""){
            $.each(data.list.SHCItems.SHCList, function(i,list){
     			var nameSpace = list.namespace;
     			var myUser = nameSpace.split('.')[1].split('.')[0];
     		
     			if(list.type == "SaveforLaterList")
     			{
     				
     				userlist = userlist+'<li class="user_list"><a id='+list.name+' href="javascript:;" myUser='+myUser+' listType="SaveforLaterList">'+list.name+'</a></li>\n'
     				flag = true;
     			}
     			else if(list.type == "ToolsIOwnList")
     			{
			     	userlist = userlist+'<li class="user_list"><a id='+list.name+' href="javascript:;" myUser='+myUser+' listType="ToolsIOwnList">'+list.name+'</a></li>\n'
     			}
     			else if(list.type != "721OFFRCNTRTYPE721")
     			{
     				userlist = userlist+'<li class="user_list"><a id='+list.name+' href="javascript:;" myUser='+myUser+' listType="QuickList">'+list.name+'</a></li>\n'
     			}
     				
			});
			}
			if(document.getElementById("remembered")!=null)
           		var rememb = document.getElementById("remembered").value;
           	else
           		var rememb = "";
			
			if(flag == false)
			{
				if(ulListCenterFlag != 'undefined' && ulListCenterFlag == "ON"){
				userlist = userlist + '	<li class="user_list"><a href="javascript:;" id="Save for Later" myUser='+userType+' flag="false" listType="SaveforLaterList">Save for Later</a></li>\n'
			}
			}
     			
     			if(data.registry.myObjectList.entries != ""){
			            $.each(data.registry.myObjectList.entries.myobject, function(i,list){
			                    registryList = registryList+'<li class="user_list"><a id='+list.name+' href="javascript:;" externalId='+list.value+' listType=Registry>'+list.name+'</a></li>\n'
			              });
			              }
			else
			{
				if(ulListCenterFlag != 'undefined' && ulListCenterFlag == "OFF"){
					 registryList += '<li><a href="'+'/shc/s/WeddingRegistryCreateView?storeId='+storeId+'&catalogId='+catalogId+'">Create GiftRegistry</a></li>';
				}
			}
			              
			              if(data.giveTogether.myObjectList.entries != ""){
			            $.each(data.giveTogether.myObjectList.entries.myobject, function(i,list){
			              var extId = list.value.split('\"')[1].split('.')[0];
			              var giftId = list.value.split('.')[1].split('\"')[0];
			                    gtList = gtList+'<li class="user_list"><a id='+list.name+' href="javascript:;" giftRegistryId='+giftId+' externalId='+extId+' listType=GT>'+list.name+'</a></li>\n'
			              });
			              }

			code = '\n'
        	+ '<ul id="ULSaveToOpts" style="display:none; width:250px;">\n'
            + userlist
            + registryList
            + gtList;
            if(ulListCenterFlag != 'undefined' && ulListCenterFlag == "ON"){
            	code += '<li><a id="addNew" href="javascript:;">Add to New List</a></li>\n';
            }
            
            code += '<li id="addNewOpts" class="new_list">\n'
            + '             <label>Name</label><br />\n'
            + '             <input class="new_list_name" type="text" /><br />\n'
            + '             <label>New list privacy</label><br />\n'
        	+ '             <input name="list_privacy" id="public" type="radio" />\n'
        	+ '             <label>Public</label><br />\n'
        	+ '             <input name="list_privacy" id="private" type="radio" checked="true" />'
        	+ '             <label>Private</label><br />\n'
        	+ '             <button>Add</button>\n'
        	+ '      </li> \n'
        	+ '	<li>'
        	+ '         <div id="successSpans">'
        	+ '             <div class="user_list"><br clear="all" /><span style="display:inline;" class="success"><img src="' + imagePath + 'img/UniversalLists/lists_header/OM_check_img.gif" /> Item added to list<a style="display:inline; margin:2px;" href="javascript:;">View List</a></span></div>'
       		+ '             <div class="new_list"><br clear="all" /><span style="display:inline" class="success"><img src="' + imagePath + 'img/UniversalLists/lists_header/OM_check_img.gif" /> Item added to new list<a style="display:inline; margin-left:2px;" href="javascript:;">View List</a></span></div>'
        	+ '         </div>'
        	+ '     </li>\n'
        	+ '</ul> \n';
        	code = $(code).appendTo('body').fadeIn(500).css({top:STLCoords.top + _thissave.height() + 12, left:STLCoords.left});
         	_global = $('#ULSaveToOpts').offset();
        
     		var inCheck = false;         
        	var actions = code.find('li.user_list a');      
         	codeHoverBind();
    		actionBind(actions);
    		addNewBind();
		});
	
	
	}
	   
	jQuery.fn.exists = function() {
	    return this.length > 0;
    };
    if (jQuery.browser.msie && jQuery.browser.version==6) {
    	if( $('#saveToList').exists() ){
    	  	$("#saveToList").attr("href","javascript:_saveToLinkClick();");}
    	else if($('.saveToList').exists())
    		$(".saveToList").attr("href","javascript:_saveToLinkClickClass();");
    	else if($('input.vendorAddCartButton').exists())
    		$("input.vendorAddCartButton").attr("href","javascript:_saveToLinkClickInputVen();");
    	else if($('img.saveList').exists())
	    	$("img.saveList").attr("href","javascript:_saveToLinkImgClickClass();");
	else if($('input.saveToListBtn').exists())
    		$("input.saveToListBtn").attr("href","javascript:_saveToLinkInputBtnClickClass();");
	} else {
		if( $('#saveToList').exists() ){
    		$("#saveToList").click(window._saveToLinkClick);}
    	else if($('.saveToList').exists())
    		$(".saveToList").click(window._saveToLinkClickClass);
    	else if($('input.vendorAddCartButton').exists())
    		$("input.vendorAddCartButton").click(window._saveToLinkClickInputVen);
    	else if($('img.saveList').exists())
	    	$("img.saveList").click(window._saveToLinkImgClickClass);
	else if($('input.saveToListBtn').exists())
    		$("input.saveToListBtn").click(window._saveToLinkInputBtnClickClass);
	}   
   
          
});

/* Function inovked for quick view pages */

function initializeSaveLaterVar(){
	
	
	
	
	
	
	
	jQuery.fn.exists = function() {
			    return this.length > 0;
		    };
		    if (jQuery.browser.msie && jQuery.browser.version==6) {
		    
		    
		    	if( $('#saveToList').exists() ){
		    	  	$("#saveToList").attr("href","javascript:_saveToLinkClick();");}
		    	else if($('.saveToList').exists())
		    		$(".saveToList").attr("href","javascript:_saveToLinkClickClass();");
			} else {
				if( $('#saveToList').exists() ){
		    		$("#saveToList").click(window._saveToLinkClick);}
		    	else if($('.saveToList').exists())
		    		$(".saveToList").click(window._saveToLinkClickClass);
		}   
	
	
	
	
	
	
	
	
	
	var code ='';
    var catEntryIds = '';
   	divObject = '';
   
	function editElement(newListName) {
        var spanValue = trim(newListName);
        if(spanValue != "" && spanValue != null && spanValue !=" '' "){
            var valWithUnsafeCharRemoved = spanValue.replace(/[\/\\\$\[\]\?\;:#~&<>|)(}{]/g, "");
                return valWithUnsafeCharRemoved;
        }
	  else
        	return spanValue;
   	}	
    function addNewBind(){     
        		var newList = $('<li class="new_list"><a href="javascript:;"></a></li>');
        		$('#addNew').unbind().click( function(){
          			$('#addNewOpts').toggle();
            		$('#addNewOpts button').unbind().click( function(){
                		var newListName = jQuery.trim(editElement($(this).parent().find('input.new_list_name').val()));
                		if (typeof newListName == 'undefined' ||(newListName == null) || (newListName.length == 0 )||( newListName == ''))
            			{
            				var mesg = 'Please enter the list name.';
							showErrorMsg(divObject,mesg,'List Center');
               				$(this).parent().find('input.new_list_name').val("");
               				return;
            			}
            			else if(newListName == '721OFFRCNTRNAME721')
				{
				  var mesg = 'Please enter another name.';
				  showErrorMsg(divObject,mesg,'List Center');
				  $(this).parent().find('input.new_list_name').val("");
				  return;
				}
                		
                		if($('#public').is(':checked'))
                		{
                			var isPrivate = false;
                		}
                		else if($('#private').is(':checked'))
                		{
                			var isPrivate = true;
                		}
                		var createUrl = '/shc/s/UniversalListsCreateView?listname='+newListName+'&storeId='+storeId+'&catalogId='+catalogId+'&fwdURL=AddToWishListStatusView&GUIDValue='+cvalue+'&listType=QuickList&isPrivate='+isPrivate;
                		
                		
                		$.getJSON(createUrl, function(data){
                			
                			var createdListName = jQuery.trim(data.listName);
                			
            				
                		    var addUrl = '/shc/s/UniversalListsAddItemView?listName='+createdListName+'&storeId='+storeId+'&fwdURL=AddToWishListStatusView&GUIDValue='+cvalue+'&priority=1&itemType=SHC&listType=QuickList&catalogId='+catalogId+catEntryIds+'&logActivity=false';
                		
							$.getJSON(addUrl, function(data){
								
					  			 $('#addNewOpts').hide();
					   			 newList.find('a').text(createdListName);
					   			 addToList(newList,createdListName);
					 		});
			    		});
            		});
        		});
        	}
        	
       function codeHoverBind() {
            	code.hover(
                	function(){ inCheck = true; },
                	function(){
                    	inCheck = false;
                    	setTimeout( function(){
                        	if(!inCheck) {
                            	code.fadeOut(500,function(){
                            	       saveListCount = 0;
                                	$(this).remove();
                                	_thissave.removeClass('active');
                            	});
                        	}
                    	},2000);
                	}
            	);
        	}
        	
        	
    	function actionBind(actions) {
				actions.unbind().click(function(){
					_thisActionClick = $(this);
            		var clickedlistName = $(this).text();
            		var listType = $(this).attr('listType');
            		var myUser = $(this).attr('myUser');
            		if(listType == "SaveforLaterList")
            		{
					var logonUrl = "GiftRegistrySignOnView?langId=-1&storeId="+storeId+"&catalogId="+catalogId+"&fromCreate=ProductPage";
            			var addToWishlistUrl = 'InterestItemDisplayCmd?storeId='+storeId+'&catalogId='+catalogId+'&listName='+clickedlistName;

            			var isPrivate = true;
            			var addUrl = '/shc/s/UniversallistsAddSFLView?listName='+clickedlistName+'&storeId='+storeId+'&fwdURL=AddToWishListStatusView&priority=1&itemType=SHC&listType='+listType+'&catalogId='+catalogId+'&userType=REG'+catEntryIds+'&GUIDValue='+cvalue;
                			$.getJSON(addUrl, function(data){
            				
            				if(userType == "G"){
					            				
					           viewURL = "javascript:fnShowLoginModal('WLAddItem','"+logonUrl+"',"+"'"+addToWishlistUrl+"');";
					            				
            				}else if(document.getElementById("remembered")!=null){
           						var remem = document.getElementById("remembered").value;
           						if(remem=="yes")
               						var viewURL	 = "javascript:fnShowLoginModal('WLAddItem','"+logonUrl+"',"+"'"+addToWishlistUrl+"');";
               					else
               						var viewURL = 'InterestItemDisplayCmd?storeId='+storeId+'&catalogId='+catalogId+'&listname='+clickedlistName;
        					}
        					else
        					{
        						var viewURL = 'InterestItemDisplayCmd?storeId='+storeId+'&catalogId='+catalogId+'&listname='+clickedlistName;
        					}
            				var targetLi = $(_thisActionClick);
            				fadeInOut(targetLi,viewURL,'list',listType);
            			});
					}
					else if((listType == 'Registry')||(listType == 'GT'))
					{
						var externalId = $(_thisActionClick).attr('externalId');
						
						var addUrl = 'AddToGiftRegistry?frompage=prodPage&storeId='+storeId+'&catalogId='+catalogId+'&externalId='+externalId+catEntryIds;
						$.getJSON(addUrl, function(data){
						
							if(listType == 'Registry')
							{
								var RegistryType ='registry';
								var isGT = '';
								var logonUrl = "GiftRegistrySignOnView?langId=-1&storeId="+storeId+"&catalogId="+catalogId+"&fromCreate=ProductPage";
								var addToWishlistUrl = "GiftRegistryItemView?storeId="+storeId+"&catalogId="+catalogId+"&sortByItem=category&fileflag=false&externalId="+externalId+"&grUserType=REGISTRANT&fwdURL=GiftRegistryItemUpdateView";
								if(document.getElementById("remembered")!=null){
           							var remem = document.getElementById("remembered").value;
           							if(remem=="yes")
           								var viewURL	 = "javascript:fnShowLoginModal('WLAddItem','"+logonUrl+"',"+"'"+addToWishlistUrl+"');";
               						else
               							var viewURL = "GiftRegistryItemView?storeId="+storeId+"&catalogId="+catalogId+"&sortByItem=category&fileflag=false&externalId="+externalId+"&grUserType=REGISTRANT&fwdURL=GiftRegistryItemUpdateView";
        						}
        						else
        						{
        							if(userType == 'G')
        							{
        								var viewURL	 = "javascript:fnShowLoginModal('WLAddItem','"+logonUrl+"',"+"'"+addToWishlistUrl+"');";
        							}
        							else
        							{
        								var viewURL = "GiftRegistryItemView?storeId="+storeId+"&catalogId="+catalogId+"&sortByItem=category&fileflag=false&externalId="+externalId+"&grUserType=REGISTRANT&fwdURL=GiftRegistryItemUpdateView";
        							}
        						}
							}
							else
							{
								var RegistryType ='gt';
								var isGT = 'gt';
								var logonUrl = "GiftRegistrySignOnView?langId=-1&storeId="+storeId+"&catalogId="+catalogId+"&fromCreate=ProductPage";
								var addToWishlistUrl = "GiveTogether?giftRegistryId="+giftRegistryId+"&nextView=GTManageEventView&storeId="+storeId+"&catalogId="+catalogId+"&sortByItem=category&externalId="+externalId+"&grUserType=REGISTRANT";
								var giftRegistryId = $(_thisActionClick).attr('giftRegistryId');
								if(document.getElementById("remembered")!=null){
           							var remem = document.getElementById("remembered").value;
           							if(remem=="yes")
               							var viewURL	 = "javascript:fnShowLoginModal('WLAddItem','"+logonUrl+"',"+"'"+addToWishlistUrl+"');";
               						else
               							var viewURL = "GiveTogether?giftRegistryId="+giftRegistryId+"&nextView=GTManageEventView&storeId="+storeId+"&catalogId='+catalogId+'&sortByItem=category&externalId="+externalId+"&grUserType=REGISTRANT";
        						}
        						else
        						{
        							if(userType == 'G')
        							{
        								var viewURL	 = "javascript:fnShowLoginModal('WLAddItem','"+logonUrl+"',"+"'"+addToWishlistUrl+"');";
        							}
        							else
        							{
        								var viewURL = "GiveTogether?giftRegistryId="+giftRegistryId+"&nextView=GTManageEventView&storeId="+storeId+"&catalogId="+catalogId+"&sortByItem=category&externalId="+externalId+"&grUserType=REGISTRANT";
        							}
        						}
							}
							
							
							var targetLi = $(_thisActionClick);
							fadeInOut(targetLi,viewURL,data,listType);
						});
						
					}
            		else
            		{
					var logonUrl = "GiftRegistrySignOnView?langId=-1&storeId="+storeId+"&catalogId="+catalogId+"&fromCreate=ProductPage";
            			var addToWishlistUrl = 'InterestItemDisplayCmd?storeId='+storeId+'&catalogId='+catalogId+'&listName='+clickedlistName;

            			var addUrl = '/shc/s/UniversalListsAddItemView?listName='+clickedlistName+'&storeId='+storeId+'&fwdURL=AddToWishListStatusView&from=prodPage&priority=1&itemType=SHC&listType='+listType+'&catalogId='+catalogId+'&userType='+myUser+catEntryIds+'&GUIDValue='+cvalue;
            			$.getJSON(addUrl, function(data){
            				
            				var targetLi = $(_thisActionClick);
            				if(document.getElementById("remembered")!=null){
           						var remem = document.getElementById("remembered").value;
           						if(remem=="yes")
               						var viewURL	 = "javascript:fnShowLoginModal('WLAddItem','"+logonUrl+"',"+"'"+addToWishlistUrl+"');";
               					else
               						var viewURL = 'InterestItemDisplayCmd?storeId='+storeId+'&catalogId='+catalogId+'&listname='+clickedlistName;
        					}
        					else
        					{
        						if(userType == 'G')
        							var viewURL	 = "javascript:fnShowLoginModal('WLAddItem','"+logonUrl+"',"+"'"+addToWishlistUrl+"');";
        						else
        							var viewURL = 'InterestItemDisplayCmd?storeId='+storeId+'&catalogId='+catalogId+'&listname='+clickedlistName;
        					}
            				fadeInOut(targetLi,viewURL,'list',listType);
            			});
            			
            		}
            		
		    	});
            	
			}
    
    	function addToList(action,createdListName)
        	{
			var logonUrl = "GiftRegistrySignOnView?langId=-1&storeId="+storeId+"&catalogId="+catalogId+"&fromCreate=ProductPage";
            	var addToWishlistUrl = 'InterestItemDisplayCmd?storeId='+storeId+'&catalogId='+catalogId+'&listName='+createdListName;
        		
        		$('#ULSaveToOpts').prepend(action);
        		if(document.getElementById("remembered")!=null){
           			var remem = document.getElementById("remembered").value;
           			if(remem=="yes")
               			var viewURL	 = "javascript:fnShowLoginModal('WLAddItem','"+logonUrl+"',"+"'"+addToWishlistUrl+"');";
               		else
               			var viewURL = 'InterestItemDisplayCmd?storeId='+storeId+'&catalogId='+catalogId+'&listname='+createdListName;
        		}
        		else
        		{
        				if(userType == 'G')
        				{
        					var viewURL	 = "javascript:fnShowLoginModal('WLAddItem','"+logonUrl+"',"+"'"+addToWishlistUrl+"');";
        				}
        				else
        				{
        					var viewURL = 'InterestItemDisplayCmd?storeId='+storeId+'&catalogId='+catalogId+'&listname='+createdListName;
        				}
        		}
            	fadeInOut($('#ULSaveToOpts li:first a'),viewURL,'list','QuickList');
        	}
        	
        function fadeInOut(trgLi,viewURL,isItemExceeded,listType){
            	
            	var linkClicked = trgLi.parent().attr("class");
            	var successDiv = $('div#successSpans .'+linkClicked).html();
            	trgLi.parent().append(successDiv);
            	if(listType == 'Registry')
            	{
            		if(isItemExceeded == 'ItemsExceeded')
            		{
            			trgLi.parent().find("span.success").html('<img src="' + imagePath + 'img/UniversalLists/lists_header/OM_check_img.gif" /> Item count exceeded<a style="display:inline; margin:2px;" href="javascript:;">View List</a>');
            		}
            		else
            		{
            			trgLi.parent().find("span.success").html('<img src="' + imagePath + 'img/UniversalLists/lists_header/OM_check_img.gif" /> Item added to Registry<a style="display:inline; margin:2px;" href="javascript:;">View List</a>');
            		}
            	}
            	else if(listType == 'GT')
            	{
            		if(isItemExceeded == 'ItemsExceeded')
            		{
            			trgLi.parent().find("span.success").html('<img src="' + imagePath + 'img/UniversalLists/lists_header/OM_check_img.gif" /> Item count exceeded<a style="display:inline; margin:2px;" href="javascript:;">View List</a>');
            		}
            		else
            		{
            			trgLi.parent().find("span.success").html('<img src="' + imagePath + 'img/UniversalLists/lists_header/OM_check_img.gif" /> Item added to Give Together<a style="display:inline; margin:2px;" href="javascript:;">View List</a>');
            		}
            	}
            	trgLi.parent().find("span.success a").attr("href",viewURL);
            	$('#ULSaveToOpts, #ULSaveToOpts a, #ULSaveToOpts button').unbind();
            	trgLi.parent().find("span.success").fadeTo(3000,1);
            	setTimeout( function() {
                	$("span.success").fadeOut(2000);
                	code.fadeOut(3000,function(){
                    	$(this).remove();
                    	_thissave.removeClass('active');
                	});
            	},1000);
        	}     
    
   
    
    	
    
    	window._saveToLinkClickClass = function(){
    
    if(saveListCount == 0) {	

    
    	
		_thissave = $(this);
		catEntryIds = '';
		divObject = this; 
		if(document.cookie.indexOf("s_r") != -1){
			var cookievalue=$.cookie("s_r");
			cookievalue=unescape(cookievalue);
			if(cookievalue != null && cookievalue.indexOf("_Y") != -1){
				//s_r cookie has value with '_Y'. User is logged In
				userType ='R';
			}
			else
				userType = 'G';
	
		}
		else
		{
			userType = 'G';
		}

		domainURL = $(this).attr('domainURL');
		mktInd =$(this).attr('mktInd');
        	var cattId = $(this).attr('cattId');
		if(typeof cattId != 'undefined' && cattId!='')
		{
		 	catEntryIds =  '&catEntryId_1='+ cattId +'&quantity_1=1';
		 	
		}
		
			
		        var variantOptionsFlag = checkVarient();
		        
				if (variantOptionsFlag == false){		
						return;
			}
		$.getJSON("http://"+domainURL+"/shc/UniversalListcookieServlet?storeId="+storeId+"&catalogId="+catalogId+"&from=prodPage&callback=?",function(data){
		
		if(data != null)
	    {	    	
	    	cname = data.myobject.name;
			cvalue = data.myobject.value;
			
		}
		if(userType == 'R')
		{
			userId = getCookie('wcid_'+storeId);
		}
	    
		retrieveUrl ='/shc/s/UniversalListCenterView?storeId='+storeId+'&catalogId='+catalogId+'&fwdURL=AddToWishListStatusView&GUIDValue='+cvalue;

		showSaveToList();
		saveListCount = 1;
		
		});
	
		} else {
		         
		      $('#ULSaveToOpts').remove();    
		      saveListCount = 0;
		        
    }
	
 //   });
    
 };
      
    
    
    
    
        
    function showSaveToList(){ 
    
    	var STLCoords = _thissave.offset();
		 var userlist = "";
		 var registryList = "";
		 var gtList = "";
		 var flag = false;
		       
       if(catEntryIds == ''|| typeof catEntryIds == 'undefined'){     
         	 
		  
		    	  catEntryIds = getCatEntryIds();  
	}
		 
		  
		 $.getJSON(retrieveUrl, function(data){
		 	var ulListCenterFlag = data.listCenterFlag;
		 	if(data.list.SHCItems != ""){
            $.each(data.list.SHCItems.SHCList, function(i,list){
     			
     			var nameSpace = list.namespace;
     			var myUser = nameSpace.split('.')[1].split('.')[0]; 
     			if(list.type == "SaveforLaterList")
     			{
     				
     				userlist = userlist+'<li class="user_list"><a id='+list.name+' href="javascript:;" myUser='+myUser+' listType="SaveforLaterList">'+list.name+'</a></li>\n'
     				flag = true;
     			}
     			else if(list.type != "721OFFRCNTRTYPE721")
     			{
     				userlist = userlist+'<li class="user_list"><a id='+list.name+' href="javascript:;" myUser='+myUser+' listType="QuickList">'+list.name+'</a></li>\n'
     			}
     				
			});
			}
			
			if(document.getElementById("remembered")!=null)
           		var remembq = document.getElementById("remembered").value;
           	else
           		var remembq = "";
           	
			if(flag == false)
			{
				if(ulListCenterFlag != 'undefined' && ulListCenterFlag == "ON"){
				userlist = userlist + '	<li class="user_list"><a href="javascript:;" id="Save for Later" myUser='+userType+' flag="false" listType="SaveforLaterList">Save for Later</a></li>\n'
			}
			}
     			
			if(data.registry.myObjectList.entries != ""){
			            $.each(data.registry.myObjectList.entries.myobject, function(i,list){
			                    registryList = registryList+'<li class="user_list"><a id='+list.name+' href="javascript:;" externalId='+list.value+' listType=Registry>'+list.name+'</a></li>\n'
			              });
			              }
			else
			{
				if(ulListCenterFlag != 'undefined' && ulListCenterFlag == "OFF"){
					 registryList += '<li><a href="'+'/shc/s/WeddingRegistryCreateView?storeId='+storeId+'&catalogId='+catalogId+'">Create GiftRegistry</a></li>';
				}
			}              
			              if(data.giveTogether.myObjectList.entries != ""){
			            $.each(data.giveTogether.myObjectList.entries.myobject, function(i,list){
			              var extId = list.value.split('\"')[1].split('.')[0];
			              var giftId = list.value.split('.')[1].split('\"')[0];
			                    gtList = gtList+'<li class="user_list"><a id='+list.name+' href="javascript:;" giftRegistryId='+giftId+' externalId='+extId+' listType=GT>'+list.name+'</a></li>\n'
			              });
			              }

			
			code = '\n'
        	+ '<ul id="ULSaveToOpts" style="display:none; width:250px;">\n'
            + userlist
            + registryList
           	+ gtList;
	    	if(ulListCenterFlag != 'undefined' && ulListCenterFlag == "ON"){
	          code += '<li><a id="addNew" href="javascript:;">Add to New List</a></li>\n';
	    	}
	               
            code += '<li id="addNewOpts" class="new_list">\n'
            + '             <label>Name</label><br />\n'
            + '             <input class="new_list_name" type="text" /><br />\n'
            + '             <label>New list privacy</label><br />\n'
        	+ '             <input name="list_privacy" id="public" type="radio" />\n'
        	+ '             <label>Public</label><br />\n'
        	+ '             <input name="list_privacy" id="private" type="radio" checked="true" />'
        	+ '             <label>Private</label><br />\n'
        	+ '             <button>Add</button>\n'
        	+ '      </li> \n'
        	+ '	<li>'
        	+ '         <div id="successSpans">'
        	+ '             <div class="user_list"><br clear="all" /><span style="display:inline;" class="success"><img src="' + imagePath + 'img/UniversalLists/lists_header/OM_check_img.gif" /> Item added to list<a style="display:inline; margin:2px;" href="javascript:;">View List</a></span></div>'
       		+ '             <div class="new_list"><br clear="all" /><span style="display:inline" class="success"><img src="' + imagePath + 'img/UniversalLists/lists_header/OM_check_img.gif" /> Item added to new list<a style="display:inline; margin-left:2px;" href="javascript:;">View List</a></span></div>'
        	+ '         </div>'
        	+ '     </li>\n'
                + '</ul> \n';
        	code = $(code).appendTo('body').fadeIn(500).css({top:STLCoords.top + _thissave.height() + 12, left:STLCoords.left});
         	
        
     		var inCheck = false;         
        	var actions = code.find('li.user_list a');      
         	codeHoverBind();
    		actionBind(actions);
    		addNewBind();
		});
	
	
	}
	
	
   
   } 
   
   
   function checkVarient(){
      
       	if(typeof variant != 'undefined' && variant == '1'){
            // qty = getQty();
            var qty = rObj('quant').value;
             
                if (qty==null || qty== "" || qty==''|| !FED.Util.isNumeric(qty) ||qty <= 0 ){
           		
           	 object = document.getElementById("saveToList"); 
            	 var mesg = 'Quantity must be a positive number.  Please enter the quantity again.';
                showErrorMsgPopUpBox(object,mesg,'List Center');
                return false;
                
   			 }else{
   			 
   				  catEntryIds = getCatEntId();
   				  object = document.getElementById("saveToList"); 
   				  if(catEntryIds == '' || catEntryIds == 'undefined' || catEntryIds == 0){
   						var strURL = document.location.search;
   		
   						if (strURL.search("catEntryIdScim") != -1){
   					
   							  var temp=new Array();
   							  temp=strURL.split("&");
   							for(var i=0;i<temp.length;i++){
   								  if(temp[i].search("catEntryIdScim") != -1){
   									 catEntryIds=temp[i].substring(temp[i].indexOf("=")+1,temp[i].length);
   									}
   							}			
   						}
   					}else{
   					
   						catEntryIds =  '&catEntryId_1='+ document.addToCart.catEntryId_1.value +'&quantity_1='+qty;
   					}
   				  
   				  if(catEntryIds == '' || catEntryIds == "undefined" || catEntryIds == 0){
   				  
   					var mesg = 'Please make a selection before adding to List';
   					showErrorMsgPopUpBox(object,mesg,'List Center');
   					return false;
   				  }
   				  
   				  return true;
   			}
   		}
         
	}
 function getQty() {
 	
 	var qty = rObj('quant').value;
 		if(qty != '' && FED.Util.isNumeric(qty) && (qty > 0) ) {
 			 return qty;
 		 }
 		 else {
 			 return 0;
 		 }
 		 return 0;
}

function showErrorMsg(o,err,btn)
{
    if(!document.getElementById('errorBox'))
    {
       newDiv=document.createElement('div');
       newDiv.className='errorPop';
       newDiv.id='errorBox';
       newDiv.innerHTML=getPopUpMsg(err,btn);
       document.body.appendChild(newDiv);
       var errBox=document.getElementById('errorBox');
       var oy = findPosY(o);
       var ox = findPosX(o);
       if(isNaN(ox) && isNaN(oy)){
		oy = 0;
		ox= 0;
           }
       if($.browser.msie)
       {
           var docWidth=document.body.scrollWidth;
           var docHeight=(document.body.scrollHeight);
           var boxH=errBox.offsetHeight;
           var boxW=errBox.offsetWidth;
 if (ox == 0 && oy == 0){

		errBox.style.top = oy + 300 + "px";
		errBox.style.left = ox + 300 + "px";
    	    }else{
           if ((ox-100)<0)
           {    //alert("1");
                errBox.style.top=(oy-50)+"px";
                errBox.style.left=(ox-15)+"px";
            } 
            else if ((ox-100)>(docWidth-boxW))
            {   //alert("2");
                errBox.style.top=(oy-100)+"px";
                errBox.style.left=(docWidth-boxW-10)+"px";
            } 
            else 
            {   //alert("3");
                 errBox.style.top=(oy-100)+"px";
                 errBox.style.left=(ox-100)+"px";
             }
}
        } 
        else 
        {
            var docWidth=document.documentElement.clientWidth;
            var docHeight=document.documentElement.clientHeight;
            var boxH=errBox.offsetHeight;
            var boxW=errBox.offsetWidth;
            
           
            if (ox == 0 && oy == 0){
            	
		errBox.style.top = oy + 300 + "px";
		errBox.style.left = ox + 300 + "px";
    	    }else{
		    if ((ox-100)<0)
		    {       
			 errBox.style.top=(oy-100)+"px";
			 errBox.style.left=(ox)+"px";
		    } 
		    else if ((ox-100)>(docWidth-boxW))
		    {  
			 errBox.style.top=(oy-100)+"px";
			 errBox.style.left=(docWidth-boxW-10)+"px";
		    } 
		    else 
		    {    
			 errBox.style.top=(oy-100)+"px";
			 errBox.style.left=(ox-100)+"px";
		    }
           }
        }
        
    }
}




