var Culture 
function EstateWeb_Objects_PropertyCartManager(){
	this.MessageBox = __EstateWeb_Objects_PropertyCartManager_MessageBox; //method that opens the message box
	this.Save = __EstateWeb_Objects_PropertyCartManager_Save; //method to save property
	this.SaveMultiple = __EstateWeb_Objects_PropertyCartManager_SaveMultiple; //method to save many properties at onces
	this.Delete = __EstateWeb_Objects_PropertyCartManager_Delete; //method to remove from saved properties
	this.DeleteAll = __EstateWeb_Objects_PropertyCartManager_DeleteAll; //method to remove all saved properties
	this.OutputContainer; //container used to output the messagebox in (default is body)
	this.EmailProperties = __EstateWeb_Objects_PropertyCartmanager_EmailProperties;
	this.RefreshInlineView = __EstateWeb_Objects_PropertyCartManager_RefreshInlineView;
	this.PropertyType = 0;
	
	Culture = PropertyCartManager.GetCultureSettings()
}

function __EstateWeb_Objects_PropertyCartManager_MessageBox(title,message,returnFunction){
	
	var oMessageManager = new EstateWeb_Objects_MessageManager();
	oMessageManager.OutputContainer = this.OutputContainer;
	oMessageManager.Show(title,message);

	setTimeout(function() { oMessageManager.Hide(); if ( returnFunction ) { eval(returnFunction+"()")}  }, 2500);
}

function __EstateWeb_Objects_PropertyCartManager_Save(ID,returnFunction,type){
	if ( isNaN(type)){
		alert("No Property Type specified");
	}
	var response = PropertyCartManager.Save(ID, ( type ? type : this.PropertyType ));
	var message;
	var title = (Culture.value == 1) ? "Imoveis Selecionados" : "Properties Saved";
	switch ( response.value ){
		case 0:
			message = (Culture.value == 1) ? "Propriedade Salva" : "Properties Saved";
		break;
		case 2:
			message = (Culture.value == 1) ? "Esta propriedade ja foi selecionada." : "This property is already saved!";

		break;
		default:
			message = "An Unknown error occured";
		break;
	}
	this.MessageBox(title, message, returnFunction);
}

function __EstateWeb_Objects_PropertyCartManager_SaveMultiple(IDs,returnFunction,type){
	var response = PropertyCartManager.SaveMultiple(IDs, ( type ? type : this.PropertyType ));
	var message;
	var title = (Culture.value == 1) ? "Imoveis Selecionados" : "Properties Saved";
	switch ( response.value ){
		case 0:
			message = (Culture.value == 1) ? "Propriedade Salva" : "Properties Saved";
			break;
		default:
			message = "An Unknown error occured";
			break;
	}
	this.MessageBox(title, message, returnFunction);
}

function __EstateWeb_Objects_PropertyCartManager_Delete(ID,returnFunction,type){
	var response = PropertyCartManager.Delete(ID, ( type ? type : this.PropertyType) );
	var message;
	var title = (Culture.value == 1) ? "Imoveis Selecionados" : "Properties Saved";
	switch ( response.value ){
		case 0:
			message = "Property Deleted";
		break;
		default:
			message = "An Unknown Error Occured";
		break;
	}
	if ( returnFunction ) { eval(returnFunction+"('"+response.value.toString()+"')"); } else { this.MessageBox(title, message); }
}

function __EstateWeb_Objects_PropertyCartManager_DeleteAll(returnFunction,type){
	var response = PropertyCartManager.DeleteAll(( type? type : this.PropertyType ));
	if ( returnFunction ){ eval(returnFunction+"()") }
}

function __EstateWeb_Objects_PropertyCartManager_RefreshInlineView(){
	if ( HttpManager.Document.GetObject("frmPropertyCartInline") ){
		HttpManager.Document.GetObject("frmPropertyCartInline").location.reload();
	}
}

function __EstateWeb_Objects_PropertyCartmanager_EmailProperties(senderName,receipientEmail,returnFunction,type, subject){
	var response = PropertyCartManager.EmailProperties(senderName,receipientEmail, ( type ? type : this.PropertyType ), subject);
	var message;
	var title = (Culture.value == 1) ? "Imoveis Selecionados" : "Properties Saved";
	
	switch ( response.value ){
		case 0:
			message = "There was an error attempting to send to "+receipientEmail;
		break;
		default:
			message = (Culture.value == 1) ? "As propriedades selecionadas foram enviadas com sucesso para o (" + receipientEmail + ")" : "Your properties were successfully sent to ("+receipientEmail +")";
		break;
	}
	if ( returnFunction ) { eval(returnFunction+"('"+response.value.toString()+"')"); } else { this.MessageBox(title, message); }
}