var gResponsePlaceId = '';

function addItemToCategory(itemId, categoryId, responsePlaceId)
{        
        this.gResponsePlaceId = responsePlaceId;
        
        var Ajax = new AjaxRequest();         
        
        if( Ajax.mRequest )
        {            
            Ajax.addEventListener( REQ_COMPLETE, requestResponse );

            Ajax.mRequest.open( "POST", "/ajax/ajaxTools.php?toolName=addItemToCategory&itemId="+itemId+"&categoryId="+categoryId , true);
            
            Ajax.mRequest.send( '1' );                    
        }
    
}
    
function removeItemFromCategory(itemId, categoryId, responsePlaceId)
{		
		this.gResponsePlaceId = responsePlaceId;
		
		var Ajax = new AjaxRequest(); 		
		
		if( Ajax.mRequest )
		{			
			Ajax.addEventListener( REQ_COMPLETE, requestResponse );

			Ajax.mRequest.open( "POST", "/ajax/removeItemFromCategory.php?itemId="+itemId+"&categoryId="+categoryId , true);
			
			Ajax.mRequest.send( '1' );					
		}
	
}

function changeItemStatus(itemId, statusCode, responsePlaceId)
{		
		this.gResponsePlaceId = responsePlaceId;
		
		var Ajax = new AjaxRequest(); 		
		
		if( Ajax.mRequest )
		{			
			Ajax.addEventListener( REQ_COMPLETE, requestResponse );

			Ajax.mRequest.open( "POST", "/ajax/changeItemStatus.php?itemId="+itemId+"&statusCode="+statusCode , true);
			
			Ajax.mRequest.send( '1' );					
		}
	
}

function createSeoName(name, responsePlaceId)
{		
		this.gResponsePlaceId = responsePlaceId;
		
		var Ajax = new AjaxRequest(); 		
		
		if( Ajax.mRequest )
		{			
			Ajax.addEventListener( REQ_COMPLETE, requestResponse );

			Ajax.mRequest.open( "POST", "/ajax/createSeoName.php?name="+name , true);
			
			Ajax.mRequest.send( '1' );					
		}
	
}

function getConditionValues(conditionType, responsePlaceId)
{
		this.gResponsePlaceId = responsePlaceId;
		
		var Ajax = new AjaxRequest(); 		
		
		if( Ajax.mRequest )
		{			
			Ajax.addEventListener( REQ_COMPLETE, requestResponse );

			Ajax.mRequest.open( "POST", "/ajax/getProductsDisplayFilterValue.php?conditionType="+conditionType+"&responseType="+responsePlaceId , true);
			
			Ajax.mRequest.send( '1' );					
		}


}

function getCategoryItems(categoryId, responseTypeWanted)
{
		var Ajax = new AjaxRequest(); 		
		
		if( Ajax.mRequest )
		{			
			Ajax.addEventListener( REQ_COMPLETE, requestedCategoryItems );

			Ajax.mRequest.open( "POST", "/ajax/getCategoryItems.php?categoryId="+categoryId+"&responseTypeWanted="+responseTypeWanted , true);
			
			Ajax.mRequest.send( '1' );					
		}
}


function flagAsDeteleCandidate(itemId)
{
		var Ajax = new AjaxRequest(); 		
		
		if( Ajax.mRequest )
		{			
			Ajax.addEventListener( REQ_COMPLETE, requestedCategoryItems );

			Ajax.mRequest.open( "POST", "/ajax/flagItem.php?flagName=deleteCandidate&itemId="+itemId , false);
			
			Ajax.mRequest.send( '1' );					
		}
}

function getDepartmentCategories(departmentId, itemId, responsePlaceId)
{
		this.gResponsePlaceId = responsePlaceId;
		
		var Ajax = new AjaxRequest(); 		
		
		if( Ajax.mRequest )
		{			
			Ajax.addEventListener( REQ_COMPLETE, requestResponse );

			Ajax.mRequest.open( "POST", "/ajax/getDepartmentCategories.php?departmentId="+departmentId+"&itemId="+itemId+"&responseType="+responsePlaceId , true);
			
			Ajax.mRequest.send( '1' );					
		}
}


function requestedCategoryItems(pAjax) 
{	
		if( pAjax.mRequest.status == 200 )
		{
			var message = pAjax.mRequest.responseText;

			document.getElementById( 'categoryItems' ).innerHTML = message;	
		} 	
		else
		{
			document.getElementById( 'categoryItems' ).innerHTML = 'Odpoved na poziadavku zlyhala!';
		}
}     

function sativaStockUpdate(cronName, csvFile, report, dbUpdate, responsePlaceId)
{		
		this.gResponsePlaceId = responsePlaceId;
		
		var Ajax = new AjaxRequest(); 		
		
		if( Ajax.mRequest )
		{			
			Ajax.addEventListener( REQ_COMPLETE, requestResponse );

			Ajax.mRequest.open( "POST", "/ajax/triggerCron.php?cronName="+cronName+"&csvFile="+csvFile+"&report="+report+"&dbUpdate="+dbUpdate , true);
			
			Ajax.mRequest.send( '1' );					
		}
	
}

function checkItemImages(cronName, responsePlaceId)
{        
        this.gResponsePlaceId = responsePlaceId;
        
        var Ajax = new AjaxRequest();         
        
        if( Ajax.mRequest )
        {            
            Ajax.addEventListener( REQ_COMPLETE, requestResponse );

            Ajax.mRequest.open( "POST", "/ajax/triggerCron.php?cronName="+cronName , true);
            
            Ajax.mRequest.send( '1' );                    
        }
    
}

function braintreeStockUpdate(cronName, who, report, dbUpdate, responsePlaceId)
{		
		this.gResponsePlaceId = responsePlaceId;
		
		var Ajax = new AjaxRequest(); 		
		
		if( Ajax.mRequest )
		{			
			Ajax.addEventListener( REQ_COMPLETE, requestResponse );

			Ajax.mRequest.open( "POST", "/ajax/triggerCron.php?cronName="+cronName+"&who="+who+"&report="+report+"&dbUpdate="+dbUpdate , true);
			
			Ajax.mRequest.send( '1' );					
		}
	
}

function getSizesForm(itemId, responsePlaceId)
{
		this.gResponsePlaceId = responsePlaceId;
		
		var Ajax = new AjaxRequest(); 		
		
		if( Ajax.mRequest )
		{			
			Ajax.addEventListener( REQ_COMPLETE, requestResponse );

			Ajax.mRequest.open( "POST", "/ajax/updateItemSizes.php?itemId="+itemId+"&responsePlaceId="+responsePlaceId , true);
			
			Ajax.mRequest.send( '1' );					
		}


}

function valueCheck(value, valueName, responsePlaceId)
{		
		this.gResponsePlaceId = responsePlaceId;
		
		var Ajax = new AjaxRequest(); 		
		
		if( Ajax.mRequest )
		{			
			Ajax.addEventListener( REQ_COMPLETE, requestResponse );

			Ajax.mRequest.open( "POST", "/ajax/valueCheck.php?value="+value+"&valueName="+valueName , true);
			
			Ajax.mRequest.send( '1' );					
		}
	
}

function requestResponse(pAjax) 
{	
		
		if( pAjax.mRequest.status == 200 )
		{
			var message = pAjax.mRequest.responseText;

			document.getElementById( gResponsePlaceId ).innerHTML = message;	
		} 	
		else
		{
			document.getElementById( gResponsePlaceId ).innerHTML = 'Odpoved na poziadavku zlyhala!';
		}
}     
