
function getErrorStatus(err,isGT)
    {
    
    var extIdd = 0;
	var giftRegistryId= "0";
    if (err.substring(0,6) == 'error7'){
        extIdd = err.substring(6,err.length);
        var err = 'error7';
        if (isGT =="gt") {
               err = 'error7_GT';
              var x = extIdd;
				var i = -1;
				i = x.indexOf('9');
				x = x.substring(i+1);				
				while(x.indexOf('0') == 0) {
					x = x.substring(i+1);
				}
               giftRegistryId = x;
               giftRegistryId = giftRegistryId.substring(0,giftRegistryId.length-6);        
    }
    }
	if (err.substring(0,6) == 'error9'){
        extIdd = err.substring(6,err.length);
        var err = 'error9';
    }
    if (err.substring(0,7) == 'error11'){
        extIdd = err.substring(7,err.length);
        var err = 'error11';
    }
    
    if (err.substring(0,7) == 'error12'){
        extIdd = err.substring(7,err.length);
        var err = 'error12';
    }    
    switch(err)
        {
        case 'error1':
            return "<h3>Add to Cart</h3>\n"+
                    "<h1>Unable to add to cart</h1>\n"+
                    "<p>You will be able to add this item to your cart after you enter a ZIP code and select a store for pickup.</p>\n"+
                    "<input type='submit' name='ok' value='OK' onclick='remove(this.parentNode);'>\n";
            break;
        case 'error2':
            var zip4=document.getElementById('zip4');
            return "<h3>Change ZIP</h3>\n"+
                    "<h1>Currently not available</h1>\n"+
                    "<p>This item is <b>currently not available</b> for delivery in your area "+zip4.value+".</p>\n"+
                    "<p><a href=''>Contact Us</a> if you need assistance</p>\n"+
                    "<input type='submit' name='ok' value='OK' onclick='remove(this.parentNode);'>\n";
            break;
        case 'error3':
            return "<h3>Add to Cart</h3>\n"+
                    "<h1>Unable to add to cart</h1>\n"+
                    "<p>Please <b></b> to check delivery availability for your area. You will be able to add this item to your cart after we check local availability.</p>\n"+
                    "<input type='submit' name='ok' value='OK' onclick='remove(this.parentNode);'>\n";
            break;
        case 'error4':
            return "<h3>Add to Cart</h3>\n"+
                    "<h1>Unable to add to cart</h1>\n"+
                    "<p>You will be able to add items of this collection to the cart after you select them using the \"Get this item\" button.</p>\n"+
                    "<input type='submit' name='ok' value='OK' onclick='remove(this.parentNode);'>\n";
            break;
        case 'error5':
            return "<h3>Get This Item</h3>\n"+
                    "<h1>Unable to get this item</h1>\n"+
                    "<p>You will be able to get this item after you chose a desired: Fit, Color, Size.</p>\n"+
                    "<input type='submit' name='ok' value='OK' onclick='remove(this.parentNode);'>\n";
            break;
        case 'error6':
	              var url2 = "InterestItemDisplayCmd?langId="+langId+"&cmdStoreId="+cmdStoreId+"&storeId="+storeId+"&catalogId="+catalogId+"&listId=.";     
	            return "<h3>Save For Later</h3>\n"+
	                    "<h1>Your item has been successfully saved for later.</h1>\n"+
	                    "<p>You can manage this item and others on your Save for Later in the My Profile page.</p>\n"+
	                    "<p><a href=\""+url2+"\">View My Save for Later list</a></p>\n"+
	                    "<input type='submit' name='ok' value='OK' onclick='remove(this.parentNode);'>\n";
            break;
            
        case 'error7_GT':
            //url = "GiftRegistryItemUpdateView?langId="+langId+"&storeId="+storeId+"&catalogId="+catalogId+"&externalId="+externalId;
            url = "GiveTogether?giftRegistryId="+giftRegistryId+"&nextView=GTManageEventView&storeId="+storeId+"&catalogId="+catalogId+"&sortByItem=category&externalId="+extIdd+"&grUserType=REGISTRANT&langId="+langId;
            return "<h3>Add to Give Together List</h3>\n"+
                    "<h1>This item has been added to your Give Together event</h1>\n"+
                    "<p><a class='btn manageMyEvent_btn' alt='Manage My Event' title='Manage My Event' href="+url+"></a></p>\n"+
                    "<a class='btn continueShop_btn' alt='Continue Shop' title='Continue Shop' onclick='javascript:$(\"div#errorBox1\").remove();'></a>\n";
                    
            break;
            
        case 'error7':
        	//url = "GiftRegistryItemUpdateView?langId="+langId+"&storeId="+storeId+"&catalogId="+catalogId+"&externalId="+externalId;
        	
        	url = "GiftRegistryItemView?storeId="+storeId+"&catalogId="+catalogId+"&sortByItem=category&fileflag=false&externalId="+extIdd+"&grUserType=REGISTRANT&fwdURL=GiftRegistryItemUpdateView&langId="+langId;
        	return "<h3>Add to Gift Registry</h3>\n"+
                    "<h1>This item has been added to your gift registry.</h1>\n"+
                    "<p><a href=\""+url+"\">View My Registry</a></p>\n"+
                    "<input type='submit' name='ok' value='OK' onclick='remove(this.parentNode);'>\n";
                    
            break;
		case 'error9':
        	//url = "GiftRegistryItemUpdateView?langId="+langId+"&storeId="+storeId+"&catalogId="+catalogId+"&externalId="+externalId;
        	     	
        	
        	//url = "SHCGiftRegistrySortCmd?storeId="+storeId+"&catalogId="+grcatalogId+"&sortByItem=category&fileflag=false&storeCatalogId="+storeCatalogId+"&externalId="+extIdd+"&grUserType=REGISTRANT";
            url = "GiftRegistryPublicWishlistView?storeId="+storeId+"&catalogId="+catalogId+"&sortByItem=category&fileflag=false&externalId="+extIdd+"&grUserType=REGISTRANT&fwdURL=GRWishListItemUpdateView&langId="+langId;
        	return "<h3>Add to WishList</h3>\n"+
                    "<h1>This item has been added to your Wishlist.</h1>\n"+
                    "<p><a href=\""+url+"\">View My WishList</a></p>\n"+
                    "<input type='submit' name='ok' value='OK' onclick='remove(this.parentNode);'>\n";
                    
            break;
       case 'error11':        	
        	url = "LogonForm?storeId="+storeId+"&catalogId="+catalogId+"&langId="+langId+"&URL=GiftRegistryItemView&cmdStoreId="+cmdStoreId+"&sortByItem=category&fileflag=false&externalId="+extIdd+"&grUserType=REGISTRANT&fwdURL=GiftRegistryItemUpdateView&langId="+langId;
        	return "<h3>Add to Gift Registry</h3>\n"+
                    "<h1>This item has been added to your gift registry.</h1>\n"+
                    "<p><a href=\""+url+"\">View My Registry</a></p>\n"+
                    "<input type='submit' name='ok' value='OK' onclick='remove(this.parentNode);'>\n";

        case 'error12':        	
            url = "LogonForm?storeId="+storeId+"&catalogId="+catalogId+"&langId="+langId+"&URL=GiftRegistryPublicWishlistView&cmdStoreId="+cmdStoreId+"&sortByItem=category&fileflag=false&externalId="+extIdd+"&grUserType=REGISTRANT&fwdURL=GRWishListItemUpdateView&langId="+langId;
        	return "<h3>Add to Gift Registry</h3>\n"+
                    "<h1>This item has been added to your Wishlist.</h1>\n"+
                    "<p><a href=\""+url+"\">View My WishList</a></p>\n"+
                    "<input type='submit' name='ok' value='OK' onclick='remove(this.parentNode);'>\n";
		
		case 'ItemsExceeded':  
		 return "<h3>Error Message</h3>"+
				"<h2>Maximum number of the same item added to a registry or wishlist cannot exceed 99</h2>"+
		        	"\n\n<input type='submit' name='ok' value='OK' onclick='remove(this.parentNode);'>\n";
        			break
        default: 
        	if(wishlistExceptionMessage != '')
			return "<h3>Error Occurred</h3>"+
				"<h2>"+wishlistExceptionMessage+"</h2>"+
				"\n\n<input type='submit' name='ok' value='OK' onclick='remove(this.parentNode);'>\n";
            else if(cartExceptionMessage != '') {
                if (errorMessageKey == '_ERR_FORMATCONFLICT_SAC' || errorMessageKey == '_ERR_FORMATCONFLICT_NSAC') {
                    return "";
                } else {
                	if(gup('xCheckOut') == "true"){
                    return   "<h3>EXPRESS CHECKOUT</h3>\n"+
                     "<h2>"+cartExceptionMessage+"</h2>"+
                     "\n\n<input type='submit' name='ok' value='OK' onclick='remove(this.parentNode);'>\n";
                     }else{
        		return	 "<h3>Add to Cart</h3>\n"+
			         "<h2>"+cartExceptionMessage+"</h2>"+
				 "\n\n<input type='submit' name='ok' value='OK' onclick='remove(this.parentNode);'>\n";
                     }
                }
            }
        	else
		         return "<h3>Error</h3>"+
				"<h2>Error Occurred</h2>"+
		        	"\n\n<input type='submit' name='ok' value='OK' onclick='remove(this.parentNode);'>\n";
        }
    }

function showErrorPopUp(o,err)
    {
    
    if(!document.getElementById('errorBox'))
        {
        newDiv=document.createElement('div');
        newDiv.className='errorPop';
        newDiv.id='errorBox';
        newDiv.innerHTML=getErrorStatus(err);
        document.body.appendChild(newDiv);
        var errBox=document.getElementById('errorBox');
        var oy = findPosY(o);
        var ox = findPosX(o);
		if(browser=="Internet Explorer"){
	        var docWidth=document.body.scrollWidth;
	        var docHeight=(document.body.scrollHeight);
	        var boxH=errBox.offsetHeight;
	        var boxW=errBox.offsetWidth;
			if ((ox-100)<0)
				{
				errBox.style.top=(oy-350)+"px";
				errBox.style.left=(ox-40)+"px";
				} 
			else if ((ox-100)>(docWidth-boxW))
				{
				errBox.style.top=(oy-400)+"px";
				errBox.style.left=(docWidth-boxW-10)+"px";
				} 
			else 
				{
		        errBox.style.top=(oy-400)+"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-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";
				}
			}
		}
	}
	
/*Following Methods are moved to store specific global.js - JS code cleanup
function findPosX(obj)
function findPosY(obj)
*/

// New method to positiont the error popup box


function showErrorPopUpBox(o,err)
    {
    
    if(!document.getElementById('errorBox')){
       
        var topPosition=0;
        var leftPosition=0;
        newDiv=document.createElement('div');
        newDiv.className='errorPop';
        newDiv.id='errorBox';
        newDiv.innerHTML=getErrorStatus(err);
        document.body.appendChild(newDiv);
        var errBox=document.getElementById('errorBox');
        var oy = findPosY(o);
        var ox = findPosX(o);
         
       
		if(browser=="Internet Explorer"){
	        var docWidth=document.body.scrollWidth;
	        var docHeight=(document.body.scrollHeight);
   	        var boxH=errBox.offsetHeight;
	        var boxW=errBox.offsetWidth;
   	      
			if ((ox-100)<0)
			{
				errBox.style.top=(oy-350)+"px";
				errBox.style.left=(ox-40)+"px";
				topPosition=oy-350;
				leftPosition=ox-40;
			} 
			else if ((ox-100)>(docWidth-boxW))
			{
				errBox.style.top=(oy-400)+"px";
				errBox.style.left=(docWidth-boxW-10)+"px";
				topPosition=oy-400;
				leftPosition=docWidth-boxW-10;
			} 
			else 
			{	
		        errBox.style.top=(oy-100)+"px";
		        errBox.style.left=(ox-100)+"px";
		        topPosition= oy-100;
		 		leftPosition= ox-100;
			}
			
			if(topPosition <=0 || leftPosition<=0)
			{
				errBox.style.top=docWidth/7+"px";
				errBox.style.left=docHeight/1.1+"px";
			}
		} else {
				var topPosition=0;
	      		var leftPosition=0;
		        var docWidth=document.documentElement.clientWidth;
		        var docHeight=document.documentElement.clientHeight;
		        var boxH=errBox.offsetHeight;
		        var boxW=errBox.offsetWidth;
		       
				if ((ox-100)<0)
				{
					errBox.style.top=(oy-100)+"px";
					errBox.style.left=(ox)+"px";
					topPosition=oy-100;
					leftPosition=ox;
				} 
				else if ((ox-100)>(docWidth-boxW))
				{
					errBox.style.top=(oy-100)+"px";
					errBox.style.left=(docWidth-boxW-10)+"px";
					topPosition=oy-100;
					leftPosition=docWidth-boxW-10;
				} 
				else 
				{
				    errBox.style.top=(oy-100)+"px";
			        errBox.style.left=(ox-100)+"px";
			        topPosition=oy-100;
					leftPosition=ox-100;
				}
			
				if(topPosition <=0 || leftPosition<=0)
				{
					errBox.style.top=docWidth/7+"px";
					errBox.style.left=docHeight/1.1+"px";
				}	
		}
	}
}









// NEW CODE STARTS HERE


function getPopUpMsg(msg,btn){
	var headMsg = '';
	if(btn == 'Cart')
	{
		headMsg = 'Add to Cart';
	}
	else if(btn == 'Wishlist')
	{
		headMsg = 'Add to Wishlist';
	}
	else if(btn == 'save for later')
	{
		headMsg = 'Save for Later';
	}
	else if(btn == 'GiftRegistry')
	{
		headMsg = 'Add to Gift Registry';
	}
	else if(btn == 'ShipCal')
	{
		headMsg = 'Shipping Calculator';
	}
	else if(btn == 'ZipCodeEnter')
	{
		headMsg = 'Enter Zip Code';
	}
	else if(btn == 'preSellEmailMe')
	{
		headMsg = 'E-mail Me';
	}
	else if(btn == 'preOrderItem')
	{
		headMsg = 'Pre-Order Item';
	}
    else if(btn == 'XCheckout')					
    {
    	headMsg = 'Express Checkout';
    }
    else if(btn == 'AKHI')					
    {
    	headMsg = 'AK / HI pricing?';
    }
     else if(btn == 'LayawayCalculator')
    {
        headMsg = 'Layaway Calculator';
    }
	return	 "<h3>"+headMsg+"</h3>\n"+
				 "<h2>"+msg+"</h2>"+
				 "\n\n<input type='submit' name='ok' value='OK' onclick='remove(this.parentNode);'>\n";
}



//This is used for generating dynamic error message popups.Used for out of stock or incomplete selection popups in product pages

function showErrorMsgPopUpBox(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(browser=="Internet Explorer")
       {
	       var docWidth=document.body.scrollWidth;
           var docHeight=(document.body.scrollHeight);
           var boxH=errBox.offsetHeight;
           var boxW=errBox.offsetWidth;
           if ((ox-100)<0)
           {	//alert("1");
	            errBox.style.top=(oy-50)+"px";
                errBox.style.left=(ox-40)+"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-100)<0)
            { 		//alert("1");
	             errBox.style.top=(oy-100)+"px";
                 errBox.style.left=(ox)+"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";
             }
        }
	}
}
